2010-06-09 00:52:24 +08:00
|
|
|
//===-- 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 ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandObjectBreakpointCommandAdd::CommandOptions::~CommandOptions ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::OptionDefinition
|
|
|
|
CommandObjectBreakpointCommandAdd::CommandOptions::g_option_table[] =
|
|
|
|
{
|
2010-06-16 02:47:14 +08:00
|
|
|
{ LLDB_OPT_SET_1, true, "script", 's', no_argument, NULL, 0, NULL,
|
2010-06-09 00:52:24 +08:00
|
|
|
"Write the breakpoint command script in the default scripting language."},
|
|
|
|
|
2010-06-16 02:47:14 +08:00
|
|
|
{ LLDB_OPT_SET_2, true, "python", 'p', no_argument, NULL, 0, NULL,
|
2010-06-09 00:52:24 +08:00
|
|
|
"Write the breakpoint command script in the Python scripting language."},
|
|
|
|
|
2010-06-16 02:47:14 +08:00
|
|
|
{ LLDB_OPT_SET_3, true, "commands", 'c', no_argument, NULL, 0, NULL,
|
2010-09-09 05:06:11 +08:00
|
|
|
"Write the breakpoint command script using standard debugger commands."},
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
{ 0, false, NULL, 0, 0, NULL, 0, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
const lldb::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 's':
|
|
|
|
m_use_commands = false;
|
|
|
|
m_use_script_language = true;
|
|
|
|
m_script_language = eScriptLanguageDefault;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
m_use_commands = false;
|
|
|
|
m_use_script_language = true;
|
|
|
|
m_script_language = eScriptLanguagePython;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
m_use_commands = true;
|
|
|
|
m_use_script_language = false;
|
|
|
|
m_script_language = eScriptLanguageNone;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CommandObjectBreakpointCommandAdd::CommandOptions::ResetOptionValues ()
|
|
|
|
{
|
|
|
|
Options::ResetOptionValues();
|
|
|
|
|
|
|
|
m_use_commands = false;
|
|
|
|
m_use_script_language = false;
|
|
|
|
m_script_language = eScriptLanguageNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// CommandObjectBreakpointCommandAdd
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
CommandObjectBreakpointCommandAdd::CommandObjectBreakpointCommandAdd () :
|
|
|
|
CommandObject ("add",
|
2010-09-09 05:06:11 +08:00
|
|
|
"Add a set of commands to a breakpoint, to be executed whenever the breakpoint is hit.",
|
2010-06-09 00:52:24 +08:00
|
|
|
"breakpoint command add <cmd-options> <breakpoint-id>")
|
|
|
|
{
|
|
|
|
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 -p 1 \n\
|
|
|
|
Enter your Python command(s). Type 'DONE' to end. \n\
|
|
|
|
> print \"Hit this breakpoint!\" \n\
|
|
|
|
> DONE \n\
|
|
|
|
\n\
|
2010-09-11 03:34:12 +08:00
|
|
|
As a convenience, this also works for a short Python one-liner: \n\
|
|
|
|
(lldb) breakpoint command add -p 1 \"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\
|
2010-06-09 00:52:24 +08:00
|
|
|
Example multiple line Python breakpoint command, using function definition: \n\
|
|
|
|
\n\
|
|
|
|
(lldb) breakpoint command add -p 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 -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\
|
2010-09-09 05:06:11 +08:00
|
|
|
Special information about debugger command breakpoint commands \n\
|
|
|
|
-------------------------------------------------------------- \n\
|
2010-06-09 00:52:24 +08:00
|
|
|
\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" );
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandObjectBreakpointCommandAdd::~CommandObjectBreakpointCommandAdd ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CommandObjectBreakpointCommandAdd::Execute
|
|
|
|
(
|
2010-06-23 09:19:29 +08:00
|
|
|
CommandInterpreter &interpreter,
|
2010-06-09 00:52:24 +08:00
|
|
|
Args& command,
|
|
|
|
CommandReturnObject &result
|
|
|
|
)
|
|
|
|
{
|
2010-08-27 05:32:51 +08:00
|
|
|
Target *target = interpreter.GetDebugger().GetSelectedTarget().get();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (command.GetArgumentCount() == 0)
|
|
|
|
{
|
|
|
|
result.AppendError ("No breakpoint specified to which to add the commands");
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointIDList valid_bp_ids;
|
|
|
|
CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids);
|
|
|
|
|
|
|
|
if (result.Succeeded())
|
|
|
|
{
|
2010-07-10 04:39:50 +08:00
|
|
|
const size_t count = valid_bp_ids.GetSize();
|
|
|
|
for (size_t i = 0; i < count; ++i)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (m_options.m_use_script_language)
|
|
|
|
{
|
Added the capability to specify a one-liner Python script as the callback
command for a breakpoint, for example:
(lldb) breakpoint command add -p 1 "conditional_break.stop_if_called_from_a()"
The ScriptInterpreter interface has an extra method:
/// Set a one-liner as the callback for the breakpoint command.
virtual void
SetBreakpointCommandCallback (CommandInterpreter &interpreter,
BreakpointOptions *bp_options,
const char *oneliner);
to accomplish the above.
Also added a test case to demonstrate lldb's use of breakpoint callback command
to stop at function c() only when its immediate caller is function a(). The
following session shows the user entering the following commands:
1) command source .lldb (set up executable, breakpoint, and breakpoint command)
2) run (the callback mechanism will skip two breakpoints where c()'s immeidate caller is not a())
3) bt (to see that indeed c()'s immediate caller is a())
4) c (to continue and finish the program)
test/conditional_break $ ../../build/Debug/lldb
(lldb) command source .lldb
Executing commands in '.lldb'.
(lldb) file a.out
Current executable set to 'a.out' (x86_64).
(lldb) breakpoint set -n c
Breakpoint created: 1: name = 'c', locations = 1
(lldb) script import sys, os
(lldb) script sys.path.append(os.path.join(os.getcwd(), os.pardir))
(lldb) script import conditional_break
(lldb) breakpoint command add -p 1 "conditional_break.stop_if_called_from_a()"
(lldb) run
run
Launching '/Volumes/data/lldb/svn/trunk/test/conditional_break/a.out' (x86_64)
(lldb) Checking call frames...
Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread:
frame #0: a.out`c at main.c:39
frame #1: a.out`b at main.c:34
frame #2: a.out`a at main.c:25
frame #3: a.out`main at main.c:44
frame #4: a.out`start
c called from b
Continuing...
Checking call frames...
Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread:
frame #0: a.out`c at main.c:39
frame #1: a.out`b at main.c:34
frame #2: a.out`main at main.c:47
frame #3: a.out`start
c called from b
Continuing...
Checking call frames...
Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread:
frame #0: a.out`c at main.c:39
frame #1: a.out`a at main.c:27
frame #2: a.out`main at main.c:50
frame #3: a.out`start
c called from a
Stopped at c() with immediate caller as a().
a(1) returns 4
b(2) returns 5
Process 20420 Stopped
* thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = breakpoint 1.1, queue = com.apple.main-thread
36
37 int c(int val)
38 {
39 -> return val + 3;
40 }
41
42 int main (int argc, char const *argv[])
(lldb) bt
bt
thread #1: tid = 0x2e03, stop reason = breakpoint 1.1, queue = com.apple.main-thread
frame #0: 0x0000000100000de8 a.out`c + 7 at main.c:39
frame #1: 0x0000000100000dbc a.out`a + 44 at main.c:27
frame #2: 0x0000000100000e4b a.out`main + 91 at main.c:50
frame #3: 0x0000000100000d88 a.out`start + 52
(lldb) c
c
Resuming process 20420
Process 20420 Exited
a(3) returns 6
(lldb)
llvm-svn: 113596
2010-09-11 02:21:10 +08:00
|
|
|
// Special handling for one-liner.
|
2010-09-11 04:15:13 +08:00
|
|
|
if (command.GetArgumentCount() == 2 && count == 1)
|
Added the capability to specify a one-liner Python script as the callback
command for a breakpoint, for example:
(lldb) breakpoint command add -p 1 "conditional_break.stop_if_called_from_a()"
The ScriptInterpreter interface has an extra method:
/// Set a one-liner as the callback for the breakpoint command.
virtual void
SetBreakpointCommandCallback (CommandInterpreter &interpreter,
BreakpointOptions *bp_options,
const char *oneliner);
to accomplish the above.
Also added a test case to demonstrate lldb's use of breakpoint callback command
to stop at function c() only when its immediate caller is function a(). The
following session shows the user entering the following commands:
1) command source .lldb (set up executable, breakpoint, and breakpoint command)
2) run (the callback mechanism will skip two breakpoints where c()'s immeidate caller is not a())
3) bt (to see that indeed c()'s immediate caller is a())
4) c (to continue and finish the program)
test/conditional_break $ ../../build/Debug/lldb
(lldb) command source .lldb
Executing commands in '.lldb'.
(lldb) file a.out
Current executable set to 'a.out' (x86_64).
(lldb) breakpoint set -n c
Breakpoint created: 1: name = 'c', locations = 1
(lldb) script import sys, os
(lldb) script sys.path.append(os.path.join(os.getcwd(), os.pardir))
(lldb) script import conditional_break
(lldb) breakpoint command add -p 1 "conditional_break.stop_if_called_from_a()"
(lldb) run
run
Launching '/Volumes/data/lldb/svn/trunk/test/conditional_break/a.out' (x86_64)
(lldb) Checking call frames...
Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread:
frame #0: a.out`c at main.c:39
frame #1: a.out`b at main.c:34
frame #2: a.out`a at main.c:25
frame #3: a.out`main at main.c:44
frame #4: a.out`start
c called from b
Continuing...
Checking call frames...
Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread:
frame #0: a.out`c at main.c:39
frame #1: a.out`b at main.c:34
frame #2: a.out`main at main.c:47
frame #3: a.out`start
c called from b
Continuing...
Checking call frames...
Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread:
frame #0: a.out`c at main.c:39
frame #1: a.out`a at main.c:27
frame #2: a.out`main at main.c:50
frame #3: a.out`start
c called from a
Stopped at c() with immediate caller as a().
a(1) returns 4
b(2) returns 5
Process 20420 Stopped
* thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = breakpoint 1.1, queue = com.apple.main-thread
36
37 int c(int val)
38 {
39 -> return val + 3;
40 }
41
42 int main (int argc, char const *argv[])
(lldb) bt
bt
thread #1: tid = 0x2e03, stop reason = breakpoint 1.1, queue = com.apple.main-thread
frame #0: 0x0000000100000de8 a.out`c + 7 at main.c:39
frame #1: 0x0000000100000dbc a.out`a + 44 at main.c:27
frame #2: 0x0000000100000e4b a.out`main + 91 at main.c:50
frame #3: 0x0000000100000d88 a.out`start + 52
(lldb) c
c
Resuming process 20420
Process 20420 Exited
a(3) returns 6
(lldb)
llvm-svn: 113596
2010-09-11 02:21:10 +08:00
|
|
|
interpreter.GetScriptInterpreter()->SetBreakpointCommandCallback (interpreter,
|
|
|
|
bp_loc_sp->GetLocationOptions(),
|
|
|
|
command.GetArgumentAtIndex(1));
|
|
|
|
else
|
|
|
|
interpreter.GetScriptInterpreter()->CollectDataForBreakpointCommandCallback (interpreter,
|
|
|
|
bp_loc_sp->GetLocationOptions(),
|
|
|
|
result);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-14 08:18:15 +08:00
|
|
|
CollectDataForBreakpointCommandCallback (interpreter,
|
|
|
|
bp_loc_sp->GetLocationOptions(),
|
|
|
|
result);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_options.m_use_script_language)
|
|
|
|
{
|
Added the capability to specify a one-liner Python script as the callback
command for a breakpoint, for example:
(lldb) breakpoint command add -p 1 "conditional_break.stop_if_called_from_a()"
The ScriptInterpreter interface has an extra method:
/// Set a one-liner as the callback for the breakpoint command.
virtual void
SetBreakpointCommandCallback (CommandInterpreter &interpreter,
BreakpointOptions *bp_options,
const char *oneliner);
to accomplish the above.
Also added a test case to demonstrate lldb's use of breakpoint callback command
to stop at function c() only when its immediate caller is function a(). The
following session shows the user entering the following commands:
1) command source .lldb (set up executable, breakpoint, and breakpoint command)
2) run (the callback mechanism will skip two breakpoints where c()'s immeidate caller is not a())
3) bt (to see that indeed c()'s immediate caller is a())
4) c (to continue and finish the program)
test/conditional_break $ ../../build/Debug/lldb
(lldb) command source .lldb
Executing commands in '.lldb'.
(lldb) file a.out
Current executable set to 'a.out' (x86_64).
(lldb) breakpoint set -n c
Breakpoint created: 1: name = 'c', locations = 1
(lldb) script import sys, os
(lldb) script sys.path.append(os.path.join(os.getcwd(), os.pardir))
(lldb) script import conditional_break
(lldb) breakpoint command add -p 1 "conditional_break.stop_if_called_from_a()"
(lldb) run
run
Launching '/Volumes/data/lldb/svn/trunk/test/conditional_break/a.out' (x86_64)
(lldb) Checking call frames...
Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread:
frame #0: a.out`c at main.c:39
frame #1: a.out`b at main.c:34
frame #2: a.out`a at main.c:25
frame #3: a.out`main at main.c:44
frame #4: a.out`start
c called from b
Continuing...
Checking call frames...
Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread:
frame #0: a.out`c at main.c:39
frame #1: a.out`b at main.c:34
frame #2: a.out`main at main.c:47
frame #3: a.out`start
c called from b
Continuing...
Checking call frames...
Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread:
frame #0: a.out`c at main.c:39
frame #1: a.out`a at main.c:27
frame #2: a.out`main at main.c:50
frame #3: a.out`start
c called from a
Stopped at c() with immediate caller as a().
a(1) returns 4
b(2) returns 5
Process 20420 Stopped
* thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = breakpoint 1.1, queue = com.apple.main-thread
36
37 int c(int val)
38 {
39 -> return val + 3;
40 }
41
42 int main (int argc, char const *argv[])
(lldb) bt
bt
thread #1: tid = 0x2e03, stop reason = breakpoint 1.1, queue = com.apple.main-thread
frame #0: 0x0000000100000de8 a.out`c + 7 at main.c:39
frame #1: 0x0000000100000dbc a.out`a + 44 at main.c:27
frame #2: 0x0000000100000e4b a.out`main + 91 at main.c:50
frame #3: 0x0000000100000d88 a.out`start + 52
(lldb) c
c
Resuming process 20420
Process 20420 Exited
a(3) returns 6
(lldb)
llvm-svn: 113596
2010-09-11 02:21:10 +08:00
|
|
|
// Special handling for one-liner.
|
2010-09-11 04:15:13 +08:00
|
|
|
if (command.GetArgumentCount() == 2 && count == 1)
|
Added the capability to specify a one-liner Python script as the callback
command for a breakpoint, for example:
(lldb) breakpoint command add -p 1 "conditional_break.stop_if_called_from_a()"
The ScriptInterpreter interface has an extra method:
/// Set a one-liner as the callback for the breakpoint command.
virtual void
SetBreakpointCommandCallback (CommandInterpreter &interpreter,
BreakpointOptions *bp_options,
const char *oneliner);
to accomplish the above.
Also added a test case to demonstrate lldb's use of breakpoint callback command
to stop at function c() only when its immediate caller is function a(). The
following session shows the user entering the following commands:
1) command source .lldb (set up executable, breakpoint, and breakpoint command)
2) run (the callback mechanism will skip two breakpoints where c()'s immeidate caller is not a())
3) bt (to see that indeed c()'s immediate caller is a())
4) c (to continue and finish the program)
test/conditional_break $ ../../build/Debug/lldb
(lldb) command source .lldb
Executing commands in '.lldb'.
(lldb) file a.out
Current executable set to 'a.out' (x86_64).
(lldb) breakpoint set -n c
Breakpoint created: 1: name = 'c', locations = 1
(lldb) script import sys, os
(lldb) script sys.path.append(os.path.join(os.getcwd(), os.pardir))
(lldb) script import conditional_break
(lldb) breakpoint command add -p 1 "conditional_break.stop_if_called_from_a()"
(lldb) run
run
Launching '/Volumes/data/lldb/svn/trunk/test/conditional_break/a.out' (x86_64)
(lldb) Checking call frames...
Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread:
frame #0: a.out`c at main.c:39
frame #1: a.out`b at main.c:34
frame #2: a.out`a at main.c:25
frame #3: a.out`main at main.c:44
frame #4: a.out`start
c called from b
Continuing...
Checking call frames...
Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread:
frame #0: a.out`c at main.c:39
frame #1: a.out`b at main.c:34
frame #2: a.out`main at main.c:47
frame #3: a.out`start
c called from b
Continuing...
Checking call frames...
Stack trace for thread id=0x2e03 name=None queue=com.apple.main-thread:
frame #0: a.out`c at main.c:39
frame #1: a.out`a at main.c:27
frame #2: a.out`main at main.c:50
frame #3: a.out`start
c called from a
Stopped at c() with immediate caller as a().
a(1) returns 4
b(2) returns 5
Process 20420 Stopped
* thread #1: tid = 0x2e03, 0x0000000100000de8 a.out`c + 7 at main.c:39, stop reason = breakpoint 1.1, queue = com.apple.main-thread
36
37 int c(int val)
38 {
39 -> return val + 3;
40 }
41
42 int main (int argc, char const *argv[])
(lldb) bt
bt
thread #1: tid = 0x2e03, stop reason = breakpoint 1.1, queue = com.apple.main-thread
frame #0: 0x0000000100000de8 a.out`c + 7 at main.c:39
frame #1: 0x0000000100000dbc a.out`a + 44 at main.c:27
frame #2: 0x0000000100000e4b a.out`main + 91 at main.c:50
frame #3: 0x0000000100000d88 a.out`start + 52
(lldb) c
c
Resuming process 20420
Process 20420 Exited
a(3) returns 6
(lldb)
llvm-svn: 113596
2010-09-11 02:21:10 +08:00
|
|
|
interpreter.GetScriptInterpreter()->SetBreakpointCommandCallback (interpreter,
|
|
|
|
bp->GetOptions(),
|
|
|
|
command.GetArgumentAtIndex(1));
|
|
|
|
else
|
|
|
|
interpreter.GetScriptInterpreter()->CollectDataForBreakpointCommandCallback (interpreter,
|
|
|
|
bp->GetOptions(),
|
|
|
|
result);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-14 08:18:15 +08:00
|
|
|
CollectDataForBreakpointCommandCallback (interpreter,
|
|
|
|
bp->GetOptions(),
|
|
|
|
result);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
(
|
2010-06-23 09:19:29 +08:00
|
|
|
CommandInterpreter &interpreter,
|
2010-06-09 00:52:24 +08:00
|
|
|
BreakpointOptions *bp_options,
|
|
|
|
CommandReturnObject &result
|
|
|
|
)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
InputReaderSP reader_sp (new InputReader(interpreter.GetDebugger()));
|
2010-06-09 00:52:24 +08:00
|
|
|
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())
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
interpreter.GetDebugger().PushInputReader (reader_sp);
|
2010-06-09 00:52:24 +08:00
|
|
|
result.SetStatus (eReturnStatusSuccessFinishNoResult);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.AppendError (err.AsCString());
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.AppendError("out of memory");
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
CommandObjectBreakpointCommandAdd::GenerateBreakpointCommandCallback
|
|
|
|
(
|
|
|
|
void *baton,
|
2010-06-23 09:19:29 +08:00
|
|
|
InputReader &reader,
|
2010-06-09 00:52:24 +08:00
|
|
|
lldb::InputReaderAction notification,
|
|
|
|
const char *bytes,
|
|
|
|
size_t bytes_len
|
|
|
|
)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
FILE *out_fh = reader.GetDebugger().GetOutputFileHandle();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
switch (notification)
|
|
|
|
{
|
|
|
|
case eInputReaderActivate:
|
|
|
|
if (out_fh)
|
|
|
|
{
|
|
|
|
::fprintf (out_fh, "%s\n", g_reader_instructions);
|
2010-06-23 09:19:29 +08:00
|
|
|
if (reader.GetPrompt())
|
|
|
|
::fprintf (out_fh, "%s", reader.GetPrompt());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eInputReaderDeactivate:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eInputReaderReactivate:
|
2010-06-23 09:19:29 +08:00
|
|
|
if (out_fh && reader.GetPrompt())
|
|
|
|
::fprintf (out_fh, "%s", reader.GetPrompt());
|
2010-06-09 00:52:24 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2010-06-23 09:19:29 +08:00
|
|
|
if (out_fh && !reader.IsDone() && reader.GetPrompt())
|
|
|
|
::fprintf (out_fh, "%s", reader.GetPrompt());
|
2010-06-09 00:52:24 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eInputReaderDone:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bytes_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// CommandObjectBreakpointCommandRemove
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
CommandObjectBreakpointCommandRemove::CommandObjectBreakpointCommandRemove () :
|
|
|
|
CommandObject ("remove",
|
|
|
|
"Remove the set of commands from a breakpoint.",
|
|
|
|
"breakpoint command remove <breakpoint-id>")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandObjectBreakpointCommandRemove::~CommandObjectBreakpointCommandRemove ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-06-23 09:19:29 +08:00
|
|
|
CommandObjectBreakpointCommandRemove::Execute
|
|
|
|
(
|
|
|
|
CommandInterpreter &interpreter,
|
|
|
|
Args& command,
|
|
|
|
CommandReturnObject &result
|
|
|
|
)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-08-27 05:32:51 +08:00
|
|
|
Target *target = interpreter.GetDebugger().GetSelectedTarget().get();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
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())
|
|
|
|
{
|
2010-07-10 04:39:50 +08:00
|
|
|
const size_t count = valid_bp_ids.GetSize();
|
|
|
|
for (size_t i = 0; i < count; ++i)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
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 () :
|
|
|
|
CommandObject ("List",
|
|
|
|
"List the script or set of commands to be executed when the breakpoint is hit.",
|
|
|
|
"breakpoint command list <breakpoint-id>")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandObjectBreakpointCommandList::~CommandObjectBreakpointCommandList ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-06-23 09:19:29 +08:00
|
|
|
CommandObjectBreakpointCommandList::Execute
|
|
|
|
(
|
|
|
|
CommandInterpreter &interpreter,
|
|
|
|
Args& command,
|
|
|
|
CommandReturnObject &result
|
|
|
|
)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-08-27 05:32:51 +08:00
|
|
|
Target *target = interpreter.GetDebugger().GetSelectedTarget().get();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
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())
|
|
|
|
{
|
2010-07-10 04:39:50 +08:00
|
|
|
const size_t count = valid_bp_ids.GetSize();
|
|
|
|
for (size_t i = 0; i < count; ++i)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2010-06-16 10:00:15 +08:00
|
|
|
const BreakpointOptions *bp_options = NULL;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID)
|
|
|
|
{
|
|
|
|
BreakpointLocationSP bp_loc_sp(bp->FindLocationByID (cur_bp_id.GetLocationID()));
|
|
|
|
if (bp_loc_sp)
|
2010-06-23 05:12:54 +08:00
|
|
|
bp_options = bp_loc_sp->GetOptionsNoCreate();
|
2010-06-09 00:52:24 +08:00
|
|
|
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());
|
2010-06-16 10:00:15 +08:00
|
|
|
const Baton *baton = bp_options->GetBaton();
|
2010-06-09 00:52:24 +08:00
|
|
|
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
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
CommandObjectBreakpointCommand::CommandObjectBreakpointCommand (CommandInterpreter &interpreter) :
|
2010-06-09 00:52:24 +08:00
|
|
|
CommandObjectMultiword ("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 ());
|
|
|
|
CommandObjectSP remove_command_object (new CommandObjectBreakpointCommandRemove ());
|
|
|
|
CommandObjectSP list_command_object (new CommandObjectBreakpointCommandList ());
|
|
|
|
|
|
|
|
add_command_object->SetCommandName ("breakpoint command add");
|
|
|
|
remove_command_object->SetCommandName ("breakpoint command remove");
|
|
|
|
list_command_object->SetCommandName ("breakpoint command list");
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
status = LoadSubCommand (interpreter, "add", add_command_object);
|
|
|
|
status = LoadSubCommand (interpreter, "remove", remove_command_object);
|
|
|
|
status = LoadSubCommand (interpreter, "list", list_command_object);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
uint32_t num_commands = commands.GetSize();
|
|
|
|
CommandReturnObject result;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (context->exe_ctx.target)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
|
|
|
|
Debugger &debugger = context->exe_ctx.target->GetDebugger();
|
|
|
|
CommandInterpreter &interpreter = debugger.GetCommandInterpreter();
|
|
|
|
|
|
|
|
FILE *out_fh = debugger.GetOutputFileHandle();
|
|
|
|
FILE *err_fh = debugger.GetErrorFileHandle();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
uint32_t i;
|
|
|
|
for (i = 0; i < num_commands; ++i)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
|
|
|
|
// First time through we use the context from the stoppoint, after that we use whatever
|
|
|
|
// has been set by the previous command.
|
|
|
|
|
|
|
|
if (!interpreter.HandleCommand (commands.GetStringAtIndex(i), false, result, &context->exe_ctx))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// FIXME: This isn't really the right way to do this. We should be able to peek at the public
|
|
|
|
// to see if there is any new events, but that is racey, since the internal process thread has to run and
|
|
|
|
// deliver the event to the public queue before a run will show up. So for now we check
|
|
|
|
// the internal thread state.
|
|
|
|
|
|
|
|
lldb::StateType internal_state = context->exe_ctx.process->GetPrivateState();
|
|
|
|
if (internal_state != eStateStopped)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (i < num_commands - 1)
|
|
|
|
{
|
|
|
|
if (out_fh)
|
|
|
|
::fprintf (out_fh, "Short-circuiting command execution because target state changed to %s."
|
|
|
|
" last command: \"%s\"\n", StateAsCString(internal_state),
|
|
|
|
commands.GetStringAtIndex(i));
|
|
|
|
}
|
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-06-23 09:19:29 +08:00
|
|
|
|
|
|
|
if (out_fh)
|
|
|
|
::fprintf (out_fh, "%s", result.GetErrorStream().GetData());
|
|
|
|
if (err_fh)
|
|
|
|
::fprintf (err_fh, "%s", result.GetOutputStream().GetData());
|
|
|
|
result.Clear();
|
|
|
|
result.SetStatus (eReturnStatusSuccessFinishNoResult);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
if (err_fh && !result.Succeeded() && i < num_commands)
|
|
|
|
::fprintf (err_fh, "Attempt to execute '%s' failed.\n", commands.GetStringAtIndex(i));
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (out_fh)
|
|
|
|
::fprintf (out_fh, "%s", result.GetErrorStream().GetData());
|
2010-06-23 09:19:29 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (err_fh)
|
2010-06-23 09:19:29 +08:00
|
|
|
::fprintf (err_fh, "%s", result.GetOutputStream().GetData());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|