Commit Graph

60 Commits

Author SHA1 Message Date
Ryan Brown 65d4d5c3c6 Add an OperatingSystem plugin to support goroutines
The Go runtime schedules user level threads (goroutines) across real threads.
This adds an OS plugin to create memory threads for goroutines.
It supports the 1.4 and 1.5 go runtime.

Differential Revision: http://reviews.llvm.org/D5871

llvm-svn: 247852
2015-09-16 21:20:44 +00:00
Tamas Berghammer 25b9f7ebd3 Use eAddressClassCode for address lookup for opcodes for stack frames
It is required because of the following edge case on arm:

bx <addr>   Non-tail call in a no return function
[data-pool] Marked with $d mapping symbol

The return address of the function call will point to the data pool but
we have to treat it as code so the StackFrame can calculate the symbols
correctly.

Differential revision: http://reviews.llvm.org/D12556

llvm-svn: 246958
2015-09-07 09:58:09 +00:00
Tamas Berghammer 0f8452ba2e Fix address adjusment in stack frame inline block lookup
When the current address is pointing 1 (unit) over the end of a
section the we have to do a section lookup after making the adjusment
of the current address.

Differential revision: http://reviews.llvm.org/D10124

llvm-svn: 238737
2015-06-01 10:38:23 +00:00
Ed Maste ff1b5c4244 Add null RegisterContext assertions
This makes these failures slightly more obvious, avoiding the need to
run LLDB under a debugger or rely on a LLDB core.  I encountered these
while bringing up a new OS/arch combination.

llvm-svn: 230236
2015-02-23 18:12:20 +00:00
Greg Clayton 8012cadbf3 Fixed more fallout from running the test suite remotely on iOS devices.
Fixed include:
- Change Platform::ResolveExecutable(...) to take a ModuleSpec instead of a FileSpec + ArchSpec to help resolve executables correctly when we have just a path + UUID (no arch).
- Add the ability to set the listener in SBLaunchInfo and SBAttachInfo in case you don't want to use the debugger as the default listener. 
- Modified all places that use the SBLaunchInfo/SBAttachInfo and the internal ProcessLaunchInfo/ProcessAttachInfo to not take a listener as a parameter since it is in the launch/attach info now
- Load a module's sections by default when removing a module from a target. Since we create JIT modules for expressions and helper functions, we could end up with stale data in the section load list if a module was removed from the target as the section load list would still have entries for the unloaded module. Target now has the following functions to help unload all sections a single or multiple modules:

    size_t
    Target::UnloadModuleSections (const ModuleList &module_list);

    size_t
    Target::UnloadModuleSections (const lldb::ModuleSP &module_sp);

llvm-svn: 222167
2014-11-17 19:39:20 +00:00
Bruce Mitchener aaa0ba31a9 Fix typos.
llvm-svn: 212553
2014-07-08 18:05:41 +00:00
Saleem Abdulrasool 324a103619 sweep up -Wformat warnings from gcc
This is a purely mechanical change explicitly casting any parameters for printf
style conversion.  This cleans up the warnings emitted by gcc 4.8 on Linux.

llvm-svn: 205607
2014-04-04 04:06:10 +00:00
Greg Clayton ec6829eac0 Patch from Todd Fiala: lldb will seg fault if for some reason there is no unwinder when StackFrameList::GetFramesUpTo() is called.
Mainly patched to stop LLDB from crashing. This can easily happen if you debug to a remote gdbserver that doesn't have any dynamic register info and you don't have a target definition file specified.

llvm-svn: 195499
2013-11-22 21:03:42 +00:00
Jason Molenda 99618476ad Add new ivars to StackFrame so it can represent a stack collected
at some point in the past.  We may have nothing more than a pc value
for this type of stack frame -- hopefully we'll have a pc and a
stop_id so we can track module loads and unloads over time and
symbolicate the pc at the correct point in time.

Also add a flag to indicate if the CFA for the frame is available
(a bit different from a CFA of LLDB_INVALID_ADDRESS) and also an
overall setting to indicate whether this is a history stack frame
or not.  A history stack frame may not have a CFA, it may not have
a register context, it may not have variables, it may not have a
frame pointer or a stack pointer.

<rdar://problem/15314068>

llvm-svn: 193987
2013-11-04 11:02:52 +00:00
Jason Molenda b57e4a1bc6 Roll back the changes I made in r193907 which created a new Frame
pure virtual base class and made StackFrame a subclass of that.  As
I started to build on top of that arrangement today, I found that it
wasn't working out like I intended.  Instead I'll try sticking with
the single StackFrame class -- there's too much code duplication to
make a more complicated class hierarchy sensible I think.

llvm-svn: 193983
2013-11-04 09:33:30 +00:00
Jason Molenda f23bf7432c Add a new base class, Frame. It is a pure virtual function which
defines a protocol that all subclasses will implement.  StackFrame
is currently the only subclass and the methods that Frame vends are
nearly identical to StackFrame's old methods.

Update all callers to use Frame*/Frame& instead of pointers to
StackFrames.

This is almost entirely a mechanical change that touches a lot of
the code base so I'm committing it alone.  No new functionality is
added with this patch, no new subclasses of Frame exist yet.

I'll probably need to tweak some of the separation, possibly moving
some of StackFrame's methods up in to Frame, but this is a good
starting point.

<rdar://problem/15314068>

llvm-svn: 193907
2013-11-02 02:23:02 +00:00
Jim Ingham 8ec10efc5d Mark the selected frame of the selected thread in backtraces.
<rdar://problem/15252474>

llvm-svn: 192989
2013-10-18 17:38:31 +00:00
Greg Clayton 7bcb93d5a5 <rdar://problem/13643315>
Fixed performance issues that arose after changing SBTarget, SBProcess, SBThread and SBFrame over to using a std::shared_ptr to a ExecutionContextRef. The ExecutionContextRef doesn't store a std::weak_ptr to a stack frame because stack frames often get replaced with new version, so it held onto a StackID object that would allow us to ask the thread each time for the frame for the StackID. The linear function was too slow for large recursive stacks. We also fixed an issue where anytime the std::shared_ptr<ExecutionContextRef> in any SBTarget, SBProcess, SBThread objects was turned into an ExecutionContext object, it would try to resolve all items in the ExecutionContext which are shared pointers. Even if the StackID in the ExecutionContextRef was invalid, it was looking through all frames in every thread. This causes a lot of unnecessary frame accesses.

llvm-svn: 182627
2013-05-24 00:58:29 +00:00
Greg Clayton 7b0992d9cd After discussing with Chris Lattner, we require C++11, so lets get rid of the macros and just use C++11.
llvm-svn: 179805
2013-04-18 22:45:39 +00:00
Greg Clayton e01e07b6e7 Since we use C++11, we should switch over to using std::unique_ptr when C++11 is being used. To do this, we follow what we have done for shared pointers and we define a STD_UNIQUE_PTR macro that can be used and it will "do the right thing". Due to some API differences in std::unique_ptr and due to the fact that we need to be able to compile without C++11, we can't use move semantics so some code needed to change so that it can compile with either C++.
Anyone wanting to use a unique_ptr or auto_ptr should now use the "STD_UNIQUE_PTR(TYPE)" macro.

llvm-svn: 179779
2013-04-18 18:10:51 +00:00
Greg Clayton b3ae876174 <rdar://problem/13491977>
Made some fixes to the OperatingSystemPython class:
- If any thread dictionary contains any "core=N" key/value pairs then the threads obtained from the lldb_private::Process itself will be placed inside the ThreadMemory threads and will be used to get the information for a thread. 
- Cleaned up all the places where a thread inside a thread was causing problems

llvm-svn: 179405
2013-04-12 20:07:46 +00:00
Greg Clayton ca5ce187fa Be sure to take the mutex when the destructor is called in case other threads are using these lists and those other threads have the mutex locked.
llvm-svn: 178262
2013-03-28 18:41:44 +00:00
Jim Ingham 5cb9a184e0 Protect against the case where the current inlined depth is wrong, and leads us to think we can't even get the
frame at index 0.  We should ALWAYS be able to get that.

<rdar://problem/13497571>

llvm-svn: 178205
2013-03-28 00:13:30 +00:00
Greg Clayton 5160ce5c72 <rdar://problem/13521159>
LLDB is crashing when logging is enabled from lldb-perf-clang. This has to do with the global destructor chain as the process and its threads are being torn down.

All logging channels now make one and only one instance that is kept in a global pointer which is never freed. This guarantees that logging can correctly continue as the process tears itself down.

llvm-svn: 178191
2013-03-27 23:08:40 +00:00
Enrico Granata ebafd2f187 <rdar://problem/13194155>
Fixing an issue where threads and frames could get out of sync and cause ValueObjects to fail to retrieve their values correctly

llvm-svn: 177166
2013-03-15 17:25:04 +00:00
Greg Clayton 90ba81150e <rdar://problem/12649160>
Added the ability to debug through your process exec'ing itself to the same architecture.

llvm-svn: 169340
2012-12-05 00:16:59 +00:00
Daniel Malea d01b2953fa Resolve printf formatting warnings on Linux:
- use macros from inttypes.h for format strings instead of OS-specific types

Patch from Matt Kopec!

llvm-svn: 168945
2012-11-29 21:49:15 +00:00
Jim Ingham 28eb57114d Bunch of cleanups for warnings found by the llvm static analyzer.
llvm-svn: 165808
2012-10-12 17:34:26 +00:00
Jim Ingham c635500dbb Fiddle with the heuristic about where to set the stop point in a nested inline stack when we get there by breakpoint. If we hit a user breakpoint, I set the stop point to the bottom-most frame 'cause that's what we did before.
<rdar://problem/12258999> Setting breakpoint in always inline function is stopping in function above it

llvm-svn: 163439
2012-09-08 00:26:49 +00:00
Jim Ingham 6cd41da75d Add SetCurrentInlinedDepth API.
In GetFramesUpTo, don't adjust the number of frames for the inlined depth if the number of frames in UINT32_MAX.

llvm-svn: 163432
2012-09-07 23:35:54 +00:00
Jim Ingham 7da851a3e2 For now, treat breakpoint hits like regular stops when calculation InlinedStackDepth.
llvm-svn: 163365
2012-09-07 01:11:08 +00:00
Jim Ingham 9786eeeb6f When you reach the bottom of the inlined stack, don't say you can do a virtual step.
llvm-svn: 163341
2012-09-06 19:24:57 +00:00
Jim Ingham e7e6ffc600 Turn on the "fancy inlined stepping."
llvm-svn: 163246
2012-09-05 21:14:28 +00:00
Jim Ingham 513c6bb88c Initial check-in of "fancy" inlined stepping. Doesn't do anything useful unless you switch LLDB_FANCY_INLINED_STEPPING to true. With that
on, basic inlined stepping works, including step-over of inlined functions.  But for some as yet mysterious reason i386 debugging gets an
assert and dies immediately.  So for now its off.

llvm-svn: 163044
2012-09-01 01:02:41 +00:00
Greg Clayton 53eb7ad2f7 <rdar://problem/11852100>
The "stop-line-count-after" and "stop-line-count-before" settings are broken. This fixes them.

llvm-svn: 160071
2012-07-11 20:33:48 +00:00
Jim Ingham 10ebffa48a Don't expose the pthread_mutex_t underlying the Mutex & Mutex::Locker classes.
No one was using it and Locker(pthread_mutex_t *) immediately asserts for 
pthread_mutex_t's that don't come from a Mutex anyway.  Rather than try to make
that work, we should maintain the Mutex abstraction and not pass around the
platform implementation...

Make Mutex::Locker::Lock take a Mutex & or a Mutex *, and remove the constructor
taking a pthread_mutex_t *.  You no longer need to call Mutex::GetMutex to pass
your mutex to a Locker (you can't in fact, since I made it private.)

llvm-svn: 156221
2012-05-04 23:02:50 +00:00
Jim Ingham 376c485493 If the unwinder fails to make us a frame 0, make one by hand from the SP & PC.
llvm-svn: 151793
2012-03-01 02:53:40 +00:00
Jim Ingham 1692b90130 Use the correct (computed by the unwinder) CallFrameAddress as the CFA for Frame 0 rather than using the stack pointer which is not constant over the life of the frame.
llvm-svn: 151744
2012-02-29 19:58:25 +00:00
Jim Ingham b0c72a5f58 Make the StackFrameList::GetFrameAtIndex only fetch as many stack frames as needed to
get the frame requested.
<rdar://problem/10943135>

llvm-svn: 151705
2012-02-29 03:40:22 +00:00
Greg Clayton 1ac04c3088 Thread hardening part 3. Now lldb_private::Thread objects have std::weak_ptr
objects for the backlink to the lldb_private::Process. The issues we were
running into before was someone was holding onto a shared pointer to a 
lldb_private::Thread for too long, and the lldb_private::Process parent object
would get destroyed and the lldb_private::Thread had a "Process &m_process"
member which would just treat whatever memory that used to be a Process as a
valid Process. This was mostly happening for lldb_private::StackFrame objects
that had a member like "Thread &m_thread". So this completes the internal
strong/weak changes.

Documented the ExecutionContext and ExecutionContextRef classes so that our
LLDB developers can understand when and where to use ExecutionContext and 
ExecutionContextRef objects.

llvm-svn: 151009
2012-02-21 00:09:25 +00:00
Greg Clayton d9e416c0ea The second part in thread hardening the internals of LLDB where we make
the lldb_private::StackFrame objects hold onto a weak pointer to the thread
object. The lldb_private::StackFrame objects the the most volatile objects
we have as when we are doing single stepping, frames can often get lost or
thrown away, only to be re-created as another object that still refers to the
same frame. We have another bug tracking that. But we need to be able to 
have frames no longer be able to get the thread when they are not part of
a thread anymore, and this is the first step (this fix makes that possible
but doesn't implement it yet).

Also changed lldb_private::ExecutionContextScope to return shared pointers to
all objects in the execution context to further thread harden the internals.

llvm-svn: 150871
2012-02-18 05:35:26 +00:00
Greg Clayton cc4d0146b4 This checking is part one of trying to add some threading safety to our
internals. The first part of this is to use a new class:

lldb_private::ExecutionContextRef

This class holds onto weak pointers to the target, process, thread and frame
and it also contains the thread ID and frame Stack ID in case the thread and
frame objects go away and come back as new objects that represent the same
logical thread/frame. 

ExecutionContextRef objcets have accessors to access shared pointers for
the target, process, thread and frame which might return NULL if the backing
object is no longer available. This allows for references to persistent program
state without needing to hold a shared pointer to each object and potentially
keeping that object around for longer than it needs to be. 

You can also "Lock" and ExecutionContextRef (which contains weak pointers)
object into an ExecutionContext (which contains strong, or shared pointers)
with code like

ExecutionContext exe_ctx (my_obj->GetExectionContextRef().Lock());

llvm-svn: 150801
2012-02-17 07:49:44 +00:00
Greg Clayton dce502ede0 Fixed the Xcode project building of LLVM to be a bit more user friendly:
- If you download and build the sources in the Xcode project, x86_64 builds
  by default using the "llvm.zip" checkpointed LLVM.
- If you delete the "lldb/llvm.zip" and the "lldb/llvm" folder, and build the
  Xcode project will download the right LLVM sources and build them from 
  scratch
- If you have a "lldb/llvm" folder already that contains a "lldb/llvm/lib"
  directory, we will use the sources you have placed in the LLDB directory.
  
Python can now be disabled for platforms that don't support it. 

Changed the way the libllvmclang.a files get used. They now all get built into
arch specific directories and never get merged into universal binaries as this
was causing issues where you would have to go and delete the file if you wanted
to build an extra architecture slice.

llvm-svn: 143678
2011-11-04 03:34:56 +00:00
Greg Clayton 5f4c61e2d7 <rdar://problem/10226227>
Fixed the root cause of what was causing an assertion to fire during single stepping. We had an issue with the inlined stack frames where when we had inlined frames that were not in the first concrete frame where we passed the wrong PC down. We needed to decrement the PC by one for these frames to make
sure we are using the same address that did the symbol context lookup.

llvm-svn: 141349
2011-10-07 01:52:19 +00:00
Greg Clayton 252d0ede74 Fixed a crasher where the m_frames collection was being accessed without
using the mutex.

llvm-svn: 141160
2011-10-05 03:14:31 +00:00
Greg Clayton 1ed54f50c5 Cleaned up the the code that figures out the inlined stack frames given a
symbol context that represents an inlined function. This function has been
renamed internally to:

bool
SymbolContext::GetParentOfInlinedScope (const Address &curr_frame_pc, 
                                        SymbolContext &next_frame_sc, 
                                        Address &next_frame_pc) const;
                                        
And externally to:

SBSymbolContext
SBSymbolContext::GetParentOfInlinedScope (const SBAddress &curr_frame_pc, 
                                          SBAddress &parent_frame_addr) const;

The correct blocks are now correctly calculated.

Switched the stack backtracing engine (in StackFrameList) and the address
context printing over to using the internal SymbolContext::GetParentOfInlinedScope(...) 
so all inlined callstacks will match exactly.

llvm-svn: 140910
2011-10-01 00:45:15 +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
Jim Ingham b7f6b2fa3c Move the SourceManager from the Debugger to the Target. That way it can store the per-Target default Source File & Line.
Set the default Source File & line to main (if it can be found.) at startup.  Selecting the current thread & or frame resets 
the current source file & line, and "source list" as well as the breakpoint command "break set -l <NUM>" will use the 
current source file.

llvm-svn: 139323
2011-09-08 22:13:49 +00:00
Johnny Chen 2c595273e0 Fix compilation error with DEBUG_STACK_FRAMES defined, patch by Filipe Cabecinhas!
With some slight modification.

llvm-svn: 138563
2011-08-25 17:27:02 +00:00
Greg Clayton 7260f6206f Centralized a lot of the status information for processes,
threads, and stack frame down in the lldb_private::Process,
lldb_private::Thread, lldb_private::StackFrameList and the 
lldb_private::StackFrame classes. We had some command line
commands that had duplicate versions of the process status
output ("thread list" and "process status" for example). 

Removed the "file" command and placed it where it should
have been: "target create". Made an alias for "file" to
"target create" so we stay compatible with GDB commands.

We can now have multple usable targets in lldb at the
same time. This is nice for comparing two runs of a program
or debugging more than one binary at the same time. The
new command is "target select <target-idx>" and also to see
a list of the current targets you can use the new "target list"
command. The flow in a debug session can be:

(lldb) target create /path/to/exe/a.out
(lldb) breakpoint set --name main
(lldb) run
... hit breakpoint
(lldb) target create /bin/ls
(lldb) run /tmp
Process 36001 exited with status = 0 (0x00000000) 
(lldb) target list
Current targets:
  target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
* target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) target select 0
Current targets:
* target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
  target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) bt
* thread #1: tid = 0x2d03, 0x0000000100000b9a a.out`main + 42 at main.c:16, stop reason = breakpoint 1.1
  frame #0: 0x0000000100000b9a a.out`main + 42 at main.c:16
  frame #1: 0x0000000100000b64 a.out`start + 52

Above we created a target for "a.out" and ran and hit a
breakpoint at "main". Then we created a new target for /bin/ls
and ran it. Then we listed the targest and selected our original
"a.out" program, so we showed two concurent debug sessions
going on at the same time.

llvm-svn: 129695
2011-04-18 08:33:37 +00:00
Stephen Wilson 71c21d18c3 Order of initialization lists.
This patch fixes all of the warnings due to unordered initialization lists.

Patch by Marco Minutoli.

llvm-svn: 129290
2011-04-11 19:41:40 +00:00
Jim Ingham 3a195b7e78 Add GetFrameWithStackID to the StackFrameList and the Thread (which routes to its StackFrameList.)
llvm-svn: 128592
2011-03-31 00:15:49 +00:00
Greg Clayton 5ccbd294b2 Fixed issues with RegisterContext classes and the subclasses. There was
an issue with the way the UnwindLLDB was handing out RegisterContexts: it
was making shared pointers to register contexts and then handing out just
the pointers (which would get put into shared pointers in the thread and
stack frame classes) and cause double free issues. MallocScribble helped to
find these issues after I did some other cleanup. To help avoid any
RegisterContext issue in the future, all code that deals with them now
returns shared pointers to the register contexts so we don't end up with
multiple deletions. Also now that the RegisterContext class doesn't require
a stack frame, we patched a memory leak where a StackFrame object was being
created and leaked.

Made the RegisterContext class not have a pointer to a StackFrame object as
one register context class can be used for N inlined stack frames so there is
not a 1 - 1 mapping. Updates the ExecutionContextScope part of the 
RegisterContext class to never return a stack frame to indicate this when it
is asked to recreate the execution context. Now register contexts point to the
concrete frame using a concrete frame index. Concrete frames are all of the
frames that are actually formed on the stack of a thread. These concrete frames
can be turned into one or more user visible frames due to inlining. Each 
inlined stack frame has the exact same register context (shared via shared
pointers) as any parent inlined stack frames all the way up to the concrete 
frame itself.

So now the stack frames and the register contexts should behave much better.

llvm-svn: 122976
2011-01-06 22:15:06 +00:00
Greg Clayton 0603aa9dc8 There are now to new "settings set" variables that live in each debugger
instance:

settings set frame-format <string>
settings set thread-format <string>

This allows users to control the information that is seen when dumping
threads and frames. The default values are set such that they do what they
used to do prior to changing over the the user defined formats.

This allows users with terminals that can display color to make different
items different colors using the escape control codes. A few alias examples
that will colorize your thread and frame prompts are:

settings set frame-format 'frame #${frame.index}: \033[0;33m${frame.pc}\033[0m{ \033[1;4;36m${module.file.basename}\033[0;36m ${function.name}{${function.pc-offset}}\033[0m}{ \033[0;35mat \033[1;35m${line.file.basename}:${line.number}}\033[0m\n'

settings set thread-format 'thread #${thread.index}: \033[1;33mtid\033[0;33m = ${thread.id}\033[0m{, \033[0;33m${frame.pc}\033[0m}{ \033[1;4;36m${module.file.basename}\033[0;36m ${function.name}{${function.pc-offset}}\033[0m}{, \033[1;35mstop reason\033[0;35m = ${thread.stop-reason}\033[0m}{, \033[1;36mname = \033[0;36m${thread.name}\033[0m}{, \033[1;32mqueue = \033[0;32m${thread.queue}}\033[0m\n'

A quick web search for "colorize terminal output" should allow you to see what
you can do to make your output look like you want it.

The "settings set" commands above can of course be added to your ~/.lldbinit
file for permanent use.

Changed the pure virtual 
    void ExecutionContextScope::Calculate (ExecutionContext&);
To:
    void ExecutionContextScope::CalculateExecutionContext (ExecutionContext&);
    
I did this because this is a class that anything in the execution context
heirarchy inherits from and "target->Calculate (exe_ctx)" didn't always tell
you what it was really trying to do unless you look at the parameter.

llvm-svn: 115485
2010-10-04 01:05:56 +00:00
Jim Ingham e4284b719c Add GetSP to the StackFrame.
llvm-svn: 114674
2010-09-23 17:40:12 +00:00