Commit Graph

67 Commits

Author SHA1 Message Date
Jim Ingham 12e9a2012f Track whether a process was Launched or Attached to. If Attached, the detach when the debugger is destroyed, rather than killing the process. Also added a Debugger::Clear, which gets called in Debugger::Destroy to deal with all the targets in the Debugger. Also made the Driver's main loop call Destroy on the debugger, rather than just Destroying the currently selected Target's process.
llvm-svn: 139852
2011-09-15 21:30:02 +00:00
Jim Ingham e64f0dc7bf Adding "-n", "-p" and "-w" flags to the lldb command-line tool to
allow attaching from the command line.

llvm-svn: 139665
2011-09-13 23:25:31 +00:00
Jim Ingham e37d605e7d SBSourceManager now gets the real source manager either from the Debugger or Target. Also, move the SourceManager file cache into the debugger
so it can be shared amongst the targets.

llvm-svn: 139564
2011-09-13 00:29:56 +00:00
Jim Ingham a9deaf971d Better help string for "lldb -- file arg1 arg2..."
llvm-svn: 137789
2011-08-16 23:57:58 +00:00
Jim Ingham 556e653b6a Document how to pass program args to lldb command-line.
llvm-svn: 137784
2011-08-16 23:15:02 +00:00
Jim Ingham 06942690b1 Add a version of SBDebugger::Create which allows us to specify whether to source
in the init files or not.

llvm-svn: 137541
2011-08-13 00:22:20 +00:00
Jason Molenda 7efc7e949c Fixes the occasional crash on exit when quitting lldb with control-D.
If the IOChannel has already freed out its m_driver member, and
there's still a character to be read/written (that is, the ^D
character), just skip that char instead of trying to write through
a null object pointer.

llvm-svn: 137421
2011-08-12 02:40:17 +00:00
Johnny Chen 25f3a3cde2 Incremental fixes of issues found by Xcode static analyzer.
llvm-svn: 137257
2011-08-10 22:06:24 +00:00
Jim Ingham 7d6811d60e Remove some commented out code that doesn't connect to anything yet...
llvm-svn: 137081
2011-08-09 00:26:56 +00:00
Johnny Chen 8f3d8384be Patch by David Forsythe to build lldb on FreeBSD!
I did not take the patch for ClangExpressionParser.cpp since there was a
recent change by Peter for the same line.  Feel free to disagree. :-)

Reference:
----------------------------------------------------------------------
r136580 | pcc | 2011-07-30 15:42:24 -0700 (Sat, 30 Jul 2011) | 3 lines

Add reloc arg to standard JIT createJIT()

Fixes non-__APPLE__ build.  Patch by Matt Johnson!
----------------------------------------------------------------------

Also, I ignore the part of the patch to remove the RegisterContextDarwin*.h/.cpp.

llvm-svn: 136720
2011-08-02 20:52:42 +00:00
Jim Ingham a5a97ebe3c Added "command history" command to dump the command history.
Also made:
(lldb) !<NUM>
(lldb) !-<NUM>
(lldb) !!

work with the history.  For added benefit:

(lldb) !<NUM><TAB>

will insert the command at position <NUM> in the history into the command line to be edited.

This is only partial, I still need to sync up editline's history list with the one kept by the interpreter.

llvm-svn: 134955
2011-07-12 03:12:18 +00:00
Greg Clayton fc3f027d33 Don't have the debugger default to ignoring EOF. This is only what the driver
(or anything running in a terminal) wants. Not what a UI (Xcode) would want 
where it creates a debugger per debug window. The current code had an infinite
loop after a debug session ended. 

llvm-svn: 132280
2011-05-29 04:06:55 +00:00
Caroline Tice b5059acc5f Fix places that were writing directly to the debugger's output
handles to go through the appropriate channels instead.

llvm-svn: 131415
2011-05-16 19:20:50 +00:00
Caroline Tice 9088b06899 Make sure writing asynchronous output only backs up
& overwrites prompt if the IOChannel input reader is the top
input reader.

llvm-svn: 131110
2011-05-09 23:06:58 +00:00
Caroline Tice 0de8d4503b Add ability to search backwards through command
history for a particular substring, using ctrl-r key.

llvm-svn: 130871
2011-05-04 21:39:02 +00:00
Caroline Tice fe1bdf291f Minor cleanup: When asynchronous output comes along,
back up over and delete the prompt before writing out the
asynchronous output, rather than just going to a new line.

llvm-svn: 130843
2011-05-04 16:44:57 +00:00
Caroline Tice 86a73f9007 Make the driver listen for asynchronous output, rather than
the IOChannel, so that it can be written out even while the
IOChannel is collecting user input.

llvm-svn: 130789
2011-05-03 20:53:11 +00:00
Caroline Tice 969ed3d10f This patch captures and serializes all output being written by the
command line driver, including the lldb prompt being output by
editline, the asynchronous process output & error messages, and
asynchronous messages written by target stop-hooks.

As part of this it introduces a new Stream class,
StreamAsynchronousIO.  A StreamAsynchronousIO object is created with a
broadcaster, who will eventually broadcast the stream's data for a
listener to handle, and an event type indicating what type of event
the broadcaster will broadcast.  When the Write method is called on a
StreamAsynchronousIO object, the data is appended to an internal
string.  When the Flush method is called on a StreamAsynchronousIO
object, it broadcasts it's data string and clears the string.

Anything in lldb-core that needs to generate asynchronous output for
the end-user should use the StreamAsynchronousIO objects.

I have also added a new notification type for InputReaders, to let
them know that a asynchronous output has been written. This is to
allow the input readers to, for example, refresh their prompts and
lines, if desired.  I added the case statements to all the input
readers to catch this notification, but I haven't added any code for
handling them yet (except to the IOChannel input reader).

llvm-svn: 130721
2011-05-02 20:41:46 +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
Greg Clayton ab65b34fdc Added auto completion for architecture names and for platforms.
Modified the OptionGroupOptions to be able to specify only some of the options
that should be appended by using the usage_mask in the group defintions and
also provided a way to remap them to a new usage mask after the copy. This 
allows options to be re-used and also targetted for specific option groups.

Modfied the CommandArgumentType to have a new eArgTypePlatform enumeration.
Taught the option parser to be able to automatically use the appropriate
auto completion for a given options if nothing is explicitly specified
in the option definition. So you don't have to specify it in the option
definition tables.

Renamed the default host platform name to "host", and the default platform
hostname to be "localhost".

Modified the "file" and "platform select" commands to make sure all options
and args are good prior to creating a new platform. Also defer the computation
of the architecture in the file command until all options are parsed and the
platform has either not been specified or reset to a new value to avoid
computing the arch more than once.

Switch the PluginManager code over to using llvm::StringRef for string
comparisons and got rid of all the AccessorXXX functions in lieu of the newer
mutex + collection singleton accessors.

llvm-svn: 129483
2011-04-13 22:47:15 +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
Greg Clayton e0d378b334 Fixed the LLDB build so that we can have private types, private enums and
public types and public enums. This was done to keep the SWIG stuff from
parsing all sorts of enums and types that weren't needed, and allows us to
abstract our API better.

llvm-svn: 128239
2011-03-24 21:19:54 +00:00
Stephen Wilson d7b15bd6b7 Fix makefile builds when llvm is configured with -enable-shared.
We were dropping the expansion of -rpath=$(LibDir) on linux, which resulted in
the build not being able to resolve libLLVM.so.  Bring in the definition before
expanding the values hanging off LD.Flags.

Thanks to Jason E. Aten for reporting this!

llvm-svn: 127570
2011-03-13 18:17:16 +00:00
Greg Clayton e996fd30be LLDB now has "Platform" plug-ins. Platform plug-ins are plug-ins that provide
an interface to a local or remote debugging platform. By default each host OS
that supports LLDB should be registering a "default" platform that will be
used unless a new platform is selected. Platforms are responsible for things
such as:
- getting process information by name or by processs ID
- finding platform files. This is useful for remote debugging where there is 
  an SDK with files that might already or need to be cached for debug access.
- getting a list of platform supported architectures in the exact order they
  should be selected. This helps the native x86 platform on MacOSX select the
  correct x86_64/i386 slice from universal binaries.
- Connect to remote platforms for remote debugging
- Resolving an executable including finding an executable inside platform
  specific bundles (macosx uses .app bundles that contain files) and also
  selecting the appropriate slice of universal files for a given platform.

So by default there is always a local platform, but remote platforms can be
connected to. I will soon be adding a new "platform" command that will support
the following commands:
(lldb) platform connect --name machine1 macosx connect://host:port
Connected to "machine1" platform.
(lldb) platform disconnect macosx

This allows LLDB to be well setup to do remote debugging and also once 
connected process listing and finding for things like:
(lldb) process attach --name x<TAB>

The currently selected platform plug-in can now auto complete any available
processes that start with "x". The responsibilities for the platform plug-in
will soon grow and expand.

llvm-svn: 127286
2011-03-08 22:40:15 +00:00
Greg Clayton 9d0402b1eb Don't limit StreamTee to just two streams. It now can contain
N streams by making the stream a vector of stream shared pointers
that is protected by a mutex. Streams can be get/set by index which
allows indexes to be defined as stream indentifiers. If a stream is
set at index 3 and there are now streams in the collection, then
empty stream objects are inserted to ensure that stream at index 3
has a valid stream. There is also an append method that allows a stream
to be pushed onto the stack. This will allow our streams to be very
flexible in where the output goes.

Modified the CommandReturnObject to use the new StreamTee functionality.
This class now defines two StreamTee indexes: 0 for the stream string
stream, and 1 for the immediate stream. This is used both on the output
and error streams.

Added the ability to get argument types as strings or as descriptions.
This is exported through the SBCommandInterpreter API to allow external
access.

Modified the Driver class to use the newly exported argument names from
SBCommandInterpreter::GetArgumentTypeAsCString().

llvm-svn: 126067
2011-02-20 02:15:07 +00:00
Jim Ingham 85e8b81492 - Changed all the places where CommandObjectReturn was exporting a StreamString to just exporting
a Stream, and then added GetOutputData & GetErrorData to get the accumulated data.
- Added a StreamTee that will tee output to two provided lldb::StreamSP's.
- Made the CommandObjectReturn use this so you can Tee the results immediately to
the debuggers output file, as well as saving up the results to return when the command
is done executing.
- HandleCommands now uses this so that if you have a set of commands that continue the target
you will see the commands come out as they are processed.
- The Driver now uses this to output the command results as you go, which makes the interface
more reactive seeming.

llvm-svn: 126015
2011-02-19 02:53:09 +00:00
Greg Clayton 2da6d49523 Patch that allows for thread_t to be something more complex than an
integer. Modified patch from Kirk Beitz.

llvm-svn: 125067
2011-02-08 01:34:25 +00:00
Greg Clayton 6083026822 Applied a fix to qualify "UUID" with the lldb_private namespace to fix
build issues on MinGW.

llvm-svn: 124888
2011-02-04 18:53:10 +00:00
Greg Clayton b766a73dfc Added support for attaching to a remote debug server with the new command:
(lldb) process connect <remote-url>

Currently when you specify a file with the file command it helps us to find
a process plug-in that is suitable for debugging. If you specify a file you
can rely upon this to find the correct debugger plug-in:

% lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) process connect connect://localhost:2345
...

If you don't specify a file, you will need to specify the plug-in name that
you wish to use:

% lldb
(lldb) process connect --plugin process.gdb-remote connect://localhost:2345

Other connection URL examples:

(lldb) process connect connect://localhost:2345
(lldb) process connect tcp://127.0.0.1
(lldb) process connect file:///dev/ttyS1

We are currently treating the "connect://host:port" as a way to do raw socket
connections. If there is a URL for this already, please let me know and we
will adopt it.

So now you can connect to a remote debug server with the ProcessGDBRemote
plug-in. After connection, it will ask for the pid info using the "qC" packet
and if it responds with a valid process ID, it will be equivalent to attaching.
If it response with an error or invalid process ID, the LLDB process will be
in a new state: eStateConnected. This allows us to then download a program or
specify the program to run (using the 'A' packet), or specify a process to
attach to (using the "vAttach" packets), or query info about the processes
that might be available.

llvm-svn: 124846
2011-02-04 01:58:07 +00:00
Jim Ingham a462f5cc07 Adding a Xcode workspace for lldb.
llvm-svn: 124416
2011-01-27 20:15:39 +00:00
Greg Clayton 8d846daa81 Any arguments that are not options to the "lldb" command line driver, now get
used as the arguments for the inferior program. So for example you can do

% lldb /bin/ls /tmp ~/Documents

And "lldb" will use "/bin/ls" as the program and send arguments "/tmp" and
"~/Documents" as the launch args.

If you specify a file, then all remaining args after option parsing
will be used for program arguments:

% lldb -f /bin/ls /tmp ~/Documents

If you need to pass option values to your inferior program, just terminate
the "lldb" command line driver options with "--":

% lldb -- /bin/ls -AFl /tmp

The arguments are placed into the "settings" variable named 
"target.process.run-args". This allows you to just run the program using
"process launch" and, if no args are specified on that command, the 
"target.process.run-args" values will be used:

% lldb -- /bin/ls -AFl /tmp
Current executable set to '/bin/ls' (x86_64).
(lldb) settings show target.process.run-args 
target.process.run-args (array):
  [0]: '-AFl'
  [1]: '/tmp'
(lldb) 
(lldb) r
Process 56753 launched: '/bin/ls' (x86_64)
lrwxr-xr-x@ 1 root  wheel  11 Nov 19  2009 /tmp@ -> private/tmp

llvm-svn: 121295
2010-12-08 22:23:24 +00:00
Greg Clayton d46c87a1a8 More reverting of the EOF stuff as the API was changed which we don't want to
do. Closing on EOF is an option that can be set on the 
lldb_private::Communication or the lldb::SBCommunication objects after they
are created. Of course the EOF support isn't hooked up, so they don't do 
anything at the moment, but they are left in so when the code is fixed, it 
will be easy to get working again.

llvm-svn: 120885
2010-12-04 02:39:47 +00:00
Caroline Tice 82305fc59a Add proper EOF handling to Communication & Connection classes:
Add bool member to Communication class indicating whether the
Connection should be closed on receiving an EOF or not.  Update the
Connection read to return an EOF status when appropriate.  Modify the
Communication class to pass the EOF along or not, and to close the
Connection or not, as appropriate.

llvm-svn: 120723
2010-12-02 18:31:56 +00:00
Caroline Tice efed613172 Add the ability to catch and do the right thing with Interrupts (often control-c)
and end-of-file (often control-d).

llvm-svn: 119837
2010-11-19 20:47:54 +00:00
Greg Clayton 2ccf8cfc4b Modified the DWARF parser for both the single DWARF file and for the case
where the DWARF is in the .o files so they can track down the actual type for
a forward declaration. This was working before for just DWARF files, but not
for DWARF in .o files where the actual definition was in another .o file.

Modified the main thread name in the driver to be more consistent with the
other LLDB thread names.

llvm-svn: 118383
2010-11-07 21:02:03 +00:00
Greg Clayton 3fcbed6bda Stop the driver from handling SIGPIPE in case we communicate with stale
sockets so the driver doesn't just crash.

Added support for connecting to named sockets (unix IPC sockets) in
ConnectionFileDescriptor.

Modified the Host::LaunchInNewTerminal() for MacOSX to return the process
ID of the inferior process instead of the process ID of the Terminal.app. This
was done by modifying the "darwin-debug" executable to connect to lldb through
a named unix socket which is passed down as an argument. This allows a quick
handshake between "lldb" and "darwin-debug" so we can get the process ID
of the inferior and then attach by process ID and avoid attaching to the 
inferior by process name since there could be more than one process with 
that name. This still has possible race conditions, those will be fixed
in the near future. This fixes the SIGPIPE issues that were sometimes being
seen when task_for_pid was failing.

llvm-svn: 116792
2010-10-19 03:25:40 +00:00
Caroline Tice 4ab31c98e6 Fix some memory leaks.
Add call to lldb.SBDebugger.Initialize() to lldb.py, so it automatically gets called when
the lldb Python module gets loaded.

llvm-svn: 116345
2010-10-12 21:57:09 +00:00
Greg Clayton e46dd32b69 Exit if the command line is started with "--help".
llvm-svn: 116180
2010-10-11 01:13:37 +00:00
Greg Clayton 6eee5aa067 Added a "--no-lldbinit" option (-n for short (which magically matches
what gdb uses)) so we can tell our "lldb" driver program to not automatically
parse any .lldbinit files. 

llvm-svn: 116179
2010-10-11 01:05:37 +00:00
Caroline Tice deaab2220e Modify command options to use the new arguments mechanism. Now all command option
arguments are specified in a standardized way, will have a standardized name, and
have functioning help.

The next step is to start writing useful help for all the argument types.

llvm-svn: 115335
2010-10-01 19:59:14 +00:00
Caroline Tice bd13b8d5ce Fix various timing/threading problems in IOChannel & Driver that
were causing the prompt to be stomped on, mangled or omitted occasionally.

llvm-svn: 115059
2010-09-29 18:35:42 +00:00
Greg Clayton a701509229 Fixed the way set/show variables were being accessed to being natively
accessed by the objects that own the settings. The previous approach wasn't
very usable and made for a lot of unnecessary code just to access variables
that were already owned by the objects.

While I fixed those things, I saw that CommandObject objects should really
have a reference to their command interpreter so they can access the terminal
with if they want to output usaage. Fixed up all CommandObjects to take
an interpreter and cleaned up the API to not need the interpreter to be
passed in.

Fixed the disassemble command to output the usage if no options are passed
down and arguments are passed (all disassebmle variants take options, there
are no "args only").

llvm-svn: 114252
2010-09-18 01:14:36 +00:00
Caroline Tice 428a9a58fa If the file the user specifies can't be found in the current directory,
and the user didn't specify a particular directory, search for the file 
using the $PATH environment variable.

llvm-svn: 113575
2010-09-10 04:48:55 +00:00
Caroline Tice dd7598578f Make API calls for setting/getting user settable variables static.
Modify Driver to handle SIGWINCH signals and automatically re-set the
term-width variable.

llvm-svn: 113506
2010-09-09 17:45:09 +00:00
Greg Clayton b0458249cf Fixed a buffer overrun error that could occur every time the program was run due to a "sprintf" with a destination string that was too short.
llvm-svn: 113180
2010-09-06 23:04:11 +00:00
Greg Clayton f7c0fd8dc8 Fixed an error where a random string would get executed after a recent fix that checked if the window column size was zero was added on the lldb driver startup.
llvm-svn: 113179
2010-09-06 23:01:25 +00:00
Caroline Tice 3df9a8dfd7 This is a very large commit that completely re-does the way lldb
handles user settable internal variables (the equivalent of set/show
variables in gdb).  In addition to the basic infrastructure (most of
which is defined in UserSettingsController.{h,cpp}, there are examples
of two classes that have been set up to contain user settable
variables (the Debugger and Process classes).  The 'settings' command
has been modified to be a command-subcommand structure, and the 'set',
'show' and 'append' commands have been moved into this sub-commabnd
structure.  The old StateVariable class has been completely replaced
by this, and the state variable dictionary has been removed from the
Command Interpreter.  Places that formerly accessed the state variable
mechanism have been modified to access the variables in this new
structure instead (checking the term-width; getting/checking the
prompt; etc.)

Variables are attached to classes; there are two basic "flavors" of
variables that can be set: "global" variables (static/class-wide), and
"instance" variables (one per instance of the class).  The whole thing
has been set up so that any global or instance variable can be set at
any time (e.g. on start up, in your .lldbinit file), whether or not
any instances actually exist (there's a whole pending and default
values mechanism to help deal with that).

llvm-svn: 113041
2010-09-04 00:03:46 +00:00
Jim Ingham 6d56d2ce84 Move "variable list" to "frame variable"
llvm-svn: 112782
2010-09-02 00:18:39 +00:00
Jim Ingham e40e42181f Added a way to open the current source file & line in an external editor, and you can turn this on with:
lldb -e

llvm-svn: 112502
2010-08-30 19:44:40 +00:00
Johnny Chen 23fd10cb4e o Exposed SBFileSpec to the Python APIs in lldb.py.
o Fixed a crasher when getting it via SBTarget.GetExecutable().

>>> filespec = target.GetExecutable()
Segmentation fault

o And renamed SBFileSpec::GetFileName() to GetFilename() to be consistent with FileSpec::GetFilename().

llvm-svn: 112308
2010-08-27 22:35:26 +00:00