mib created this revision.
mib added reviewers: JDevlieghere, jingham, jasonmolenda, labath, LLDB.
mib added a project: LLDB.
Herald added a subscriber: dang.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.
This patch adds a new command options to the CommandObjectProecessLaunch
for scripted processes.
Among the options, the user need to specify the class name managing the
scripted process. The user can also use a key-value dictionary holding
arbitrary data that will be passed to the managing class.
rdar://65508855
Signed-off-by: Med Ismail Bennani <[email protected]>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D95710
Files:
lldb/include/lldb/Host/ProcessLaunchInfo.h
lldb/source/Commands/CommandObjectPlatform.cpp
lldb/source/Commands/CommandObjectProcess.cpp
lldb/source/Commands/CommandOptionsProcessLaunch.cpp
lldb/source/Commands/CommandOptionsProcessLaunch.h
lldb/source/Commands/Options.td
lldb/source/Host/common/ProcessLaunchInfo.cpp
Index: lldb/source/Host/common/ProcessLaunchInfo.cpp
===================================================================
--- lldb/source/Host/common/ProcessLaunchInfo.cpp
+++ lldb/source/Host/common/ProcessLaunchInfo.cpp
@@ -32,7 +32,9 @@
: ProcessInfo(), m_working_dir(), m_plugin_name(), m_flags(0),
m_file_actions(), m_pty(new PseudoTerminal), m_resume_count(0),
m_monitor_callback(nullptr), m_monitor_callback_baton(nullptr),
- m_monitor_signals(false), m_listener_sp(), m_hijack_listener_sp() {}
+ m_monitor_signals(false), m_listener_sp(), m_hijack_listener_sp(),
+ m_scripted_process(false), m_scripted_process_class_name(),
+ m_scripted_process_dictionary_sp() {}
ProcessLaunchInfo::ProcessLaunchInfo(const FileSpec &stdin_file_spec,
const FileSpec &stdout_file_spec,
@@ -42,7 +44,9 @@
: ProcessInfo(), m_working_dir(), m_plugin_name(), m_flags(launch_flags),
m_file_actions(), m_pty(new PseudoTerminal), m_resume_count(0),
m_monitor_callback(nullptr), m_monitor_callback_baton(nullptr),
- m_monitor_signals(false), m_listener_sp(), m_hijack_listener_sp() {
+ m_monitor_signals(false), m_listener_sp(), m_hijack_listener_sp(),
+ m_scripted_process(false), m_scripted_process_class_name(),
+ m_scripted_process_dictionary_sp() {
if (stdin_file_spec) {
FileAction file_action;
const bool read = true;
@@ -171,6 +175,9 @@
m_resume_count = 0;
m_listener_sp.reset();
m_hijack_listener_sp.reset();
+ m_scripted_process = false;
+ m_scripted_process_class_name = "";
+ m_scripted_process_dictionary_sp.reset();
}
void ProcessLaunchInfo::SetMonitorProcessCallback(
Index: lldb/source/Commands/Options.td
===================================================================
--- lldb/source/Commands/Options.td
+++ lldb/source/Commands/Options.td
@@ -673,6 +673,8 @@
Desc<"Do not set up for terminal I/O to go to running process.">;
def process_launch_shell_expand_args : Option<"shell-expand-args", "X">, Group<4>,
Arg<"Boolean">, Desc<"Set whether to shell expand arguments to the process when launching.">;
+ def process_launch_scripted : Option<"scripted", "S">, GroupRange<1,4>,
+ Desc<"Whether the process launched is a scripted process.">;
}
let Command = "process attach" in {
Index: lldb/source/Commands/CommandOptionsProcessLaunch.h
===================================================================
--- lldb/source/Commands/CommandOptionsProcessLaunch.h
+++ lldb/source/Commands/CommandOptionsProcessLaunch.h
@@ -1,4 +1,4 @@
-//===-- CommandOptionsProcessLaunch.h -------------------------------------===//
+//===-- CommandOptionsProcessLaunch.h ---------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -16,9 +16,9 @@
// CommandOptionsProcessLaunch
-class CommandOptionsProcessLaunch : public lldb_private::Options {
+class CommandOptionsProcessLaunch : public lldb_private::OptionGroup {
public:
- CommandOptionsProcessLaunch() : lldb_private::Options() {
+ CommandOptionsProcessLaunch() : lldb_private::OptionGroup() {
// Keep default values of all options in one place: OptionParsingStarting
// ()
OptionParsingStarting(nullptr);
Index: lldb/source/Commands/CommandOptionsProcessLaunch.cpp
===================================================================
--- lldb/source/Commands/CommandOptionsProcessLaunch.cpp
+++ lldb/source/Commands/CommandOptionsProcessLaunch.cpp
@@ -30,7 +30,7 @@
uint32_t option_idx, llvm::StringRef option_arg,
ExecutionContext *execution_context) {
Status error;
- const int short_option = m_getopt_table[option_idx].val;
+ const int short_option = g_process_launch_options[option_idx].short_option;
switch (short_option) {
case 's': // Stop at program entry point
@@ -134,6 +134,11 @@
launch_info.GetEnvironment().insert(option_arg);
break;
+ case 'S':
+ launch_info.SetScriptedProcess(true);
+ launch_info.SetProcessPluginName("ScriptedProcess");
+ break;
+
default:
error.SetErrorStringWithFormat("unrecognized short option character '%c'",
short_option);
Index: lldb/source/Commands/CommandObjectProcess.cpp
===================================================================
--- lldb/source/Commands/CommandObjectProcess.cpp
+++ lldb/source/Commands/CommandObjectProcess.cpp
@@ -17,6 +17,7 @@
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Interpreter/OptionArgParser.h"
+#include "lldb/Interpreter/OptionGroupPythonClassWithDict.h"
#include "lldb/Interpreter/Options.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
@@ -108,7 +109,13 @@
interpreter, "process launch",
"Launch the executable in the debugger.", nullptr,
eCommandRequiresTarget, "restart"),
- m_options() {
+ m_options(), m_class_options("scripted process (use with --Scripted)"),
+ m_all_options() {
+ m_all_options.Append(&m_options);
+ m_all_options.Append(&m_class_options, LLDB_OPT_SET_1 | LLDB_OPT_SET_2,
+ LLDB_OPT_SET_1);
+ m_all_options.Finalize();
+
CommandArgumentEntry arg;
CommandArgumentData run_args_arg;
@@ -135,7 +142,7 @@
request, nullptr);
}
- Options *GetOptions() override { return &m_options; }
+ Options *GetOptions() override { return &m_all_options; }
const char *GetRepeatCommand(Args ¤t_command_args,
uint32_t index) override {
@@ -180,6 +187,14 @@
disable_aslr = target->GetDisableASLR();
}
+ if (m_options.launch_info.IsScriptedProcess()) {
+ 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 (disable_aslr)
m_options.launch_info.GetFlags().Set(eLaunchFlagDisableASLR);
else
@@ -253,6 +268,8 @@
}
CommandOptionsProcessLaunch m_options;
+ OptionGroupPythonClassWithDict m_class_options;
+ OptionGroupOptions m_all_options;
};
#define LLDB_OPTIONS_process_attach
Index: lldb/source/Commands/CommandObjectPlatform.cpp
===================================================================
--- lldb/source/Commands/CommandObjectPlatform.cpp
+++ lldb/source/Commands/CommandObjectPlatform.cpp
@@ -1009,11 +1009,14 @@
"Launch a new process on a remote platform.",
"platform process launch program",
eCommandRequiresTarget | eCommandTryTargetAPILock),
- m_options() {}
+ m_options(), m_all_options() {
+ m_all_options.Append(&m_options);
+ m_all_options.Finalize();
+ }
~CommandObjectPlatformProcessLaunch() override = default;
- Options *GetOptions() override { return &m_options; }
+ Options *GetOptions() override { return &m_all_options; }
protected:
bool DoExecute(Args &args, CommandReturnObject &result) override {
@@ -1085,6 +1088,7 @@
}
CommandOptionsProcessLaunch m_options;
+ OptionGroupOptions m_all_options;
};
// "platform process list"
Index: lldb/include/lldb/Host/ProcessLaunchInfo.h
===================================================================
--- lldb/include/lldb/Host/ProcessLaunchInfo.h
+++ lldb/include/lldb/Host/ProcessLaunchInfo.h
@@ -20,6 +20,7 @@
#include "lldb/Host/PseudoTerminal.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/ProcessInfo.h"
+#include "lldb/Utility/StructuredData.h"
namespace lldb_private {
@@ -146,6 +147,28 @@
return m_flags.Test(lldb::eLaunchFlagDetachOnError);
}
+ bool IsScriptedProcess() const { return m_scripted_process; }
+
+ void SetScriptedProcess(bool b) { m_scripted_process = b; }
+
+ llvm::StringRef GetScriptedProcessClassName() const {
+ return m_scripted_process_class_name;
+ }
+
+ void SetScriptedProcessClassName(llvm::StringRef name) {
+ m_scripted_process_class_name = name;
+ }
+
+ lldb_private::StructuredData::DictionarySP
+ GetScriptedProcessDictionarySP() const {
+ return m_scripted_process_dictionary_sp;
+ }
+
+ void SetScriptedProcessDictionarySP(
+ lldb_private::StructuredData::DictionarySP dictionary_sp) {
+ m_scripted_process_dictionary_sp = dictionary_sp;
+ }
+
protected:
FileSpec m_working_dir;
std::string m_plugin_name;
@@ -161,6 +184,9 @@
// meaning to the upper levels of lldb.
lldb::ListenerSP m_listener_sp;
lldb::ListenerSP m_hijack_listener_sp;
+ bool m_scripted_process;
+ llvm::StringRef m_scripted_process_class_name;
+ StructuredData::DictionarySP m_scripted_process_dictionary_sp;
};
}
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits