aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectPlatform.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/CommandObjectPlatform.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/CommandObjectPlatform.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectPlatform.cpp102
1 files changed, 37 insertions, 65 deletions
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index 1ab218f..40e037a 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "CommandObjectPlatform.h"
+#include "CommandOptionsProcessAttach.h"
#include "CommandOptionsProcessLaunch.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Module.h"
@@ -18,6 +19,8 @@
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Interpreter/OptionGroupFile.h"
#include "lldb/Interpreter/OptionGroupPlatform.h"
+#include "lldb/Interpreter/OptionGroupPythonClassWithDict.h"
+#include "lldb/Interpreter/ScriptedMetadata.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
@@ -1144,8 +1147,11 @@ public:
: CommandObjectParsed(interpreter, "platform process launch",
"Launch a new process on a remote platform.",
"platform process launch program",
- eCommandRequiresTarget | eCommandTryTargetAPILock) {
+ eCommandRequiresTarget | eCommandTryTargetAPILock),
+ 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();
CommandArgumentData run_arg_arg{eArgTypeRunArgs, eArgRepeatStar};
m_arguments.push_back({run_arg_arg});
@@ -1180,6 +1186,15 @@ protected:
m_options.launch_info.GetArchitecture() = exe_module->GetArchitecture();
}
+ if (!m_class_options.GetName().empty()) {
+ m_options.launch_info.SetProcessPluginName("ScriptedProcess");
+ m_options.launch_info.SetScriptedProcessClassName(
+ m_class_options.GetName());
+ m_options.launch_info.SetScriptedProcessDictionarySP(
+ m_class_options.GetStructuredData());
+ target->SetProcessLaunchInfo(m_options.launch_info);
+ }
+
if (argc > 0) {
if (m_options.launch_info.GetExecutableFile()) {
// We already have an executable file, so we will use this and all
@@ -1223,6 +1238,7 @@ protected:
}
CommandOptionsProcessLaunch m_options;
+ OptionGroupPythonClassWithDict m_class_options;
OptionGroupOptions m_all_options;
};
@@ -1572,71 +1588,16 @@ protected:
class CommandObjectPlatformProcessAttach : public CommandObjectParsed {
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;
- char short_option = (char)m_getopt_table[option_idx].val;
- switch (short_option) {
- case 'p': {
- lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
- 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;
-
- 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_platform_process_attach_options);
- }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
-
- // Instance variables to hold the values for command options.
-
- ProcessAttachInfo attach_info;
- };
-
CommandObjectPlatformProcessAttach(CommandInterpreter &interpreter)
: CommandObjectParsed(interpreter, "platform process attach",
"Attach to a process.",
- "platform process attach <cmd-options>") {}
+ "platform process attach <cmd-options>"),
+ 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();
+ }
~CommandObjectPlatformProcessAttach() override = default;
@@ -1644,6 +1605,15 @@ public:
PlatformSP platform_sp(
GetDebugger().GetPlatformList().GetSelectedPlatform());
if (platform_sp) {
+
+ 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());
+ }
+
Status err;
ProcessSP remote_process_sp = platform_sp->Attach(
m_options.attach_info, GetDebugger(), nullptr, err);
@@ -1659,10 +1629,12 @@ public:
return result.Succeeded();
}
- Options *GetOptions() override { return &m_options; }
+ Options *GetOptions() override { return &m_all_options; }
protected:
- CommandOptions m_options;
+ CommandOptionsProcessAttach m_options;
+ OptionGroupPythonClassWithDict m_class_options;
+ OptionGroupOptions m_all_options;
};
class CommandObjectPlatformProcess : public CommandObjectMultiword {