Commit Graph

4277 Commits

Author SHA1 Message Date
Johnny Chen 9dad8ae6c6 Fix typos.
llvm-svn: 149710
2012-02-03 20:50:56 +00:00
Johnny Chen 15f247ad8c Add test cases for APIs to get template arguments from an SBType.
llvm-svn: 149707
2012-02-03 20:43:00 +00:00
Enrico Granata 4cee9e5247 Fixing issues where synthetic children providers for STL containers std::list and std::map where not doing their job properly
llvm-svn: 149700
2012-02-03 18:11:52 +00:00
Greg Clayton 7edbdfc97c Expose more convenience functionality in the python classes.
lldb.SBValueList now exposes the len() method and also allows item access:

lldb.SBValueList[<int>] - where <int> is an integer index into the list, returns a single lldb.SBValue which might be empty if the index is out of range
lldb.SBValueList[<str>] - where <str> is the name to look for, returns a list() of lldb.SBValue objects with any matching values (the list might be empty if nothing matches)
lldb.SBValueList[<re>]  - where <re> is a compiles regular expression, returns a list of lldb.SBValue objects for containing any matches or a empty list if nothing matches

lldb.SBFrame now exposes:

lldb.SBFrame.variables => SBValueList of all variables that are in scope
lldb.SBFrame.vars => see lldb.SBFrame.variables
lldb.SBFrame.locals => SBValueList of all variables that are locals in the current frame
lldb.SBFrame.arguments => SBValueList of all variables that are arguments in the current frame
lldb.SBFrame.args => see lldb.SBFrame.arguments
lldb.SBFrame.statics => SBValueList of all static variables
lldb.SBFrame.registers => SBValueList of all registers for the current frame
lldb.SBFrame.regs => see lldb.SBFrame.registers

Combine any of the above properties with the new lldb.SBValueList functionality
and now you can do:

y = lldb.frame.vars['rect.origin.y']

or

vars = lldb.frame.vars
for i in range len(vars):
  print vars[i]

Also expose "lldb.SBFrame.var(<str>)" where <str> can be en expression path
for any variable or child within the variable. This makes it easier to get a
value from the current frame like "rect.origin.y". The resulting value is also
not a constant result as expressions will return, but a live value that will
continue to track the current value for the variable expression path.

lldb.SBValue now exposes:

lldb.SBValue.unsigned => unsigned integer for the value
lldb.SBValue.signed => a signed integer for the value

llvm-svn: 149684
2012-02-03 07:02:37 +00:00
Greg Clayton 9a142cf84d Fixed casting in the lldb::SBValue::Cast(SBType) function.
llvm-svn: 149673
2012-02-03 05:34:10 +00:00
Greg Clayton b62bb8cedc Cleaned up the documentation strings for many helper objects and added
lldb.SBModule.section and lldb.SBModule.sections property access.

llvm-svn: 149665
2012-02-03 03:22:53 +00:00
Enrico Granata 1d261d1c0c Adding support for an "equivalents map". This can be useful when compilers emit multiple, different names for the same actual type. In such scenarios, one of the type names can actually be found during a type lookup, while the others are just aliases. This can cause issues when trying to work with these aliased names and being unable to resolve them to an actual type (e.g. getting an SBType for the aliased name).
Currently, no code is using this feature, since we can hopefully rely on the new template support in SBType to get the same stuff done, but the support is there just in case it turns out to be useful for some future need.

llvm-svn: 149661
2012-02-03 01:41:25 +00:00
Greg Clayton 402230e633 Added support to SBType for getting template arguments from a SBType:
uint32_t
SBType::GetNumberOfTemplateArguments ();

lldb::SBType
SBType::GetTemplateArgumentType (uint32_t idx);

lldb::TemplateArgumentKind
SBType::GetTemplateArgumentKind (uint32_t idx);

Some lldb::TemplateArgumentKind values don't have a corresponding SBType
that will be returned from SBType::GetTemplateArgumentType(). This will
help our data formatters do their job by being able to find out the
type of template params and do smart things with those.

llvm-svn: 149658
2012-02-03 01:30:30 +00:00
Johnny Chen 60b4f13c11 Add a couple of simple completion test cases for 'target ' and 'target va'.
llvm-svn: 149656
2012-02-03 01:14:42 +00:00
Enrico Granata a6a60d0d87 Added a new --omit-names (-O, uppercase letter o) option to "type summary add".
When used in conjunction with --inline-children, this option will cause the names of the values to be omitted from the output. This can be beneficial in cases such as vFloat, where it will compact the representation from
([0]=1,[1]=2,[2]=3,[3]=4) to (1, 2, 3, 4).
Added a test case to check that the new option works correctly.
Also took some time to revisit SummaryFormat and related classes and tweak them for added readability and maintainability.
Finally, added a new class name to which the std::string summary should be applied.

llvm-svn: 149644
2012-02-02 23:34:52 +00:00
Johnny Chen 04ef9492fd Should have used the convenience function:
bool
lldb_private::StateIsStoppedState (StateType state, bool must_exist)

instead.

llvm-svn: 149637
2012-02-02 22:11:13 +00:00
Johnny Chen fd72fbef41 For processes which are not in one of the "launched and stopped" state, 'target variable' command
should use Target::ReadMemory() call to read from the file section offset address.
Also remove the @expectedFailure decorator..

'target variable' command fails if the target program has been run
rdar://problem/9763907

llvm-svn: 149629
2012-02-02 19:55:18 +00:00
Greg Clayton f571b89054 Fixed terminal settings not being properly restored when "quit" was run.
This affected bash users.

llvm-svn: 149623
2012-02-02 19:28:31 +00:00
Greg Clayton fb640c2d4c Kill our child process that we launch when we can't get the task_for_pid()
otherwise we will have a launched process stopped at the entry point and
it will get reparented when debugserver goes away and we won't be able to
kill the process later.

llvm-svn: 149622
2012-02-02 19:23:22 +00:00
Greg Clayton ff7692a867 Fixed a build breakage when trying to assign a shared pointer using a raw pointer.
llvm-svn: 149609
2012-02-02 18:16:59 +00:00
Enrico Granata 9d2063e49e ensure that changes to the typemaps are properly detected and cause SWIG to rebuild LLDBWrapPython.cpp
llvm-svn: 149606
2012-02-02 17:26:00 +00:00
Greg Clayton 890ff5615a Fixed an issue where we might accept the wrong type when completing
a type when we have a forward declaration. We always have found a 
type by basename, but now we also compare the decl context of the 
die we are trying to complete with the matches we find from the accelerator
tables to ensure we get the right one.

llvm-svn: 149593
2012-02-02 05:48:16 +00:00
Greg Clayton 43484c5cd7 When outputting hex values use unsigned integer values so we don't get
negative hex values. Also added a very rudimentary version of the == and !=
operators to the lldb.value helper class.

llvm-svn: 149564
2012-02-02 00:12:47 +00:00
Johnny Chen ccfa90a5fe Fix indentation.
llvm-svn: 149529
2012-02-01 19:35:55 +00:00
Johnny Chen fdad6794ac Add const-ness to BreakpointLocation::IsEnabled().
llvm-svn: 149523
2012-02-01 19:05:20 +00:00
Johnny Chen 3cfb9c672c Add @expectedFailure decorators.
llvm-svn: 149519
2012-02-01 18:26:25 +00:00
Greg Clayton 6b2bd93918 Added many more python convenience accessors:
You can now access a frame in a thread using:

lldb.SBThread.frame[int] -> lldb.SBFrame object for a frame in a thread

Where "int" is an integer index. You can also access a list object with all of
the frames using:

lldb.SBThread.frames => list() of lldb.SBFrame objects

All SB objects that give out SBAddress objects have properties named "addr"

lldb.SBInstructionList now has the following convenience accessors for len() and
instruction access using an index:

insts = lldb.frame.function.instructions
for idx in range(len(insts)):
    print insts[idx]
    
Instruction lists can also lookup an isntruction using a lldb.SBAddress as the key:

pc_inst = lldb.frame.function.instructions[lldb.frame.addr]

lldb.SBProcess now exposes:

lldb.SBProcess.is_alive => BOOL Check if a process is exists and is alive
lldb.SBProcess.is_running => BOOL check if a process is running (or stepping):
lldb.SBProcess.is_running => BOOL check if a process is currently stopped or crashed:
lldb.SBProcess.thread[int] => lldb.SBThreads for a given "int" zero based index
lldb.SBProcess.threads => list() containing all lldb.SBThread objects in a process

SBInstruction now exposes:
lldb.SBInstruction.mnemonic => python string for instruction mnemonic
lldb.SBInstruction.operands => python string for instruction operands
lldb.SBInstruction.command => python string for instruction comment

SBModule now exposes:

lldb.SBModule.uuid => uuid.UUID(), an UUID object from the "uuid" python module
lldb.SBModule.symbol[int] => lldb.Symbol, lookup symbol by zero based index
lldb.SBModule.symbol[str] => list() of lldb.Symbol objects that match "str"
lldb.SBModule.symbol[re] => list() of lldb.Symbol objecxts that match the regex
lldb.SBModule.symbols => list() of all symbols in a module

  
SBAddress objects can now access the current load address with the "lldb.SBAddress.load_addr"
property. The current "lldb.target" will be used to try and resolve the load address.

Load addresses can also be set using this accessor:

addr = lldb.SBAddress()
addd.load_addr = 0x123023

Then you can check the section and offset to see if the address got resolved.

SBTarget now exposes:

lldb.SBTarget.module[int] => lldb.SBModule from zero based module index
lldb.SBTarget.module[str] => lldb.SBModule by basename or fullpath or uuid string
lldb.SBTarget.module[uuid.UUID()] => lldb.SBModule whose UUID matches
lldb.SBTarget.module[re] => list() of lldb.SBModule objects that match the regex
lldb.SBTarget.modules => list() of all lldb.SBModule objects in the target

SBSymbol now exposes:

lldb.SBSymbol.name => python string for demangled symbol name
lldb.SBSymbol.mangled => python string for mangled symbol name or None if there is none
lldb.SBSymbol.type => lldb.eSymbolType enum value
lldb.SBSymbol.addr => SBAddress object that represents the start address for this symbol (if there is one)
lldb.SBSymbol.end_addr => SBAddress for the end address of the symbol  (if there is one)
lldb.SBSymbol.prologue_size => pythin int containing The size of the prologue in bytes
lldb.SBSymbol.instructions => SBInstructionList containing all instructions for this symbol

SBFunction now also has these new properties in addition to what is already has:
lldb.SBFunction.addr => SBAddress object that represents the start address for this function
lldb.SBFunction.end_addr => SBAddress for the end address of the function
lldb.SBFunction.instructions => SBInstructionList containing all instructions for this function

SBFrame now exposes the SBAddress for the frame:
lldb.SBFrame.addr => SBAddress which is the section offset address for the current frame PC

These are all in addition to what was already added. Documentation and website
updates coming soon.

llvm-svn: 149489
2012-02-01 08:09:32 +00:00
Greg Clayton 2415586faa Added a new convenience property on lldb.SBThread names "frames" which always returns a complete list of all lldb.SBFrame objects:
(lldb) script
>>> frames = lldb.thread.frames
>>> for frame in frames:
...   print frame

Also changed all of the "__repr__" methods to strip any trailing newline characters so we don't end up with entra newlines.

llvm-svn: 149466
2012-02-01 02:30:27 +00:00
Johnny Chen fdc80a5cf7 lldb should warn when dSYM does not match the binary.
o Symbols.cpp:

  Emit a warning message when dSYM does not match the binary.

o warnings/uuid:

  Added regression test case.

o lldbtest.py:

  Modified to allow test case writer to demand that the build command does not begin
  with a clean first; required to make TestUUIDMismatchWanring.py work.

rdar://problem/10515708

llvm-svn: 149465
2012-02-01 01:49:50 +00:00
Greg Clayton 05e8d19446 Added a new class to the lldb python module:
lldb.value()

It it designed to be given a lldb.SBValue object and it allows natural
use of a variable value:

    pt = lldb.value(lldb.frame.FindVariable("pt"))
    print pt
    print pt.x
    print pt.y

    pt = lldb.frame.FindVariable("rectangle_array")
    print rectangle_array[12]
    print rectangle_array[5].origin.x

Note that array access works just fine and works on arrays or pointers:

pt = lldb.frame.FindVariable("point_ptr")
print point_ptr[5].y

Also note that pointer child accesses are done using a "." instead of "->":

print point_ptr.x

llvm-svn: 149464
2012-02-01 01:46:19 +00:00
Enrico Granata 8680c713a6 remove spurious leftover code from std::list testcase
llvm-svn: 149461
2012-02-01 00:43:33 +00:00
Greg Clayton fbf1b64173 Added fuzz testing for when we call API calls with an invalid object.
We previously weren't catching that SBValue::Cast(...) would crash
if we had an invalid (empty) SBValue object.

Cleaned up the SBType API a bit.

llvm-svn: 149447
2012-01-31 23:19:33 +00:00
Jim Ingham 92087d8607 Threads now store their "temporary" resume state, so we know whether they were suspended in the most
recent step, and if they weren't allowed to run, don't ask questions about their state unless explicitly
requested to do so.

llvm-svn: 149443
2012-01-31 23:09:20 +00:00
Enrico Granata 896e4bd7d5 Test case for std::map synthetic children provider (currently an expected failure)
llvm-svn: 149421
2012-01-31 21:30:00 +00:00
Enrico Granata 726fa56fcb Test case for std::list synthetic children provider (currently an expected failure)
llvm-svn: 149420
2012-01-31 21:27:09 +00:00
Enrico Granata d197e7b24f Test case for std::vector synthetic children provider
llvm-svn: 149419
2012-01-31 21:03:57 +00:00
Enrico Granata 56a27bb5fa Splitting test case for Python synthetic children: part 1 test is only testing the synthetic children feature itself. More test cases will be commited for individual STL containers
llvm-svn: 149393
2012-01-31 17:50:00 +00:00
Enrico Granata 7b59f755f4 Comments edited to better reflect what the function really does
llvm-svn: 149390
2012-01-31 17:18:40 +00:00
Enrico Granata bac45f610d This commit provides a new default summary for Objective-C boolean variables, which shows YES or NO instead of the character value. A new category named objc is added to contain this summary provider. Any future Objective-C related formatters would probably fit here
llvm-svn: 149388
2012-01-31 17:01:51 +00:00
Greg Clayton 74d4193e2f Cleaned up the Communication class when it tears down ConnectionFileDescriptor
instances to not pthread_cancel the read threads and wreak havoc on the mutex
in our ConnectionFileDescriptor class.

Also cleaned up some shutdown delays.

llvm-svn: 149355
2012-01-31 04:56:17 +00:00
Greg Clayton ef496d5c4d <rdar://problem/10776614>
Fixed an issue where we can crash if you call cast when the SBValue
doesn't contain a valid value.

llvm-svn: 149345
2012-01-31 04:25:15 +00:00
Enrico Granata cff58989d7 quick fixes for two issues that were causing LLDB to crash
llvm-svn: 149338
2012-01-31 02:21:45 +00:00
Johnny Chen 6b68c98f7d Add some more test cases for the "watchpoint set" command.
llvm-svn: 149324
2012-01-31 01:26:28 +00:00
Johnny Chen 5d0d607b6b Add a period.
llvm-svn: 149305
2012-01-31 00:48:02 +00:00
Johnny Chen 8f8a2a7774 Add a '-u ENV_VAR_NAME' option to the test driver, whose purpose is to unset the said
environment variable before starting the test runner which executes the test cases and
may spawn child processes.  An example:

    ./dotest.py -u MY_ENV1 -u MY_ENV2 -v -p TestWatchLocationWithWatchSet.py

llvm-svn: 149304
2012-01-31 00:38:03 +00:00
Johnny Chen 3926837056 Trivial indentation change.
llvm-svn: 149297
2012-01-30 23:26:57 +00:00
Johnny Chen 5b3b5f07fe Fixed a typo in the test case. Updated comment.
llvm-svn: 149295
2012-01-30 23:17:07 +00:00
Johnny Chen 50df1f96dc Reverted 149277 changeset. It was coded that way for a reason.
llvm-svn: 149292
2012-01-30 22:48:10 +00:00
Johnny Chen dedb67ab9b Add "watch set" command as a more general interface in conjunction with "frame var -w".
Also add test cases for watching a variable as well as a location expressed as an expression.

o TestMyFirstWatchpoint.py:

  Modified to test "watchpoint set -w write global".

o TestWatchLocationWithWatchSet.py:

  Added to test "watchpoint set -w write -x 1 g_char_ptr + 7" where a contrived example program
  with several threads is supposed to only access the array index within the range [0..6], but
  there's some misbehaving thread writing past the range.

rdar://problem/10701761

llvm-svn: 149280
2012-01-30 21:46:17 +00:00
Johnny Chen a5822c0501 Make BreakpointLocation::IsEnabled() consistent with the BreakpointLocation::SetEnabled() implementation.
llvm-svn: 149277
2012-01-30 21:16:22 +00:00
Greg Clayton 0a94b6614a Added a new lldb.SBValue helper module that has two classes:
sbvalue.value (<SBValue>)
sbvalue.variable (<SBValue>)

Initialize both with a lldb.SBValue

sbvalue.value() make all sorts of convenience properties. Type "help(sbvalue.value)" 
in the embedded python interpreter to see what is available.

sbvalue.variable() wraps a lldb.SBValue and allows you to play with your variable just
as you would expect:

pt = sbvalue.variable (lldb.frame.FindVariable("pt"))

print pt.x
print py.y

argv = sbvalue.variable (lldb.frame.FindVariable("argv"))
print argv[0]

Member access and array acccess is all taken care of!

llvm-svn: 149260
2012-01-30 19:32:25 +00:00
Greg Clayton acdbe81637 lldb::SBTarget and lldb::SBProcess are now thread hardened. They both still
contain shared pointers to the lldb_private::Target and lldb_private::Process
objects respectively as we won't want the target or process just going away.

Also cleaned up the lldb::SBModule to remove dangerous pointer accessors.

For any code the public API files, we should always be grabbing shared 
pointers to any objects for the current class, and any other classes prior
to running code with them.

llvm-svn: 149238
2012-01-30 09:04:36 +00:00
Greg Clayton b9556acc9e SBFrame is now threadsafe using some extra tricks. One issue is that stack
frames might go away (the object itself, not the actual logical frame) when
we are single stepping due to the way we currently sometimes end up flushing
frames when stepping in/out/over. They later will come back to life 
represented by another object yet they have the same StackID. Now when you get
a lldb::SBFrame object, it will track the frame it is initialized with until 
the thread goes away or the StackID no longer exists in the stack for the 
thread it was created on. It uses a weak_ptr to both the frame and thread and
also stores the StackID. These three items allow us to determine when the
stack frame object has gone away (the weak_ptr will be NULL) and allows us to
find the correct frame again. In our test suite we had such cases where we
were just getting lucky when something like this happened:

1 - stop at breakpoint
2 - get first frame in thread where we stopped
3 - run an expression that causes the program to JIT and run code
4 - run more expressions on the frame from step 2 which was very very luckily
    still around inside a shared pointer, yet, not part of the current 
    thread (a new stack frame object had appeared with the same stack ID and
    depth). 
    
We now avoid all such issues and properly keep up to date, or we start 
returning errors when the frame doesn't exist and always responds with
invalid answers.

Also fixed the UserSettingsController  (not going to rewrite this just yet)
so that it doesn't crash on shutdown. Using weak_ptr's came in real handy to
track when the master controller has already gone away and this allowed me to
pull out the previous NotifyOwnerIsShuttingDown() patch as it is no longer 
needed.

llvm-svn: 149231
2012-01-30 07:41:31 +00:00
Greg Clayton 17a6ad05c1 Removed the "lldb-forward-rtti.h" header file as it was designed to contain
all RTTI types, and since we don't use RTTI anymore since clang and llvm don't
we don't really need this header file. All shared pointer definitions have
been moved into "lldb-forward.h".

Defined std::tr1::weak_ptr definitions for all of the types that inherit from
enable_shared_from_this() in "lldb-forward.h" in preparation for thread
hardening our public API.

The first in the thread hardening check-ins. First we start with SBThread.
We have issues in our lldb::SB API right now where if you have one object
that is being used by two threads we have a race condition. Consider the
following code:

 1    int
 2    SBThread::SomeFunction()
 3    {
 4        int result = -1;
 5        if (m_opaque_sp)
 6        {
 7            result = m_opaque_sp->DoSomething();
 8        }
 9        return result;
10    }

And now this happens:

Thread 1 enters any SBThread function and checks its m_opaque_sp and is about
to execute the code on line 7 but hasn't yet
Thread 2 gets to run and class sb_thread.Clear() which calls m_opaque_sp.clear()
and clears the contents of the shared pointer member
Thread 1 now crashes when it resumes.

The solution is to use std::tr1::weak_ptr. Now the SBThread class contains a
lldb::ThreadWP (weak pointer to our lldb_private::Thread class) and this 
function would look like:

 1    int
 2    SBThread::SomeFunction()
 3    {
 4        int result = -1;
 5        ThreadSP thread_sp(m_opaque_wp.lock());
 6        if (thread_sp)
 7        {
 8            result = m_opaque_sp->DoSomething();
 9        }
10        return result;
11    }

Now we have a solid thread safe API where we get a local copy of our thread
shared pointer from our weak_ptr and then we are guaranteed it can't go away
during our function.

So lldb::SBThread has been thread hardened, more checkins to follow shortly.

llvm-svn: 149218
2012-01-30 02:53:15 +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