Commit Graph

409 Commits

Author SHA1 Message Date
Sean Callanan 686b2319e5 I made the ClangASTImporter owned by the target
rather than individually on behalf of each
ASTContext.  This allows the ASTImporter to know
about all containers of types, which will let it
be smarter about forwarding information about
type origins.  That means that the following
sequence of steps will be possible (after a few
more changes):

- Import a type from a Module's ASTContext into
  an expression parser ASTContext, tracking its
  origin information -- this works now.

- Because the result of the expression uses that
  type, import it from the expression parser
  ASTContext into the Target's scratch AST
  context, forwarding the origin information --
  this needs to be added.

- For a later expression that uses the result,
  import the type from the Target's scratch AST
  context, still forwarding origin information
  -- this also needs to be added.

- Use the intact origin information to complete
  the type as needed -- this works now if the
  origin information is present.

To this end, I made the following changes:

- ASTImporter top-level copy functions now
  require both a source and a destination AST
  context parameter.

- The ASTImporter now knows how to purge
  records related to an ASTContext that is
  going away.

- The Target now owns and creates the ASTImporter
  whenever the main executable changes or (in the
  absence of a main executable) on demand.

llvm-svn: 144802
2011-11-16 18:20:47 +00:00
Sean Callanan ed8d58fcc1 Fixed a crash when we merrily went on to try to log
information about a nonexistent function declaration.

llvm-svn: 144744
2011-11-16 00:40:13 +00:00
Sean Callanan a6cbf06d0a Two fixes for Objetive-C methods that return struct
types.  First, I added handling for the memset intrinsic
in the IR, which is used to zero out the returned struct.
Second, I fixed the object-checking instrumentation
to objc_msgSend_stret, and generally tightened up how
the object-checking functions get inserted.

llvm-svn: 144741
2011-11-16 00:20:50 +00:00
Sean Callanan 100d74e267 Eliminated a compile warning by removing dyn_cast
where isa is good enough.

llvm-svn: 144704
2011-11-15 21:50:18 +00:00
Sean Callanan fe5d139b51 Fixed a bug where the variable-resolution code
would occasionally try to resolve the placeholder
variable used for static data allocation.

llvm-svn: 144677
2011-11-15 19:13:54 +00:00
Sean Callanan d5c17edb04 Pulled in a new version of LLVM/Clang to solve a variety
of problems with Objective-C object completion.  To go
along with the LLVM/Clang-side fixes, we have a variety
of Objective-C improvements.

Fixes include:

- It is now possible to run expressions when stopped in
  an Objective-C class method and have "self" act just
  like "self" would act in the class method itself (i.e.,
  [self classMethod] works without casting the return
  type if debug info is present).  To accomplish this,
  the expression masquerades as a class method added by
  a category.

- Objective-C objects can now provide methods and
  properties and methods to Clang on demand (i.e., the
  ASTImporter sets hasExternalVisibleDecls on Objective-C
  interface objects).

- Objective-C built-in types, which had long been a bone
  of contention (should we be using "id"?  "id*"?), are
  now fetched correctly using accessor functions on
  ClangASTContext.  We inhibit searches for them in the
  debug information.

There are also a variety of logging fixes, and I made two
changes to the test suite:

- Enabled a test case for Objective-C properties in the
  current translation unit.

- Added a test case for calling Objective-C class methods
  when stopped in a class method.

llvm-svn: 144607
2011-11-15 02:11:17 +00:00
Sean Callanan 4fb79b790f Fixed Objective-C method lookup for methods with
a single argument.  We assumed that the : was
omitted from the selector name, but actually Clang
adds the : in the one-argument case.

llvm-svn: 144544
2011-11-14 18:29:46 +00:00
Greg Clayton 2fc93eabf7 <rdar://problem/10338439>
This is the actual fix for the above radar where global variables that weren't
initialized were not being shown correctly when leaving the DWARF in the .o 
files. Global variables that aren't intialized have symbols in the .o files
that specify they are undefined and external to the .o file, yet document the
size of the variable. This allows the compiler to emit a single copy, but makes
it harder for our DWARF in .o files with the executable having a debug map
because the symbol for the global in the .o file doesn't exist in a section
that we can assign a fixed up linked address to, and also the DWARF contains
an invalid address in the "DW_OP_addr" location (always zero). This means that
the DWARF is incorrect and actually maps all such global varaibles to the
first file address in the .o file which is usually the first function. So we
can fix this in either of two ways: make a new fake section in the .o file
so that we have a file address in the .o file that we can relink, or fix the 
the variable as it is created in the .o file DWARF parser and actually give it
the file address from the executable. Each variable contains a 
SymbolContextScope, or a single pointer that helps us to recreate where the
variables came from (which module, file, function, etc). This context helps
us to resolve any file addresses that might be in the location description of
the variable by pointing us to which file the file address comes from, so we
can just replace the SymbolContextScope and also fix up the location, which we
would have had to do for the other case as well, and update the file address.
Now globals display correctly.

The above changes made it possible to determine if a variable is a global
or static variable when parsing DWARF. The DWARF emits a DW_TAG_variable tag
for each variable (local, global, or static), yet DWARF provides no way for
us to classify these variables into these categories. We can now detect when
a variable has a simple address expressions as its location and this will help
us classify these correctly.

While making the above changes I also noticed that we had two symbol types:
eSymbolTypeExtern and eSymbolTypeUndefined which mean essentially the same
thing: the symbol is not defined in the current object file. Symbol objects
also have a bit that specifies if a symbol is externally visible, so I got
rid of the eSymbolTypeExtern symbol type and moved all code locations that
used it to use the eSymbolTypeUndefined type.
 

llvm-svn: 144489
2011-11-13 04:15:56 +00:00
Sean Callanan 46198ff824 Updated LLVM/Clang to pull in a fix for Objective-C
interfaces.  This allows us to pull in Objective-C
method types on demand, which is also now implemented.

Also added a minor fix to prevent multiple-definition
errors for "Class" and "id".

llvm-svn: 144405
2011-11-11 20:37:26 +00:00
Sean Callanan 0730e9c992 Added a function to ClangASTSource to service
lookups for Objective-C methods by selector.
Right now all it does is print log information.

Also improved the logging for imported TagDecls
to indicate whether or not the definition for
the imported TagDecl is complete.

llvm-svn: 144203
2011-11-09 19:33:21 +00:00
Jim Ingham 0faa43f964 Do a better job of detecting when a breakpoint command has set the target running again (except you have to ignore
cases where the breakpoint runs expressions, those don't count as really "running again").

llvm-svn: 144064
2011-11-08 03:00:11 +00:00
Sean Callanan c7b650670e Added a language parameter to the expression parser,
which will in the future allow expressions to be
compiled as C, C++, and Objective-C instead of the
current default Objective-C++.  This feature requires
some additional support from Clang -- specifically, it
requires reference types in the parser regardless of
language -- so it is not yet exposed to the user.

llvm-svn: 144042
2011-11-07 23:35:40 +00:00
Sean Callanan 82695d6259 Additional logging to track original versions of
imported variables.

llvm-svn: 144041
2011-11-07 23:32:52 +00:00
Sean Callanan bfb237bc02 Updated LLVM/Clang to pick up a fix for imports of
C++ vtables, fixing a record layout problem in the
expression parser.

Also fixed various problems with the generation 
and unpacking of llvm.zip given our new better
handling of multiple architectures in the LLVM
build.

(And added a log message that will hopefully catch
record layout problems in the future.)

llvm-svn: 143741
2011-11-04 22:46:46 +00:00
Sean Callanan 744756e389 Occasionally LLDB runs into contexts where the
target is stopped in a C++ or Objective-C method
but the "self" pointer's valid range actually
doesn't cover the current location.  Before, that
was confusing Clang to the point where it crashed;
now, we sanity-check and fall back to pretending
we're in a C function if "self" or "this" isn't
available.

llvm-svn: 143676
2011-11-04 02:09:33 +00:00
Sean Callanan 3dea5c7cad Fixed a problem where the "this" pointer didn't
have the correct value in the IRInterpreter.

llvm-svn: 143663
2011-11-03 22:48:37 +00:00
Sean Callanan 9c95fd2ed6 Fixed the function that gets values for the
IRInterpreter to get the value, not the location,
of references.  The location of a reference has
type T&&, which is meaningless to Clang.

llvm-svn: 143592
2011-11-02 23:24:30 +00:00
Sean Callanan c832475cd2 Updated LLVM/Clang to pull in an MCJIT fix that
allows us to set __attribute__ ((used)) on expressions
that masquerade as methods.  When we are stopped in
classes in anonymous namespaces, this fix (and enabling
__attribute__ ((used)) on the method) will allow
expressions to run.

llvm-svn: 143560
2011-11-02 18:09:01 +00:00
Sean Callanan dbb583992a Sometimes the debug information includes artifically-
generated special member functions (constructors,
destructors, etc.) for classes that don't really have
them.  We needed to mark these as artificial to reflect
the debug information; this bug does that for
constructors and destructors.

The "etc." case (certain assignment operators, mostly)
remains to be fixed.

llvm-svn: 143526
2011-11-02 01:38:59 +00:00
Sean Callanan fc89c142d3 Added functionality to call Objective-C class methods
correctly, and added a testcase to check that it works.

The main problem here is that Objective-C class method
selectors are external references stored in a special
data structure in the LLVM IR module for an expression.
I just had to extract them and ensure that the real
class object locations were properly resolved.

llvm-svn: 143520
2011-11-01 23:38:03 +00:00
Sean Callanan c1b732d782 Added the capability (turned off for now) to mark a
method as __attribute__ ((used)) when adding it to a
class.  This functionality is useful when stopped in
anonymous namespaces: expressions attached to classes
in anonymous namespaces are typically elided by Clang's
CodeGen because they have no namespaces are intended
not to be externally visible.  __attribute__ ((used))
forces CodeGen to emit the function.

Right now, __attribute__ ((used)) causes the JIT not to
emit the function, so we're not enabling it until we
fix that.

llvm-svn: 143469
2011-11-01 18:07:13 +00:00
Sean Callanan ea685aeb3c Minor logging changes: added logging right before
the expression makes it to the JIT, and made some
logging only appear in verbose mode.

llvm-svn: 143467
2011-11-01 17:33:54 +00:00
Jim Ingham ce553d885a Enhanced the ObjC DynamicCheckerFunction to test for "object responds to selector" as well as
"object borked"...  Also made the error when the checker fails reflect this fact rather than
report a crash at 0x0.

Also a little cleanup:
- StopInfoMachException had a redundant copy of the description string.
- ThreadPlanCallFunction had a redundant copy of the thread, and had a 
copy of the process that it didn't really need.

llvm-svn: 143419
2011-11-01 02:46:54 +00:00
Daniel Dunbar a08823fd10 warnings: Fix a bunch of -Wreorder problems.
llvm-svn: 143381
2011-10-31 22:50:49 +00:00
Sean Callanan fc8feb8137 The IRDynamicChecks subsystem was not properly
detecting Objective-C method calls because the
"lldb.call.realName" metadata was no longer
being correctly installed.  I fixed this problem.

llvm-svn: 143371
2011-10-31 22:11:40 +00:00
Sean Callanan fb3e4306af Cloned FindExternalVisibleDecls from
ClangExpressionDeclMap to ClangASTSource, and
moved all general type and namespace lookups
into ClangASTSource.  Now ClangASTSource is ready
to complete types given nothing more than a target
and an AST context.

llvm-svn: 143292
2011-10-29 19:50:43 +00:00
Sean Callanan ba0aca72f0 Moved FindExternalLexicalDecls and a few smaller
functions from ClangExpressionDeclMap to ClangASTSource.

llvm-svn: 143276
2011-10-29 02:28:18 +00:00
Sean Callanan 1ee44b741d I moved the responsibility for interacting with the
AST importer on completing namespace mappings from
ClangExpressionDeclMap to ClangASTSource.

ClangASTSource now contains a TargetSP which it
uses to lookup namespaces in all of a target's
modules.  I will use the TargetSP in the future to
look up globals.

llvm-svn: 143275
2011-10-29 01:58:46 +00:00
Sean Callanan eddeb3b96f As part of a general refactoring of ClangASTSource to
allow it to complete types on behalf of any AST context
(including the "scratch" AST context associated with
the target), I scrapped its role as intermediary between
the Clang parser and ClangExpressionDeclMap, and instead
made ClangExpressionDeclMap inherit from ClangASTSource.

After this, I will migrate the functions that complete
types and perform namespace lookups from
ClangExpressionDeclMap to ClangASTSource.  Ultimately
ClangExpressionDeclMap's only responsiblity will be to
look up variables and ensure that they are materialized
and dematerialized correctly.

llvm-svn: 143253
2011-10-28 23:38:38 +00:00
Sean Callanan da1452dc29 Added a bunch of logging to CompleteType for TagDecls
and ObjCInterfaceDecls.

llvm-svn: 143181
2011-10-28 02:08:32 +00:00
Sean Callanan 9829801437 Changed the way the expression parser handles variables
of reference types.  Previously, such variables were
materialized as references to those references, which
caused undesried behavior in Clang and was useless anyway
(the benefit of using references to variables is that it
allows expressions to modify variables in place, but for
references that's not required).

Now we just materialize the references directly, which
fixes a variety of expressions that use references.

llvm-svn: 143137
2011-10-27 19:41:13 +00:00
Sean Callanan 7f9be0fdc1 Liberalized the "id" check a little; now "id" can
be found in namespaces.

llvm-svn: 143096
2011-10-27 02:10:28 +00:00
Sean Callanan fb40b0d4b5 Disabled lookups for the Objective-C builtin type "id;"
the compiler should pick this type up automatically.

llvm-svn: 143094
2011-10-27 02:06:03 +00:00
Sean Callanan 7ba9636f0a Added an extra parameter to the object-checker
functions in the Objective-C language runtime
that is set to the selector that is being passed
to the object.

llvm-svn: 143083
2011-10-27 00:02:05 +00:00
Sean Callanan d2cb626ac1 Extended the IR interpreter to handle the variables
"_cmd", "this", and "self".  These variables are handled
differently from all other external variables used by
the expression.  Other variables are used indirectly
through the $__lldb_arg operand; only _cmd, this, and
self are passed directly through the ABI.

There are two modifications:

 - I added a function to ClangExpressionDeclMap that
   retrives the value of one of these variables by name;
   and

 - I made IRInterpreter fetch these values when needed,
   and ensured that the proper level of indirection is
   used.

llvm-svn: 143065
2011-10-26 21:20:00 +00:00
Sean Callanan efa7d1f117 Fixed a problem where local variables conflict with
types of the same name.  If a local variable with the
given name is found (and we are not searching a
specific namespace) we stop right then and there and
report it.

llvm-svn: 142962
2011-10-25 20:36:57 +00:00
Sean Callanan c70ed46dda Improved handling of static data in the expression
parser.  Now expression like the following work as
expected:

-
(lldb) expr struct { int a; int b; } $blah = { 10, 20 }
<no result>
(lldb) expr $blah
(<anonymous struct at Parse:6:5>) $blah = {
  (int) a = 10
  (int) b = 20
}
-

Now the IRForTarget subsystem knows how to handle
static initializers of various composite types.

Also removed an unnecessary parameter from
ClangExpressionDeclMap::GetFunctionInfo.

llvm-svn: 142936
2011-10-25 18:36:40 +00:00
Sean Callanan f463856fd0 Fixed our handling of const functions, compensating
for debug information that occasionally gets the
const-ness of member functions wrong.  We used to
demangle the name, add "const," and remangle it; now
we handle the mangled name directly, which is more
robust.

llvm-svn: 142933
2011-10-25 18:02:05 +00:00
Greg Clayton f0705c8b90 Added template support when parsing DWARF into types. We can now use STL
classes in the expression parser.

llvm-svn: 142717
2011-10-22 03:33:13 +00:00
Sean Callanan a76eadd8bb Made the expression parser handle persistent variables
correctly even after the process has quit.

llvm-svn: 142712
2011-10-22 01:58:08 +00:00
Sean Callanan 2e2b8b844c Enabled dedicated debugger support in Clang, meaning
that Objective-C methods returning types incompatible
with "id" can be properly cast.

llvm-svn: 142702
2011-10-21 23:40:00 +00:00
Sean Callanan b226916528 Implemented an extension to the namespace map that
permits a namespace map to be created and populated
when the namespace is imported, not just when it is
requested via FindExternalVisibleDecls().

llvm-svn: 142690
2011-10-21 22:18:07 +00:00
Sean Callanan 80c48c10d0 Made the IR interpreter more robust in the presence
of arbitrary pointers, allowing direct dereferences
of literal addresses.  Also disabled special-cased
generation of certain expression results (especially
casts), substituting the IR interpreter.

llvm-svn: 142638
2011-10-21 05:18:02 +00:00
Greg Clayton 64bc6ca595 Modified the ASTDumper to return a "const char *" instead of a copy of the
std::string and modified all places that used the std::string it returned
to use the "const char *".

Also modified the expression parser to not crash when a function type fails
to copy into the expression AST context.

llvm-svn: 142561
2011-10-20 00:47:21 +00:00
Sean Callanan 80a3f3c8a9 Removed some debug support I accidentally
committed.

llvm-svn: 142376
2011-10-18 17:45:25 +00:00
Sean Callanan 35c7f98734 Improved logging, replacing the old ASTDumper (which
we never used) with a much simpler class that wraps
the relevant dump functions in Clang.  This class also
knows to disable external lookups on DeclContexts
being dumped so it should be safe to print incomplete
Decls.

llvm-svn: 142359
2011-10-18 16:46:55 +00:00
Sean Callanan 7dd9812675 Improved expression logging. Now all calls to
FindExternalVisibleDecls and FindExternalLexicalDecls
are marked and given unique IDs, so that all logging
done as part of their execution can be traced back to
the proper call.

Also there was some logging that really wasn't helpful
in most cases so I disabled it unless verbose logging
(log enable -v lldb expr) is enabled.

llvm-svn: 141987
2011-10-14 20:34:21 +00:00
Sean Callanan 187de46132 Improved logging for FindExternalLexicalDecls to
make it easier to track down which members belong
to which structs (and which call to 
FindExternalLexicalDecls is doing the reporting).

llvm-svn: 141930
2011-10-14 01:15:27 +00:00
Sean Callanan c6bba3e46d Cleaned up a few functions that never get used.
Specifically, the expression parser used to use
functions attached to SymbolContext to do lookups,
but nowadays it searches a ModuleList or Module
directly instead.  These functions had no
remaining clients so I removed them to prevent
bit rot.

I also removed a stray callback function from
ClangExpressionDeclMap.

llvm-svn: 141899
2011-10-13 22:18:56 +00:00
Sean Callanan ebe6067a8c Enabled the namespace-specific search functionality,
which had previously been commented out while I tested
it.  It's not fully working yet, but it doesn't break
our testsuite and it's an important piece of
functionality.

Also added some logging to SymbolFileDWARF to help
diagnose entities that are found in a symbol file,
but do not reside in the expected namespace.

llvm-svn: 141894
2011-10-13 21:50:33 +00:00
Sean Callanan c41e68b127 Moved the list of found namespaces into the search
context object.  Having it populated and registered
within a single FindExternalVisibleDecls call worked
fine when there was only one call (i.e., when we were
just looking in the global namespace).  

However, now FindExternalVisibleDecls is called for
nested namespaces as well, which means that it is
called not once but many times (once per module in
which the parent namespace appears).  This means that
the namespace mapping is built up across many calls
to the inferior FindExternalVisibleDecls, so I moved
it into a data structure (the search context) that is
shared by all calls.

I also added some logging to make it easier to see
what is happening during a namespace search, and 
cleaned up some existing logging.

llvm-svn: 141888
2011-10-13 21:08:11 +00:00
Sean Callanan b96ff33b0e Removed namespace qualification from symbol queries.
llvm-svn: 141866
2011-10-13 16:49:47 +00:00
Sean Callanan 213fdb8bf6 Completed the glue that passes a ClangNamespaceDecl *
down through Module and SymbolVendor into SymbolFile.
Added checks to SymbolFileDWARF that restrict symbol
searches when a namespace is passed in.

llvm-svn: 141847
2011-10-13 01:49:10 +00:00
Sean Callanan 8e5b8b9631 Now that we know the values are going to stick around,
we don't need to look them up again when materializing.

Switched over the materialization mechanism (for JIT
expressions) and the lookup mechanism (for interpreted
expressions) to use the VariableSP/Symbol that were
found during parsing.

llvm-svn: 141839
2011-10-13 00:09:20 +00:00
Sean Callanan e3aef1d063 Extended the lifetime of Clang parser objects to the
lifetime of ClangExpressionDeclMap.  This allows
ClangExpressionVariables found during parsing to be
queried for their containing namespaces during
expression execution.

Other clients (like ClangFunction) explicitly delete
this state, so they should not result in any memory
leaks.

llvm-svn: 141821
2011-10-12 22:20:02 +00:00
Sean Callanan ca4e0fd7e6 Refactoring in preparation for having multiple
calls to the FindExternalVisibleDecls function.

FindExternalVisibleDecls was recording whether
it had found generic function symbols in variables
that were local to the function.  Now, however,
multiple calls occur in response to one request
from Clang, since we may be searching across
namespaces.  To support that, I moved the local
variables into a bitfield in NameSearchContext.

llvm-svn: 141808
2011-10-12 20:29:25 +00:00
Sean Callanan 1a2c5386cd Made the expression parser's type search call the
proper namespace-aware APIs.

llvm-svn: 141797
2011-10-12 18:44:30 +00:00
Sean Callanan 4c3977c278 Added support to ClagnExpressionDeclMap for finding
data symbols in namespaces.

llvm-svn: 141792
2011-10-12 18:00:53 +00:00
Sean Callanan 25ea08ef8c Changed FindExternalVisibleDecls() to use the module
level FindFunctions() where appropriate and not use
SymbolContext::FindFunctionsByName().

llvm-svn: 141789
2011-10-12 17:38:09 +00:00
Sean Callanan 1fd3f4f14c Made FindGlobalVariable() optionally search a specific
module and namespace.  Also made it use FindGlobalVariables()
instead of the more heavyweight 
GetVariablesForVariableExpressionPath().

llvm-svn: 141783
2011-10-12 16:59:31 +00:00
Sean Callanan b6d70ebc0a Added ClangNamespaceDecl * parameters to several
core Module functions that the expression parser
will soon be using.

llvm-svn: 141766
2011-10-12 02:08:07 +00:00
Sean Callanan 8897224363 Cleanups in preparation for making FindExternalVisibleDecls
look in individual modules rather than globally.

Also some whitespace fixes.

llvm-svn: 141765
2011-10-12 01:39:28 +00:00
Greg Clayton d4e2552c73 Fix preprocessor warnings for no newline at the end of the source files.
llvm-svn: 141755
2011-10-12 00:53:29 +00:00
Sean Callanan 503aa525ea Implemented a namespace map that allows searching
of namespaces (only in the modules where they've
been found) for entities inside those namespaces.

For each NamespaceDecl that has been imported into
the parser, we maintain a map containing
[ModuleSP, ClangNamespaceDecl] pairs in the ASTImporter.
This map has one entry for each module in which the
namespace has been found.  When we later scan for an
entity inside a namespace, we search only the modules
in which that namespace was found.

Also made a small whitespace fix in 
ClangExpressionParser.cpp.

llvm-svn: 141748
2011-10-12 00:12:34 +00:00
Jim Ingham eb6ba39033 Fix the last testsuite regression from the apple-names stuff.
llvm-svn: 141468
2011-10-08 01:11:42 +00:00
Sean Callanan 2590b9ac6f Fixed a memory leak of ASTResultSynthesizers,
by attaching them to the ClangExpressionParser.

llvm-svn: 141452
2011-10-08 00:21:35 +00:00
Sean Callanan 880e680fa3 Updated LLVM/Clang to pull in the latest ARM disassembler.
This involved minor changes to the way we report Objective-C
methods, as well as cosmetic changes and added parameters
for a variety of Clang APIs.

llvm-svn: 141437
2011-10-07 23:18:13 +00:00
Sean Callanan 9bc838415e Factored out handling of the source code for an
expression into a separate class.  This class
encapsulates wrapping the function as needed.  I
am also moving from using booleans to indicate
what the expression's language should be to using
lldb::LanguageType instead.

llvm-svn: 140545
2011-09-26 18:45:31 +00:00
Greg Clayton c14ee32db5 Converted the lldb_private::Process over to use the intrusive
shared pointers.

Changed the ExecutionContext over to use shared pointers for
the target, process, thread and frame since these objects can
easily go away at any time and any object that was holding onto
an ExecutionContext was running the risk of using a bad object.

Now that the shared pointers for target, process, thread and
frame are just a single pointer (they all use the instrusive
shared pointers) the execution context is much safer and still
the same size. 

Made the shared pointers in the the ExecutionContext class protected
and made accessors for all of the various ways to get at the pointers,
references, and shared pointers.

llvm-svn: 140298
2011-09-22 04:58:26 +00:00
Sean Callanan 0886e5657b Fixed a problem with the IR interpreter that caused
it to generate result variables that were not bound
to their underlying data.  This allowed the SBValue
class to use the interpreter (if possible).

Also made sure that any result variables that point
to stack allocations in the stack frame of the
interpreted expressions do not get live data.

llvm-svn: 140285
2011-09-22 00:41:11 +00:00
Sean Callanan 90539456a1 Fixed a problem where expressions would attempt to
allocate memory in a process that did not support
expression execution.  Also improved detection of
whether or not a process can execute expressions.

llvm-svn: 140202
2011-09-20 23:01:51 +00:00
Jason Molenda fd54b368ea Update declarations for all functions/methods that accept printf-style
stdarg formats to use __attribute__ format so the compiler can flag
incorrect uses.  Fix all incorrect uses.  Most of these are innocuous,
a few were resulting in crashes.

llvm-svn: 140185
2011-09-20 21:44:10 +00:00
Jason Molenda 7e589a6011 Change Error::SetErrorStringWithFormat() prototype to use an
__attribute__ format so the compiler knows that this method takes
printf style formatter arguments and checks that it's being used
correctly.  Fix a couple dozen incorrect SetErrorStringWithFormat()
calls throughout the sources.

llvm-svn: 140115
2011-09-20 00:26:08 +00:00
Greg Clayton 4d122c4009 Adopt the intrusive pointers in:
lldb_private::Breakpoint
lldb_private::BreakpointLocations
lldb_private::BreakpointSite
lldb_private::Debugger
lldb_private::StackFrame
lldb_private::Thread
lldb_private::Target

llvm-svn: 139985
2011-09-17 08:33:22 +00:00
Greg Clayton 747bcb03d2 Convert lldb::ModuleSP to use an instrusive ref counted pointer.
We had some cases where getting the shared pointer for a module from
the global module list was causing a performance issue when debugging
with DWARF in .o files. Now that the module uses intrusive ref counts,
we can easily convert any pointer to a shared pointer.

llvm-svn: 139983
2011-09-17 06:21:20 +00:00
Sean Callanan c2ff27446d Fixed a problem where the symbol context was not
being initialized properly in the absence of a
process.

llvm-svn: 139823
2011-09-15 18:41:04 +00:00
Sean Callanan 64fe1994d8 Fixed a problem where the expression parser would
attempt to obtain information from the process even
in cases where the process isn't available.

llvm-svn: 139803
2011-09-15 17:43:00 +00:00
Sean Callanan 3bfdaa2a47 This patch modifies the expression parser to allow it
to execute expressions even in the absence of a process.
This allows expressions to run in situations where the
target cannot run -- e.g., to perform calculations based
on type information, or to inspect a binary's static
data.

This modification touches the following files:

lldb-private-enumerations.h
  Introduce a new enum specifying the policy for
  processing an expression.  Some expressions should
  always be JITted, for example if they are functions
  that will be used over and over again.  Some
  expressions should always be interpreted, for
  example if the target is unsafe to run.  For most,
  it is acceptable to JIT them, but interpretation
  is preferable when possible.

Target.[h,cpp]
  Have EvaluateExpression now accept the new enum.

ClangExpressionDeclMap.[cpp,h]
  Add support for the IR interpreter and also make
  the ClangExpressionDeclMap more robust in the 
  absence of a process.

ClangFunction.[cpp,h]
  Add support for the new enum.

IRInterpreter.[cpp,h]
  New implementation.

ClangUserExpression.[cpp,h]
  Add support for the new enum, and for running 
  expressions in the absence of a process.

ClangExpression.h
  Remove references to the old DWARF-based method
  of evaluating expressions, because it has been
  superseded for now.

ClangUtilityFunction.[cpp,h]
  Add support for the new enum.

ClangExpressionParser.[cpp,h]
  Add support for the new enum, remove references
  to DWARF, and add support for checking whether
  the expression could be evaluated statically.

IRForTarget.[h,cpp]
  Add support for the new enum, and add utility
  functions to support the interpreter.

IRToDWARF.cpp
  Removed

CommandObjectExpression.cpp
  Remove references to the obsolete -i option.

Process.cpp 
  Modify calls to ClangUserExpression::Evaluate
  to pass the correct enum (for dlopen/dlclose)

SBValue.cpp
  Add support for the new enum.

SBFrame.cpp
  Add support for he new enum.

BreakpointOptions.cpp
  Add support for the new enum.

llvm-svn: 139772
2011-09-15 02:13:07 +00:00
Greg Clayton cce8671fca Fixed some incorrect return values.
llvm-svn: 139582
2011-09-13 04:03:52 +00:00
Greg Clayton d4a2b37091 Huge memory and performance improvements in the DWARF parser.
Address ranges are now split up into two different tables: 
- one in DWARFDebugInfo that is compile unit specific
- one in each DWARFCompileUnit that has exact function DIE offsets

This helps keep the size of the aranges down since the main table will get
uniqued and sorted and have consecutive ranges merged. We then only parse the
compile unit one on demand once we have determined that a compile unit contains
the address in question. We also now use the .debug_aranges section if there 
is one instead of always indexing the DWARF manually.

NameToDIE now uses a UniqueCStringMap<dw_offset> map instead of a std::map.
std::map is very bulky as each node has 3 pointers and the key and value types.
This gets our NameToDIE entry down to 12 bytes each instead of 48 which saves
us a lot of memory when we have very large DWARF.

DWARFDebugAranges now has a smaller footprint for each range it contains to 
save on memory.

llvm-svn: 139557
2011-09-12 23:21:58 +00:00
Greg Clayton afacd14b0b Added the ability for DWARF locations to use the ABI plug-ins to resolve
register names when dumping variable locations and location lists. Also did
some cleanup where "int" types were being used for "lldb::RegisterKind"
values.

llvm-svn: 138988
2011-09-02 01:15:17 +00:00
Sean Callanan 737330c1de Fixed a bug where the target for an expression was
not set if the containing function could not be
found.  This caused LLDB to crash later in
expression parsing.

llvm-svn: 138499
2011-08-24 22:18:12 +00:00
Sean Callanan bccce81340 Added support for persistent types to the
expression parser.  You can use a persistent
type like this:

(lldb) expr struct $foo { int a; int b; };
(lldb) struct $foo i; i.a = 2; i.b = 3; i
($foo) $0 = {
  (int) a = 2
  (int) b = 3
}

typedefs work similarly.

This patch affects the following files:

test/expression_command/persistent_types/*
  A test case for persistent types,
  in particular structs and typedefs.

ClangForward.h
  Added TypeDecl, needed to declare some
  functions in ASTResultSynthesizer.h

ClangPersistentVariables.[h,cpp]
  Added a list of persistent types to the
  persistent variable store.

ASTResultSynthesizer.[h,cpp]
  Made the AST result synthesizer iterate
  across TypeDecls in the expression, and
  record any persistent types found.  Also
  made a minor documentation fix.

ClangUserExpression.[h,cpp]
  Extended the user expression class to
  keep the state needed to report the
  persistent variable store for the target
  to the AST result synthesizers. 

  Also introduced a new error code for
  expressions that executed normally but
  did not return a result.

CommandObjectExpression.cpp
  Improved output for expressions (like 
  declarations of new persistent types) that
  don't return a result.  This is no longer
  treated as an error.

llvm-svn: 138383
2011-08-23 21:20:51 +00:00
Sean Callanan efe9a42379 Fixed a performance problem where functions were
being searched for in too heavyweight a way.  Now,
when asking for the address of a function, the
expression parser just asks for a corresponding
data symbol.

llvm-svn: 137731
2011-08-16 18:09:29 +00:00
Greg Clayton 7e9b1fd045 We were leaking a stack frame in StackFrameList in Thread.cpp which could
cause extra shared pointer references to one or more modules to be leaked.
This would cause many object files to stay around the life of LLDB, so after
a recompile and rexecution, we would keep adding more and more memory. After
fixing the leak, we found many cases where leaked stack frames were still
being used and causing crashes in the test suite. These are now all resolved.

llvm-svn: 137516
2011-08-12 21:40:01 +00:00
Sean Callanan 912855fd27 Fixed LLDB's handling of ElaboratedTypes, which was
causing problems with printing the values of persistent
variables with struct types.

llvm-svn: 137392
2011-08-11 23:56:13 +00:00
Sean Callanan 5207a340e5 Fixed a problem that prevented access to members
of string literals ("hello"[2]).  Also fixed a
problem in which empty string literals were not
being compiled correctly ((int)printf("") would
print garbage).

Added a testcase that covers both.

llvm-svn: 137247
2011-08-10 21:05:52 +00:00
Greg Clayton 3418c85771 While tracking down memory consumption issue a few things were needed: the
ability to dump more information about modules in "target modules list". We
can now dump the shared pointer reference count for modules, the pointer to
the module itself (in case performance tools can help track down who has
references to said pointer), and the modification time.

Added "target delete [target-idx ...]" to be able to delete targets when they
are no longer needed. This will help track down memory usage issues and help 
to resolve when module ref counts keep getting incremented. If the command gets
no arguments, the currently selected target will be deleted. If any arguments 
are given, they must all be valid target indexes (use the "target list" 
command to get the current target indexes).

Took care of a bunch of "no newline at end of file" warnings.

TimeValue objects can now dump their time to a lldb_private::Stream object.

Modified the "target modules list --global" command to not error out if there
are no targets since it doesn't require a target.

Fixed an issue in the MacOSX DYLD dynamic loader plug-in where if a shared 
library was updated on disk, we would keep using the older one, even if it was
updated.

Don't allow the ModuleList::GetSharedModule(...) to return an empty module.
Previously we could specify a valid path on disc to a module, and specify an
architecture that wasn't contained in that module and get a shared pointer to
a module that wouldn't be able to return an object file or a symbol file. We
now make sure an object file can be extracted prior to adding the shared pointer
to the module to get added to the shared list.

llvm-svn: 137196
2011-08-10 02:10:13 +00:00
Johnny Chen ee7a359d59 Check log shared pointer before using it.
llvm-svn: 137173
2011-08-09 23:10:20 +00:00
Johnny Chen e95fcf7860 Check log shared pointer before using it.
llvm-svn: 137169
2011-08-09 22:52:27 +00:00
Jim Ingham 41c7591a1a Add EvaluateWithError static method. Fix a bug in handling constant expressions - we weren't setting the result even though the expression evaluation succeeded...
llvm-svn: 137077
2011-08-09 00:00:49 +00:00
Sean Callanan 69b5341c6a Made the expression parser use the StackFrame's
variable search API rather than rolling its own,
fixing one of our testcases.

llvm-svn: 137004
2011-08-06 00:28:14 +00:00
Sean Callanan 72e4940bd1 This is an overhaul of the expression parser code
that detects what context the current expression is
meant to execute in.  LLDB now properly consults
the method declaration in the debug information
rather than trying to hunt down the "this" or "self"
pointer by name, which can be misleading.

Other fixes include:

- LLDB now properly detects that it is inside
  an inlined C++ member function.

- LLDB now allows access to non-const members when
  in const code.

- The functions in SymbolFile that locate the
  DeclContext containing a DIE have been renamed
  to reflect what they actually do.  I have added
  new functions that find the DeclContext for the
  DIE itself.

I have also introduced testcases for C++ and 
Objective-C.

llvm-svn: 136999
2011-08-05 23:43:37 +00:00
Sean Callanan 0c4d8d25a7 Fixed a problem that caused LLDB to fail to execute
expressions that used function pointers.  The problem
was that IRForTarget previously only scanned the IR
for the expression for call instructions; if a function
was used in another context, it was ignored.

Now LLDB scans the Module for functions that are only
declared (not also defined -- so these are externals);
it then constructs function pointers for these
functions and substitutes them wherever the function
is used.

Also made some changes so that "expr main" works just
as well as "expr &main"; they end up being the same
code, but LLDB was generating the result variable in
different ways.

llvm-svn: 136928
2011-08-04 21:37:47 +00:00
Sean Callanan a789aa770e Improved the expression parser's detection of the
current context.  Previously, if there was a variable
called "self" available, the expression parser
assumed it was inside a method.  But class methods
in Objective-C also take a "self" parameter, of DWARF
type "id".  We now detect this properly, and only
assume we're in an instance method if "self" is a
pointer to an Objective-C object.

llvm-svn: 136784
2011-08-03 16:23:08 +00:00
Sean Callanan 7f3755b5ff Fixed a problem in the expression parser that
caused functions that were cast as part of the
call to have that cast ignored once their 
addresses were resolved.

Notably, in the case of objc_msgSend(), if
the function was cast from something returning
i8* to something returning i8, the expression
parser was discarding the cast as part of its
resolution.  This caused crashes later on.

llvm-svn: 136648
2011-08-01 20:53:53 +00:00
Sean Callanan b995119900 Added checking to make sure that the target has a
scratch AST context before attempting to parse.

llvm-svn: 136631
2011-08-01 18:18:33 +00:00
Sean Callanan af8e96c185 Fixed a bug where named constants were being
treated as externals, causing problems when we
tried to look their locations up in the debug
info.  For example:

expr char c[] = "foo"; c[0]

would terminate when trying to find c in the
debug information, despite the fact that c was
defined inside the expression.

llvm-svn: 136629
2011-08-01 17:41:38 +00:00
Peter Collingbourne eb72547f09 Add reloc arg to standard JIT createJIT()
Fixes non-__APPLE__ build.  Patch by Matt Johnson!

llvm-svn: 136580
2011-07-30 22:42:24 +00:00
Sean Callanan cc427fadec This change brings in the latest LLVM/Clang, and
completes the support in the LLDB expression parser
for incomplete types.  Clang now imports types
lazily, and we complete those types as necessary.

Changes include:

- ClangASTSource now supports three APIs which it
  passes to ClangExpressionDeclMap.  CompleteType
  completes a TagDecl or an ObjCInterfaceDecl when
  needed; FindExternalVisibleDecls finds named
  entities that are visible in the expression's
  scope; and FindExternalLexicalDecls performs a
  (potentially restricted) search for entities
  inside a lexical scope like a namespace.  These
  changes mean that entities in namespaces should
  work normally.

- The SymbolFileDWARF code for searching a context
  for a specific name is now more general, and can
  search arbitrary contexts.

- We are continuing to adapt our calls into LLVM
  from interfaces that take start and end iterators
  when accepting multiple items to interfaces that
  use ArrayRef.

- I have cleaned up some code, especially our use
  of namespaces.

This change is neutral for our testsuite and greatly
improves correctness for large programs (like Clang)
with complicated type systems.  It should also lay
the groundwork for improving the expression parser's
performance as we are lazier and lazier about
providing type information.

llvm-svn: 136555
2011-07-30 02:42:06 +00:00