summaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpointCommand.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpointCommand.cpp')
-rw-r--r--contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpointCommand.cpp125
1 files changed, 59 insertions, 66 deletions
diff --git a/contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpointCommand.cpp b/contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpointCommand.cpp
index 2be0b5b154e0..1b83e885d27e 100644
--- a/contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpointCommand.cpp
+++ b/contrib/llvm-project/lldb/source/Commands/CommandObjectWatchpointCommand.cpp
@@ -18,34 +18,42 @@
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Target/Target.h"
-#include "lldb/Target/Thread.h"
-#include "lldb/Utility/State.h"
using namespace lldb;
using namespace lldb_private;
-// CommandObjectWatchpointCommandAdd
-
// 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.
-
+// 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 constexpr OptionEnumValueElement g_script_option_enumeration[] = {
- {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."} };
+ {
+ eScriptLanguageNone,
+ "command",
+ "Commands are in the lldb command interpreter language",
+ },
+ {
+ eScriptLanguagePython,
+ "python",
+ "Commands are in the Python language.",
+ },
+ {
+ eScriptLanguageLua,
+ "lua",
+ "Commands are in the Python language.",
+ },
+ {
+ eSortOrderByName,
+ "default-script",
+ "Commands are in the default scripting language.",
+ },
+};
static constexpr OptionEnumValues ScriptOptionEnum() {
return OptionEnumValues(g_script_option_enumeration);
}
-static constexpr OptionDefinition g_watchpoint_command_add_options[] = {
#define LLDB_OPTIONS_watchpoint_command_add
#include "CommandOptions.inc"
-};
class CommandObjectWatchpointCommandAdd : public CommandObjectParsed,
public IOHandlerDelegateMultiline {
@@ -54,7 +62,7 @@ public:
: CommandObjectParsed(interpreter, "add",
"Add a set of LLDB commands to a watchpoint, to be "
"executed whenever the watchpoint is hit.",
- nullptr),
+ nullptr, eCommandRequiresTarget),
IOHandlerDelegateMultiline("DONE",
IOHandlerDelegate::Completion::LLDBCommand),
m_options() {
@@ -202,7 +210,7 @@ are no syntax errors may indicate that a function was declared but never called.
Options *GetOptions() override { return &m_options; }
void IOHandlerActivated(IOHandler &io_handler, bool interactive) override {
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ StreamFileSP output_sp(io_handler.GetOutputStreamFileSP());
if (output_sp && interactive) {
output_sp->PutCString(
"Enter your debugger command(s). Type 'DONE' to end.\n");
@@ -235,7 +243,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
wp_options); // Baton for the "io_handler" that will be passed back into
// our IOHandlerDelegate functions
}
@@ -328,8 +335,16 @@ are no syntax errors may indicate that a function was declared but never called.
option_arg, GetDefinitions()[option_idx].enum_values,
eScriptLanguageNone, error);
- m_use_script_language = (m_script_language == eScriptLanguagePython ||
- m_script_language == eScriptLanguageDefault);
+ switch (m_script_language) {
+ case eScriptLanguagePython:
+ case eScriptLanguageLua:
+ m_use_script_language = true;
+ break;
+ case eScriptLanguageNone:
+ case eScriptLanguageUnknown:
+ m_use_script_language = false;
+ break;
+ }
break;
case 'e': {
@@ -344,12 +359,11 @@ are no syntax errors may indicate that a function was declared but never called.
case 'F':
m_use_one_liner = false;
- m_use_script_language = true;
m_function_name.assign(option_arg);
break;
default:
- break;
+ llvm_unreachable("Unimplemented option");
}
return error;
}
@@ -384,14 +398,7 @@ are no syntax errors may indicate that a function was declared but never called.
protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
- Target *target = GetDebugger().GetSelectedTarget().get();
-
- if (target == nullptr) {
- result.AppendError("There is not a current executable; there are no "
- "watchpoints to which to add commands");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
+ Target *target = &GetSelectedTarget();
const WatchpointList &watchpoints = target->GetWatchpointList();
size_t num_watchpoints = watchpoints.GetSize();
@@ -402,12 +409,11 @@ 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 "
- "watchpoint command");
- result.SetStatus(eReturnStatusFailed);
- return false;
+ if (!m_options.m_function_name.empty()) {
+ if (!m_options.m_use_script_language) {
+ m_options.m_script_language = GetDebugger().GetScriptLanguage();
+ m_options.m_use_script_language = true;
+ }
}
std::vector<uint32_t> valid_wp_ids;
@@ -437,9 +443,11 @@ 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(
+ /*can_create=*/true, m_options.m_script_language);
// Special handling for one-liner specified inline.
if (m_options.m_use_one_liner) {
- GetDebugger().GetScriptInterpreter()->SetWatchpointCommandCallback(
+ script_interp->SetWatchpointCommandCallback(
wp_options, m_options.m_one_liner.c_str());
}
// Special handling for using a Python function by name instead of
@@ -449,12 +457,11 @@ protected:
else if (!m_options.m_function_name.empty()) {
std::string oneliner(m_options.m_function_name);
oneliner += "(frame, wp, internal_dict)";
- GetDebugger().GetScriptInterpreter()->SetWatchpointCommandCallback(
+ script_interp->SetWatchpointCommandCallback(
wp_options, oneliner.c_str());
} else {
- GetDebugger()
- .GetScriptInterpreter()
- ->CollectDataForWatchpointCommandCallback(wp_options, result);
+ script_interp->CollectDataForWatchpointCommandCallback(wp_options,
+ result);
}
} else {
// Special handling for one-liner specified inline.
@@ -481,7 +488,7 @@ public:
CommandObjectWatchpointCommandDelete(CommandInterpreter &interpreter)
: CommandObjectParsed(interpreter, "delete",
"Delete the set of commands from a watchpoint.",
- nullptr) {
+ nullptr, eCommandRequiresTarget) {
CommandArgumentEntry arg;
CommandArgumentData wp_id_arg;
@@ -501,14 +508,7 @@ public:
protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
- Target *target = GetDebugger().GetSelectedTarget().get();
-
- if (target == nullptr) {
- result.AppendError("There is not a current executable; there are no "
- "watchpoints from which to delete commands");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
+ Target *target = &GetSelectedTarget();
const WatchpointList &watchpoints = target->GetWatchpointList();
size_t num_watchpoints = watchpoints.GetSize();
@@ -557,10 +557,10 @@ protected:
class CommandObjectWatchpointCommandList : public CommandObjectParsed {
public:
CommandObjectWatchpointCommandList(CommandInterpreter &interpreter)
- : CommandObjectParsed(interpreter, "list", "List the script or set of "
- "commands to be executed when "
- "the watchpoint is hit.",
- nullptr) {
+ : CommandObjectParsed(interpreter, "list",
+ "List the script or set of commands to be executed "
+ "when the watchpoint is hit.",
+ nullptr, eCommandRequiresTarget) {
CommandArgumentEntry arg;
CommandArgumentData wp_id_arg;
@@ -580,14 +580,7 @@ public:
protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
- Target *target = GetDebugger().GetSelectedTarget().get();
-
- if (target == nullptr) {
- result.AppendError("There is not a current executable; there are no "
- "watchpoints for which to list commands");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
+ Target *target = &GetSelectedTarget();
const WatchpointList &watchpoints = target->GetWatchpointList();
size_t num_watchpoints = watchpoints.GetSize();
@@ -627,10 +620,10 @@ protected:
const Baton *baton = wp_options->GetBaton();
if (baton) {
result.GetOutputStream().Printf("Watchpoint %u:\n", cur_wp_id);
- result.GetOutputStream().IndentMore();
- baton->GetDescription(&result.GetOutputStream(),
- eDescriptionLevelFull);
- result.GetOutputStream().IndentLess();
+ baton->GetDescription(result.GetOutputStream().AsRawOstream(),
+ eDescriptionLevelFull,
+ result.GetOutputStream().GetIndentLevel() +
+ 2);
} else {
result.AppendMessageWithFormat(
"Watchpoint %u does not have an associated command.\n",