7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " CommandObjectPlatform.h"
10
+ #include " CommandOptionsProcessAttach.h"
10
11
#include " CommandOptionsProcessLaunch.h"
11
12
#include " lldb/Core/Debugger.h"
12
13
#include " lldb/Core/Module.h"
18
19
#include " lldb/Interpreter/CommandReturnObject.h"
19
20
#include " lldb/Interpreter/OptionGroupFile.h"
20
21
#include " lldb/Interpreter/OptionGroupPlatform.h"
22
+ #include " lldb/Interpreter/OptionGroupPythonClassWithDict.h"
23
+ #include " lldb/Interpreter/ScriptedMetadata.h"
21
24
#include " lldb/Target/ExecutionContext.h"
22
25
#include " lldb/Target/Platform.h"
23
26
#include " lldb/Target/Process.h"
@@ -1143,8 +1146,11 @@ class CommandObjectPlatformProcessLaunch : public CommandObjectParsed {
1143
1146
: CommandObjectParsed(interpreter, " platform process launch" ,
1144
1147
" Launch a new process on a remote platform." ,
1145
1148
" platform process launch program" ,
1146
- eCommandRequiresTarget | eCommandTryTargetAPILock) {
1149
+ eCommandRequiresTarget | eCommandTryTargetAPILock),
1150
+ m_class_options (" scripted process" , true , ' C' , ' k' , ' v' , 0 ) {
1147
1151
m_all_options.Append (&m_options);
1152
+ m_all_options.Append (&m_class_options, LLDB_OPT_SET_1 | LLDB_OPT_SET_2,
1153
+ LLDB_OPT_SET_ALL);
1148
1154
m_all_options.Finalize ();
1149
1155
CommandArgumentData run_arg_arg{eArgTypeRunArgs, eArgRepeatStar};
1150
1156
m_arguments.push_back ({run_arg_arg});
@@ -1179,6 +1185,15 @@ class CommandObjectPlatformProcessLaunch : public CommandObjectParsed {
1179
1185
m_options.launch_info .GetArchitecture () = exe_module->GetArchitecture ();
1180
1186
}
1181
1187
1188
+ if (!m_class_options.GetName ().empty ()) {
1189
+ m_options.launch_info .SetProcessPluginName (" ScriptedProcess" );
1190
+ m_options.launch_info .SetScriptedProcessClassName (
1191
+ m_class_options.GetName ());
1192
+ m_options.launch_info .SetScriptedProcessDictionarySP (
1193
+ m_class_options.GetStructuredData ());
1194
+ target->SetProcessLaunchInfo (m_options.launch_info );
1195
+ }
1196
+
1182
1197
if (argc > 0 ) {
1183
1198
if (m_options.launch_info .GetExecutableFile ()) {
1184
1199
// We already have an executable file, so we will use this and all
@@ -1222,6 +1237,7 @@ class CommandObjectPlatformProcessLaunch : public CommandObjectParsed {
1222
1237
}
1223
1238
1224
1239
CommandOptionsProcessLaunch m_options;
1240
+ OptionGroupPythonClassWithDict m_class_options;
1225
1241
OptionGroupOptions m_all_options;
1226
1242
};
1227
1243
@@ -1571,78 +1587,32 @@ class CommandObjectPlatformProcessInfo : public CommandObjectParsed {
1571
1587
1572
1588
class CommandObjectPlatformProcessAttach : public CommandObjectParsed {
1573
1589
public:
1574
- class CommandOptions : public Options {
1575
- public:
1576
- CommandOptions () {
1577
- // Keep default values of all options in one place: OptionParsingStarting
1578
- // ()
1579
- OptionParsingStarting (nullptr );
1580
- }
1581
-
1582
- ~CommandOptions () override = default ;
1583
-
1584
- Status SetOptionValue (uint32_t option_idx, llvm::StringRef option_arg,
1585
- ExecutionContext *execution_context) override {
1586
- Status error;
1587
- char short_option = (char )m_getopt_table[option_idx].val ;
1588
- switch (short_option) {
1589
- case ' p' : {
1590
- lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
1591
- if (option_arg.getAsInteger (0 , pid)) {
1592
- error.SetErrorStringWithFormat (" invalid process ID '%s'" ,
1593
- option_arg.str ().c_str ());
1594
- } else {
1595
- attach_info.SetProcessID (pid);
1596
- }
1597
- } break ;
1598
-
1599
- case ' P' :
1600
- attach_info.SetProcessPluginName (option_arg);
1601
- break ;
1602
-
1603
- case ' n' :
1604
- attach_info.GetExecutableFile ().SetFile (option_arg,
1605
- FileSpec::Style::native);
1606
- break ;
1607
-
1608
- case ' w' :
1609
- attach_info.SetWaitForLaunch (true );
1610
- break ;
1611
-
1612
- default :
1613
- llvm_unreachable (" Unimplemented option" );
1614
- }
1615
- return error;
1616
- }
1617
-
1618
- void OptionParsingStarting (ExecutionContext *execution_context) override {
1619
- attach_info.Clear ();
1620
- }
1621
-
1622
- llvm::ArrayRef<OptionDefinition> GetDefinitions () override {
1623
- return llvm::makeArrayRef (g_platform_process_attach_options);
1624
- }
1625
-
1626
- // Options table: Required for subclasses of Options.
1627
-
1628
- static OptionDefinition g_option_table[];
1629
-
1630
- // Instance variables to hold the values for command options.
1631
-
1632
- ProcessAttachInfo attach_info;
1633
- };
1634
-
1635
1590
CommandObjectPlatformProcessAttach (CommandInterpreter &interpreter)
1636
1591
: CommandObjectParsed(interpreter, " platform process attach" ,
1637
1592
" Attach to a process." ,
1638
- " platform process attach <cmd-options>" ) {}
1593
+ " platform process attach <cmd-options>" ),
1594
+ m_class_options (" scripted process" , true , ' C' , ' k' , ' v' , 0 ) {
1595
+ m_all_options.Append (&m_options);
1596
+ m_all_options.Append (&m_class_options, LLDB_OPT_SET_1 | LLDB_OPT_SET_2,
1597
+ LLDB_OPT_SET_ALL);
1598
+ m_all_options.Finalize ();
1599
+ }
1639
1600
1640
1601
~CommandObjectPlatformProcessAttach () override = default ;
1641
1602
1642
1603
bool DoExecute (Args &command, CommandReturnObject &result) override {
1643
1604
PlatformSP platform_sp (
1644
1605
GetDebugger ().GetPlatformList ().GetSelectedPlatform ());
1645
1606
if (platform_sp) {
1607
+
1608
+ if (!m_class_options.GetName ().empty ()) {
1609
+ m_options.attach_info .SetProcessPluginName (" ScriptedProcess" );
1610
+ m_options.attach_info .SetScriptedProcessClassName (
1611
+ m_class_options.GetName ());
1612
+ m_options.attach_info .SetScriptedProcessDictionarySP (
1613
+ m_class_options.GetStructuredData ());
1614
+ }
1615
+
1646
1616
Status err;
1647
1617
ProcessSP remote_process_sp = platform_sp->Attach (
1648
1618
m_options.attach_info , GetDebugger (), nullptr , err);
@@ -1658,10 +1628,12 @@ class CommandObjectPlatformProcessAttach : public CommandObjectParsed {
1658
1628
return result.Succeeded ();
1659
1629
}
1660
1630
1661
- Options *GetOptions () override { return &m_options ; }
1631
+ Options *GetOptions () override { return &m_all_options ; }
1662
1632
1663
1633
protected:
1664
- CommandOptions m_options;
1634
+ CommandOptionsProcessAttach m_options;
1635
+ OptionGroupPythonClassWithDict m_class_options;
1636
+ OptionGroupOptions m_all_options;
1665
1637
};
1666
1638
1667
1639
class CommandObjectPlatformProcess : public CommandObjectMultiword {
0 commit comments