mirror of
https://github.com/intel/llvm.git
synced 2026-01-14 11:57:39 +08:00
class now implements the Host functionality for a lot of things that make
sense by default so that subclasses can check:
int
PlatformSubclass::Foo ()
{
if (IsHost())
return Platform::Foo (); // Let the platform base class do the host specific stuff
// Platform subclass specific code...
int result = ...
return result;
}
Added new functions to the platform:
virtual const char *Platform::GetUserName (uint32_t uid);
virtual const char *Platform::GetGroupName (uint32_t gid);
The user and group names are cached locally so that remote platforms can avoid
sending packets multiple times to resolve this information.
Added the parent process ID to the ProcessInfo class.
Added a new ProcessInfoMatch class which helps us to match processes up
and changed the Host layer over to using this new class. The new class allows
us to search for processs:
1 - by name (equal to, starts with, ends with, contains, and regex)
2 - by pid
3 - And further check for parent pid == value, uid == value, gid == value,
euid == value, egid == value, arch == value, parent == value.
This is all hookup up to the "platform process list" command which required
adding dumping routines to dump process information. If the Host class
implements the process lookup routines, you can now lists processes on
your local machine:
machine1.foo.com % lldb
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
94727 244 username usergroup username usergroup x86_64-apple-darwin Xcode
92742 92710 username usergroup username usergroup i386-apple-darwin debugserver
This of course also works remotely with the lldb-platform:
machine1.foo.com % lldb-platform --listen 1234
machine2.foo.com % lldb
(lldb) platform create remote-macosx
Platform: remote-macosx
Connected: no
(lldb) platform connect connect://localhost:1444
Platform: remote-macosx
Triple: x86_64-apple-darwin
OS Version: 10.6.7 (10J869)
Kernel: Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386
Hostname: machine1.foo.com
Connected: yes
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99556 244 username usergroup username usergroup x86_64-apple-darwin trustevaluation
99548 65539 username usergroup username usergroup x86_64-apple-darwin lldb
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
The lldb-platform implements everything with the Host:: layer, so this should
"just work" for linux. I will probably be adding more stuff to the Host layer
for launching processes and attaching to processes so that this support should
eventually just work as well.
Modified the target to be able to be created with an architecture that differs
from the main executable. This is needed for iOS debugging since we can have
an "armv6" binary which can run on an "armv7" machine, so we want to be able
to do:
% lldb
(lldb) platform create remote-ios
(lldb) file --arch armv7 a.out
Where "a.out" is an armv6 executable. The platform then can correctly decide
to open all "armv7" images for all dependent shared libraries.
Modified the disassembly to show the current PC value. Example output:
(lldb) disassemble --frame
a.out`main:
0x1eb7: pushl %ebp
0x1eb8: movl %esp, %ebp
0x1eba: pushl %ebx
0x1ebb: subl $20, %esp
0x1ebe: calll 0x1ec3 ; main + 12 at test.c:18
0x1ec3: popl %ebx
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
0x1edb: leal 213(%ebx), %eax
0x1ee1: movl %eax, (%esp)
0x1ee4: calll 0x1f1e ; puts
0x1ee9: calll 0x1f0c ; getchar
0x1eee: movl $20, (%esp)
0x1ef5: calll 0x1e6a ; sleep_loop at test.c:6
0x1efa: movl $12, %eax
0x1eff: addl $20, %esp
0x1f02: popl %ebx
0x1f03: leave
0x1f04: ret
This can be handy when dealing with the new --line options that was recently
added:
(lldb) disassemble --line
a.out`main + 13 at test.c:19
18 {
-> 19 printf("Process: %i\n\n", getpid());
20 puts("Press any key to continue..."); getchar();
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
Modified the ModuleList to have a lookup based solely on a UUID. Since the
UUID is typically the MD5 checksum of a binary image, there is no need
to give the path and architecture when searching for a pre-existing
image in an image list.
Now that we support remote debugging a bit better, our lldb_private::Module
needs to be able to track what the original path for file was as the platform
knows it, as well as where the file is locally. The module has the two
following functions to retrieve both paths:
const FileSpec &Module::GetFileSpec () const;
const FileSpec &Module::GetPlatformFileSpec () const;
llvm-svn: 128563
820 lines
30 KiB
C++
820 lines
30 KiB
C++
//===-- CommandObjectBreakpointCommand.cpp ----------------------*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// C Includes
|
|
// C++ Includes
|
|
|
|
|
|
#include "CommandObjectBreakpointCommand.h"
|
|
#include "CommandObjectBreakpoint.h"
|
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
|
#include "lldb/Target/Target.h"
|
|
#include "lldb/Target/Thread.h"
|
|
#include "lldb/Breakpoint/BreakpointIDList.h"
|
|
#include "lldb/Breakpoint/Breakpoint.h"
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
|
#include "lldb/Breakpoint/StoppointCallbackContext.h"
|
|
#include "lldb/Core/State.h"
|
|
|
|
using namespace lldb;
|
|
using namespace lldb_private;
|
|
|
|
//-------------------------------------------------------------------------
|
|
// CommandObjectBreakpointCommandAdd::CommandOptions
|
|
//-------------------------------------------------------------------------
|
|
|
|
CommandObjectBreakpointCommandAdd::CommandOptions::CommandOptions () :
|
|
Options (),
|
|
m_use_commands (false),
|
|
m_use_script_language (false),
|
|
m_script_language (eScriptLanguageNone),
|
|
m_use_one_liner (false),
|
|
m_one_liner()
|
|
{
|
|
}
|
|
|
|
CommandObjectBreakpointCommandAdd::CommandOptions::~CommandOptions ()
|
|
{
|
|
}
|
|
|
|
// FIXME: "script-type" needs to have its contents determined dynamically, so somebody can add a new scripting
|
|
// language to lldb and have it pickable here without having to change this enumeration by hand and rebuild lldb proper.
|
|
|
|
static OptionEnumValueElement
|
|
g_script_option_enumeration[4] =
|
|
{
|
|
{ eScriptLanguageNone, "command", "Commands are in the lldb command interpreter language"},
|
|
{ eScriptLanguagePython, "python", "Commands are in the Python language."},
|
|
{ eSortOrderByName, "default-script", "Commands are in the default scripting language."},
|
|
{ 0, NULL, NULL }
|
|
};
|
|
|
|
OptionDefinition
|
|
CommandObjectBreakpointCommandAdd::CommandOptions::g_option_table[] =
|
|
{
|
|
{ LLDB_OPT_SET_ALL, false, "one-liner", 'o', required_argument, NULL, NULL, eArgTypeOneLiner,
|
|
"Specify a one-line breakpoint command inline. Be sure to surround it with quotes." },
|
|
|
|
{ LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', required_argument, NULL, NULL, eArgTypeBoolean,
|
|
"Specify whether breakpoint command execution should terminate on error." },
|
|
|
|
{ LLDB_OPT_SET_ALL, false, "script-type", 's', required_argument, g_script_option_enumeration, NULL, eArgTypeNone,
|
|
"Specify the language for the commands - if none is specified, the lldb command interpreter will be used."},
|
|
|
|
{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
|
|
};
|
|
|
|
const OptionDefinition*
|
|
CommandObjectBreakpointCommandAdd::CommandOptions::GetDefinitions ()
|
|
{
|
|
return g_option_table;
|
|
}
|
|
|
|
|
|
Error
|
|
CommandObjectBreakpointCommandAdd::CommandOptions::SetOptionValue
|
|
(
|
|
int option_idx,
|
|
const char *option_arg
|
|
)
|
|
{
|
|
Error error;
|
|
char short_option = (char) m_getopt_table[option_idx].val;
|
|
|
|
switch (short_option)
|
|
{
|
|
case 'o':
|
|
m_use_one_liner = true;
|
|
m_one_liner = option_arg;
|
|
break;
|
|
break;
|
|
case 's':
|
|
{
|
|
bool found_one = false;
|
|
m_script_language = (lldb::ScriptLanguage) Args::StringToOptionEnum (option_arg,
|
|
g_option_table[option_idx].enum_values,
|
|
eScriptLanguageNone,
|
|
&found_one);
|
|
if (!found_one)
|
|
error.SetErrorStringWithFormat("Invalid enumeration value '%s' for option '%c'.\n",
|
|
option_arg,
|
|
short_option);
|
|
|
|
if (m_script_language == eScriptLanguagePython || m_script_language == eScriptLanguageDefault)
|
|
{
|
|
m_use_commands = false;
|
|
m_use_script_language = true;
|
|
}
|
|
else
|
|
{
|
|
m_use_commands = true;
|
|
m_use_script_language = false;
|
|
}
|
|
}
|
|
break;
|
|
case 'e':
|
|
bool success_ptr;
|
|
m_stop_on_error = Args::StringToBoolean(option_arg, false, &success_ptr);
|
|
if (!success_ptr)
|
|
error.SetErrorStringWithFormat("Invalid value for stop-on-error: \"%s\".\n", option_arg);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return error;
|
|
}
|
|
|
|
void
|
|
CommandObjectBreakpointCommandAdd::CommandOptions::ResetOptionValues ()
|
|
{
|
|
m_use_commands = true;
|
|
m_use_script_language = false;
|
|
m_script_language = eScriptLanguageNone;
|
|
|
|
m_use_one_liner = false;
|
|
m_stop_on_error = true;
|
|
m_one_liner.clear();
|
|
}
|
|
|
|
//-------------------------------------------------------------------------
|
|
// CommandObjectBreakpointCommandAdd
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
CommandObjectBreakpointCommandAdd::CommandObjectBreakpointCommandAdd (CommandInterpreter &interpreter) :
|
|
CommandObject (interpreter,
|
|
"add",
|
|
"Add a set of commands to a breakpoint, to be executed whenever the breakpoint is hit.",
|
|
NULL)
|
|
{
|
|
SetHelpLong (
|
|
"\nGeneral information about entering breakpoint commands \n\
|
|
------------------------------------------------------ \n\
|
|
\n\
|
|
This command will cause you to be prompted to enter the command or set \n\
|
|
of commands you wish to be executed when the specified breakpoint is \n\
|
|
hit. You will be told to enter your command(s), and will see a '> ' \n\
|
|
prompt. Because you can enter one or many commands to be executed when \n\
|
|
a breakpoint is hit, you will continue to be prompted after each \n\
|
|
new-line that you enter, until you enter the word 'DONE', which will \n\
|
|
cause the commands you have entered to be stored with the breakpoint \n\
|
|
and executed when the breakpoint is hit. \n\
|
|
\n\
|
|
Syntax checking is not necessarily done when breakpoint commands are \n\
|
|
entered. An improperly written breakpoint command will attempt to get \n\
|
|
executed when the breakpoint gets hit, and usually silently fail. If \n\
|
|
your breakpoint command does not appear to be getting executed, go \n\
|
|
back and check your syntax. \n\
|
|
\n\
|
|
\n\
|
|
Special information about PYTHON breakpoint commands \n\
|
|
---------------------------------------------------- \n\
|
|
\n\
|
|
You may enter either one line of Python or multiple lines of Python \n\
|
|
(including defining whole functions, if desired). If you enter a \n\
|
|
single line of Python, that will be passed to the Python interpreter \n\
|
|
'as is' when the breakpoint gets hit. If you enter function \n\
|
|
definitions, they will be passed to the Python interpreter as soon as \n\
|
|
you finish entering the breakpoint command, and they can be called \n\
|
|
later (don't forget to add calls to them, if you want them called when \n\
|
|
the breakpoint is hit). If you enter multiple lines of Python that \n\
|
|
are not function definitions, they will be collected into a new, \n\
|
|
automatically generated Python function, and a call to the newly \n\
|
|
generated function will be attached to the breakpoint. Important \n\
|
|
Note: Because loose Python code gets collected into functions, if you \n\
|
|
want to access global variables in the 'loose' code, you need to \n\
|
|
specify that they are global, using the 'global' keyword. Be sure to \n\
|
|
use correct Python syntax, including indentation, when entering Python \n\
|
|
breakpoint commands. \n\
|
|
\n\
|
|
Example Python one-line breakpoint command: \n\
|
|
\n\
|
|
(lldb) breakpoint command add -s python 1 \n\
|
|
Enter your Python command(s). Type 'DONE' to end. \n\
|
|
> print \"Hit this breakpoint!\" \n\
|
|
> DONE \n\
|
|
\n\
|
|
As a convenience, this also works for a short Python one-liner: \n\
|
|
(lldb) breakpoint command add -s python 1 -o \"import time; print time.asctime()\" \n\
|
|
(lldb) run \n\
|
|
Launching '.../a.out' (x86_64) \n\
|
|
(lldb) Fri Sep 10 12:17:45 2010 \n\
|
|
Process 21778 Stopped \n\
|
|
* thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = breakpoint 1.1, queue = com.apple.main-thread \n\
|
|
36 \n\
|
|
37 int c(int val)\n\
|
|
38 {\n\
|
|
39 -> return val + 3;\n\
|
|
40 }\n\
|
|
41 \n\
|
|
42 int main (int argc, char const *argv[])\n\
|
|
(lldb) \n\
|
|
\n\
|
|
Example multiple line Python breakpoint command, using function definition: \n\
|
|
\n\
|
|
(lldb) breakpoint command add -s python 1 \n\
|
|
Enter your Python command(s). Type 'DONE' to end. \n\
|
|
> def breakpoint_output (bp_no): \n\
|
|
> out_string = \"Hit breakpoint number \" + repr (bp_no) \n\
|
|
> print out_string \n\
|
|
> return True \n\
|
|
> breakpoint_output (1) \n\
|
|
> DONE \n\
|
|
\n\
|
|
\n\
|
|
Example multiple line Python breakpoint command, using 'loose' Python: \n\
|
|
\n\
|
|
(lldb) breakpoint command add -s p 1 \n\
|
|
Enter your Python command(s). Type 'DONE' to end. \n\
|
|
> global bp_count \n\
|
|
> bp_count = bp_count + 1 \n\
|
|
> print \"Hit this breakpoint \" + repr(bp_count) + \" times!\" \n\
|
|
> DONE \n\
|
|
\n\
|
|
In this case, since there is a reference to a global variable, \n\
|
|
'bp_count', you will also need to make sure 'bp_count' exists and is \n\
|
|
initialized: \n\
|
|
\n\
|
|
(lldb) script \n\
|
|
>>> bp_count = 0 \n\
|
|
>>> quit() \n\
|
|
\n\
|
|
(lldb) \n\
|
|
\n\
|
|
\n\
|
|
Final Note: If you get a warning that no breakpoint command was generated, \n\
|
|
but you did not get any syntax errors, you probably forgot to add a call \n\
|
|
to your functions. \n\
|
|
\n\
|
|
Special information about debugger command breakpoint commands \n\
|
|
-------------------------------------------------------------- \n\
|
|
\n\
|
|
You may enter any debugger command, exactly as you would at the \n\
|
|
debugger prompt. You may enter as many debugger commands as you like, \n\
|
|
but do NOT enter more than one command per line. \n" );
|
|
|
|
|
|
CommandArgumentEntry arg;
|
|
CommandArgumentData bp_id_arg;
|
|
|
|
// Define the first (and only) variant of this arg.
|
|
bp_id_arg.arg_type = eArgTypeBreakpointID;
|
|
bp_id_arg.arg_repetition = eArgRepeatPlain;
|
|
|
|
// There is only one variant this argument could be; put it into the argument entry.
|
|
arg.push_back (bp_id_arg);
|
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
m_arguments.push_back (arg);
|
|
}
|
|
|
|
CommandObjectBreakpointCommandAdd::~CommandObjectBreakpointCommandAdd ()
|
|
{
|
|
}
|
|
|
|
bool
|
|
CommandObjectBreakpointCommandAdd::Execute
|
|
(
|
|
Args& command,
|
|
CommandReturnObject &result
|
|
)
|
|
{
|
|
Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
|
|
|
|
if (target == NULL)
|
|
{
|
|
result.AppendError ("There is not a current executable; there are no breakpoints to which to add commands");
|
|
result.SetStatus (eReturnStatusFailed);
|
|
return false;
|
|
}
|
|
|
|
const BreakpointList &breakpoints = target->GetBreakpointList();
|
|
size_t num_breakpoints = breakpoints.GetSize();
|
|
|
|
if (num_breakpoints == 0)
|
|
{
|
|
result.AppendError ("No breakpoints exist to have commands added");
|
|
result.SetStatus (eReturnStatusFailed);
|
|
return false;
|
|
}
|
|
|
|
BreakpointIDList valid_bp_ids;
|
|
CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
|
|
|
|
if (result.Succeeded())
|
|
{
|
|
const size_t count = valid_bp_ids.GetSize();
|
|
for (size_t i = 0; i < count; ++i)
|
|
{
|
|
BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
|
|
if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
|
|
{
|
|
Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
|
|
BreakpointOptions *bp_options = NULL;
|
|
if (cur_bp_id.GetLocationID() == LLDB_INVALID_BREAK_ID)
|
|
{
|
|
// This breakpoint does not have an associated location.
|
|
bp_options = bp->GetOptions();
|
|
}
|
|
else
|
|
{
|
|
BreakpointLocationSP bp_loc_sp(bp->FindLocationByID (cur_bp_id.GetLocationID()));
|
|
// This breakpoint does have an associated location.
|
|
// Get its breakpoint options.
|
|
if (bp_loc_sp)
|
|
bp_options = bp_loc_sp->GetLocationOptions();
|
|
}
|
|
|
|
// Skip this breakpoint if bp_options is not good.
|
|
if (bp_options == NULL) continue;
|
|
|
|
// If we are using script language, get the script interpreter
|
|
// in order to set or collect command callback. Otherwise, call
|
|
// the methods associated with this object.
|
|
if (m_options.m_use_script_language)
|
|
{
|
|
// Special handling for one-liner specified inline.
|
|
if (m_options.m_use_one_liner)
|
|
m_interpreter.GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options,
|
|
m_options.m_one_liner.c_str());
|
|
else
|
|
m_interpreter.GetScriptInterpreter()->CollectDataForBreakpointCommandCallback (bp_options,
|
|
result);
|
|
}
|
|
else
|
|
{
|
|
// Special handling for one-liner specified inline.
|
|
if (m_options.m_use_one_liner)
|
|
SetBreakpointCommandCallback (bp_options,
|
|
m_options.m_one_liner.c_str());
|
|
else
|
|
CollectDataForBreakpointCommandCallback (bp_options,
|
|
result);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return result.Succeeded();
|
|
}
|
|
|
|
Options *
|
|
CommandObjectBreakpointCommandAdd::GetOptions ()
|
|
{
|
|
return &m_options;
|
|
}
|
|
|
|
const char *g_reader_instructions = "Enter your debugger command(s). Type 'DONE' to end.";
|
|
|
|
void
|
|
CommandObjectBreakpointCommandAdd::CollectDataForBreakpointCommandCallback
|
|
(
|
|
BreakpointOptions *bp_options,
|
|
CommandReturnObject &result
|
|
)
|
|
{
|
|
InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger()));
|
|
std::auto_ptr<BreakpointOptions::CommandData> data_ap(new BreakpointOptions::CommandData());
|
|
if (reader_sp && data_ap.get())
|
|
{
|
|
BatonSP baton_sp (new BreakpointOptions::CommandBaton (data_ap.release()));
|
|
bp_options->SetCallback (CommandObjectBreakpointCommand::BreakpointOptionsCallbackFunction, baton_sp);
|
|
|
|
Error err (reader_sp->Initialize (CommandObjectBreakpointCommandAdd::GenerateBreakpointCommandCallback,
|
|
bp_options, // baton
|
|
eInputReaderGranularityLine, // token size, to pass to callback function
|
|
"DONE", // end token
|
|
"> ", // prompt
|
|
true)); // echo input
|
|
if (err.Success())
|
|
{
|
|
m_interpreter.GetDebugger().PushInputReader (reader_sp);
|
|
result.SetStatus (eReturnStatusSuccessFinishNoResult);
|
|
}
|
|
else
|
|
{
|
|
result.AppendError (err.AsCString());
|
|
result.SetStatus (eReturnStatusFailed);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result.AppendError("out of memory");
|
|
result.SetStatus (eReturnStatusFailed);
|
|
}
|
|
|
|
}
|
|
|
|
// Set a one-liner as the callback for the breakpoint.
|
|
void
|
|
CommandObjectBreakpointCommandAdd::SetBreakpointCommandCallback (BreakpointOptions *bp_options,
|
|
const char *oneliner)
|
|
{
|
|
std::auto_ptr<BreakpointOptions::CommandData> data_ap(new BreakpointOptions::CommandData());
|
|
|
|
// It's necessary to set both user_source and script_source to the oneliner.
|
|
// The former is used to generate callback description (as in breakpoint command list)
|
|
// while the latter is used for Python to interpret during the actual callback.
|
|
data_ap->user_source.AppendString (oneliner);
|
|
data_ap->script_source.AppendString (oneliner);
|
|
data_ap->stop_on_error = m_options.m_stop_on_error;
|
|
|
|
BatonSP baton_sp (new BreakpointOptions::CommandBaton (data_ap.release()));
|
|
bp_options->SetCallback (CommandObjectBreakpointCommand::BreakpointOptionsCallbackFunction, baton_sp);
|
|
|
|
return;
|
|
}
|
|
|
|
size_t
|
|
CommandObjectBreakpointCommandAdd::GenerateBreakpointCommandCallback
|
|
(
|
|
void *baton,
|
|
InputReader &reader,
|
|
lldb::InputReaderAction notification,
|
|
const char *bytes,
|
|
size_t bytes_len
|
|
)
|
|
{
|
|
File &out_file = reader.GetDebugger().GetOutputFile();
|
|
|
|
switch (notification)
|
|
{
|
|
case eInputReaderActivate:
|
|
out_file.Printf ("%s\n", g_reader_instructions);
|
|
if (reader.GetPrompt())
|
|
out_file.Printf ("%s", reader.GetPrompt());
|
|
out_file.Flush();
|
|
break;
|
|
|
|
case eInputReaderDeactivate:
|
|
break;
|
|
|
|
case eInputReaderReactivate:
|
|
if (reader.GetPrompt())
|
|
{
|
|
out_file.Printf ("%s", reader.GetPrompt());
|
|
out_file.Flush();
|
|
}
|
|
break;
|
|
|
|
case eInputReaderGotToken:
|
|
if (bytes && bytes_len && baton)
|
|
{
|
|
BreakpointOptions *bp_options = (BreakpointOptions *) baton;
|
|
if (bp_options)
|
|
{
|
|
Baton *bp_options_baton = bp_options->GetBaton();
|
|
if (bp_options_baton)
|
|
((BreakpointOptions::CommandData *)bp_options_baton->m_data)->user_source.AppendString (bytes, bytes_len);
|
|
}
|
|
}
|
|
if (!reader.IsDone() && reader.GetPrompt())
|
|
{
|
|
out_file.Printf ("%s", reader.GetPrompt());
|
|
out_file.Flush();
|
|
}
|
|
break;
|
|
|
|
case eInputReaderInterrupt:
|
|
{
|
|
// Finish, and cancel the breakpoint command.
|
|
reader.SetIsDone (true);
|
|
BreakpointOptions *bp_options = (BreakpointOptions *) baton;
|
|
if (bp_options)
|
|
{
|
|
Baton *bp_options_baton = bp_options->GetBaton ();
|
|
if (bp_options_baton)
|
|
{
|
|
((BreakpointOptions::CommandData *) bp_options_baton->m_data)->user_source.Clear();
|
|
((BreakpointOptions::CommandData *) bp_options_baton->m_data)->script_source.Clear();
|
|
}
|
|
}
|
|
out_file.Printf ("Warning: No command attached to breakpoint.\n");
|
|
out_file.Flush();
|
|
}
|
|
break;
|
|
|
|
case eInputReaderEndOfFile:
|
|
reader.SetIsDone (true);
|
|
break;
|
|
|
|
case eInputReaderDone:
|
|
break;
|
|
}
|
|
|
|
return bytes_len;
|
|
}
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
// CommandObjectBreakpointCommandRemove
|
|
//-------------------------------------------------------------------------
|
|
|
|
CommandObjectBreakpointCommandRemove::CommandObjectBreakpointCommandRemove (CommandInterpreter &interpreter) :
|
|
CommandObject (interpreter,
|
|
"remove",
|
|
"Remove the set of commands from a breakpoint.",
|
|
NULL)
|
|
{
|
|
CommandArgumentEntry arg;
|
|
CommandArgumentData bp_id_arg;
|
|
|
|
// Define the first (and only) variant of this arg.
|
|
bp_id_arg.arg_type = eArgTypeBreakpointID;
|
|
bp_id_arg.arg_repetition = eArgRepeatPlain;
|
|
|
|
// There is only one variant this argument could be; put it into the argument entry.
|
|
arg.push_back (bp_id_arg);
|
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
m_arguments.push_back (arg);
|
|
}
|
|
|
|
CommandObjectBreakpointCommandRemove::~CommandObjectBreakpointCommandRemove ()
|
|
{
|
|
}
|
|
|
|
bool
|
|
CommandObjectBreakpointCommandRemove::Execute
|
|
(
|
|
Args& command,
|
|
CommandReturnObject &result
|
|
)
|
|
{
|
|
Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
|
|
|
|
if (target == NULL)
|
|
{
|
|
result.AppendError ("There is not a current executable; there are no breakpoints from which to remove commands");
|
|
result.SetStatus (eReturnStatusFailed);
|
|
return false;
|
|
}
|
|
|
|
const BreakpointList &breakpoints = target->GetBreakpointList();
|
|
size_t num_breakpoints = breakpoints.GetSize();
|
|
|
|
if (num_breakpoints == 0)
|
|
{
|
|
result.AppendError ("No breakpoints exist to have commands removed");
|
|
result.SetStatus (eReturnStatusFailed);
|
|
return false;
|
|
}
|
|
|
|
if (command.GetArgumentCount() == 0)
|
|
{
|
|
result.AppendError ("No breakpoint specified from which to remove the commands");
|
|
result.SetStatus (eReturnStatusFailed);
|
|
return false;
|
|
}
|
|
|
|
BreakpointIDList valid_bp_ids;
|
|
CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
|
|
|
|
if (result.Succeeded())
|
|
{
|
|
const size_t count = valid_bp_ids.GetSize();
|
|
for (size_t i = 0; i < count; ++i)
|
|
{
|
|
BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
|
|
if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
|
|
{
|
|
Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
|
|
if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
|
|
{
|
|
BreakpointLocationSP bp_loc_sp (bp->FindLocationByID (cur_bp_id.GetLocationID()));
|
|
if (bp_loc_sp)
|
|
bp_loc_sp->ClearCallback();
|
|
else
|
|
{
|
|
result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n",
|
|
cur_bp_id.GetBreakpointID(),
|
|
cur_bp_id.GetLocationID());
|
|
result.SetStatus (eReturnStatusFailed);
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bp->ClearCallback();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return result.Succeeded();
|
|
}
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
// CommandObjectBreakpointCommandList
|
|
//-------------------------------------------------------------------------
|
|
|
|
CommandObjectBreakpointCommandList::CommandObjectBreakpointCommandList (CommandInterpreter &interpreter) :
|
|
CommandObject (interpreter,
|
|
"list",
|
|
"List the script or set of commands to be executed when the breakpoint is hit.",
|
|
NULL)
|
|
{
|
|
CommandArgumentEntry arg;
|
|
CommandArgumentData bp_id_arg;
|
|
|
|
// Define the first (and only) variant of this arg.
|
|
bp_id_arg.arg_type = eArgTypeBreakpointID;
|
|
bp_id_arg.arg_repetition = eArgRepeatPlain;
|
|
|
|
// There is only one variant this argument could be; put it into the argument entry.
|
|
arg.push_back (bp_id_arg);
|
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
m_arguments.push_back (arg);
|
|
}
|
|
|
|
CommandObjectBreakpointCommandList::~CommandObjectBreakpointCommandList ()
|
|
{
|
|
}
|
|
|
|
bool
|
|
CommandObjectBreakpointCommandList::Execute
|
|
(
|
|
Args& command,
|
|
CommandReturnObject &result
|
|
)
|
|
{
|
|
Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
|
|
|
|
if (target == NULL)
|
|
{
|
|
result.AppendError ("There is not a current executable; there are no breakpoints for which to list commands");
|
|
result.SetStatus (eReturnStatusFailed);
|
|
return false;
|
|
}
|
|
|
|
const BreakpointList &breakpoints = target->GetBreakpointList();
|
|
size_t num_breakpoints = breakpoints.GetSize();
|
|
|
|
if (num_breakpoints == 0)
|
|
{
|
|
result.AppendError ("No breakpoints exist for which to list commands");
|
|
result.SetStatus (eReturnStatusFailed);
|
|
return false;
|
|
}
|
|
|
|
if (command.GetArgumentCount() == 0)
|
|
{
|
|
result.AppendError ("No breakpoint specified for which to list the commands");
|
|
result.SetStatus (eReturnStatusFailed);
|
|
return false;
|
|
}
|
|
|
|
BreakpointIDList valid_bp_ids;
|
|
CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
|
|
|
|
if (result.Succeeded())
|
|
{
|
|
const size_t count = valid_bp_ids.GetSize();
|
|
for (size_t i = 0; i < count; ++i)
|
|
{
|
|
BreakpointID cur_bp_id = valid_bp_ids.GetBreakpointIDAtIndex (i);
|
|
if (cur_bp_id.GetBreakpointID() != LLDB_INVALID_BREAK_ID)
|
|
{
|
|
Breakpoint *bp = target->GetBreakpointByID (cur_bp_id.GetBreakpointID()).get();
|
|
|
|
if (bp)
|
|
{
|
|
const BreakpointOptions *bp_options = NULL;
|
|
if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
|
|
{
|
|
BreakpointLocationSP bp_loc_sp(bp->FindLocationByID (cur_bp_id.GetLocationID()));
|
|
if (bp_loc_sp)
|
|
bp_options = bp_loc_sp->GetOptionsNoCreate();
|
|
else
|
|
{
|
|
result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n",
|
|
cur_bp_id.GetBreakpointID(),
|
|
cur_bp_id.GetLocationID());
|
|
result.SetStatus (eReturnStatusFailed);
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bp_options = bp->GetOptions();
|
|
}
|
|
|
|
if (bp_options)
|
|
{
|
|
StreamString id_str;
|
|
BreakpointID::GetCanonicalReference (&id_str,
|
|
cur_bp_id.GetBreakpointID(),
|
|
cur_bp_id.GetLocationID());
|
|
const Baton *baton = bp_options->GetBaton();
|
|
if (baton)
|
|
{
|
|
result.GetOutputStream().Printf ("Breakpoint %s:\n", id_str.GetData());
|
|
result.GetOutputStream().IndentMore ();
|
|
baton->GetDescription(&result.GetOutputStream(), eDescriptionLevelFull);
|
|
result.GetOutputStream().IndentLess ();
|
|
}
|
|
else
|
|
{
|
|
result.AppendMessageWithFormat ("Breakpoint %s does not have an associated command.\n",
|
|
id_str.GetData());
|
|
}
|
|
}
|
|
result.SetStatus (eReturnStatusSuccessFinishResult);
|
|
}
|
|
else
|
|
{
|
|
result.AppendErrorWithFormat("Invalid breakpoint ID: %u.\n", cur_bp_id.GetBreakpointID());
|
|
result.SetStatus (eReturnStatusFailed);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
return result.Succeeded();
|
|
}
|
|
|
|
//-------------------------------------------------------------------------
|
|
// CommandObjectBreakpointCommand
|
|
//-------------------------------------------------------------------------
|
|
|
|
CommandObjectBreakpointCommand::CommandObjectBreakpointCommand (CommandInterpreter &interpreter) :
|
|
CommandObjectMultiword (interpreter,
|
|
"command",
|
|
"A set of commands for adding, removing and examining bits of code to be executed when the breakpoint is hit (breakpoint 'commmands').",
|
|
"command <sub-command> [<sub-command-options>] <breakpoint-id>")
|
|
{
|
|
bool status;
|
|
CommandObjectSP add_command_object (new CommandObjectBreakpointCommandAdd (interpreter));
|
|
CommandObjectSP remove_command_object (new CommandObjectBreakpointCommandRemove (interpreter));
|
|
CommandObjectSP list_command_object (new CommandObjectBreakpointCommandList (interpreter));
|
|
|
|
add_command_object->SetCommandName ("breakpoint command add");
|
|
remove_command_object->SetCommandName ("breakpoint command remove");
|
|
list_command_object->SetCommandName ("breakpoint command list");
|
|
|
|
status = LoadSubCommand ("add", add_command_object);
|
|
status = LoadSubCommand ("remove", remove_command_object);
|
|
status = LoadSubCommand ("list", list_command_object);
|
|
}
|
|
|
|
|
|
CommandObjectBreakpointCommand::~CommandObjectBreakpointCommand ()
|
|
{
|
|
}
|
|
|
|
bool
|
|
CommandObjectBreakpointCommand::BreakpointOptionsCallbackFunction
|
|
(
|
|
void *baton,
|
|
StoppointCallbackContext *context,
|
|
lldb::user_id_t break_id,
|
|
lldb::user_id_t break_loc_id
|
|
)
|
|
{
|
|
bool ret_value = true;
|
|
if (baton == NULL)
|
|
return true;
|
|
|
|
|
|
BreakpointOptions::CommandData *data = (BreakpointOptions::CommandData *) baton;
|
|
StringList &commands = data->user_source;
|
|
|
|
if (commands.GetSize() > 0)
|
|
{
|
|
if (context->exe_ctx.target)
|
|
{
|
|
CommandReturnObject result;
|
|
Debugger &debugger = context->exe_ctx.target->GetDebugger();
|
|
// Rig up the results secondary output stream to the debugger's, so the output will come out synchronously
|
|
// if the debugger is set up that way.
|
|
|
|
result.SetImmediateOutputFile (debugger.GetOutputFile().GetStream());
|
|
result.SetImmediateErrorFile (debugger.GetErrorFile().GetStream());
|
|
|
|
bool stop_on_continue = true;
|
|
bool echo_commands = false;
|
|
bool print_results = true;
|
|
|
|
debugger.GetCommandInterpreter().HandleCommands (commands,
|
|
&(context->exe_ctx),
|
|
stop_on_continue,
|
|
data->stop_on_error,
|
|
echo_commands,
|
|
print_results,
|
|
result);
|
|
}
|
|
}
|
|
return ret_value;
|
|
}
|
|
|