diff options
author | Enrico Granata <egranata@apple.com> | 2012-04-04 17:30:31 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2012-04-04 17:30:31 +0000 |
commit | 8d4a8010cf9a9e2d7b7aa047677a6fc29cca630a (patch) | |
tree | fc2308f067c2fd39a95635fccb8e0fa47f2ef941 /lldb/source/Commands/CommandObjectBreakpointCommand.cpp | |
parent | f264d5dc01c06b74ca41801ecc967e5b9b8f21ac (diff) | |
download | bcm5719-llvm-8d4a8010cf9a9e2d7b7aa047677a6fc29cca630a.tar.gz bcm5719-llvm-8d4a8010cf9a9e2d7b7aa047677a6fc29cca630a.zip |
Adding a new --python-function (-F) option to breakpoint command add. The option allows the user to specify a Python function name instead of a Python oneliner or interactive script input as a breakpoint command
llvm-svn: 154026
Diffstat (limited to 'lldb/source/Commands/CommandObjectBreakpointCommand.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectBreakpointCommand.cpp | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp index 5ab93d72632..dcc9f9bb858 100644 --- a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp @@ -37,7 +37,8 @@ CommandObjectBreakpointCommandAdd::CommandOptions::CommandOptions (CommandInterp m_use_script_language (false), m_script_language (eScriptLanguageNone), m_use_one_liner (false), - m_one_liner() + m_one_liner(), + m_function_name() { } @@ -60,7 +61,7 @@ g_script_option_enumeration[4] = OptionDefinition CommandObjectBreakpointCommandAdd::CommandOptions::g_option_table[] = { - { LLDB_OPT_SET_ALL, false, "one-liner", 'o', required_argument, NULL, NULL, eArgTypeOneLiner, + { LLDB_OPT_SET_1, 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, @@ -69,6 +70,9 @@ CommandObjectBreakpointCommandAdd::CommandOptions::g_option_table[] = { 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."}, + { LLDB_OPT_SET_2, false, "python-function", 'F', required_argument, NULL, NULL, eArgTypePythonFunction, + "Give the name of a Python function to run as command for this breakpoint. Be sure to give a module name if appropriate."}, + { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } }; @@ -104,12 +108,10 @@ CommandObjectBreakpointCommandAdd::CommandOptions::SetOptionValue 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; @@ -122,6 +124,14 @@ CommandObjectBreakpointCommandAdd::CommandOptions::SetOptionValue error.SetErrorStringWithFormat("invalid value for stop-on-error: \"%s\"", option_arg); } break; + + case 'F': + { + m_use_one_liner = false; + m_use_script_language = true; + m_function_name.assign(option_arg); + } + break; default: break; @@ -139,6 +149,7 @@ CommandObjectBreakpointCommandAdd::CommandOptions::OptionParsingStarting () m_use_one_liner = false; m_stop_on_error = true; m_one_liner.clear(); + m_function_name.clear(); } //------------------------------------------------------------------------- @@ -191,7 +202,8 @@ 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\ +breakpoint commands. \nAs a third option, you can pass the name of an already \ +existing Python function and that function will be attached to the breakpoint. \n\ \n\ Example Python one-line breakpoint command: \n\ \n\ @@ -304,6 +316,13 @@ CommandObjectBreakpointCommandAdd::Execute return false; } + if (m_options.m_use_script_language == false && m_options.m_function_name.size()) + { + result.AppendError ("need to enable scripting to have a function run as a breakpoint command"); + result.SetStatus (eReturnStatusFailed); + return false; + } + BreakpointIDList valid_bp_ids; CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); @@ -341,11 +360,25 @@ CommandObjectBreakpointCommandAdd::Execute { // 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()); + } + // Special handling for using a Python function by name + // instead of extending the breakpoint callback data structures, we just automatize + // what the user would do manually: make their breakpoint command be a function call + else if (m_options.m_function_name.size()) + { + std::string oneliner(m_options.m_function_name); + oneliner += "(frame, bp_loc, dict)"; + m_interpreter.GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options, + oneliner.c_str()); + } else + { m_interpreter.GetScriptInterpreter()->CollectDataForBreakpointCommandCallback (bp_options, result); + } } else { |