Commit Graph

409 Commits

Author SHA1 Message Date
Sean Callanan 933693b621 Fixed a bunch of ownership problems with the expression
parser.  Specifically:

- ClangUserExpression now keeps weak pointers to the
  structures it needs and then locks them when needed.
  This ensures that they continue to be valid without
  leaking memory if the ClangUserExpression is long
  lived.

- ClangExpressionDeclMap, instead of keeping a pointer
  to an ExecutionContext, now contains an
  ExecutionContext.  This prevents bugs if the pointer
  or its contents somehow become stale.  It also no
  longer requires that ExecutionContexts be passed
  into any function except its initialization function,
  since it can count on the ExecutionContext still
  being around.

There's a lot of room for improvement (specifically,
ClangExpressionDeclMap should also use weak pointers
insetad of shared pointers) but this is an important
first step that codifies assumptions that already
existed in the code.

llvm-svn: 150217
2012-02-10 01:22:05 +00:00
Sean Callanan d2b465f17a Brought LLVM/Clang up to top of tree. The only
change (besides logging) is that now string
literals in the IR are ConstantDataArrays instead
of ConstantArrays.

llvm-svn: 150142
2012-02-09 03:22:41 +00:00
Sean Callanan 80ef1245cc Added support to the expression parser for reading
variables that are only available in symbols.

llvm-svn: 150103
2012-02-08 21:55:14 +00:00
Sean Callanan aa719af082 In the absence of a valid process, the expression
parser now at least tries to generate IR for the
target.

llvm-svn: 150079
2012-02-08 18:43:35 +00:00
Sean Callanan c03bdd9c80 Fixed ClangExpressionDeclMap to use the debug
information about the current frame rather than
the debug information about "this" and "self"
when determining the types of those pointers.
This allows expressions to work in frames that
don't have valid "this" and "self" pointers,
working around poor debug information.

llvm-svn: 150051
2012-02-08 03:45:08 +00:00
Sean Callanan 94a9a39ec4 The IRInterpreter's constant evaluator wasn't
sufficiently general - it could only handle
literals and operations that didn't change the
data.  Now the constant evaluator passes APInt
values around, and can handle GetElementPtr
constants.

llvm-svn: 150034
2012-02-08 01:27:49 +00:00
Sean Callanan 7e2863b416 I left some stray debugging messages in the source
code.  Removing these.

llvm-svn: 149903
2012-02-06 21:28:03 +00:00
Sean Callanan 5b26f27f46 I have brought LLDB up-to-date with top of tree
LLVM/Clang.  This brings in several fixes, including:

- Improvements in the Just-In-Time compiler's
  allocation of memory: the JIT now allocates
  memory in chunks of sections, improving its
  ability to generate relocations.  I have
  revamped the RecordingMemoryManager to reflect
  these changes, as well as to get the memory
  allocation and data copying out fo the
  ClangExpressionParser code.  Jim Grosbach wrote
  the updates to the JIT on the LLVM side.

- A new ExternalASTSource interface to allow LLDB to
  report accurate structure layout information to
  Clang.  Previously we could only report the sizes
  of fields, not their offsets.  This meant that if
  data structures included field alignment
  directives, we could not communicate the necessary
  alignment to Clang and accesses to the data would
  fail.  Now we can (and I have update the relevant
  test case).  Thanks to Doug Gregor for implementing
  the Clang side of this fix.

- The way Objective-C interfaces are completed by
  Clang has been made consistent with RecordDecls;
  with help from Doug Gregor and Greg Clayton I have
  ensured that this still works.

- I have eliminated all local LLVM and Clang patches,
  committing the ones that are still relevant to LLVM
  and Clang as needed.

I have tested the changes extensively locally, but
please let me know if they cause any trouble for you.

llvm-svn: 149775
2012-02-04 08:49:35 +00:00
Greg Clayton e1cd1be6d6 Switching back to using std::tr1::shared_ptr. We originally switched away
due to RTTI worries since llvm and clang don't use RTTI, but I was able to 
switch back with no issues as far as I can tell. Once the RTTI issue wasn't
an issue, we were looking for a way to properly track weak pointers to objects
to solve some of the threading issues we have been running into which naturally
led us back to std::tr1::weak_ptr. We also wanted the ability to make a shared 
pointer from just a pointer, which is also easily solved using the 
std::tr1::enable_shared_from_this class. 

The main reason for this move back is so we can start properly having weak
references to objects. Currently a lldb_private::Thread class has a refrence
to its parent lldb_private::Process. This doesn't work well when we now hand
out a SBThread object that contains a shared pointer to a lldb_private::Thread
as this SBThread can be held onto by external clients and if they end up
using one of these objects we can easily crash.

So the next task is to start adopting std::tr1::weak_ptr where ever it makes
sense which we can do with lldb_private::Debugger, lldb_private::Target,
lldb_private::Process, lldb_private::Thread, lldb_private::StackFrame, and
many more objects now that they are no longer using intrusive ref counted
pointer objects (you can't do std::tr1::weak_ptr functionality with intrusive
pointers).

llvm-svn: 149207
2012-01-29 20:56:30 +00:00
Sean Callanan 175a0d04b6 Added a mechanism for the IR interpreter to return
an error along with its boolean result.  The
expression parser reports this error if the 
interpreter fails and the expression could not be
run in the target.

llvm-svn: 148870
2012-01-24 22:06:48 +00:00
Sean Callanan a9bc065607 Fixed a problem where maintaining the ObjCInterfaceMap
for each ObjCInterfaceDecl was imposing performance
penalties for Objective-C apps.  Instead, we now use
the normal function query mechanisms, which use the
relevant accelerator tables.

This fix also includes some modifications to the
SymbolFile which allow us to find Objective-C methods
and report their Clang Decls correctly.

llvm-svn: 148457
2012-01-19 02:17:40 +00:00
Sean Callanan a6e61a7820 Fixed some logging in the AST source and added
more information.

llvm-svn: 148144
2012-01-13 22:05:55 +00:00
Sean Callanan ee458a7785 After thinking about it, it doesn't seem right
to make assumptions if the type is unsized.  We
just give up (and let the JIT handle it) instead.

llvm-svn: 147915
2012-01-11 02:23:25 +00:00
Sean Callanan 285e4b22f5 If the size of a type can't be determined, default
to assume it's of pointer size.

llvm-svn: 147906
2012-01-11 01:36:21 +00:00
Sean Callanan d1a5e01ff9 Fixed a bug where the DWARF location expression
parser was creating malformed resuls.  When the
location of a variable is computed by reading a
register and adding an offset, we shouldn't say
that the variable's value is located in that
register.  This was confusing the expression
parser when trying to read a variable captured
by a block.

llvm-svn: 147668
2012-01-06 18:24:47 +00:00
Johnny Chen b49440fa92 http://llvm.org/bugs/show_bug.cgi?id=11618
lldb::SBValue::AddressOf does not work on dereferenced registers in synthetic children provider

Patch submitted by Enrico Granata.

llvm-svn: 147637
2012-01-06 00:35:38 +00:00
Greg Clayton 96c09687bc <rdar://problem/10507811>
Be better at detecting when DWARF changes and handle this more
gracefully than asserting and exiting.

Also fixed up a bunch of system calls that weren't properly checking
for EINTR.

llvm-svn: 147559
2012-01-04 22:56:43 +00:00
Sean Callanan 3441d5ae34 Added logging to track when the IR interpreter
resolves values in registers.

llvm-svn: 147551
2012-01-04 21:42:46 +00:00
Sean Callanan 694e244176 Added checking to prevent a rare crash when getting
the name for an external variable in the IR.

llvm-svn: 147178
2011-12-22 21:24:49 +00:00
Jim Ingham ef65160016 Improve the x86_64 return value decoder to handle most structure returns.
Switch from GetReturnValue, which was hardly ever used, to GetReturnValueObject
which is much more convenient.
Return the "return value object" as a persistent variable if requested.

llvm-svn: 147157
2011-12-22 19:12:40 +00:00
Sean Callanan 960534c866 Made IRForTarget error out correctly when it can't
complete the result type, preventing crashes later.

llvm-svn: 147107
2011-12-21 23:44:05 +00:00
Sean Callanan 20bb3aa53a The "desired result type" code in the expression
parser has hitherto been an implementation waiting
for a use.  I have now tied the '-o' option for
the expression command -- which indicates that the
result is an Objective-C object and needs to be
printed -- to the ExpressionParser, which
communicates the desired type to Clang.

Now, if the result of an expression is determined
by an Objective-C method call for which there is
no type information, that result is implicitly
cast to id if and only if the -o option is passed
to the expression command.  (Otherwise if there
is no explicit cast Clang will issue an error.
This behavior is identical to what happened before
r146756.)

Also added a testcase for -o enabled and disabled.

llvm-svn: 147099
2011-12-21 22:22:58 +00:00
Sean Callanan bfb7c68b5f Added some strength to the checks that prevent
"id" from being found by the parser as an
externally-defined type.  Before, "id" would
sometimes make it through if it was defined in
a namespace, but this sometimes caused
confusion, for example when it conflicted with
std::locale::id.

llvm-svn: 146891
2011-12-19 19:38:39 +00:00
Jim Ingham 105d7234df Remove an unnecessary #include.
llvm-svn: 146798
2011-12-17 00:58:46 +00:00
Johnny Chen b456b792e0 http://llvm.org/bugs/show_bug.cgi?id=11588
valobj.AddressOf() returns None when an address is expected in a SyntheticChildrenProvider

Patch from Enrico Granata:

The problem was that the frozen object created by the expression parser was a copy of the contents of the StgClosure, rather than a pointer to it. Thus, the expression parser was correctly computing the result of the arithmetic&cast operation along with its address, but only saving it in the live object. This meant that the frozen copy acted as an address-less variable, hence the problem.

The fix attached to this email lets the expression parser store the "live address" in the frozen copy of the address when the object is built without a valid address of its own.
Doing so, along with delegating ValueObjectConstResult to calculate its own address when necessary, solves the issue. I have also added a new test case to check for regressions in this area, and checked that existing test cases pass correctly.

llvm-svn: 146768
2011-12-16 23:04:52 +00:00
Sean Callanan bb12004c38 Updated Clang to take an enhancement to the way
we handle Objective-C method calls.  Currently,
LLDB treats the result of an Objective-C method
as unknown if the type information doesn't have
the method's signature.  Now Clang can cast the
result to id if it isn't explicitly cast.

I also added a test case for this, as well as a
fix for a type import problem that this feature
exposed.

llvm-svn: 146756
2011-12-16 21:06:35 +00:00
Sean Callanan fc4f2fb0da This commit is the result of a general audit of
the expression parser to locate instances where
dyn_cast<>() and isa<>() are used on types, and
replace them with getAs<>() as appropriate.

The difference is that dyn_cast<>() and isa<>()
are essentially LLVM/Clang's equivalent of RTTI
-- that is, they try to downcast the object and
return NULL if they cannot -- but getAs<>() can
traverse typedefs to perform a semantic cast.

llvm-svn: 146537
2011-12-14 01:13:04 +00:00
Sean Callanan d5cc132b98 I have modified the part of the code that finds and
validates the "self," "this," and "_cmd" pointers
that get passed into expressions.  It used to check
them aggressively for validity before allowing the
expression to run as an object method; now, this
functionality is gated by a bool and off by default.

Now the default is that when LLDB is stopped in a
method of a class, code entered using "expr" will
always masquerade as an instance method.  If for
some reason "self," "this," or "_cmd" is unavailable
it will be reported as NULL.  This may cause the
expression to crash if it relies on those pointers,
but for example getting the addresses of ivars will
now work as the user would expect.

llvm-svn: 146465
2011-12-13 01:42:04 +00:00
Sean Callanan fd1ba911f8 Fixed a problem where if a frame was present the
expression parser would never try getting typed
variables from the target.

llvm-svn: 146317
2011-12-10 04:03:38 +00:00
Sean Callanan 9b3569bacc Two fixes for file variables:
- Even if a frame isn't present, we always try
  to use FindGlobalVariable to find variables.
  Instead of using frame->TrackGlobalVariable()
  to promote the VariableSP into a ValueObject,
  we now simply use ValueObjectVariable.

- When requesting the value of a variable, we
  allow returning of the "live version" of the
  variable -- that is, the variable in the
  target instead of a pointer to its freeze
  dried version in LLDB -- even if there is no
  process present.

llvm-svn: 146315
2011-12-10 03:12:34 +00:00
Sean Callanan 12014a0471 If the expression parser is unable to complete a TagDecl
in the context in which it was originally found, the
expression parser now goes hunting for it in all modules
(in the appropriate namespace, if applicable).  This means
that forward-declared types that exist in another shared
library will now be resolved correctly.

Added a test case to cover this.  The test case also tests
"frame variable," which does not have this functionality
yet.

llvm-svn: 146204
2011-12-08 23:45:45 +00:00
Sean Callanan 5780f9df56 Added the ability to dereference an Objective-C object
pointer to make the result of an expression.  LLDB now
dumps the ivars of the Objective-C object and all of
its parents.  This just required fixing a bug where we
didn't distinguish between Objective-C object pointers
and regular C-style pointers.

Also added a testcase to verify that this continues to
work.

llvm-svn: 146164
2011-12-08 19:04:34 +00:00
Greg Clayton 161f367047 Don't crash due to not checking log shared pointer.
llvm-svn: 146126
2011-12-08 01:32:28 +00:00
Sean Callanan 610baf42ce Fixed a few details of method lookup in Objective-C
symbols.  Now we find the correct method.

Unfortunately we don't get the superclass from the
runtime yet so the method doesn't import correctly
(and I added a check to make sure that doesn't hurt
us) but once we get that information right we will
report methods correctly to the parser as well.

Getting superclass information requires a common AST
context for all Objective-C runtime information,
meaning that the superclass and the subclass are in
the same AST context in all cases.  That is the next
thing that needs to be done here.

llvm-svn: 146089
2011-12-07 22:39:39 +00:00
Sean Callanan ae6d614118 Fixed a potential crasher if the frame is not
avalable when a global variable is looked up.
In ClangExpressionDeclMap, a frame should usually
be available.

llvm-svn: 146066
2011-12-07 20:41:47 +00:00
Jim Ingham b35274095c Fix assert string to be more informative.
llvm-svn: 146061
2011-12-07 20:10:58 +00:00
Sean Callanan 0eed0d42a0 As part of the work to make Objective-C type information
from symbols more accessible, I have added a second
map to the ClangASTImporter: the ObjCInterfaceMetaMap.
This map keeps track of all type definitions found for
a particular Objective-C interface, allowing the
ClangASTSource to refer to all possible sources when
looking for method definitions.

There is a bug in lookup that I still need to figure out,
but after that we should be able to report full method
information for Objective-C classes shown in symbols.

Also fixed some errors I ran into when enabling the maps
for the persistent type store.  The persistent type store
previously did not use the ClangASTImporter to import
types, instead using ASTImporters that got allocated each
time a type needed copying.  To support the requirements
of the persistent type store -- namely, that types must be
copied, completed, and then completely severed from their
origin in the parser's AST context (which will go away) --
I added a new function called DeportType which severs all
these connections.

llvm-svn: 145914
2011-12-06 03:41:14 +00:00
Greg Clayton 1075acafeb Added the ability for clients to grab a set of symbol table indexes and then
add them to a fast lookup map. lldb_private::Symtab now export the following
public typedefs:

namespace lldb_private {

	class Symtab {
		typedef std::vector<uint32_t> IndexCollection;
		typedef UniqueCStringMap<uint32_t> NameToIndexMap;
	};
}

Clients can then find symbols by name and or type and end up with a 
Symtab::IndexCollection that is filled with indexes. These indexes can then
be put into a name to index lookup map and control if the mangled and 
demangled names get added to the map:

bool add_demangled = true;
bool add_mangled = true;
Symtab::NameToIndexMap name_to_index;
symtab->AppendSymbolNamesToMap (indexes, add_demangled, add_mangled, name_to_index).

This can be repeated as many times as needed to get a lookup table that
you are happy with, and then this can be sorted:

name_to_index.Sort();

Now name lookups can be done using a subset of the symbols you extracted from
the symbol table. This is currently being used to extract objective C types
from object files when there is no debug info in SymbolFileSymtab.

Cleaned up how the objective C types were being vended to be more efficient
and fixed some errors in the regular expression that was being used.

llvm-svn: 145777
2011-12-03 20:02:42 +00:00
Greg Clayton 456809c161 Added new symbol types for Objective C classes, metaclasses, and ivars. Each
object file can correctly make these symbols which will abstract us from the
file format and ABI and we can then ask for the objective C class symbol for
a class and find out which object file it was defined in.

llvm-svn: 145744
2011-12-03 02:30:59 +00:00
Sean Callanan e0a64f7302 Modified clients of ClangASTImporter to be more robust
in the face of failures to import types, since blithely
passing on NULL types can sometimes lead to trouble.

Also eliminated a use of getAs and replaced it with
dyn_cast, which is more robust.

llvm-svn: 145628
2011-12-01 21:04:37 +00:00
Sean Callanan a5230ce303 Picked up a new revision of Clang to pull in Objective-C
enhancements.  With these enhancements, the return values
of Objective-C methods with unknown return types can be
implicitly cast to id for the purpose of making method
calls.

So what would have required this:

(int)[(id)[ClassWithNoDebugInfo methodReturningObject] methodReturningInt]

can now be written as:

(int)[[ClassWithNoDebugInfo methodReturningObject] methodReturningInt]

llvm-svn: 145567
2011-12-01 04:31:46 +00:00
Greg Clayton eaeaf6f906 <rdar://problem/10507811>
Avoid a crash for the new DW_OP_stack_value and DW_OP_implicit_value opcodes
that was due to an assertion.

llvm-svn: 145564
2011-12-01 04:06:15 +00:00
Jim Ingham f220d59399 If we are going to assert due to an unhanded opcode, stuff the opcode value into the CrashReporter string first.
llvm-svn: 145558
2011-12-01 03:01:30 +00:00
Sean Callanan 947ccc7396 Made symbol lookup in the expression parser more
robust:

- Now a client can specify what kind of symbols
  are needed; notably, this allows looking up
  Objective-C class symbols specifically.

- In the class of symbols being looked up, if
  one is non-NULL and others are NULL, LLDB now
  prefers the non-NULL one.

llvm-svn: 145554
2011-12-01 02:04:16 +00:00
Johnny Chen 60e2c6aa43 rdar://problem/10501020
ClangASTSource::~ClangASTSource() was calling

    ClangASTContext *scratch_clang_ast_context = m_target->GetScratchClangASTContext();

which had the side effect of deleting this very ClangASTSource instance.  Not good.
Change it to

    // We are in the process of destruction, don't create clang ast context on demand
    // by passing false to Target::GetScratchClangASTContext(create_on_demand).
    ClangASTContext *scratch_clang_ast_context = m_target->GetScratchClangASTContext(false);

The Target::GetScratchClangASTContext(bool create_on_demand=true) has a new signature.

llvm-svn: 145537
2011-11-30 23:18:53 +00:00
Sean Callanan 09ab4b777c Added support to the Objective-C language runtime
to find Objective-C class types by looking in the
symbol tables for the individual object files.

I did this as follows:

- I added code to SymbolFileSymtab that vends
  Clang types for symbols matching the pattern
  "_OBJC_CLASS_$_NSMyClassName," making them
  appear as Objective-C classes.  This only occurs
  in modules that do not have debug information,
  since otherwise SymbolFileDWARF would be in
  charge of looking up types.

- I made a new SymbolVendor subclass for the
  Apple Objective-C runtime that is in charge of
  making global lookups of Objective-C types.  It
  currently just sends out type lookup requests to
  the appropriate SymbolFiles, but in the future we
  will probably extend it to query the runtime more
  completely.

I also modified a testcase whose behavior is changed
by the fact that we now actually return an Objective-C
type for __NSCFString.

llvm-svn: 145526
2011-11-30 22:11:59 +00:00
Sean Callanan 0712f46f4f Modified ClangExpressionDeclMap to use existing
ValueObjects when creating variables referring to
live data rather than constructing
ValueObjectConstResults.

llvm-svn: 145437
2011-11-29 22:03:21 +00:00
Sean Callanan 9973231fb0 Changed ClangASTImporter to allow finer-grained
management of what allocations remain after an
expression finishes executing.  This saves around
2.5KiB per expression for simple expressions.

llvm-svn: 145342
2011-11-29 00:42:02 +00:00
Sean Callanan 7f27d6044e Pulled in a new revision of LLVM/Clang and added
several patches.  These patches fix a problem
where templated types were not being completed the
first time they were used, and fix a variety of
minor issues I discovered while fixing that problem.

One of the previous local patches was resolved in
the most recent Clang, so I removed it.  The others
will be removed in due course.

llvm-svn: 144984
2011-11-19 02:54:21 +00:00
Sean Callanan 00f43622e1 This commit completes the rearchitecting of ClangASTSource
to allow variables in the persistent variable store to know
how to complete themselves from debug information.  That
fixes a variety of bugs during dematerialization of 
expression results and also makes persistent variable and
result variables ($foo, $4, ...) more useful.

I have also added logging improvements that make it much
easier to figure out how types are moving from place to 
place, and made some checking a little more aggressive.

The commit includes patches to Clang which are currently being
integrated into Clang proper; once these fixes are in Clang
top-of-tree, these patches will be removed.  The patches don't
fix API; rather, they fix some internal bugs in Clang's 
ASTImporter that were exposed when LLDB was moving types from
place to place multiple times.

llvm-svn: 144969
2011-11-18 03:28:09 +00:00