Commit Graph

115 Commits

Author SHA1 Message Date
Greg Clayton b29e6c6e84 Patch from Andrew Kaylor that fixes Linux default host triple values.
llvm-svn: 165728
2012-10-11 17:38:58 +00:00
Jason Molenda 0a72520f22 Patch from Dan Malea to fix a build break I introduced yesterday.
Thanks again Dan!

llvm-svn: 165519
2012-10-09 18:40:44 +00:00
Enrico Granata 21dfcd9d41 Implementing plugins that provide commands.
This checkin adds the capability for LLDB to load plugins from external dylibs that can provide new commands
It exports an SBCommand class from the public API layer, and a new SBCommandPluginInterface

There is a minimal load-only plugin manager built into the debugger, which can be accessed via Debugger::LoadPlugin.

Plugins are loaded from two locations at debugger startup (LLDB.framework/Resources/PlugIns and ~/Library/Application Support/LLDB/PlugIns) and more can be (re)loaded via the "plugin load" command

For an example of how to make a plugin, refer to the fooplugin.cpp file in examples/plugins/commands

Caveats:
	Currently, the new API objects and features are not exposed via Python.
	The new commands can only be "parsed" (i.e. not raw) and get their command line via a char** parameter (we do not expose our internal Args object)
	There is no unloading feature, which can potentially lead to leaks if you overwrite the commands by reloading the same or different plugins
	There is no API exposed for option parsing, which means you may need to use getopt or roll-your-own

llvm-svn: 164865
2012-09-28 23:57:51 +00:00
Greg Clayton c8f814d1df Added the ability to download a symboled executable and symbol file given a UUID.
llvm-svn: 164753
2012-09-27 03:13:55 +00:00
Greg Clayton 813ddfcdd0 <rdar://problem/12219840>
Don't leak mach ports when calling "mach_thread_self()".

llvm-svn: 164152
2012-09-18 18:19:49 +00:00
Greg Clayton 103f02820d <rdar://problem/11374963>
Partial fix for the above radar where we now resolve dsym mach-o files within the dSYM bundle when using "add-dsym" through the platform.

llvm-svn: 163676
2012-09-12 02:03:59 +00:00
Greg Clayton 542e407581 Patch from Andrew Kaylor for linux:
The attached patch adds support for debugging 32-bit processes when running a 64-bit lldb on an x86_64 Linux system.
 
Making this work required two basic changes:
 
1)      Getting lldb to report that it could debug 32-bit processes
2)      Changing an assumption about how ptrace works when debugging cross-platform
 
For the first change, I took a conservative approach and only enabled this for x86_64 Linux platforms.  It may be that the change I made in Host.cpp could be extended to other 64-bit Linux platforms, but I'm not familiar enough with the other platforms to know for sure.
 
For the second change, the Linux ProcessMonitor class was assuming that ptrace(PTRACE_[PEEK|POKE]DATA...) would read/write a "word" based on the child process word size.  However, the ptrace documentation says that the "word" size read or written is "determined by the OS variant."  I verified experimentally that when ptracing a 32-bit child from a 64-bit parent a 64-bit word is read or written.

llvm-svn: 163398
2012-09-07 17:49:29 +00:00
Greg Clayton 0b0b512fd6 OptionValueFileSpec had an accessor to read the contents of the file and return the data. This can end up being used to get the string contents of a text file and could end up not being NULL terminated. I added accessors to get the file contents raw, or with a null terminator. Added the needed calls to make this happen in the FileSpec and File classes.
llvm-svn: 162921
2012-08-30 18:15:10 +00:00
Greg Clayton 1f7460716b <rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file". 
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()

Cleaned up header includes a bit as well.

llvm-svn: 162860
2012-08-29 21:13:06 +00:00
Greg Clayton 67cc06366c Reimplemented the code that backed the "settings" in lldb. There were many issues with the previous implementation:
- no setting auto completion
- very manual and error prone way of getting/setting variables
- tons of code duplication
- useless instance names for processes, threads

Now settings can easily be defined like option values. The new settings makes use of the "OptionValue" classes so we can re-use the option value code that we use to set settings in command options. No more instances, just "does the right thing".

llvm-svn: 162366
2012-08-22 17:17:09 +00:00
Filipe Cabecinhas cffbd09a56 Make glibc and its developers happy. Circumvent the lack of strlcat in glibc.
llvm-svn: 160979
2012-07-30 18:56:10 +00:00
Filipe Cabecinhas 0b75116ae9 Fixed ePathTypePythonDir for Linux and FreeBSD (at least). This works for non-installed compilations. I will test further.
llvm-svn: 160963
2012-07-30 16:46:32 +00:00
Greg Clayton 23f59509a8 Ran the static analyzer on the codebase and found a few things.
llvm-svn: 160338
2012-07-17 03:23:13 +00:00
Filipe Cabecinhas 2ada3104ec Fixed errors and warnings on debug code.
llvm-svn: 159929
2012-07-09 13:34:19 +00:00
Jim Ingham 4ceb928f02 Change the Mutex::Locker class so that it takes the Mutex object and locks it, rather
than being given the pthread_mutex_t from the Mutex and locks that.  That allows us to
track ownership of the Mutex better.  

Used this to switch the LLDB_CONFIGURATION_DEBUG enabled assert when we can't get the
gdb-remote sequence mutex to assert when the thread that had the mutex releases it.  This
is generally more useful information than saying just who failed to get it (since the
code that had it locked often had released it by the time the assert fired.)

llvm-svn: 158240
2012-06-08 22:50:40 +00:00
Filipe Cabecinhas 721ba3ff77 Fixes the case where we created a dummy target, deleted it, and then tried to evaluate an expression with no target.
llvm-svn: 157110
2012-05-19 09:59:08 +00:00
Filipe Cabecinhas b018345ddc We shouldn't save g_dummy_target_sp. Other code will simply call Destroy() on it.
TestBackticksWithoutATarget.BackticksWithNoTargetTestCase was calling
GetDummyTarget() when executing for x86_64. When performing session
tearDown, it would get destroyed (and everything would be invalid (arch,
etc).

Then the test would run for i386. The dummy target wasn't being
reinitialized and was invalid. lldb complained that 'current process state
is unsuitable for expression parsing'.

llvm-svn: 156994
2012-05-17 15:48:02 +00:00
Greg Clayton 8910c90cdc <rdar://problem/11451919>
Fixed the test suite not working on i386 due to recent default arch detection changes.

llvm-svn: 156796
2012-05-15 02:44:13 +00:00
Greg Clayton 1a362fbb86 <rdar://problem/11439169>
"lldb -a i386" doesn't set the calculator mode correctly if run on a 64 bit system. 

The previous logic always used the current host architecture, not the default architecture. The default arch gets set into a static varaible in lldb_private::Target when an arch is set from the command line:

lldb -a i386

We now use the default arch correctly.

llvm-svn: 156680
2012-05-12 00:26:42 +00:00
Greg Clayton 950971f77c <rdar://problem/11439022>
Restore expressions with no target.

llvm-svn: 156669
2012-05-12 00:01:21 +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 c075ecd833 Fix a think in Mutex::Locker::Locker(pthread_mutex_t *) Really should lock the mutex handed in, not the m_mutex_ptr that you've set to NULL...
Rework the Host.cpp::ThreadNameAccessor to use ThreadSafeSTLMap - we've got it so we might as well use it.  Also works around a problem with the
Mutex::Locker class raising fallacious asserts in debug mode when used with pthread_mutex_t's that weren't backed by Mutex objects.

llvm-svn: 156193
2012-05-04 19:24:49 +00:00
Greg Clayton d1cf11a74d Added a new host function that allows us to run shell command and get the output from them along with the status and signal:
Error
Host::RunShellCommand (const char *command,
                       const char *working_dir,
                       int *status_ptr,
                       int *signo_ptr,
                       std::string *command_output_ptr,
                       uint32_t timeout_sec);

This will allow us to use this functionality in the host lldb_private::Platform, and also use it in our lldb-platform binary. It leverages the existing code in Host::LaunchProcess and ProcessLaunchInfo.

llvm-svn: 154730
2012-04-14 01:42:46 +00:00
Sean Callanan 2a7d20405d Made sure that the collections of mutexes used in
checking for LLDB mutex validity are static so
that entries put in there actually persist between
calls to error_check_mutex.

llvm-svn: 154727
2012-04-14 01:05:29 +00:00
Jim Ingham 99ff2c42f6 In debug mode, assert if we haven't initialized a mutex we thought we'd initialized.
llvm-svn: 154710
2012-04-13 23:28:33 +00:00
Greg Clayton ce7d345a57 Added more complete error checking for mutexes only for "Debug" builds where we always check if a mutex is valid prior to doing stuff with it. We also track when mutexes are initialized and destroyed and keep these in sets that can very subsequent pthread_mutex_XXX API calls.
llvm-svn: 154637
2012-04-13 00:21:53 +00:00
Greg Clayton 37a0a24a5f No functionality changes, mostly cleanup.
Cleaned up the Mutex::Locker and the ReadWriteLock classes a bit.

Also cleaned up the GDBRemoteCommunication class to not have so many packet functions. Used the "NoLock" versions of send/receive packet functions when possible for a bit of performance.

llvm-svn: 154458
2012-04-11 00:24:49 +00:00
Jason Molenda b9e88d4186 Fix a integer trauction issue - calculating the current time in
nanoseconds in 32-bit expression would cause pthread_cond_timedwait
to time out immediately.  Add explicit casts to the TimeValue::TimeValue
ctor that takes a struct timeval and change the NanoSecsPerSec etc
constants defined in TimeValue to be uint64_t so any other calculations
involving these should be promoted to 64-bit even when lldb is built
for 32-bit.

<rdar://problem/11204073>, <rdar://problem/11179821>, <rdar://problem/11194705>.

llvm-svn: 154250
2012-04-07 04:55:02 +00:00
Jim Ingham 372787fc19 We sometimes need to be able to call functions (via Process::RunThreadPlan) from code run on the private state thread. To do that we have to
spin up a temporary "private state thread" that will respond to events from the lower level process plugins.  This check-in should work to do
that, but it is still buggy.  However, if you don't call functions on the private state thread, these changes make no difference.

This patch also moves the code in the AppleObjCRuntime step-through-trampoline handler that might call functions (in the case where the debug
server doesn't support the memory allocate/deallocate packet) out to a safe place to do that call.

llvm-svn: 154230
2012-04-07 00:00:41 +00:00
Greg Clayton b9a01b3990 Made a ModuleSpec class in Module.h which can specify a module using one or
more of the local path, platform path, associated symbol file, UUID, arch,
object name and object offset. This allows many of the calls that were
GetSharedModule to reduce the number of arguments that were used in a call
to these functions. It also allows a module to be created with a ModuleSpec
which allows many things to be specified prior to any accessors being called
on the Module class itself. 

I was running into problems when adding support for "target symbol add"
where you can specify a stand alone debug info file after debugging has started
where I needed to specify the associated symbol file path and if I waited until
after construction, the wrong  symbol file had already been located. By using
the ModuleSpec it allows us to construct a module with as little or as much
information as needed and not have to change the parameter list.

llvm-svn: 151476
2012-02-26 05:51:37 +00:00
Han Ming Ong 846470482c <rdar://problem/3535148>
Added ability to debug root processes on OS X. This uses XPC service that is available on Lion and above only.

llvm-svn: 151419
2012-02-25 01:07:38 +00:00
Greg Clayton c859e2d524 Full core file support has been added for mach-o core files.
Tracking modules down when you have a UUID and a path has been improved.

DynamicLoaderDarwinKernel no longer parses mach-o load commands and it
now uses the memory based modules now that we can load modules from memory.

Added a target setting named "target.exec-search-paths" which can be used
to supply a list of directories to use when trying to look for executables.
This allows one or more directories to be used when searching for modules
that may not exist in the SDK/PDK. The target automatically adds the directory
for the main executable to this list so this should help us in tracking down
shared libraries and other binaries. 

llvm-svn: 150426
2012-02-13 23:10:39 +00:00
Johnny Chen f8f0fd765e Fix typo.
llvm-svn: 149140
2012-01-27 18:53:22 +00:00
Greg Clayton ecc6116950 Enable extra error checking for debug builds in our mutexes by
watching for errors from pthread_mutex_destroy () (usually "Resource
busy" errors for when you have a mutex locked and try to destroy
it), and pthread_mutex_lock, and pthread_mutex_unlock (usually for
trying to lock an invalid mutex that might have possible already
been freed).

llvm-svn: 149135
2012-01-27 18:29:47 +00:00
Greg Clayton 4017fa399b <rdar://problem/10652336>
Fixed a crasher when trying to load an expression prefix file:

% touch /tmp/carp.txt
% xcrun lldb
(lldb) settings set target.expr-prefix /tmp/carp.txt
Segmentation fault

llvm-svn: 147646
2012-01-06 02:01:06 +00:00
Greg Clayton e38a5edd9e Added code in the Host layer that can report system log messages
so that we don't have "fprintf (stderr, ...)" calls sprinkled everywhere.
Changed all needed locations over to using this.

For non-darwin, we log to stderr only. On darwin, we log to stderr _and_
to ASL (Apple System Log facility). This will allow GUI apps to have a place
for these error and warning messages to go, and also allows the command line
apps to log directly to the terminal.

llvm-svn: 147596
2012-01-05 03:57:59 +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
Greg Clayton 1c4cd07aff Now that I fixed the uninitialized callback problem, I can enable GCD pid
monitoring on darwin in the host layer.

llvm-svn: 144918
2011-11-17 19:41:57 +00:00
Greg Clayton e4e45924d7 Made the darwin host layer properly reap any child processes that it spawns.
After recent changes we weren't reaping child processes resulting in many
zombie processes. 

This was fixed by adding more settings to the ProcessLaunchOptions class
that allow clients to specify a callback function and baton to be notified
when their process dies. If one is not supplied a default callback will be
used that "does the right thing". 

Cleaned up a race condition in the ProcessGDBRemote class that would attempt
to monitor when debugserver died. 

Added an extra boolean to the process monitor callbacks that indicate if a
process exited or not. If your process exited with a zero exit status and no
signal, both items could be zero.

Modified the process monitor functions to not require a callback function
in order to reap the child process.

llvm-svn: 144780
2011-11-16 05:37:56 +00:00
Peter Collingbourne 1f6198d404 Update a missed getHostTriple call, fixes non-__APPLE__ build
llvm-svn: 143774
2011-11-05 01:35:31 +00:00
Benjamin Kramer 44030f12f1 Fix linux build after r143679.
llvm-svn: 143703
2011-11-04 16:06:40 +00:00
Greg Clayton 0ddf6be103 Fixed a build issue on an older Xcode.
llvm-svn: 143679
2011-11-04 03:42:38 +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
Benjamin Kramer f82d8064d4 The alpha and system z backends were removed.
llvm-svn: 143613
2011-11-03 12:13:52 +00:00
Sean Callanan c0a6e0619d Added a function to the Host that gets a dummy target
for it, so that people who want to use LLDB as a
calculator can run simple expressions without needing
a target or process.

llvm-svn: 143147
2011-10-27 21:22:25 +00:00
Greg Clayton 86edbf41d1 Cleaned up many error codes. For any who is filling in error strings into
lldb_private::Error objects the rules are:
- short strings that don't start with a capitol letter unless the name is a
  class or anything else that is always capitolized
- no trailing newline character
- should be one line if possible

Implemented a first pass at adding "--gdb-format" support to anything that
accepts format with optional size/count.

llvm-svn: 142999
2011-10-26 00:56:27 +00:00
Johnny Chen f5df537d26 Fix build under gcc.
Patch from Dawn.

llvm-svn: 142402
2011-10-18 19:28:30 +00:00
Enrico Granata a9dbf4325e this patch introduces a new command script import command which takes as input a filename for a Python script and imports the module contained in that file. the containing directory is added to the Python path such that dependencies are honored. also, the module may contain an __lldb_init_module(debugger,dict) function, which gets called after importing, and which can somehow initialize the module's interaction with lldb
llvm-svn: 142283
2011-10-17 21:45:27 +00:00
Jim Ingham 87df91b866 Added the ability to restrict breakpoints by function name, function regexp, selector
etc to specific source files.
Added SB API's to specify these source files & also more than one module.
Added an "exact" option to CompileUnit's FindLineEntry API.

llvm-svn: 140362
2011-09-23 00:54:11 +00:00
Greg Clayton 6372d1cda2 Changed to using an "operator bool" instead of an "operator void*"
and avoid returning a pointer to the current object. In the new 
"operator bool" implementation, check the filename object first 
since many times we have FileSpec objects with a filename, yet no
directory.

llvm-svn: 139488
2011-09-12 04:00:42 +00:00