aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectProcess.cpp
diff options
context:
space:
mode:
authorMed Ismail Bennani <medismail.bennani@gmail.com>2023-03-03 15:27:07 -0800
committerMed Ismail Bennani <medismail.bennani@gmail.com>2023-03-03 19:33:02 -0800
commit3014a1c5a130daeb73f6d3b7280c5ceaeadc66a8 (patch)
tree974442f6679db5d845094e5813bc982e1bff20e7 /lldb/source/Commands/CommandObjectProcess.cpp
parent2d5348be2561402e284e26a9adf3a2e28e70c1f5 (diff)
downloadllvm-3014a1c5a130daeb73f6d3b7280c5ceaeadc66a8.zip
llvm-3014a1c5a130daeb73f6d3b7280c5ceaeadc66a8.tar.gz
llvm-3014a1c5a130daeb73f6d3b7280c5ceaeadc66a8.tar.bz2
[lldb] Add scripted process launch/attach option to {,platform }process commands
This patch does several things: First, it refactors the `CommandObject{,Platform}ProcessObject` command option class into a separate `CommandOptionsProcessAttach` option group. This will make sure both the `platform process attach` and `process attach` command options will always stay in sync without having with duplicate them each time. But more importantly, making this class an `OptionGroup` allows us to combine with a `OptionGroupPythonClassWithDict` to add support for the scripted process managing class name and user-provided dictionary options. This patch also improves feature parity between `ProcessLaunchInfo` and `ProcessAttachInfo` with regard to ScriptedProcesses, by exposing the various getters and setters necessary to use them through the SBAPI. This is foundation work for adding support to "attach" to a process from the scripted platform. Differential Revision: https://reviews.llvm.org/D139945 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
Diffstat (limited to 'lldb/source/Commands/CommandObjectProcess.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectProcess.cpp87
1 files changed, 21 insertions, 66 deletions
diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp
index a45371f..ff9992a 100644
--- a/lldb/source/Commands/CommandObjectProcess.cpp
+++ b/lldb/source/Commands/CommandObjectProcess.cpp
@@ -9,6 +9,7 @@
#include "CommandObjectProcess.h"
#include "CommandObjectBreakpoint.h"
#include "CommandObjectTrace.h"
+#include "CommandOptionsProcessAttach.h"
#include "CommandOptionsProcessLaunch.h"
#include "lldb/Breakpoint/Breakpoint.h"
#include "lldb/Breakpoint/BreakpointIDList.h"
@@ -24,6 +25,7 @@
#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionGroupPythonClassWithDict.h"
#include "lldb/Interpreter/Options.h"
+#include "lldb/Interpreter/ScriptedMetadata.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/StopInfo.h"
@@ -304,77 +306,20 @@ protected:
#pragma mark CommandObjectProcessAttach
class CommandObjectProcessAttach : public CommandObjectProcessLaunchOrAttach {
public:
- class CommandOptions : public Options {
- public:
- CommandOptions() {
- // Keep default values of all options in one place: OptionParsingStarting
- // ()
- OptionParsingStarting(nullptr);
- }
-
- ~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;
- switch (short_option) {
- case 'c':
- attach_info.SetContinueOnceAttached(true);
- break;
-
- case 'p': {
- lldb::pid_t pid;
- if (option_arg.getAsInteger(0, pid)) {
- error.SetErrorStringWithFormat("invalid process ID '%s'",
- option_arg.str().c_str());
- } else {
- attach_info.SetProcessID(pid);
- }
- } break;
-
- case 'P':
- attach_info.SetProcessPluginName(option_arg);
- break;
-
- case 'n':
- attach_info.GetExecutableFile().SetFile(option_arg,
- FileSpec::Style::native);
- break;
-
- case 'w':
- attach_info.SetWaitForLaunch(true);
- break;
-
- case 'i':
- attach_info.SetIgnoreExisting(false);
- break;
-
- default:
- llvm_unreachable("Unimplemented option");
- }
- return error;
- }
-
- void OptionParsingStarting(ExecutionContext *execution_context) override {
- attach_info.Clear();
- }
-
- llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
- return llvm::ArrayRef(g_process_attach_options);
- }
-
- ProcessAttachInfo attach_info;
- };
-
CommandObjectProcessAttach(CommandInterpreter &interpreter)
: CommandObjectProcessLaunchOrAttach(
interpreter, "process attach", "Attach to a process.",
- "process attach <cmd-options>", 0, "attach") {}
+ "process attach <cmd-options>", 0, "attach"),
+ m_class_options("scripted process", true, 'C', 'k', 'v', 0) {
+ m_all_options.Append(&m_options);
+ m_all_options.Append(&m_class_options, LLDB_OPT_SET_1 | LLDB_OPT_SET_2,
+ LLDB_OPT_SET_ALL);
+ m_all_options.Finalize();
+ }
~CommandObjectProcessAttach() override = default;
- Options *GetOptions() override { return &m_options; }
+ Options *GetOptions() override { return &m_all_options; }
protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
@@ -409,6 +354,14 @@ protected:
}
}
+ if (!m_class_options.GetName().empty()) {
+ m_options.attach_info.SetProcessPluginName("ScriptedProcess");
+ m_options.attach_info.SetScriptedProcessClassName(
+ m_class_options.GetName());
+ m_options.attach_info.SetScriptedProcessDictionarySP(
+ m_class_options.GetStructuredData());
+ }
+
// Record the old executable module, we want to issue a warning if the
// process of attaching changed the current executable (like somebody said
// "file foo" then attached to a PID whose executable was bar.)
@@ -483,7 +436,9 @@ protected:
return result.Succeeded();
}
- CommandOptions m_options;
+ CommandOptionsProcessAttach m_options;
+ OptionGroupPythonClassWithDict m_class_options;
+ OptionGroupOptions m_all_options;
};
// CommandObjectProcessContinue