summaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectBreakpointCommand.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Commands/CommandObjectBreakpointCommand.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectBreakpointCommand.cpp105
1 files changed, 57 insertions, 48 deletions
diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp
index a6bcd1d8dc32e..bbd2ca5701266 100644
--- a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp
+++ b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp
@@ -11,17 +11,13 @@
#include "lldb/Breakpoint/Breakpoint.h"
#include "lldb/Breakpoint/BreakpointIDList.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
-#include "lldb/Breakpoint/StoppointCallbackContext.h"
#include "lldb/Core/IOHandler.h"
#include "lldb/Host/OptionParser.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Interpreter/OptionArgParser.h"
+#include "lldb/Interpreter/OptionGroupPythonClassWithDict.h"
#include "lldb/Target/Target.h"
-#include "lldb/Target/Thread.h"
-#include "lldb/Utility/State.h"
-
-#include "llvm/ADT/STLExtras.h"
using namespace lldb;
using namespace lldb_private;
@@ -41,7 +37,12 @@ static constexpr OptionEnumValueElement g_script_option_enumeration[] = {
"Commands are in the Python language.",
},
{
- eSortOrderByName,
+ eScriptLanguageLua,
+ "lua",
+ "Commands are in the Lua language.",
+ },
+ {
+ eScriptLanguageDefault,
"default-script",
"Commands are in the default scripting language.",
},
@@ -66,7 +67,7 @@ public:
nullptr),
IOHandlerDelegateMultiline("DONE",
IOHandlerDelegate::Completion::LLDBCommand),
- m_options() {
+ m_options(), m_func_options("breakpoint command", false, 'F') {
SetHelpLong(
R"(
General information about entering breakpoint commands
@@ -201,6 +202,11 @@ LLDB to stop."
"Final Note: A warning that no breakpoint command was generated when there \
are no syntax errors may indicate that a function was declared but never called.");
+ m_all_options.Append(&m_options);
+ m_all_options.Append(&m_func_options, LLDB_OPT_SET_2 | LLDB_OPT_SET_3,
+ LLDB_OPT_SET_2);
+ m_all_options.Finalize();
+
CommandArgumentEntry arg;
CommandArgumentData bp_id_arg;
@@ -218,7 +224,7 @@ are no syntax errors may indicate that a function was declared but never called.
~CommandObjectBreakpointCommandAdd() override = default;
- Options *GetOptions() override { return &m_options; }
+ Options *GetOptions() override { return &m_all_options; }
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
@@ -250,7 +256,6 @@ are no syntax errors may indicate that a function was declared but never called.
m_interpreter.GetLLDBCommandsFromIOHandler(
"> ", // Prompt
*this, // IOHandlerDelegate
- true, // Run IOHandler in async mode
&bp_options_vec); // Baton for the "io_handler" that will be passed back
// into our IOHandlerDelegate functions
}
@@ -269,19 +274,20 @@ are no syntax errors may indicate that a function was declared but never called.
}
}
- class CommandOptions : public Options {
+ class CommandOptions : public OptionGroup {
public:
CommandOptions()
- : Options(), m_use_commands(false), m_use_script_language(false),
+ : OptionGroup(), m_use_commands(false), m_use_script_language(false),
m_script_language(eScriptLanguageNone), m_use_one_liner(false),
- m_one_liner(), m_function_name() {}
+ m_one_liner() {}
~CommandOptions() override = default;
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
ExecutionContext *execution_context) override {
Status error;
- const int short_option = m_getopt_table[option_idx].val;
+ const int short_option =
+ g_breakpoint_command_add_options[option_idx].short_option;
switch (short_option) {
case 'o':
@@ -294,12 +300,15 @@ are no syntax errors may indicate that a function was declared but never called.
option_arg,
g_breakpoint_command_add_options[option_idx].enum_values,
eScriptLanguageNone, error);
-
- if (m_script_language == eScriptLanguagePython ||
- m_script_language == eScriptLanguageDefault) {
+ switch (m_script_language) {
+ case eScriptLanguagePython:
+ case eScriptLanguageLua:
m_use_script_language = true;
- } else {
+ break;
+ case eScriptLanguageNone:
+ case eScriptLanguageUnknown:
m_use_script_language = false;
+ break;
}
break;
@@ -313,12 +322,6 @@ are no syntax errors may indicate that a function was declared but never called.
option_arg.str().c_str());
} break;
- case 'F':
- m_use_one_liner = false;
- m_use_script_language = true;
- m_function_name.assign(option_arg);
- break;
-
case 'D':
m_use_dummy = true;
break;
@@ -337,7 +340,6 @@ are no syntax errors may indicate that a function was declared but never called.
m_use_one_liner = false;
m_stop_on_error = true;
m_one_liner.clear();
- m_function_name.clear();
m_use_dummy = false;
}
@@ -355,7 +357,6 @@ are no syntax errors may indicate that a function was declared but never called.
bool m_use_one_liner;
std::string m_one_liner;
bool m_stop_on_error;
- std::string m_function_name;
bool m_use_dummy;
};
@@ -372,12 +373,12 @@ protected:
return false;
}
- if (!m_options.m_use_script_language &&
- !m_options.m_function_name.empty()) {
- result.AppendError("need to enable scripting to have a function run as a "
- "breakpoint command");
- result.SetStatus(eReturnStatusFailed);
- return false;
+ if (!m_func_options.GetName().empty()) {
+ m_options.m_use_one_liner = false;
+ if (!m_options.m_use_script_language) {
+ m_options.m_script_language = GetDebugger().GetScriptLanguage();
+ m_options.m_use_script_language = true;
+ }
}
BreakpointIDList valid_bp_ids;
@@ -416,14 +417,18 @@ protected:
// to set or collect command callback. Otherwise, call the methods
// associated with this object.
if (m_options.m_use_script_language) {
- ScriptInterpreter *script_interp = GetDebugger().GetScriptInterpreter();
+ ScriptInterpreter *script_interp = GetDebugger().GetScriptInterpreter(
+ /*can_create=*/true, m_options.m_script_language);
// Special handling for one-liner specified inline.
if (m_options.m_use_one_liner) {
script_interp->SetBreakpointCommandCallback(
m_bp_options_vec, m_options.m_one_liner.c_str());
- } else if (!m_options.m_function_name.empty()) {
- script_interp->SetBreakpointCommandCallbackFunction(
- m_bp_options_vec, m_options.m_function_name.c_str());
+ } else if (!m_func_options.GetName().empty()) {
+ Status error = script_interp->SetBreakpointCommandCallbackFunction(
+ m_bp_options_vec, m_func_options.GetName().c_str(),
+ m_func_options.GetStructuredData());
+ if (!error.Success())
+ result.SetError(error);
} else {
script_interp->CollectDataForBreakpointCommandCallback(
m_bp_options_vec, result);
@@ -443,6 +448,9 @@ protected:
private:
CommandOptions m_options;
+ OptionGroupPythonClassWithDict m_func_options;
+ OptionGroupOptions m_all_options;
+
std::vector<BreakpointOptions *> m_bp_options_vec; // This stores the
// breakpoint options that
// we are currently
@@ -646,9 +654,8 @@ protected:
if (bp) {
BreakpointLocationSP bp_loc_sp;
if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) {
- bp_loc_sp = bp->FindLocationByID(cur_bp_id.GetLocationID());
- if (!bp_loc_sp)
- {
+ bp_loc_sp = bp->FindLocationByID(cur_bp_id.GetLocationID());
+ if (!bp_loc_sp) {
result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n",
cur_bp_id.GetBreakpointID(),
cur_bp_id.GetLocationID());
@@ -663,19 +670,20 @@ protected:
cur_bp_id.GetLocationID());
const Baton *baton = nullptr;
if (bp_loc_sp)
- baton = bp_loc_sp
- ->GetOptionsSpecifyingKind(BreakpointOptions::eCallback)
- ->GetBaton();
+ baton =
+ bp_loc_sp
+ ->GetOptionsSpecifyingKind(BreakpointOptions::eCallback)
+ ->GetBaton();
else
baton = bp->GetOptions()->GetBaton();
if (baton) {
result.GetOutputStream().Printf("Breakpoint %s:\n",
id_str.GetData());
- result.GetOutputStream().IndentMore();
- baton->GetDescription(&result.GetOutputStream(),
- eDescriptionLevelFull);
- result.GetOutputStream().IndentLess();
+ baton->GetDescription(result.GetOutputStream().AsRawOstream(),
+ eDescriptionLevelFull,
+ result.GetOutputStream().GetIndentLevel() +
+ 2);
} else {
result.AppendMessageWithFormat(
"Breakpoint %s does not have an associated command.\n",
@@ -700,9 +708,10 @@ protected:
CommandObjectBreakpointCommand::CommandObjectBreakpointCommand(
CommandInterpreter &interpreter)
: CommandObjectMultiword(
- interpreter, "command", "Commands for adding, removing and listing "
- "LLDB commands executed when a breakpoint is "
- "hit.",
+ interpreter, "command",
+ "Commands for adding, removing and listing "
+ "LLDB commands executed when a breakpoint is "
+ "hit.",
"command <sub-command> [<sub-command-options>] <breakpoint-id>") {
CommandObjectSP add_command_object(
new CommandObjectBreakpointCommandAdd(interpreter));