1ac7ddfbfSEd Maste //===-- CommandObjectPlatform.cpp -------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste
104bb0738eSEd Maste #include <mutex>
114bb0738eSEd Maste #include "CommandObjectPlatform.h"
12ac7ddfbfSEd Maste #include "lldb/Core/Debugger.h"
13ac7ddfbfSEd Maste #include "lldb/Core/Module.h"
14ac7ddfbfSEd Maste #include "lldb/Core/PluginManager.h"
15f678e45dSDimitry Andric #include "lldb/Host/OptionParser.h"
161c3bbb01SEd Maste #include "lldb/Host/StringConvert.h"
17ac7ddfbfSEd Maste #include "lldb/Interpreter/CommandInterpreter.h"
180127ef0fSEd Maste #include "lldb/Interpreter/CommandOptionValidators.h"
19ac7ddfbfSEd Maste #include "lldb/Interpreter/CommandReturnObject.h"
20b952cd58SEd Maste #include "lldb/Interpreter/OptionGroupFile.h"
21ac7ddfbfSEd Maste #include "lldb/Interpreter/OptionGroupPlatform.h"
22ac7ddfbfSEd Maste #include "lldb/Target/ExecutionContext.h"
23ac7ddfbfSEd Maste #include "lldb/Target/Platform.h"
24ac7ddfbfSEd Maste #include "lldb/Target/Process.h"
254ba319b5SDimitry Andric #include "lldb/Utility/Args.h"
26f678e45dSDimitry Andric #include "lldb/Utility/DataExtractor.h"
27ac7ddfbfSEd Maste
28435933ddSDimitry Andric #include "llvm/ADT/SmallString.h"
29f678e45dSDimitry Andric #include "llvm/Support/Threading.h"
30435933ddSDimitry Andric
31ac7ddfbfSEd Maste using namespace lldb;
32ac7ddfbfSEd Maste using namespace lldb_private;
33ac7ddfbfSEd Maste
34435933ddSDimitry Andric static mode_t ParsePermissionString(const char *) = delete;
35435933ddSDimitry Andric
ParsePermissionString(llvm::StringRef permissions)36435933ddSDimitry Andric static mode_t ParsePermissionString(llvm::StringRef permissions) {
37435933ddSDimitry Andric if (permissions.size() != 9)
3835617911SEd Maste return (mode_t)(-1);
39435933ddSDimitry Andric bool user_r, user_w, user_x, group_r, group_w, group_x, world_r, world_w,
40435933ddSDimitry Andric world_x;
4135617911SEd Maste
4235617911SEd Maste user_r = (permissions[0] == 'r');
4335617911SEd Maste user_w = (permissions[1] == 'w');
4435617911SEd Maste user_x = (permissions[2] == 'x');
4535617911SEd Maste
4635617911SEd Maste group_r = (permissions[3] == 'r');
4735617911SEd Maste group_w = (permissions[4] == 'w');
4835617911SEd Maste group_x = (permissions[5] == 'x');
4935617911SEd Maste
5035617911SEd Maste world_r = (permissions[6] == 'r');
5135617911SEd Maste world_w = (permissions[7] == 'w');
5235617911SEd Maste world_x = (permissions[8] == 'x');
5335617911SEd Maste
5435617911SEd Maste mode_t user, group, world;
5535617911SEd Maste user = (user_r ? 4 : 0) | (user_w ? 2 : 0) | (user_x ? 1 : 0);
5635617911SEd Maste group = (group_r ? 4 : 0) | (group_w ? 2 : 0) | (group_x ? 1 : 0);
5735617911SEd Maste world = (world_r ? 4 : 0) | (world_w ? 2 : 0) | (world_x ? 1 : 0);
5835617911SEd Maste
5935617911SEd Maste return user | group | world;
6035617911SEd Maste }
6135617911SEd Maste
62*b5893f02SDimitry Andric static constexpr OptionDefinition g_permissions_options[] = {
63435933ddSDimitry Andric // clang-format off
64*b5893f02SDimitry Andric {LLDB_OPT_SET_ALL, false, "permissions-value", 'v', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypePermissionsNumber, "Give out the numeric value for permissions (e.g. 757)"},
65*b5893f02SDimitry Andric {LLDB_OPT_SET_ALL, false, "permissions-string", 's', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypePermissionsString, "Give out the string value for permissions (e.g. rwxr-xr--)."},
66*b5893f02SDimitry Andric {LLDB_OPT_SET_ALL, false, "user-read", 'r', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Allow user to read."},
67*b5893f02SDimitry Andric {LLDB_OPT_SET_ALL, false, "user-write", 'w', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Allow user to write."},
68*b5893f02SDimitry Andric {LLDB_OPT_SET_ALL, false, "user-exec", 'x', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Allow user to execute."},
69*b5893f02SDimitry Andric {LLDB_OPT_SET_ALL, false, "group-read", 'R', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Allow group to read."},
70*b5893f02SDimitry Andric {LLDB_OPT_SET_ALL, false, "group-write", 'W', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Allow group to write."},
71*b5893f02SDimitry Andric {LLDB_OPT_SET_ALL, false, "group-exec", 'X', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Allow group to execute."},
72*b5893f02SDimitry Andric {LLDB_OPT_SET_ALL, false, "world-read", 'd', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Allow world to read."},
73*b5893f02SDimitry Andric {LLDB_OPT_SET_ALL, false, "world-write", 't', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Allow world to write."},
74*b5893f02SDimitry Andric {LLDB_OPT_SET_ALL, false, "world-exec", 'e', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Allow world to execute."},
75435933ddSDimitry Andric // clang-format on
7635617911SEd Maste };
7735617911SEd Maste
78435933ddSDimitry Andric class OptionPermissions : public OptionGroup {
7935617911SEd Maste public:
OptionPermissions()80435933ddSDimitry Andric OptionPermissions() {}
8135617911SEd Maste
824bb0738eSEd Maste ~OptionPermissions() override = default;
8335617911SEd Maste
845517e702SDimitry Andric lldb_private::Status
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)85435933ddSDimitry Andric SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
86435933ddSDimitry Andric ExecutionContext *execution_context) override {
875517e702SDimitry Andric Status error;
8835617911SEd Maste char short_option = (char)GetDefinitions()[option_idx].short_option;
89435933ddSDimitry Andric switch (short_option) {
90435933ddSDimitry Andric case 'v': {
91435933ddSDimitry Andric if (option_arg.getAsInteger(8, m_permissions)) {
92435933ddSDimitry Andric m_permissions = 0777;
93435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid value for permissions: %s",
94435933ddSDimitry Andric option_arg.str().c_str());
9535617911SEd Maste }
96435933ddSDimitry Andric
97435933ddSDimitry Andric } break;
98435933ddSDimitry Andric case 's': {
9935617911SEd Maste mode_t perms = ParsePermissionString(option_arg);
10035617911SEd Maste if (perms == (mode_t)-1)
101435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid value for permissions: %s",
102435933ddSDimitry Andric option_arg.str().c_str());
10335617911SEd Maste else
10435617911SEd Maste m_permissions = perms;
105435933ddSDimitry Andric } break;
10635617911SEd Maste case 'r':
107b952cd58SEd Maste m_permissions |= lldb::eFilePermissionsUserRead;
10835617911SEd Maste break;
10935617911SEd Maste case 'w':
110b952cd58SEd Maste m_permissions |= lldb::eFilePermissionsUserWrite;
11135617911SEd Maste break;
11235617911SEd Maste case 'x':
113b952cd58SEd Maste m_permissions |= lldb::eFilePermissionsUserExecute;
11435617911SEd Maste break;
11535617911SEd Maste case 'R':
116b952cd58SEd Maste m_permissions |= lldb::eFilePermissionsGroupRead;
11735617911SEd Maste break;
11835617911SEd Maste case 'W':
119b952cd58SEd Maste m_permissions |= lldb::eFilePermissionsGroupWrite;
12035617911SEd Maste break;
12135617911SEd Maste case 'X':
122b952cd58SEd Maste m_permissions |= lldb::eFilePermissionsGroupExecute;
12335617911SEd Maste break;
12435617911SEd Maste case 'd':
125b952cd58SEd Maste m_permissions |= lldb::eFilePermissionsWorldRead;
12635617911SEd Maste break;
12735617911SEd Maste case 't':
128b952cd58SEd Maste m_permissions |= lldb::eFilePermissionsWorldWrite;
12935617911SEd Maste break;
13035617911SEd Maste case 'e':
131b952cd58SEd Maste m_permissions |= lldb::eFilePermissionsWorldExecute;
13235617911SEd Maste break;
13335617911SEd Maste default:
13435617911SEd Maste error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
13535617911SEd Maste break;
13635617911SEd Maste }
13735617911SEd Maste
13835617911SEd Maste return error;
13935617911SEd Maste }
14035617911SEd Maste
OptionParsingStarting(ExecutionContext * execution_context)141435933ddSDimitry Andric void OptionParsingStarting(ExecutionContext *execution_context) override {
14235617911SEd Maste m_permissions = 0;
14335617911SEd Maste }
14435617911SEd Maste
GetDefinitions()145435933ddSDimitry Andric llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
146435933ddSDimitry Andric return llvm::makeArrayRef(g_permissions_options);
14735617911SEd Maste }
14835617911SEd Maste
14935617911SEd Maste // Instance variables to hold the values for command options.
15035617911SEd Maste
15135617911SEd Maste uint32_t m_permissions;
1524bb0738eSEd Maste
15335617911SEd Maste private:
15435617911SEd Maste DISALLOW_COPY_AND_ASSIGN(OptionPermissions);
15535617911SEd Maste };
156ac7ddfbfSEd Maste
157ac7ddfbfSEd Maste //----------------------------------------------------------------------
158ac7ddfbfSEd Maste // "platform select <platform-name>"
159ac7ddfbfSEd Maste //----------------------------------------------------------------------
160435933ddSDimitry Andric class CommandObjectPlatformSelect : public CommandObjectParsed {
161ac7ddfbfSEd Maste public:
CommandObjectPlatformSelect(CommandInterpreter & interpreter)162435933ddSDimitry Andric CommandObjectPlatformSelect(CommandInterpreter &interpreter)
163435933ddSDimitry Andric : CommandObjectParsed(interpreter, "platform select",
164435933ddSDimitry Andric "Create a platform if needed and select it as the "
165435933ddSDimitry Andric "current platform.",
166435933ddSDimitry Andric "platform select <platform-name>", 0),
167435933ddSDimitry Andric m_option_group(),
168435933ddSDimitry Andric m_platform_options(
169435933ddSDimitry Andric false) // Don't include the "--platform" option by passing false
170ac7ddfbfSEd Maste {
171ac7ddfbfSEd Maste m_option_group.Append(&m_platform_options, LLDB_OPT_SET_ALL, 1);
172ac7ddfbfSEd Maste m_option_group.Finalize();
173ac7ddfbfSEd Maste }
174ac7ddfbfSEd Maste
1754bb0738eSEd Maste ~CommandObjectPlatformSelect() override = default;
176ac7ddfbfSEd Maste
HandleCompletion(CompletionRequest & request)1774ba319b5SDimitry Andric int HandleCompletion(CompletionRequest &request) override {
1784ba319b5SDimitry Andric CommandCompletions::PlatformPluginNames(GetCommandInterpreter(), request,
1794ba319b5SDimitry Andric nullptr);
1804ba319b5SDimitry Andric return request.GetNumberOfMatches();
181ac7ddfbfSEd Maste }
182ac7ddfbfSEd Maste
GetOptions()183435933ddSDimitry Andric Options *GetOptions() override { return &m_option_group; }
184ac7ddfbfSEd Maste
185ac7ddfbfSEd Maste protected:
DoExecute(Args & args,CommandReturnObject & result)186435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
187435933ddSDimitry Andric if (args.GetArgumentCount() == 1) {
188ac7ddfbfSEd Maste const char *platform_name = args.GetArgumentAtIndex(0);
189435933ddSDimitry Andric if (platform_name && platform_name[0]) {
190ac7ddfbfSEd Maste const bool select = true;
191ac7ddfbfSEd Maste m_platform_options.SetPlatformName(platform_name);
1925517e702SDimitry Andric Status error;
193ac7ddfbfSEd Maste ArchSpec platform_arch;
194435933ddSDimitry Andric PlatformSP platform_sp(m_platform_options.CreatePlatformWithOptions(
195435933ddSDimitry Andric m_interpreter, ArchSpec(), select, error, platform_arch));
196435933ddSDimitry Andric if (platform_sp) {
197435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().SetSelectedPlatform(
198435933ddSDimitry Andric platform_sp);
1991c3bbb01SEd Maste
200ac7ddfbfSEd Maste platform_sp->GetStatus(result.GetOutputStream());
201ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
202435933ddSDimitry Andric } else {
203ac7ddfbfSEd Maste result.AppendError(error.AsCString());
204ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
205ac7ddfbfSEd Maste }
206435933ddSDimitry Andric } else {
207ac7ddfbfSEd Maste result.AppendError("invalid platform name");
208ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
209ac7ddfbfSEd Maste }
210435933ddSDimitry Andric } else {
211435933ddSDimitry Andric result.AppendError(
212435933ddSDimitry Andric "platform create takes a platform name as an argument\n");
213ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
214ac7ddfbfSEd Maste }
215ac7ddfbfSEd Maste return result.Succeeded();
216ac7ddfbfSEd Maste }
217ac7ddfbfSEd Maste
218ac7ddfbfSEd Maste OptionGroupOptions m_option_group;
219ac7ddfbfSEd Maste OptionGroupPlatform m_platform_options;
220ac7ddfbfSEd Maste };
221ac7ddfbfSEd Maste
222ac7ddfbfSEd Maste //----------------------------------------------------------------------
223ac7ddfbfSEd Maste // "platform list"
224ac7ddfbfSEd Maste //----------------------------------------------------------------------
225435933ddSDimitry Andric class CommandObjectPlatformList : public CommandObjectParsed {
226ac7ddfbfSEd Maste public:
CommandObjectPlatformList(CommandInterpreter & interpreter)227435933ddSDimitry Andric CommandObjectPlatformList(CommandInterpreter &interpreter)
228435933ddSDimitry Andric : CommandObjectParsed(interpreter, "platform list",
229435933ddSDimitry Andric "List all platforms that are available.", nullptr,
230435933ddSDimitry Andric 0) {}
231ac7ddfbfSEd Maste
2324bb0738eSEd Maste ~CommandObjectPlatformList() override = default;
233ac7ddfbfSEd Maste
234ac7ddfbfSEd Maste protected:
DoExecute(Args & args,CommandReturnObject & result)235435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
236ac7ddfbfSEd Maste Stream &ostrm = result.GetOutputStream();
237ac7ddfbfSEd Maste ostrm.Printf("Available platforms:\n");
238ac7ddfbfSEd Maste
2397aa51b79SEd Maste PlatformSP host_platform_sp(Platform::GetHostPlatform());
240435933ddSDimitry Andric ostrm.Printf("%s: %s\n", host_platform_sp->GetPluginName().GetCString(),
241ac7ddfbfSEd Maste host_platform_sp->GetDescription());
242ac7ddfbfSEd Maste
243ac7ddfbfSEd Maste uint32_t idx;
244435933ddSDimitry Andric for (idx = 0; 1; ++idx) {
245435933ddSDimitry Andric const char *plugin_name =
246435933ddSDimitry Andric PluginManager::GetPlatformPluginNameAtIndex(idx);
2474bb0738eSEd Maste if (plugin_name == nullptr)
248ac7ddfbfSEd Maste break;
249435933ddSDimitry Andric const char *plugin_desc =
250435933ddSDimitry Andric PluginManager::GetPlatformPluginDescriptionAtIndex(idx);
2514bb0738eSEd Maste if (plugin_desc == nullptr)
252ac7ddfbfSEd Maste break;
253ac7ddfbfSEd Maste ostrm.Printf("%s: %s\n", plugin_name, plugin_desc);
254ac7ddfbfSEd Maste }
255ac7ddfbfSEd Maste
256435933ddSDimitry Andric if (idx == 0) {
257ac7ddfbfSEd Maste result.AppendError("no platforms are available\n");
258ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
259435933ddSDimitry Andric } else
260ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
261ac7ddfbfSEd Maste return result.Succeeded();
262ac7ddfbfSEd Maste }
263ac7ddfbfSEd Maste };
264ac7ddfbfSEd Maste
265ac7ddfbfSEd Maste //----------------------------------------------------------------------
266ac7ddfbfSEd Maste // "platform status"
267ac7ddfbfSEd Maste //----------------------------------------------------------------------
268435933ddSDimitry Andric class CommandObjectPlatformStatus : public CommandObjectParsed {
269ac7ddfbfSEd Maste public:
CommandObjectPlatformStatus(CommandInterpreter & interpreter)2704bb0738eSEd Maste CommandObjectPlatformStatus(CommandInterpreter &interpreter)
271435933ddSDimitry Andric : CommandObjectParsed(interpreter, "platform status",
272435933ddSDimitry Andric "Display status for the current platform.", nullptr,
273435933ddSDimitry Andric 0) {}
274ac7ddfbfSEd Maste
2754bb0738eSEd Maste ~CommandObjectPlatformStatus() override = default;
276ac7ddfbfSEd Maste
277ac7ddfbfSEd Maste protected:
DoExecute(Args & args,CommandReturnObject & result)278435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
279ac7ddfbfSEd Maste Stream &ostrm = result.GetOutputStream();
280ac7ddfbfSEd Maste
281ac7ddfbfSEd Maste Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
282ac7ddfbfSEd Maste PlatformSP platform_sp;
283435933ddSDimitry Andric if (target) {
284ac7ddfbfSEd Maste platform_sp = target->GetPlatform();
285ac7ddfbfSEd Maste }
286435933ddSDimitry Andric if (!platform_sp) {
287435933ddSDimitry Andric platform_sp =
288435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform();
289ac7ddfbfSEd Maste }
290435933ddSDimitry Andric if (platform_sp) {
291ac7ddfbfSEd Maste platform_sp->GetStatus(ostrm);
292ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
293435933ddSDimitry Andric } else {
294acac075bSDimitry Andric result.AppendError("no platform is currently selected\n");
295ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
296ac7ddfbfSEd Maste }
297ac7ddfbfSEd Maste return result.Succeeded();
298ac7ddfbfSEd Maste }
299ac7ddfbfSEd Maste };
300ac7ddfbfSEd Maste
301ac7ddfbfSEd Maste //----------------------------------------------------------------------
302ac7ddfbfSEd Maste // "platform connect <connect-url>"
303ac7ddfbfSEd Maste //----------------------------------------------------------------------
304435933ddSDimitry Andric class CommandObjectPlatformConnect : public CommandObjectParsed {
305ac7ddfbfSEd Maste public:
CommandObjectPlatformConnect(CommandInterpreter & interpreter)3064bb0738eSEd Maste CommandObjectPlatformConnect(CommandInterpreter &interpreter)
307435933ddSDimitry Andric : CommandObjectParsed(
308435933ddSDimitry Andric interpreter, "platform connect",
3094bb0738eSEd Maste "Select the current platform by providing a connection URL.",
310435933ddSDimitry Andric "platform connect <connect-url>", 0) {}
311ac7ddfbfSEd Maste
3124bb0738eSEd Maste ~CommandObjectPlatformConnect() override = default;
313ac7ddfbfSEd Maste
314ac7ddfbfSEd Maste protected:
DoExecute(Args & args,CommandReturnObject & result)315435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
316ac7ddfbfSEd Maste Stream &ostrm = result.GetOutputStream();
317ac7ddfbfSEd Maste
318435933ddSDimitry Andric PlatformSP platform_sp(
319435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
320435933ddSDimitry Andric if (platform_sp) {
3215517e702SDimitry Andric Status error(platform_sp->ConnectRemote(args));
322435933ddSDimitry Andric if (error.Success()) {
323ac7ddfbfSEd Maste platform_sp->GetStatus(ostrm);
324ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
3259f2f44ceSEd Maste
326435933ddSDimitry Andric platform_sp->ConnectToWaitingProcesses(m_interpreter.GetDebugger(),
327435933ddSDimitry Andric error);
328435933ddSDimitry Andric if (error.Fail()) {
3299f2f44ceSEd Maste result.AppendError(error.AsCString());
3309f2f44ceSEd Maste result.SetStatus(eReturnStatusFailed);
3319f2f44ceSEd Maste }
332435933ddSDimitry Andric } else {
333ac7ddfbfSEd Maste result.AppendErrorWithFormat("%s\n", error.AsCString());
334ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
335ac7ddfbfSEd Maste }
336435933ddSDimitry Andric } else {
33735617911SEd Maste result.AppendError("no platform is currently selected\n");
338ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
339ac7ddfbfSEd Maste }
340ac7ddfbfSEd Maste return result.Succeeded();
341ac7ddfbfSEd Maste }
34235617911SEd Maste
GetOptions()343435933ddSDimitry Andric Options *GetOptions() override {
344435933ddSDimitry Andric PlatformSP platform_sp(
345435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
3464bb0738eSEd Maste OptionGroupOptions *m_platform_options = nullptr;
347435933ddSDimitry Andric if (platform_sp) {
34835617911SEd Maste m_platform_options = platform_sp->GetConnectionOptions(m_interpreter);
3494bb0738eSEd Maste if (m_platform_options != nullptr && !m_platform_options->m_did_finalize)
35035617911SEd Maste m_platform_options->Finalize();
35135617911SEd Maste }
35235617911SEd Maste return m_platform_options;
35335617911SEd Maste }
354ac7ddfbfSEd Maste };
355ac7ddfbfSEd Maste
356ac7ddfbfSEd Maste //----------------------------------------------------------------------
357ac7ddfbfSEd Maste // "platform disconnect"
358ac7ddfbfSEd Maste //----------------------------------------------------------------------
359435933ddSDimitry Andric class CommandObjectPlatformDisconnect : public CommandObjectParsed {
360ac7ddfbfSEd Maste public:
CommandObjectPlatformDisconnect(CommandInterpreter & interpreter)3614bb0738eSEd Maste CommandObjectPlatformDisconnect(CommandInterpreter &interpreter)
362435933ddSDimitry Andric : CommandObjectParsed(interpreter, "platform disconnect",
363435933ddSDimitry Andric "Disconnect from the current platform.",
364435933ddSDimitry Andric "platform disconnect", 0) {}
365ac7ddfbfSEd Maste
3664bb0738eSEd Maste ~CommandObjectPlatformDisconnect() override = default;
367ac7ddfbfSEd Maste
368ac7ddfbfSEd Maste protected:
DoExecute(Args & args,CommandReturnObject & result)369435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
370435933ddSDimitry Andric PlatformSP platform_sp(
371435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
372435933ddSDimitry Andric if (platform_sp) {
373435933ddSDimitry Andric if (args.GetArgumentCount() == 0) {
3745517e702SDimitry Andric Status error;
375ac7ddfbfSEd Maste
376435933ddSDimitry Andric if (platform_sp->IsConnected()) {
3774ba319b5SDimitry Andric // Cache the instance name if there is one since we are about to
3784ba319b5SDimitry Andric // disconnect and the name might go with it.
379ac7ddfbfSEd Maste const char *hostname_cstr = platform_sp->GetHostname();
380ac7ddfbfSEd Maste std::string hostname;
381ac7ddfbfSEd Maste if (hostname_cstr)
382ac7ddfbfSEd Maste hostname.assign(hostname_cstr);
383ac7ddfbfSEd Maste
384ac7ddfbfSEd Maste error = platform_sp->DisconnectRemote();
385435933ddSDimitry Andric if (error.Success()) {
386ac7ddfbfSEd Maste Stream &ostrm = result.GetOutputStream();
387ac7ddfbfSEd Maste if (hostname.empty())
388435933ddSDimitry Andric ostrm.Printf("Disconnected from \"%s\"\n",
389435933ddSDimitry Andric platform_sp->GetPluginName().GetCString());
390ac7ddfbfSEd Maste else
391ac7ddfbfSEd Maste ostrm.Printf("Disconnected from \"%s\"\n", hostname.c_str());
392ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
393435933ddSDimitry Andric } else {
394ac7ddfbfSEd Maste result.AppendErrorWithFormat("%s", error.AsCString());
395ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
396ac7ddfbfSEd Maste }
397435933ddSDimitry Andric } else {
398ac7ddfbfSEd Maste // Not connected...
399435933ddSDimitry Andric result.AppendErrorWithFormat(
400435933ddSDimitry Andric "not connected to '%s'",
401435933ddSDimitry Andric platform_sp->GetPluginName().GetCString());
402ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
403ac7ddfbfSEd Maste }
404435933ddSDimitry Andric } else {
405ac7ddfbfSEd Maste // Bad args
406435933ddSDimitry Andric result.AppendError(
407435933ddSDimitry Andric "\"platform disconnect\" doesn't take any arguments");
408ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
409ac7ddfbfSEd Maste }
410435933ddSDimitry Andric } else {
411ac7ddfbfSEd Maste result.AppendError("no platform is currently selected");
412ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
413ac7ddfbfSEd Maste }
414ac7ddfbfSEd Maste return result.Succeeded();
415ac7ddfbfSEd Maste }
416ac7ddfbfSEd Maste };
41735617911SEd Maste
41835617911SEd Maste //----------------------------------------------------------------------
419b952cd58SEd Maste // "platform settings"
420b952cd58SEd Maste //----------------------------------------------------------------------
421435933ddSDimitry Andric class CommandObjectPlatformSettings : public CommandObjectParsed {
422b952cd58SEd Maste public:
CommandObjectPlatformSettings(CommandInterpreter & interpreter)423435933ddSDimitry Andric CommandObjectPlatformSettings(CommandInterpreter &interpreter)
424435933ddSDimitry Andric : CommandObjectParsed(interpreter, "platform settings",
425435933ddSDimitry Andric "Set settings for the current target's platform, "
426435933ddSDimitry Andric "or for a platform by name.",
427435933ddSDimitry Andric "platform settings", 0),
428435933ddSDimitry Andric m_options(),
429435933ddSDimitry Andric m_option_working_dir(LLDB_OPT_SET_1, false, "working-dir", 'w', 0,
430435933ddSDimitry Andric eArgTypePath,
431435933ddSDimitry Andric "The working directory for the platform.") {
432b952cd58SEd Maste m_options.Append(&m_option_working_dir, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
433b952cd58SEd Maste }
434b952cd58SEd Maste
4354bb0738eSEd Maste ~CommandObjectPlatformSettings() override = default;
436b952cd58SEd Maste
437b952cd58SEd Maste protected:
DoExecute(Args & args,CommandReturnObject & result)438435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
439435933ddSDimitry Andric PlatformSP platform_sp(
440435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
441435933ddSDimitry Andric if (platform_sp) {
442b952cd58SEd Maste if (m_option_working_dir.GetOptionValue().OptionWasSet())
443435933ddSDimitry Andric platform_sp->SetWorkingDirectory(
444435933ddSDimitry Andric m_option_working_dir.GetOptionValue().GetCurrentValue());
445435933ddSDimitry Andric } else {
446b952cd58SEd Maste result.AppendError("no platform is currently selected");
447b952cd58SEd Maste result.SetStatus(eReturnStatusFailed);
448b952cd58SEd Maste }
449b952cd58SEd Maste return result.Succeeded();
450b952cd58SEd Maste }
451b952cd58SEd Maste
GetOptions()452435933ddSDimitry Andric Options *GetOptions() override {
4534bb0738eSEd Maste if (!m_options.DidFinalize())
454b952cd58SEd Maste m_options.Finalize();
455b952cd58SEd Maste return &m_options;
456b952cd58SEd Maste }
457b952cd58SEd Maste
4584bb0738eSEd Maste protected:
459b952cd58SEd Maste OptionGroupOptions m_options;
460b952cd58SEd Maste OptionGroupFile m_option_working_dir;
461b952cd58SEd Maste };
462b952cd58SEd Maste
463b952cd58SEd Maste //----------------------------------------------------------------------
46435617911SEd Maste // "platform mkdir"
46535617911SEd Maste //----------------------------------------------------------------------
466435933ddSDimitry Andric class CommandObjectPlatformMkDir : public CommandObjectParsed {
46735617911SEd Maste public:
CommandObjectPlatformMkDir(CommandInterpreter & interpreter)468435933ddSDimitry Andric CommandObjectPlatformMkDir(CommandInterpreter &interpreter)
469435933ddSDimitry Andric : CommandObjectParsed(interpreter, "platform mkdir",
470435933ddSDimitry Andric "Make a new directory on the remote end.", nullptr,
47135617911SEd Maste 0),
472435933ddSDimitry Andric m_options() {}
47335617911SEd Maste
4744bb0738eSEd Maste ~CommandObjectPlatformMkDir() override = default;
47535617911SEd Maste
DoExecute(Args & args,CommandReturnObject & result)476435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
477435933ddSDimitry Andric PlatformSP platform_sp(
478435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
479435933ddSDimitry Andric if (platform_sp) {
48035617911SEd Maste std::string cmd_line;
48135617911SEd Maste args.GetCommandString(cmd_line);
482b952cd58SEd Maste uint32_t mode;
483435933ddSDimitry Andric const OptionPermissions *options_permissions =
484435933ddSDimitry Andric (const OptionPermissions *)m_options.GetGroupWithOption('r');
48535617911SEd Maste if (options_permissions)
486b952cd58SEd Maste mode = options_permissions->m_permissions;
48735617911SEd Maste else
488435933ddSDimitry Andric mode = lldb::eFilePermissionsUserRWX | lldb::eFilePermissionsGroupRWX |
489435933ddSDimitry Andric lldb::eFilePermissionsWorldRX;
490*b5893f02SDimitry Andric Status error = platform_sp->MakeDirectory(FileSpec(cmd_line), mode);
491435933ddSDimitry Andric if (error.Success()) {
49235617911SEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
493435933ddSDimitry Andric } else {
494b952cd58SEd Maste result.AppendError(error.AsCString());
495b952cd58SEd Maste result.SetStatus(eReturnStatusFailed);
496b952cd58SEd Maste }
497435933ddSDimitry Andric } else {
49835617911SEd Maste result.AppendError("no platform currently selected\n");
49935617911SEd Maste result.SetStatus(eReturnStatusFailed);
50035617911SEd Maste }
50135617911SEd Maste return result.Succeeded();
50235617911SEd Maste }
50335617911SEd Maste
GetOptions()504435933ddSDimitry Andric Options *GetOptions() override {
505435933ddSDimitry Andric if (!m_options.DidFinalize()) {
50635617911SEd Maste m_options.Append(new OptionPermissions());
50735617911SEd Maste m_options.Finalize();
50835617911SEd Maste }
50935617911SEd Maste return &m_options;
51035617911SEd Maste }
51135617911SEd Maste
5124bb0738eSEd Maste OptionGroupOptions m_options;
51335617911SEd Maste };
51435617911SEd Maste
51535617911SEd Maste //----------------------------------------------------------------------
51635617911SEd Maste // "platform fopen"
51735617911SEd Maste //----------------------------------------------------------------------
518435933ddSDimitry Andric class CommandObjectPlatformFOpen : public CommandObjectParsed {
51935617911SEd Maste public:
CommandObjectPlatformFOpen(CommandInterpreter & interpreter)520435933ddSDimitry Andric CommandObjectPlatformFOpen(CommandInterpreter &interpreter)
521435933ddSDimitry Andric : CommandObjectParsed(interpreter, "platform file open",
522435933ddSDimitry Andric "Open a file on the remote end.", nullptr, 0),
523435933ddSDimitry Andric m_options() {}
52435617911SEd Maste
5254bb0738eSEd Maste ~CommandObjectPlatformFOpen() override = default;
52635617911SEd Maste
DoExecute(Args & args,CommandReturnObject & result)527435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
528435933ddSDimitry Andric PlatformSP platform_sp(
529435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
530435933ddSDimitry Andric if (platform_sp) {
5315517e702SDimitry Andric Status error;
53235617911SEd Maste std::string cmd_line;
53335617911SEd Maste args.GetCommandString(cmd_line);
53435617911SEd Maste mode_t perms;
535435933ddSDimitry Andric const OptionPermissions *options_permissions =
536435933ddSDimitry Andric (const OptionPermissions *)m_options.GetGroupWithOption('r');
53735617911SEd Maste if (options_permissions)
53835617911SEd Maste perms = options_permissions->m_permissions;
53935617911SEd Maste else
540435933ddSDimitry Andric perms = lldb::eFilePermissionsUserRW | lldb::eFilePermissionsGroupRW |
541435933ddSDimitry Andric lldb::eFilePermissionsWorldRead;
542435933ddSDimitry Andric lldb::user_id_t fd = platform_sp->OpenFile(
543*b5893f02SDimitry Andric FileSpec(cmd_line),
54435617911SEd Maste File::eOpenOptionRead | File::eOpenOptionWrite |
54535617911SEd Maste File::eOpenOptionAppend | File::eOpenOptionCanCreate,
546435933ddSDimitry Andric perms, error);
547435933ddSDimitry Andric if (error.Success()) {
54835617911SEd Maste result.AppendMessageWithFormat("File Descriptor = %" PRIu64 "\n", fd);
54935617911SEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
550435933ddSDimitry Andric } else {
55135617911SEd Maste result.AppendError(error.AsCString());
55235617911SEd Maste result.SetStatus(eReturnStatusFailed);
55335617911SEd Maste }
554435933ddSDimitry Andric } else {
55535617911SEd Maste result.AppendError("no platform currently selected\n");
55635617911SEd Maste result.SetStatus(eReturnStatusFailed);
55735617911SEd Maste }
55835617911SEd Maste return result.Succeeded();
55935617911SEd Maste }
5604bb0738eSEd Maste
GetOptions()561435933ddSDimitry Andric Options *GetOptions() override {
562435933ddSDimitry Andric if (!m_options.DidFinalize()) {
56335617911SEd Maste m_options.Append(new OptionPermissions());
56435617911SEd Maste m_options.Finalize();
56535617911SEd Maste }
56635617911SEd Maste return &m_options;
56735617911SEd Maste }
5684bb0738eSEd Maste
56935617911SEd Maste OptionGroupOptions m_options;
57035617911SEd Maste };
57135617911SEd Maste
57235617911SEd Maste //----------------------------------------------------------------------
57335617911SEd Maste // "platform fclose"
57435617911SEd Maste //----------------------------------------------------------------------
575435933ddSDimitry Andric class CommandObjectPlatformFClose : public CommandObjectParsed {
57635617911SEd Maste public:
CommandObjectPlatformFClose(CommandInterpreter & interpreter)577435933ddSDimitry Andric CommandObjectPlatformFClose(CommandInterpreter &interpreter)
578435933ddSDimitry Andric : CommandObjectParsed(interpreter, "platform file close",
579435933ddSDimitry Andric "Close a file on the remote end.", nullptr, 0) {}
58035617911SEd Maste
5814bb0738eSEd Maste ~CommandObjectPlatformFClose() override = default;
58235617911SEd Maste
DoExecute(Args & args,CommandReturnObject & result)583435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
584435933ddSDimitry Andric PlatformSP platform_sp(
585435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
586435933ddSDimitry Andric if (platform_sp) {
58735617911SEd Maste std::string cmd_line;
58835617911SEd Maste args.GetCommandString(cmd_line);
589435933ddSDimitry Andric const lldb::user_id_t fd =
590435933ddSDimitry Andric StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX);
5915517e702SDimitry Andric Status error;
59235617911SEd Maste bool success = platform_sp->CloseFile(fd, error);
593435933ddSDimitry Andric if (success) {
59435617911SEd Maste result.AppendMessageWithFormat("file %" PRIu64 " closed.\n", fd);
59535617911SEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
596435933ddSDimitry Andric } else {
59735617911SEd Maste result.AppendError(error.AsCString());
59835617911SEd Maste result.SetStatus(eReturnStatusFailed);
59935617911SEd Maste }
600435933ddSDimitry Andric } else {
60135617911SEd Maste result.AppendError("no platform currently selected\n");
60235617911SEd Maste result.SetStatus(eReturnStatusFailed);
60335617911SEd Maste }
60435617911SEd Maste return result.Succeeded();
60535617911SEd Maste }
60635617911SEd Maste };
60735617911SEd Maste
60835617911SEd Maste //----------------------------------------------------------------------
60935617911SEd Maste // "platform fread"
61035617911SEd Maste //----------------------------------------------------------------------
611435933ddSDimitry Andric
612*b5893f02SDimitry Andric static constexpr OptionDefinition g_platform_fread_options[] = {
613435933ddSDimitry Andric // clang-format off
614*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeIndex, "Offset into the file at which to start reading." },
615*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeCount, "Number of bytes to read from the file." },
616435933ddSDimitry Andric // clang-format on
617435933ddSDimitry Andric };
618435933ddSDimitry Andric
619435933ddSDimitry Andric class CommandObjectPlatformFRead : public CommandObjectParsed {
62035617911SEd Maste public:
CommandObjectPlatformFRead(CommandInterpreter & interpreter)621435933ddSDimitry Andric CommandObjectPlatformFRead(CommandInterpreter &interpreter)
622435933ddSDimitry Andric : CommandObjectParsed(interpreter, "platform file read",
623435933ddSDimitry Andric "Read data from a file on the remote end.", nullptr,
62435617911SEd Maste 0),
625435933ddSDimitry Andric m_options() {}
62635617911SEd Maste
6274bb0738eSEd Maste ~CommandObjectPlatformFRead() override = default;
62835617911SEd Maste
DoExecute(Args & args,CommandReturnObject & result)629435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
630435933ddSDimitry Andric PlatformSP platform_sp(
631435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
632435933ddSDimitry Andric if (platform_sp) {
63335617911SEd Maste std::string cmd_line;
63435617911SEd Maste args.GetCommandString(cmd_line);
635435933ddSDimitry Andric const lldb::user_id_t fd =
636435933ddSDimitry Andric StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX);
63735617911SEd Maste std::string buffer(m_options.m_count, 0);
6385517e702SDimitry Andric Status error;
639435933ddSDimitry Andric uint32_t retcode = platform_sp->ReadFile(
640435933ddSDimitry Andric fd, m_options.m_offset, &buffer[0], m_options.m_count, error);
64135617911SEd Maste result.AppendMessageWithFormat("Return = %d\n", retcode);
64235617911SEd Maste result.AppendMessageWithFormat("Data = \"%s\"\n", buffer.c_str());
64335617911SEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
644435933ddSDimitry Andric } else {
64535617911SEd Maste result.AppendError("no platform currently selected\n");
64635617911SEd Maste result.SetStatus(eReturnStatusFailed);
64735617911SEd Maste }
64835617911SEd Maste return result.Succeeded();
64935617911SEd Maste }
6504bb0738eSEd Maste
GetOptions()651435933ddSDimitry Andric Options *GetOptions() override { return &m_options; }
65235617911SEd Maste
65335617911SEd Maste protected:
654435933ddSDimitry Andric class CommandOptions : public Options {
65535617911SEd Maste public:
CommandOptions()656435933ddSDimitry Andric CommandOptions() : Options() {}
65735617911SEd Maste
6584bb0738eSEd Maste ~CommandOptions() override = default;
65935617911SEd Maste
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)6605517e702SDimitry Andric Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
661435933ddSDimitry Andric ExecutionContext *execution_context) override {
6625517e702SDimitry Andric Status error;
66335617911SEd Maste char short_option = (char)m_getopt_table[option_idx].val;
66435617911SEd Maste
665435933ddSDimitry Andric switch (short_option) {
66635617911SEd Maste case 'o':
667435933ddSDimitry Andric if (option_arg.getAsInteger(0, m_offset))
668435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid offset: '%s'",
669435933ddSDimitry Andric option_arg.str().c_str());
67035617911SEd Maste break;
67135617911SEd Maste case 'c':
672435933ddSDimitry Andric if (option_arg.getAsInteger(0, m_count))
673435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid offset: '%s'",
674435933ddSDimitry Andric option_arg.str().c_str());
67535617911SEd Maste break;
67635617911SEd Maste default:
677435933ddSDimitry Andric error.SetErrorStringWithFormat("unrecognized option '%c'",
678435933ddSDimitry Andric short_option);
67935617911SEd Maste break;
68035617911SEd Maste }
68135617911SEd Maste
68235617911SEd Maste return error;
68335617911SEd Maste }
68435617911SEd Maste
OptionParsingStarting(ExecutionContext * execution_context)685435933ddSDimitry Andric void OptionParsingStarting(ExecutionContext *execution_context) override {
68635617911SEd Maste m_offset = 0;
68735617911SEd Maste m_count = 1;
68835617911SEd Maste }
68935617911SEd Maste
GetDefinitions()690435933ddSDimitry Andric llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
691435933ddSDimitry Andric return llvm::makeArrayRef(g_platform_fread_options);
69235617911SEd Maste }
69335617911SEd Maste
69435617911SEd Maste // Instance variables to hold the values for command options.
69535617911SEd Maste
69635617911SEd Maste uint32_t m_offset;
69735617911SEd Maste uint32_t m_count;
69835617911SEd Maste };
6994bb0738eSEd Maste
70035617911SEd Maste CommandOptions m_options;
70135617911SEd Maste };
7024bb0738eSEd Maste
70335617911SEd Maste //----------------------------------------------------------------------
70435617911SEd Maste // "platform fwrite"
70535617911SEd Maste //----------------------------------------------------------------------
706435933ddSDimitry Andric
707*b5893f02SDimitry Andric static constexpr OptionDefinition g_platform_fwrite_options[] = {
708435933ddSDimitry Andric // clang-format off
709*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeIndex, "Offset into the file at which to start reading." },
710*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "data", 'd', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeValue, "Text to write to the file." },
711435933ddSDimitry Andric // clang-format on
712435933ddSDimitry Andric };
713435933ddSDimitry Andric
714435933ddSDimitry Andric class CommandObjectPlatformFWrite : public CommandObjectParsed {
71535617911SEd Maste public:
CommandObjectPlatformFWrite(CommandInterpreter & interpreter)716435933ddSDimitry Andric CommandObjectPlatformFWrite(CommandInterpreter &interpreter)
717435933ddSDimitry Andric : CommandObjectParsed(interpreter, "platform file write",
718435933ddSDimitry Andric "Write data to a file on the remote end.", nullptr,
71935617911SEd Maste 0),
720435933ddSDimitry Andric m_options() {}
72135617911SEd Maste
7224bb0738eSEd Maste ~CommandObjectPlatformFWrite() override = default;
72335617911SEd Maste
DoExecute(Args & args,CommandReturnObject & result)724435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
725435933ddSDimitry Andric PlatformSP platform_sp(
726435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
727435933ddSDimitry Andric if (platform_sp) {
72835617911SEd Maste std::string cmd_line;
72935617911SEd Maste args.GetCommandString(cmd_line);
7305517e702SDimitry Andric Status error;
731435933ddSDimitry Andric const lldb::user_id_t fd =
732435933ddSDimitry Andric StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX);
733435933ddSDimitry Andric uint32_t retcode =
734435933ddSDimitry Andric platform_sp->WriteFile(fd, m_options.m_offset, &m_options.m_data[0],
735435933ddSDimitry Andric m_options.m_data.size(), error);
73635617911SEd Maste result.AppendMessageWithFormat("Return = %d\n", retcode);
73735617911SEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
738435933ddSDimitry Andric } else {
73935617911SEd Maste result.AppendError("no platform currently selected\n");
74035617911SEd Maste result.SetStatus(eReturnStatusFailed);
74135617911SEd Maste }
74235617911SEd Maste return result.Succeeded();
74335617911SEd Maste }
7444bb0738eSEd Maste
GetOptions()745435933ddSDimitry Andric Options *GetOptions() override { return &m_options; }
74635617911SEd Maste
74735617911SEd Maste protected:
748435933ddSDimitry Andric class CommandOptions : public Options {
74935617911SEd Maste public:
CommandOptions()750435933ddSDimitry Andric CommandOptions() : Options() {}
75135617911SEd Maste
7524bb0738eSEd Maste ~CommandOptions() override = default;
75335617911SEd Maste
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)7545517e702SDimitry Andric Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
755435933ddSDimitry Andric ExecutionContext *execution_context) override {
7565517e702SDimitry Andric Status error;
75735617911SEd Maste char short_option = (char)m_getopt_table[option_idx].val;
75835617911SEd Maste
759435933ddSDimitry Andric switch (short_option) {
76035617911SEd Maste case 'o':
761435933ddSDimitry Andric if (option_arg.getAsInteger(0, m_offset))
762435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid offset: '%s'",
763435933ddSDimitry Andric option_arg.str().c_str());
76435617911SEd Maste break;
76535617911SEd Maste case 'd':
76635617911SEd Maste m_data.assign(option_arg);
76735617911SEd Maste break;
76835617911SEd Maste default:
769435933ddSDimitry Andric error.SetErrorStringWithFormat("unrecognized option '%c'",
770435933ddSDimitry Andric short_option);
77135617911SEd Maste break;
77235617911SEd Maste }
77335617911SEd Maste
77435617911SEd Maste return error;
77535617911SEd Maste }
77635617911SEd Maste
OptionParsingStarting(ExecutionContext * execution_context)777435933ddSDimitry Andric void OptionParsingStarting(ExecutionContext *execution_context) override {
77835617911SEd Maste m_offset = 0;
77935617911SEd Maste m_data.clear();
78035617911SEd Maste }
78135617911SEd Maste
GetDefinitions()782435933ddSDimitry Andric llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
783435933ddSDimitry Andric return llvm::makeArrayRef(g_platform_fwrite_options);
78435617911SEd Maste }
78535617911SEd Maste
78635617911SEd Maste // Instance variables to hold the values for command options.
78735617911SEd Maste
78835617911SEd Maste uint32_t m_offset;
78935617911SEd Maste std::string m_data;
79035617911SEd Maste };
7914bb0738eSEd Maste
79235617911SEd Maste CommandOptions m_options;
79335617911SEd Maste };
7944bb0738eSEd Maste
795435933ddSDimitry Andric class CommandObjectPlatformFile : public CommandObjectMultiword {
79635617911SEd Maste public:
79735617911SEd Maste //------------------------------------------------------------------
79835617911SEd Maste // Constructors and Destructors
79935617911SEd Maste //------------------------------------------------------------------
CommandObjectPlatformFile(CommandInterpreter & interpreter)8004bb0738eSEd Maste CommandObjectPlatformFile(CommandInterpreter &interpreter)
801435933ddSDimitry Andric : CommandObjectMultiword(
802435933ddSDimitry Andric interpreter, "platform file",
803435933ddSDimitry Andric "Commands to access files on the current platform.",
804435933ddSDimitry Andric "platform file [open|close|read|write] ...") {
805435933ddSDimitry Andric LoadSubCommand(
806435933ddSDimitry Andric "open", CommandObjectSP(new CommandObjectPlatformFOpen(interpreter)));
807435933ddSDimitry Andric LoadSubCommand(
808435933ddSDimitry Andric "close", CommandObjectSP(new CommandObjectPlatformFClose(interpreter)));
809435933ddSDimitry Andric LoadSubCommand(
810435933ddSDimitry Andric "read", CommandObjectSP(new CommandObjectPlatformFRead(interpreter)));
811435933ddSDimitry Andric LoadSubCommand(
812435933ddSDimitry Andric "write", CommandObjectSP(new CommandObjectPlatformFWrite(interpreter)));
81335617911SEd Maste }
81435617911SEd Maste
8154bb0738eSEd Maste ~CommandObjectPlatformFile() override = default;
81635617911SEd Maste
81735617911SEd Maste private:
81835617911SEd Maste //------------------------------------------------------------------
81935617911SEd Maste // For CommandObjectPlatform only
82035617911SEd Maste //------------------------------------------------------------------
82135617911SEd Maste DISALLOW_COPY_AND_ASSIGN(CommandObjectPlatformFile);
82235617911SEd Maste };
82335617911SEd Maste
82435617911SEd Maste //----------------------------------------------------------------------
82535617911SEd Maste // "platform get-file remote-file-path host-file-path"
82635617911SEd Maste //----------------------------------------------------------------------
827435933ddSDimitry Andric class CommandObjectPlatformGetFile : public CommandObjectParsed {
82835617911SEd Maste public:
CommandObjectPlatformGetFile(CommandInterpreter & interpreter)829435933ddSDimitry Andric CommandObjectPlatformGetFile(CommandInterpreter &interpreter)
830435933ddSDimitry Andric : CommandObjectParsed(
831435933ddSDimitry Andric interpreter, "platform get-file",
83235617911SEd Maste "Transfer a file from the remote end to the local host.",
833435933ddSDimitry Andric "platform get-file <remote-file-spec> <local-file-spec>", 0) {
83435617911SEd Maste SetHelpLong(
835b91a7dfcSDimitry Andric R"(Examples:
836b91a7dfcSDimitry Andric
837b91a7dfcSDimitry Andric (lldb) platform get-file /the/remote/file/path /the/local/file/path
838b91a7dfcSDimitry Andric
839435933ddSDimitry Andric Transfer a file from the remote end with file path /the/remote/file/path to the local host.)");
84035617911SEd Maste
84135617911SEd Maste CommandArgumentEntry arg1, arg2;
84235617911SEd Maste CommandArgumentData file_arg_remote, file_arg_host;
84335617911SEd Maste
84435617911SEd Maste // Define the first (and only) variant of this arg.
84535617911SEd Maste file_arg_remote.arg_type = eArgTypeFilename;
84635617911SEd Maste file_arg_remote.arg_repetition = eArgRepeatPlain;
847435933ddSDimitry Andric // There is only one variant this argument could be; put it into the
848435933ddSDimitry Andric // argument entry.
84935617911SEd Maste arg1.push_back(file_arg_remote);
85035617911SEd Maste
85135617911SEd Maste // Define the second (and only) variant of this arg.
85235617911SEd Maste file_arg_host.arg_type = eArgTypeFilename;
85335617911SEd Maste file_arg_host.arg_repetition = eArgRepeatPlain;
854435933ddSDimitry Andric // There is only one variant this argument could be; put it into the
855435933ddSDimitry Andric // argument entry.
85635617911SEd Maste arg2.push_back(file_arg_host);
85735617911SEd Maste
8584ba319b5SDimitry Andric // Push the data for the first and the second arguments into the
8594ba319b5SDimitry Andric // m_arguments vector.
86035617911SEd Maste m_arguments.push_back(arg1);
86135617911SEd Maste m_arguments.push_back(arg2);
86235617911SEd Maste }
86335617911SEd Maste
8644bb0738eSEd Maste ~CommandObjectPlatformGetFile() override = default;
86535617911SEd Maste
DoExecute(Args & args,CommandReturnObject & result)866435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
86735617911SEd Maste // If the number of arguments is incorrect, issue an error message.
868435933ddSDimitry Andric if (args.GetArgumentCount() != 2) {
869435933ddSDimitry Andric result.GetErrorStream().Printf("error: required arguments missing; "
870435933ddSDimitry Andric "specify both the source and destination "
871435933ddSDimitry Andric "file paths\n");
87235617911SEd Maste result.SetStatus(eReturnStatusFailed);
87335617911SEd Maste return false;
87435617911SEd Maste }
87535617911SEd Maste
876435933ddSDimitry Andric PlatformSP platform_sp(
877435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
878435933ddSDimitry Andric if (platform_sp) {
87935617911SEd Maste const char *remote_file_path = args.GetArgumentAtIndex(0);
88035617911SEd Maste const char *local_file_path = args.GetArgumentAtIndex(1);
881*b5893f02SDimitry Andric Status error = platform_sp->GetFile(FileSpec(remote_file_path),
882*b5893f02SDimitry Andric FileSpec(local_file_path));
883435933ddSDimitry Andric if (error.Success()) {
884435933ddSDimitry Andric result.AppendMessageWithFormat(
885435933ddSDimitry Andric "successfully get-file from %s (remote) to %s (host)\n",
88635617911SEd Maste remote_file_path, local_file_path);
88735617911SEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
888435933ddSDimitry Andric } else {
889435933ddSDimitry Andric result.AppendMessageWithFormat("get-file failed: %s\n",
890435933ddSDimitry Andric error.AsCString());
89135617911SEd Maste result.SetStatus(eReturnStatusFailed);
89235617911SEd Maste }
893435933ddSDimitry Andric } else {
89435617911SEd Maste result.AppendError("no platform currently selected\n");
89535617911SEd Maste result.SetStatus(eReturnStatusFailed);
89635617911SEd Maste }
89735617911SEd Maste return result.Succeeded();
89835617911SEd Maste }
89935617911SEd Maste };
90035617911SEd Maste
90135617911SEd Maste //----------------------------------------------------------------------
90235617911SEd Maste // "platform get-size remote-file-path"
90335617911SEd Maste //----------------------------------------------------------------------
904435933ddSDimitry Andric class CommandObjectPlatformGetSize : public CommandObjectParsed {
90535617911SEd Maste public:
CommandObjectPlatformGetSize(CommandInterpreter & interpreter)906435933ddSDimitry Andric CommandObjectPlatformGetSize(CommandInterpreter &interpreter)
907435933ddSDimitry Andric : CommandObjectParsed(interpreter, "platform get-size",
90835617911SEd Maste "Get the file size from the remote end.",
909435933ddSDimitry Andric "platform get-size <remote-file-spec>", 0) {
91035617911SEd Maste SetHelpLong(
911b91a7dfcSDimitry Andric R"(Examples:
912b91a7dfcSDimitry Andric
913b91a7dfcSDimitry Andric (lldb) platform get-size /the/remote/file/path
914b91a7dfcSDimitry Andric
915435933ddSDimitry Andric Get the file size from the remote end with path /the/remote/file/path.)");
91635617911SEd Maste
91735617911SEd Maste CommandArgumentEntry arg1;
91835617911SEd Maste CommandArgumentData file_arg_remote;
91935617911SEd Maste
92035617911SEd Maste // Define the first (and only) variant of this arg.
92135617911SEd Maste file_arg_remote.arg_type = eArgTypeFilename;
92235617911SEd Maste file_arg_remote.arg_repetition = eArgRepeatPlain;
923435933ddSDimitry Andric // There is only one variant this argument could be; put it into the
924435933ddSDimitry Andric // argument entry.
92535617911SEd Maste arg1.push_back(file_arg_remote);
92635617911SEd Maste
92735617911SEd Maste // Push the data for the first argument into the m_arguments vector.
92835617911SEd Maste m_arguments.push_back(arg1);
92935617911SEd Maste }
93035617911SEd Maste
9314bb0738eSEd Maste ~CommandObjectPlatformGetSize() override = default;
93235617911SEd Maste
DoExecute(Args & args,CommandReturnObject & result)933435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
93435617911SEd Maste // If the number of arguments is incorrect, issue an error message.
935435933ddSDimitry Andric if (args.GetArgumentCount() != 1) {
936435933ddSDimitry Andric result.GetErrorStream().Printf("error: required argument missing; "
937435933ddSDimitry Andric "specify the source file path as the only "
938435933ddSDimitry Andric "argument\n");
93935617911SEd Maste result.SetStatus(eReturnStatusFailed);
94035617911SEd Maste return false;
94135617911SEd Maste }
94235617911SEd Maste
943435933ddSDimitry Andric PlatformSP platform_sp(
944435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
945435933ddSDimitry Andric if (platform_sp) {
94635617911SEd Maste std::string remote_file_path(args.GetArgumentAtIndex(0));
947*b5893f02SDimitry Andric user_id_t size = platform_sp->GetFileSize(FileSpec(remote_file_path));
948435933ddSDimitry Andric if (size != UINT64_MAX) {
949435933ddSDimitry Andric result.AppendMessageWithFormat("File size of %s (remote): %" PRIu64
950435933ddSDimitry Andric "\n",
951435933ddSDimitry Andric remote_file_path.c_str(), size);
95235617911SEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
953435933ddSDimitry Andric } else {
954435933ddSDimitry Andric result.AppendMessageWithFormat(
955435933ddSDimitry Andric "Error getting file size of %s (remote)\n",
956435933ddSDimitry Andric remote_file_path.c_str());
95735617911SEd Maste result.SetStatus(eReturnStatusFailed);
95835617911SEd Maste }
959435933ddSDimitry Andric } else {
96035617911SEd Maste result.AppendError("no platform currently selected\n");
96135617911SEd Maste result.SetStatus(eReturnStatusFailed);
96235617911SEd Maste }
96335617911SEd Maste return result.Succeeded();
96435617911SEd Maste }
96535617911SEd Maste };
96635617911SEd Maste
96735617911SEd Maste //----------------------------------------------------------------------
96835617911SEd Maste // "platform put-file"
96935617911SEd Maste //----------------------------------------------------------------------
970435933ddSDimitry Andric class CommandObjectPlatformPutFile : public CommandObjectParsed {
97135617911SEd Maste public:
CommandObjectPlatformPutFile(CommandInterpreter & interpreter)972435933ddSDimitry Andric CommandObjectPlatformPutFile(CommandInterpreter &interpreter)
973435933ddSDimitry Andric : CommandObjectParsed(
974435933ddSDimitry Andric interpreter, "platform put-file",
975435933ddSDimitry Andric "Transfer a file from this system to the remote end.", nullptr, 0) {
97635617911SEd Maste }
97735617911SEd Maste
9784bb0738eSEd Maste ~CommandObjectPlatformPutFile() override = default;
97935617911SEd Maste
DoExecute(Args & args,CommandReturnObject & result)980435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
98135617911SEd Maste const char *src = args.GetArgumentAtIndex(0);
98235617911SEd Maste const char *dst = args.GetArgumentAtIndex(1);
98335617911SEd Maste
984*b5893f02SDimitry Andric FileSpec src_fs(src);
985*b5893f02SDimitry Andric FileSystem::Instance().Resolve(src_fs);
986*b5893f02SDimitry Andric FileSpec dst_fs(dst ? dst : src_fs.GetFilename().GetCString());
98735617911SEd Maste
988435933ddSDimitry Andric PlatformSP platform_sp(
989435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
990435933ddSDimitry Andric if (platform_sp) {
9915517e702SDimitry Andric Status error(platform_sp->PutFile(src_fs, dst_fs));
992435933ddSDimitry Andric if (error.Success()) {
99335617911SEd Maste result.SetStatus(eReturnStatusSuccessFinishNoResult);
994435933ddSDimitry Andric } else {
99535617911SEd Maste result.AppendError(error.AsCString());
99635617911SEd Maste result.SetStatus(eReturnStatusFailed);
99735617911SEd Maste }
998435933ddSDimitry Andric } else {
99935617911SEd Maste result.AppendError("no platform currently selected\n");
100035617911SEd Maste result.SetStatus(eReturnStatusFailed);
100135617911SEd Maste }
100235617911SEd Maste return result.Succeeded();
100335617911SEd Maste }
100435617911SEd Maste };
100535617911SEd Maste
1006ac7ddfbfSEd Maste //----------------------------------------------------------------------
1007ac7ddfbfSEd Maste // "platform process launch"
1008ac7ddfbfSEd Maste //----------------------------------------------------------------------
1009435933ddSDimitry Andric class CommandObjectPlatformProcessLaunch : public CommandObjectParsed {
1010ac7ddfbfSEd Maste public:
CommandObjectPlatformProcessLaunch(CommandInterpreter & interpreter)1011435933ddSDimitry Andric CommandObjectPlatformProcessLaunch(CommandInterpreter &interpreter)
1012435933ddSDimitry Andric : CommandObjectParsed(interpreter, "platform process launch",
1013ac7ddfbfSEd Maste "Launch a new process on a remote platform.",
1014ac7ddfbfSEd Maste "platform process launch program",
10151c3bbb01SEd Maste eCommandRequiresTarget | eCommandTryTargetAPILock),
1016435933ddSDimitry Andric m_options() {}
1017ac7ddfbfSEd Maste
10184bb0738eSEd Maste ~CommandObjectPlatformProcessLaunch() override = default;
1019ac7ddfbfSEd Maste
GetOptions()1020435933ddSDimitry Andric Options *GetOptions() override { return &m_options; }
1021ac7ddfbfSEd Maste
1022ac7ddfbfSEd Maste protected:
DoExecute(Args & args,CommandReturnObject & result)1023435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
1024ac7ddfbfSEd Maste Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1025ac7ddfbfSEd Maste PlatformSP platform_sp;
1026435933ddSDimitry Andric if (target) {
1027ac7ddfbfSEd Maste platform_sp = target->GetPlatform();
1028ac7ddfbfSEd Maste }
1029435933ddSDimitry Andric if (!platform_sp) {
1030435933ddSDimitry Andric platform_sp =
1031435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform();
1032ac7ddfbfSEd Maste }
1033ac7ddfbfSEd Maste
1034435933ddSDimitry Andric if (platform_sp) {
10355517e702SDimitry Andric Status error;
1036ac7ddfbfSEd Maste const size_t argc = args.GetArgumentCount();
1037ac7ddfbfSEd Maste Target *target = m_exe_ctx.GetTargetPtr();
1038ac7ddfbfSEd Maste Module *exe_module = target->GetExecutableModulePointer();
1039435933ddSDimitry Andric if (exe_module) {
1040ac7ddfbfSEd Maste m_options.launch_info.GetExecutableFile() = exe_module->GetFileSpec();
1041*b5893f02SDimitry Andric llvm::SmallString<128> exe_path;
1042435933ddSDimitry Andric m_options.launch_info.GetExecutableFile().GetPath(exe_path);
1043435933ddSDimitry Andric if (!exe_path.empty())
1044ac7ddfbfSEd Maste m_options.launch_info.GetArguments().AppendArgument(exe_path);
1045ac7ddfbfSEd Maste m_options.launch_info.GetArchitecture() = exe_module->GetArchitecture();
1046ac7ddfbfSEd Maste }
1047ac7ddfbfSEd Maste
1048435933ddSDimitry Andric if (argc > 0) {
1049435933ddSDimitry Andric if (m_options.launch_info.GetExecutableFile()) {
10504ba319b5SDimitry Andric // We already have an executable file, so we will use this and all
10514ba319b5SDimitry Andric // arguments to this function are extra arguments
1052ac7ddfbfSEd Maste m_options.launch_info.GetArguments().AppendArguments(args);
1053435933ddSDimitry Andric } else {
1054ac7ddfbfSEd Maste // We don't have any file yet, so the first argument is our
1055ac7ddfbfSEd Maste // executable, and the rest are program arguments
1056ac7ddfbfSEd Maste const bool first_arg_is_executable = true;
1057ac7ddfbfSEd Maste m_options.launch_info.SetArguments(args, first_arg_is_executable);
1058ac7ddfbfSEd Maste }
1059ac7ddfbfSEd Maste }
1060ac7ddfbfSEd Maste
1061435933ddSDimitry Andric if (m_options.launch_info.GetExecutableFile()) {
1062ac7ddfbfSEd Maste Debugger &debugger = m_interpreter.GetDebugger();
1063ac7ddfbfSEd Maste
1064ac7ddfbfSEd Maste if (argc == 0)
1065ac7ddfbfSEd Maste target->GetRunArguments(m_options.launch_info.GetArguments());
1066ac7ddfbfSEd Maste
1067435933ddSDimitry Andric ProcessSP process_sp(platform_sp->DebugProcess(
1068435933ddSDimitry Andric m_options.launch_info, debugger, target, error));
1069435933ddSDimitry Andric if (process_sp && process_sp->IsAlive()) {
1070ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessFinishNoResult);
1071ac7ddfbfSEd Maste return true;
1072ac7ddfbfSEd Maste }
1073ac7ddfbfSEd Maste
1074ac7ddfbfSEd Maste if (error.Success())
1075ac7ddfbfSEd Maste result.AppendError("process launch failed");
1076ac7ddfbfSEd Maste else
1077ac7ddfbfSEd Maste result.AppendError(error.AsCString());
1078ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1079435933ddSDimitry Andric } else {
1080435933ddSDimitry Andric result.AppendError("'platform process launch' uses the current target "
1081435933ddSDimitry Andric "file and arguments, or the executable and its "
1082435933ddSDimitry Andric "arguments can be specified in this command");
1083ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1084ac7ddfbfSEd Maste return false;
1085ac7ddfbfSEd Maste }
1086435933ddSDimitry Andric } else {
1087ac7ddfbfSEd Maste result.AppendError("no platform is selected\n");
1088ac7ddfbfSEd Maste }
1089ac7ddfbfSEd Maste return result.Succeeded();
1090ac7ddfbfSEd Maste }
1091ac7ddfbfSEd Maste
1092ac7ddfbfSEd Maste protected:
1093ac7ddfbfSEd Maste ProcessLaunchCommandOptions m_options;
1094ac7ddfbfSEd Maste };
1095ac7ddfbfSEd Maste
1096ac7ddfbfSEd Maste //----------------------------------------------------------------------
1097ac7ddfbfSEd Maste // "platform process list"
1098ac7ddfbfSEd Maste //----------------------------------------------------------------------
1099ac7ddfbfSEd Maste
1100*b5893f02SDimitry Andric static OptionDefinition g_platform_process_list_options[] = {
1101435933ddSDimitry Andric // clang-format off
1102*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "pid", 'p', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypePid, "List the process info for a specific process ID." },
1103*b5893f02SDimitry Andric { LLDB_OPT_SET_2, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeProcessName, "Find processes with executable basenames that match a string." },
1104*b5893f02SDimitry Andric { LLDB_OPT_SET_3, true, "ends-with", 'e', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeProcessName, "Find processes with executable basenames that end with a string." },
1105*b5893f02SDimitry Andric { LLDB_OPT_SET_4, true, "starts-with", 's', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeProcessName, "Find processes with executable basenames that start with a string." },
1106*b5893f02SDimitry Andric { LLDB_OPT_SET_5, true, "contains", 'c', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeProcessName, "Find processes with executable basenames that contain a string." },
1107*b5893f02SDimitry Andric { LLDB_OPT_SET_6, true, "regex", 'r', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeRegularExpression, "Find processes with executable basenames that match a regular expression." },
1108*b5893f02SDimitry Andric { LLDB_OPT_SET_FROM_TO(2, 6), false, "parent", 'P', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypePid, "Find processes that have a matching parent process ID." },
1109*b5893f02SDimitry Andric { LLDB_OPT_SET_FROM_TO(2, 6), false, "uid", 'u', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeUnsignedInteger, "Find processes that have a matching user ID." },
1110*b5893f02SDimitry Andric { LLDB_OPT_SET_FROM_TO(2, 6), false, "euid", 'U', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeUnsignedInteger, "Find processes that have a matching effective user ID." },
1111*b5893f02SDimitry Andric { LLDB_OPT_SET_FROM_TO(2, 6), false, "gid", 'g', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeUnsignedInteger, "Find processes that have a matching group ID." },
1112*b5893f02SDimitry Andric { LLDB_OPT_SET_FROM_TO(2, 6), false, "egid", 'G', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeUnsignedInteger, "Find processes that have a matching effective group ID." },
1113*b5893f02SDimitry Andric { LLDB_OPT_SET_FROM_TO(2, 6), false, "arch", 'a', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeArchitecture, "Find processes that have a matching architecture." },
1114*b5893f02SDimitry Andric { LLDB_OPT_SET_FROM_TO(1, 6), false, "show-args", 'A', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Show process arguments instead of the process executable basename." },
1115*b5893f02SDimitry Andric { LLDB_OPT_SET_FROM_TO(1, 6), false, "verbose", 'v', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Enable verbose output." },
1116435933ddSDimitry Andric // clang-format on
1117435933ddSDimitry Andric };
1118435933ddSDimitry Andric
1119435933ddSDimitry Andric class CommandObjectPlatformProcessList : public CommandObjectParsed {
1120435933ddSDimitry Andric public:
CommandObjectPlatformProcessList(CommandInterpreter & interpreter)1121435933ddSDimitry Andric CommandObjectPlatformProcessList(CommandInterpreter &interpreter)
1122435933ddSDimitry Andric : CommandObjectParsed(interpreter, "platform process list",
1123435933ddSDimitry Andric "List processes on a remote platform by name, pid, "
1124435933ddSDimitry Andric "or many other matching attributes.",
1125435933ddSDimitry Andric "platform process list", 0),
1126435933ddSDimitry Andric m_options() {}
1127435933ddSDimitry Andric
1128435933ddSDimitry Andric ~CommandObjectPlatformProcessList() override = default;
1129435933ddSDimitry Andric
GetOptions()1130435933ddSDimitry Andric Options *GetOptions() override { return &m_options; }
1131435933ddSDimitry Andric
1132435933ddSDimitry Andric protected:
DoExecute(Args & args,CommandReturnObject & result)1133435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
1134435933ddSDimitry Andric Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1135435933ddSDimitry Andric PlatformSP platform_sp;
1136435933ddSDimitry Andric if (target) {
1137435933ddSDimitry Andric platform_sp = target->GetPlatform();
1138435933ddSDimitry Andric }
1139435933ddSDimitry Andric if (!platform_sp) {
1140435933ddSDimitry Andric platform_sp =
1141435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform();
1142435933ddSDimitry Andric }
1143435933ddSDimitry Andric
1144435933ddSDimitry Andric if (platform_sp) {
11455517e702SDimitry Andric Status error;
1146435933ddSDimitry Andric if (args.GetArgumentCount() == 0) {
1147435933ddSDimitry Andric if (platform_sp) {
1148435933ddSDimitry Andric Stream &ostrm = result.GetOutputStream();
1149435933ddSDimitry Andric
1150435933ddSDimitry Andric lldb::pid_t pid =
1151435933ddSDimitry Andric m_options.match_info.GetProcessInfo().GetProcessID();
1152435933ddSDimitry Andric if (pid != LLDB_INVALID_PROCESS_ID) {
1153435933ddSDimitry Andric ProcessInstanceInfo proc_info;
1154435933ddSDimitry Andric if (platform_sp->GetProcessInfo(pid, proc_info)) {
1155435933ddSDimitry Andric ProcessInstanceInfo::DumpTableHeader(ostrm, platform_sp.get(),
1156435933ddSDimitry Andric m_options.show_args,
1157435933ddSDimitry Andric m_options.verbose);
1158435933ddSDimitry Andric proc_info.DumpAsTableRow(ostrm, platform_sp.get(),
1159435933ddSDimitry Andric m_options.show_args, m_options.verbose);
1160435933ddSDimitry Andric result.SetStatus(eReturnStatusSuccessFinishResult);
1161435933ddSDimitry Andric } else {
1162435933ddSDimitry Andric result.AppendErrorWithFormat(
1163435933ddSDimitry Andric "no process found with pid = %" PRIu64 "\n", pid);
1164435933ddSDimitry Andric result.SetStatus(eReturnStatusFailed);
1165435933ddSDimitry Andric }
1166435933ddSDimitry Andric } else {
1167435933ddSDimitry Andric ProcessInstanceInfoList proc_infos;
1168435933ddSDimitry Andric const uint32_t matches =
1169435933ddSDimitry Andric platform_sp->FindProcesses(m_options.match_info, proc_infos);
1170435933ddSDimitry Andric const char *match_desc = nullptr;
1171435933ddSDimitry Andric const char *match_name =
1172435933ddSDimitry Andric m_options.match_info.GetProcessInfo().GetName();
1173435933ddSDimitry Andric if (match_name && match_name[0]) {
1174435933ddSDimitry Andric switch (m_options.match_info.GetNameMatchType()) {
1175f678e45dSDimitry Andric case NameMatch::Ignore:
1176435933ddSDimitry Andric break;
1177f678e45dSDimitry Andric case NameMatch::Equals:
1178435933ddSDimitry Andric match_desc = "matched";
1179435933ddSDimitry Andric break;
1180f678e45dSDimitry Andric case NameMatch::Contains:
1181435933ddSDimitry Andric match_desc = "contained";
1182435933ddSDimitry Andric break;
1183f678e45dSDimitry Andric case NameMatch::StartsWith:
1184435933ddSDimitry Andric match_desc = "started with";
1185435933ddSDimitry Andric break;
1186f678e45dSDimitry Andric case NameMatch::EndsWith:
1187435933ddSDimitry Andric match_desc = "ended with";
1188435933ddSDimitry Andric break;
1189f678e45dSDimitry Andric case NameMatch::RegularExpression:
1190435933ddSDimitry Andric match_desc = "matched the regular expression";
1191435933ddSDimitry Andric break;
1192435933ddSDimitry Andric }
1193435933ddSDimitry Andric }
1194435933ddSDimitry Andric
1195435933ddSDimitry Andric if (matches == 0) {
1196435933ddSDimitry Andric if (match_desc)
1197435933ddSDimitry Andric result.AppendErrorWithFormat(
1198435933ddSDimitry Andric "no processes were found that %s \"%s\" on the \"%s\" "
1199435933ddSDimitry Andric "platform\n",
1200435933ddSDimitry Andric match_desc, match_name,
1201435933ddSDimitry Andric platform_sp->GetPluginName().GetCString());
1202435933ddSDimitry Andric else
1203435933ddSDimitry Andric result.AppendErrorWithFormat(
1204435933ddSDimitry Andric "no processes were found on the \"%s\" platform\n",
1205435933ddSDimitry Andric platform_sp->GetPluginName().GetCString());
1206435933ddSDimitry Andric result.SetStatus(eReturnStatusFailed);
1207435933ddSDimitry Andric } else {
1208435933ddSDimitry Andric result.AppendMessageWithFormat(
1209435933ddSDimitry Andric "%u matching process%s found on \"%s\"", matches,
1210435933ddSDimitry Andric matches > 1 ? "es were" : " was",
1211435933ddSDimitry Andric platform_sp->GetName().GetCString());
1212435933ddSDimitry Andric if (match_desc)
1213435933ddSDimitry Andric result.AppendMessageWithFormat(" whose name %s \"%s\"",
1214435933ddSDimitry Andric match_desc, match_name);
1215435933ddSDimitry Andric result.AppendMessageWithFormat("\n");
1216435933ddSDimitry Andric ProcessInstanceInfo::DumpTableHeader(ostrm, platform_sp.get(),
1217435933ddSDimitry Andric m_options.show_args,
1218435933ddSDimitry Andric m_options.verbose);
1219435933ddSDimitry Andric for (uint32_t i = 0; i < matches; ++i) {
1220435933ddSDimitry Andric proc_infos.GetProcessInfoAtIndex(i).DumpAsTableRow(
1221435933ddSDimitry Andric ostrm, platform_sp.get(), m_options.show_args,
1222435933ddSDimitry Andric m_options.verbose);
1223435933ddSDimitry Andric }
1224435933ddSDimitry Andric }
1225435933ddSDimitry Andric }
1226435933ddSDimitry Andric }
1227435933ddSDimitry Andric } else {
1228435933ddSDimitry Andric result.AppendError("invalid args: process list takes only options\n");
1229435933ddSDimitry Andric result.SetStatus(eReturnStatusFailed);
1230435933ddSDimitry Andric }
1231435933ddSDimitry Andric } else {
1232435933ddSDimitry Andric result.AppendError("no platform is selected\n");
1233435933ddSDimitry Andric result.SetStatus(eReturnStatusFailed);
1234435933ddSDimitry Andric }
1235435933ddSDimitry Andric return result.Succeeded();
1236435933ddSDimitry Andric }
1237435933ddSDimitry Andric
1238435933ddSDimitry Andric class CommandOptions : public Options {
1239435933ddSDimitry Andric public:
CommandOptions()1240435933ddSDimitry Andric CommandOptions()
1241435933ddSDimitry Andric : Options(), match_info(), show_args(false), verbose(false) {
1242f678e45dSDimitry Andric static llvm::once_flag g_once_flag;
1243f678e45dSDimitry Andric llvm::call_once(g_once_flag, []() {
1244435933ddSDimitry Andric PosixPlatformCommandOptionValidator *posix_validator =
1245435933ddSDimitry Andric new PosixPlatformCommandOptionValidator();
1246435933ddSDimitry Andric for (auto &Option : g_platform_process_list_options) {
1247435933ddSDimitry Andric switch (Option.short_option) {
1248435933ddSDimitry Andric case 'u':
1249435933ddSDimitry Andric case 'U':
1250435933ddSDimitry Andric case 'g':
1251435933ddSDimitry Andric case 'G':
1252435933ddSDimitry Andric Option.validator = posix_validator;
1253435933ddSDimitry Andric break;
1254435933ddSDimitry Andric default:
1255435933ddSDimitry Andric break;
1256435933ddSDimitry Andric }
1257435933ddSDimitry Andric }
1258435933ddSDimitry Andric });
1259435933ddSDimitry Andric }
1260435933ddSDimitry Andric
1261435933ddSDimitry Andric ~CommandOptions() override = default;
1262435933ddSDimitry Andric
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)12635517e702SDimitry Andric Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1264435933ddSDimitry Andric ExecutionContext *execution_context) override {
12655517e702SDimitry Andric Status error;
1266435933ddSDimitry Andric const int short_option = m_getopt_table[option_idx].val;
1267435933ddSDimitry Andric bool success = false;
1268435933ddSDimitry Andric
1269435933ddSDimitry Andric uint32_t id = LLDB_INVALID_PROCESS_ID;
1270435933ddSDimitry Andric success = !option_arg.getAsInteger(0, id);
1271435933ddSDimitry Andric switch (short_option) {
1272435933ddSDimitry Andric case 'p': {
1273435933ddSDimitry Andric match_info.GetProcessInfo().SetProcessID(id);
1274435933ddSDimitry Andric if (!success)
1275435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid process ID string: '%s'",
1276435933ddSDimitry Andric option_arg.str().c_str());
1277435933ddSDimitry Andric break;
1278435933ddSDimitry Andric }
1279435933ddSDimitry Andric case 'P':
1280435933ddSDimitry Andric match_info.GetProcessInfo().SetParentProcessID(id);
1281435933ddSDimitry Andric if (!success)
1282435933ddSDimitry Andric error.SetErrorStringWithFormat(
1283435933ddSDimitry Andric "invalid parent process ID string: '%s'",
1284435933ddSDimitry Andric option_arg.str().c_str());
1285435933ddSDimitry Andric break;
1286435933ddSDimitry Andric
1287435933ddSDimitry Andric case 'u':
1288435933ddSDimitry Andric match_info.GetProcessInfo().SetUserID(success ? id : UINT32_MAX);
1289435933ddSDimitry Andric if (!success)
1290435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid user ID string: '%s'",
1291435933ddSDimitry Andric option_arg.str().c_str());
1292435933ddSDimitry Andric break;
1293435933ddSDimitry Andric
1294435933ddSDimitry Andric case 'U':
1295435933ddSDimitry Andric match_info.GetProcessInfo().SetEffectiveUserID(success ? id
1296435933ddSDimitry Andric : UINT32_MAX);
1297435933ddSDimitry Andric if (!success)
1298435933ddSDimitry Andric error.SetErrorStringWithFormat(
1299435933ddSDimitry Andric "invalid effective user ID string: '%s'",
1300435933ddSDimitry Andric option_arg.str().c_str());
1301435933ddSDimitry Andric break;
1302435933ddSDimitry Andric
1303435933ddSDimitry Andric case 'g':
1304435933ddSDimitry Andric match_info.GetProcessInfo().SetGroupID(success ? id : UINT32_MAX);
1305435933ddSDimitry Andric if (!success)
1306435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid group ID string: '%s'",
1307435933ddSDimitry Andric option_arg.str().c_str());
1308435933ddSDimitry Andric break;
1309435933ddSDimitry Andric
1310435933ddSDimitry Andric case 'G':
1311435933ddSDimitry Andric match_info.GetProcessInfo().SetEffectiveGroupID(success ? id
1312435933ddSDimitry Andric : UINT32_MAX);
1313435933ddSDimitry Andric if (!success)
1314435933ddSDimitry Andric error.SetErrorStringWithFormat(
1315435933ddSDimitry Andric "invalid effective group ID string: '%s'",
1316435933ddSDimitry Andric option_arg.str().c_str());
1317435933ddSDimitry Andric break;
1318435933ddSDimitry Andric
1319435933ddSDimitry Andric case 'a': {
1320435933ddSDimitry Andric TargetSP target_sp =
1321435933ddSDimitry Andric execution_context ? execution_context->GetTargetSP() : TargetSP();
1322435933ddSDimitry Andric DebuggerSP debugger_sp =
1323435933ddSDimitry Andric target_sp ? target_sp->GetDebugger().shared_from_this()
1324435933ddSDimitry Andric : DebuggerSP();
1325435933ddSDimitry Andric PlatformSP platform_sp =
1326435933ddSDimitry Andric debugger_sp ? debugger_sp->GetPlatformList().GetSelectedPlatform()
1327435933ddSDimitry Andric : PlatformSP();
1328acac075bSDimitry Andric match_info.GetProcessInfo().GetArchitecture() =
1329acac075bSDimitry Andric Platform::GetAugmentedArchSpec(platform_sp.get(), option_arg);
1330435933ddSDimitry Andric } break;
1331435933ddSDimitry Andric
1332435933ddSDimitry Andric case 'n':
13334ba319b5SDimitry Andric match_info.GetProcessInfo().GetExecutableFile().SetFile(
1334*b5893f02SDimitry Andric option_arg, FileSpec::Style::native);
1335f678e45dSDimitry Andric match_info.SetNameMatchType(NameMatch::Equals);
1336435933ddSDimitry Andric break;
1337435933ddSDimitry Andric
1338435933ddSDimitry Andric case 'e':
13394ba319b5SDimitry Andric match_info.GetProcessInfo().GetExecutableFile().SetFile(
1340*b5893f02SDimitry Andric option_arg, FileSpec::Style::native);
1341f678e45dSDimitry Andric match_info.SetNameMatchType(NameMatch::EndsWith);
1342435933ddSDimitry Andric break;
1343435933ddSDimitry Andric
1344435933ddSDimitry Andric case 's':
13454ba319b5SDimitry Andric match_info.GetProcessInfo().GetExecutableFile().SetFile(
1346*b5893f02SDimitry Andric option_arg, FileSpec::Style::native);
1347f678e45dSDimitry Andric match_info.SetNameMatchType(NameMatch::StartsWith);
1348435933ddSDimitry Andric break;
1349435933ddSDimitry Andric
1350435933ddSDimitry Andric case 'c':
13514ba319b5SDimitry Andric match_info.GetProcessInfo().GetExecutableFile().SetFile(
1352*b5893f02SDimitry Andric option_arg, FileSpec::Style::native);
1353f678e45dSDimitry Andric match_info.SetNameMatchType(NameMatch::Contains);
1354435933ddSDimitry Andric break;
1355435933ddSDimitry Andric
1356435933ddSDimitry Andric case 'r':
13574ba319b5SDimitry Andric match_info.GetProcessInfo().GetExecutableFile().SetFile(
1358*b5893f02SDimitry Andric option_arg, FileSpec::Style::native);
1359f678e45dSDimitry Andric match_info.SetNameMatchType(NameMatch::RegularExpression);
1360435933ddSDimitry Andric break;
1361435933ddSDimitry Andric
1362435933ddSDimitry Andric case 'A':
1363435933ddSDimitry Andric show_args = true;
1364435933ddSDimitry Andric break;
1365435933ddSDimitry Andric
1366435933ddSDimitry Andric case 'v':
1367435933ddSDimitry Andric verbose = true;
1368435933ddSDimitry Andric break;
1369435933ddSDimitry Andric
1370435933ddSDimitry Andric default:
1371435933ddSDimitry Andric error.SetErrorStringWithFormat("unrecognized option '%c'",
1372435933ddSDimitry Andric short_option);
1373435933ddSDimitry Andric break;
1374435933ddSDimitry Andric }
1375435933ddSDimitry Andric
1376435933ddSDimitry Andric return error;
1377435933ddSDimitry Andric }
1378435933ddSDimitry Andric
OptionParsingStarting(ExecutionContext * execution_context)1379435933ddSDimitry Andric void OptionParsingStarting(ExecutionContext *execution_context) override {
1380435933ddSDimitry Andric match_info.Clear();
1381435933ddSDimitry Andric show_args = false;
1382435933ddSDimitry Andric verbose = false;
1383435933ddSDimitry Andric }
1384435933ddSDimitry Andric
GetDefinitions()1385435933ddSDimitry Andric llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1386435933ddSDimitry Andric return llvm::makeArrayRef(g_platform_process_list_options);
1387435933ddSDimitry Andric }
1388435933ddSDimitry Andric
1389435933ddSDimitry Andric // Instance variables to hold the values for command options.
1390435933ddSDimitry Andric
1391435933ddSDimitry Andric ProcessInstanceInfoMatch match_info;
1392435933ddSDimitry Andric bool show_args;
1393435933ddSDimitry Andric bool verbose;
1394435933ddSDimitry Andric };
1395435933ddSDimitry Andric
1396435933ddSDimitry Andric CommandOptions m_options;
1397ac7ddfbfSEd Maste };
1398ac7ddfbfSEd Maste
1399ac7ddfbfSEd Maste //----------------------------------------------------------------------
1400ac7ddfbfSEd Maste // "platform process info"
1401ac7ddfbfSEd Maste //----------------------------------------------------------------------
1402435933ddSDimitry Andric class CommandObjectPlatformProcessInfo : public CommandObjectParsed {
1403ac7ddfbfSEd Maste public:
CommandObjectPlatformProcessInfo(CommandInterpreter & interpreter)1404435933ddSDimitry Andric CommandObjectPlatformProcessInfo(CommandInterpreter &interpreter)
1405435933ddSDimitry Andric : CommandObjectParsed(
1406435933ddSDimitry Andric interpreter, "platform process info",
1407ac7ddfbfSEd Maste "Get detailed information for one or more process by process ID.",
1408435933ddSDimitry Andric "platform process info <pid> [<pid> <pid> ...]", 0) {
1409ac7ddfbfSEd Maste CommandArgumentEntry arg;
1410ac7ddfbfSEd Maste CommandArgumentData pid_args;
1411ac7ddfbfSEd Maste
1412ac7ddfbfSEd Maste // Define the first (and only) variant of this arg.
1413ac7ddfbfSEd Maste pid_args.arg_type = eArgTypePid;
1414ac7ddfbfSEd Maste pid_args.arg_repetition = eArgRepeatStar;
1415ac7ddfbfSEd Maste
1416435933ddSDimitry Andric // There is only one variant this argument could be; put it into the
1417435933ddSDimitry Andric // argument entry.
1418ac7ddfbfSEd Maste arg.push_back(pid_args);
1419ac7ddfbfSEd Maste
1420ac7ddfbfSEd Maste // Push the data for the first argument into the m_arguments vector.
1421ac7ddfbfSEd Maste m_arguments.push_back(arg);
1422ac7ddfbfSEd Maste }
1423ac7ddfbfSEd Maste
14244bb0738eSEd Maste ~CommandObjectPlatformProcessInfo() override = default;
1425ac7ddfbfSEd Maste
1426ac7ddfbfSEd Maste protected:
DoExecute(Args & args,CommandReturnObject & result)1427435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
1428ac7ddfbfSEd Maste Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1429ac7ddfbfSEd Maste PlatformSP platform_sp;
1430435933ddSDimitry Andric if (target) {
1431ac7ddfbfSEd Maste platform_sp = target->GetPlatform();
1432ac7ddfbfSEd Maste }
1433435933ddSDimitry Andric if (!platform_sp) {
1434435933ddSDimitry Andric platform_sp =
1435435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform();
1436ac7ddfbfSEd Maste }
1437ac7ddfbfSEd Maste
1438435933ddSDimitry Andric if (platform_sp) {
1439ac7ddfbfSEd Maste const size_t argc = args.GetArgumentCount();
1440435933ddSDimitry Andric if (argc > 0) {
14415517e702SDimitry Andric Status error;
1442ac7ddfbfSEd Maste
1443435933ddSDimitry Andric if (platform_sp->IsConnected()) {
1444ac7ddfbfSEd Maste Stream &ostrm = result.GetOutputStream();
1445435933ddSDimitry Andric for (auto &entry : args.entries()) {
1446435933ddSDimitry Andric lldb::pid_t pid;
1447435933ddSDimitry Andric if (entry.ref.getAsInteger(0, pid)) {
1448435933ddSDimitry Andric result.AppendErrorWithFormat("invalid process ID argument '%s'",
1449435933ddSDimitry Andric entry.ref.str().c_str());
1450435933ddSDimitry Andric result.SetStatus(eReturnStatusFailed);
1451435933ddSDimitry Andric break;
1452435933ddSDimitry Andric } else {
1453ac7ddfbfSEd Maste ProcessInstanceInfo proc_info;
1454435933ddSDimitry Andric if (platform_sp->GetProcessInfo(pid, proc_info)) {
1455435933ddSDimitry Andric ostrm.Printf("Process information for process %" PRIu64 ":\n",
1456435933ddSDimitry Andric pid);
1457ac7ddfbfSEd Maste proc_info.Dump(ostrm, platform_sp.get());
1458435933ddSDimitry Andric } else {
1459435933ddSDimitry Andric ostrm.Printf("error: no process information is available for "
1460435933ddSDimitry Andric "process %" PRIu64 "\n",
1461435933ddSDimitry Andric pid);
1462ac7ddfbfSEd Maste }
1463ac7ddfbfSEd Maste ostrm.EOL();
1464ac7ddfbfSEd Maste }
1465ac7ddfbfSEd Maste }
1466435933ddSDimitry Andric } else {
1467ac7ddfbfSEd Maste // Not connected...
1468435933ddSDimitry Andric result.AppendErrorWithFormat(
1469435933ddSDimitry Andric "not connected to '%s'",
1470435933ddSDimitry Andric platform_sp->GetPluginName().GetCString());
1471ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1472ac7ddfbfSEd Maste }
1473435933ddSDimitry Andric } else {
1474ac7ddfbfSEd Maste // No args
1475ac7ddfbfSEd Maste result.AppendError("one or more process id(s) must be specified");
1476ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1477ac7ddfbfSEd Maste }
1478435933ddSDimitry Andric } else {
1479ac7ddfbfSEd Maste result.AppendError("no platform is currently selected");
1480ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1481ac7ddfbfSEd Maste }
1482ac7ddfbfSEd Maste return result.Succeeded();
1483ac7ddfbfSEd Maste }
1484ac7ddfbfSEd Maste };
1485ac7ddfbfSEd Maste
1486*b5893f02SDimitry Andric static constexpr OptionDefinition g_platform_process_attach_options[] = {
1487435933ddSDimitry Andric // clang-format off
1488*b5893f02SDimitry Andric { LLDB_OPT_SET_ALL, false, "plugin", 'P', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypePlugin, "Name of the process plugin you want to use." },
1489*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "pid", 'p', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypePid, "The process ID of an existing process to attach to." },
1490*b5893f02SDimitry Andric { LLDB_OPT_SET_2, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeProcessName, "The name of the process to attach to." },
1491*b5893f02SDimitry Andric { LLDB_OPT_SET_2, false, "waitfor", 'w', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Wait for the process with <process-name> to launch." },
1492435933ddSDimitry Andric // clang-format on
1493435933ddSDimitry Andric };
1494435933ddSDimitry Andric
1495435933ddSDimitry Andric class CommandObjectPlatformProcessAttach : public CommandObjectParsed {
149635617911SEd Maste public:
1497435933ddSDimitry Andric class CommandOptions : public Options {
149835617911SEd Maste public:
CommandOptions()1499435933ddSDimitry Andric CommandOptions() : Options() {
1500435933ddSDimitry Andric // Keep default values of all options in one place: OptionParsingStarting
1501435933ddSDimitry Andric // ()
1502435933ddSDimitry Andric OptionParsingStarting(nullptr);
150335617911SEd Maste }
150435617911SEd Maste
15054bb0738eSEd Maste ~CommandOptions() override = default;
150635617911SEd Maste
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)15075517e702SDimitry Andric Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1508435933ddSDimitry Andric ExecutionContext *execution_context) override {
15095517e702SDimitry Andric Status error;
151035617911SEd Maste char short_option = (char)m_getopt_table[option_idx].val;
1511435933ddSDimitry Andric switch (short_option) {
1512435933ddSDimitry Andric case 'p': {
1513435933ddSDimitry Andric lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
1514435933ddSDimitry Andric if (option_arg.getAsInteger(0, pid)) {
1515435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid process ID '%s'",
1516435933ddSDimitry Andric option_arg.str().c_str());
1517435933ddSDimitry Andric } else {
151835617911SEd Maste attach_info.SetProcessID(pid);
151935617911SEd Maste }
1520435933ddSDimitry Andric } break;
152135617911SEd Maste
152235617911SEd Maste case 'P':
152335617911SEd Maste attach_info.SetProcessPluginName(option_arg);
152435617911SEd Maste break;
152535617911SEd Maste
152635617911SEd Maste case 'n':
1527*b5893f02SDimitry Andric attach_info.GetExecutableFile().SetFile(option_arg,
15284ba319b5SDimitry Andric FileSpec::Style::native);
152935617911SEd Maste break;
153035617911SEd Maste
153135617911SEd Maste case 'w':
153235617911SEd Maste attach_info.SetWaitForLaunch(true);
153335617911SEd Maste break;
153435617911SEd Maste
153535617911SEd Maste default:
1536435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid short option character '%c'",
1537435933ddSDimitry Andric short_option);
153835617911SEd Maste break;
153935617911SEd Maste }
154035617911SEd Maste return error;
154135617911SEd Maste }
154235617911SEd Maste
OptionParsingStarting(ExecutionContext * execution_context)1543435933ddSDimitry Andric void OptionParsingStarting(ExecutionContext *execution_context) override {
154435617911SEd Maste attach_info.Clear();
154535617911SEd Maste }
154635617911SEd Maste
GetDefinitions()1547435933ddSDimitry Andric llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1548435933ddSDimitry Andric return llvm::makeArrayRef(g_platform_process_attach_options);
154935617911SEd Maste }
155035617911SEd Maste
HandleOptionArgumentCompletion(CompletionRequest & request,OptionElementVector & opt_element_vector,int opt_element_index,CommandInterpreter & interpreter)1551435933ddSDimitry Andric bool HandleOptionArgumentCompletion(
15524ba319b5SDimitry Andric CompletionRequest &request, OptionElementVector &opt_element_vector,
15534ba319b5SDimitry Andric int opt_element_index, CommandInterpreter &interpreter) override {
155435617911SEd Maste int opt_arg_pos = opt_element_vector[opt_element_index].opt_arg_pos;
155535617911SEd Maste int opt_defs_index = opt_element_vector[opt_element_index].opt_defs_index;
155635617911SEd Maste
155735617911SEd Maste // We are only completing the name option for now...
155835617911SEd Maste
1559435933ddSDimitry Andric if (GetDefinitions()[opt_defs_index].short_option == 'n') {
156035617911SEd Maste // Are we in the name?
156135617911SEd Maste
1562435933ddSDimitry Andric // Look to see if there is a -P argument provided, and if so use that
15634ba319b5SDimitry Andric // plugin, otherwise use the default plugin.
156435617911SEd Maste
15654bb0738eSEd Maste const char *partial_name = nullptr;
15664ba319b5SDimitry Andric partial_name = request.GetParsedLine().GetArgumentAtIndex(opt_arg_pos);
156735617911SEd Maste
1568435933ddSDimitry Andric PlatformSP platform_sp(interpreter.GetPlatform(true));
1569435933ddSDimitry Andric if (platform_sp) {
157035617911SEd Maste ProcessInstanceInfoList process_infos;
157135617911SEd Maste ProcessInstanceInfoMatch match_info;
1572435933ddSDimitry Andric if (partial_name) {
1573435933ddSDimitry Andric match_info.GetProcessInfo().GetExecutableFile().SetFile(
1574*b5893f02SDimitry Andric partial_name, FileSpec::Style::native);
1575f678e45dSDimitry Andric match_info.SetNameMatchType(NameMatch::StartsWith);
157635617911SEd Maste }
157735617911SEd Maste platform_sp->FindProcesses(match_info, process_infos);
157835617911SEd Maste const uint32_t num_matches = process_infos.GetSize();
1579435933ddSDimitry Andric if (num_matches > 0) {
1580435933ddSDimitry Andric for (uint32_t i = 0; i < num_matches; ++i) {
15814ba319b5SDimitry Andric request.AddCompletion(llvm::StringRef(
1582435933ddSDimitry Andric process_infos.GetProcessNameAtIndex(i),
15834ba319b5SDimitry Andric process_infos.GetProcessNameLengthAtIndex(i)));
158435617911SEd Maste }
158535617911SEd Maste }
158635617911SEd Maste }
158735617911SEd Maste }
158835617911SEd Maste
158935617911SEd Maste return false;
159035617911SEd Maste }
159135617911SEd Maste
159235617911SEd Maste // Options table: Required for subclasses of Options.
159335617911SEd Maste
159435617911SEd Maste static OptionDefinition g_option_table[];
159535617911SEd Maste
159635617911SEd Maste // Instance variables to hold the values for command options.
159735617911SEd Maste
159835617911SEd Maste ProcessAttachInfo attach_info;
159935617911SEd Maste };
160035617911SEd Maste
CommandObjectPlatformProcessAttach(CommandInterpreter & interpreter)1601435933ddSDimitry Andric CommandObjectPlatformProcessAttach(CommandInterpreter &interpreter)
1602435933ddSDimitry Andric : CommandObjectParsed(interpreter, "platform process attach",
160335617911SEd Maste "Attach to a process.",
160435617911SEd Maste "platform process attach <cmd-options>"),
1605435933ddSDimitry Andric m_options() {}
160635617911SEd Maste
16074bb0738eSEd Maste ~CommandObjectPlatformProcessAttach() override = default;
160835617911SEd Maste
DoExecute(Args & command,CommandReturnObject & result)1609435933ddSDimitry Andric bool DoExecute(Args &command, CommandReturnObject &result) override {
1610435933ddSDimitry Andric PlatformSP platform_sp(
1611435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
1612435933ddSDimitry Andric if (platform_sp) {
16135517e702SDimitry Andric Status err;
1614435933ddSDimitry Andric ProcessSP remote_process_sp = platform_sp->Attach(
1615435933ddSDimitry Andric m_options.attach_info, m_interpreter.GetDebugger(), nullptr, err);
1616435933ddSDimitry Andric if (err.Fail()) {
161735617911SEd Maste result.AppendError(err.AsCString());
161835617911SEd Maste result.SetStatus(eReturnStatusFailed);
1619435933ddSDimitry Andric } else if (!remote_process_sp) {
162035617911SEd Maste result.AppendError("could not attach: unknown reason");
162135617911SEd Maste result.SetStatus(eReturnStatusFailed);
1622435933ddSDimitry Andric } else
162335617911SEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
1624435933ddSDimitry Andric } else {
162535617911SEd Maste result.AppendError("no platform is currently selected");
162635617911SEd Maste result.SetStatus(eReturnStatusFailed);
162735617911SEd Maste }
162835617911SEd Maste return result.Succeeded();
162935617911SEd Maste }
163035617911SEd Maste
GetOptions()1631435933ddSDimitry Andric Options *GetOptions() override { return &m_options; }
163235617911SEd Maste
163335617911SEd Maste protected:
163435617911SEd Maste CommandOptions m_options;
163535617911SEd Maste };
163635617911SEd Maste
1637435933ddSDimitry Andric class CommandObjectPlatformProcess : public CommandObjectMultiword {
1638ac7ddfbfSEd Maste public:
1639ac7ddfbfSEd Maste //------------------------------------------------------------------
1640ac7ddfbfSEd Maste // Constructors and Destructors
1641ac7ddfbfSEd Maste //------------------------------------------------------------------
CommandObjectPlatformProcess(CommandInterpreter & interpreter)16424bb0738eSEd Maste CommandObjectPlatformProcess(CommandInterpreter &interpreter)
16434bb0738eSEd Maste : CommandObjectMultiword(interpreter, "platform process",
1644435933ddSDimitry Andric "Commands to query, launch and attach to "
1645435933ddSDimitry Andric "processes on the current platform.",
1646435933ddSDimitry Andric "platform process [attach|launch|list] ...") {
1647435933ddSDimitry Andric LoadSubCommand(
1648435933ddSDimitry Andric "attach",
1649435933ddSDimitry Andric CommandObjectSP(new CommandObjectPlatformProcessAttach(interpreter)));
1650435933ddSDimitry Andric LoadSubCommand(
1651435933ddSDimitry Andric "launch",
1652435933ddSDimitry Andric CommandObjectSP(new CommandObjectPlatformProcessLaunch(interpreter)));
1653435933ddSDimitry Andric LoadSubCommand("info", CommandObjectSP(new CommandObjectPlatformProcessInfo(
1654435933ddSDimitry Andric interpreter)));
1655435933ddSDimitry Andric LoadSubCommand("list", CommandObjectSP(new CommandObjectPlatformProcessList(
1656435933ddSDimitry Andric interpreter)));
1657ac7ddfbfSEd Maste }
1658ac7ddfbfSEd Maste
16594bb0738eSEd Maste ~CommandObjectPlatformProcess() override = default;
1660ac7ddfbfSEd Maste
1661ac7ddfbfSEd Maste private:
1662ac7ddfbfSEd Maste //------------------------------------------------------------------
1663ac7ddfbfSEd Maste // For CommandObjectPlatform only
1664ac7ddfbfSEd Maste //------------------------------------------------------------------
1665ac7ddfbfSEd Maste DISALLOW_COPY_AND_ASSIGN(CommandObjectPlatformProcess);
1666ac7ddfbfSEd Maste };
1667ac7ddfbfSEd Maste
166835617911SEd Maste //----------------------------------------------------------------------
166935617911SEd Maste // "platform shell"
167035617911SEd Maste //----------------------------------------------------------------------
1671*b5893f02SDimitry Andric static constexpr OptionDefinition g_platform_shell_options[] = {
1672435933ddSDimitry Andric // clang-format off
1673*b5893f02SDimitry Andric { LLDB_OPT_SET_ALL, false, "timeout", 't', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeValue, "Seconds to wait for the remote host to finish running the command." },
1674435933ddSDimitry Andric // clang-format on
1675435933ddSDimitry Andric };
1676435933ddSDimitry Andric
1677435933ddSDimitry Andric class CommandObjectPlatformShell : public CommandObjectRaw {
1678ac7ddfbfSEd Maste public:
1679435933ddSDimitry Andric class CommandOptions : public Options {
168035617911SEd Maste public:
CommandOptions()16814ba319b5SDimitry Andric CommandOptions() : Options() {}
168235617911SEd Maste
16834bb0738eSEd Maste ~CommandOptions() override = default;
168435617911SEd Maste
GetDefinitions()1685435933ddSDimitry Andric llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1686435933ddSDimitry Andric return llvm::makeArrayRef(g_platform_shell_options);
168735617911SEd Maste }
168835617911SEd Maste
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)16895517e702SDimitry Andric Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1690435933ddSDimitry Andric ExecutionContext *execution_context) override {
16915517e702SDimitry Andric Status error;
169235617911SEd Maste
1693435933ddSDimitry Andric const char short_option = (char)GetDefinitions()[option_idx].short_option;
169435617911SEd Maste
1695435933ddSDimitry Andric switch (short_option) {
169635617911SEd Maste case 't':
16974ba319b5SDimitry Andric uint32_t timeout_sec;
16984ba319b5SDimitry Andric if (option_arg.getAsInteger(10, timeout_sec))
1699435933ddSDimitry Andric error.SetErrorStringWithFormat(
1700435933ddSDimitry Andric "could not convert \"%s\" to a numeric value.",
1701435933ddSDimitry Andric option_arg.str().c_str());
17024ba319b5SDimitry Andric else
17034ba319b5SDimitry Andric timeout = std::chrono::seconds(timeout_sec);
170435617911SEd Maste break;
170535617911SEd Maste default:
1706435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid short option character '%c'",
1707435933ddSDimitry Andric short_option);
170835617911SEd Maste break;
170935617911SEd Maste }
171035617911SEd Maste
171135617911SEd Maste return error;
171235617911SEd Maste }
171335617911SEd Maste
OptionParsingStarting(ExecutionContext * execution_context)1714435933ddSDimitry Andric void OptionParsingStarting(ExecutionContext *execution_context) override {}
171535617911SEd Maste
17164ba319b5SDimitry Andric Timeout<std::micro> timeout = std::chrono::seconds(10);
171735617911SEd Maste };
171835617911SEd Maste
CommandObjectPlatformShell(CommandInterpreter & interpreter)17194bb0738eSEd Maste CommandObjectPlatformShell(CommandInterpreter &interpreter)
1720435933ddSDimitry Andric : CommandObjectRaw(interpreter, "platform shell",
1721435933ddSDimitry Andric "Run a shell command on the current platform.",
17224bb0738eSEd Maste "platform shell <shell-command>", 0),
1723435933ddSDimitry Andric m_options() {}
1724ac7ddfbfSEd Maste
17254bb0738eSEd Maste ~CommandObjectPlatformShell() override = default;
1726ac7ddfbfSEd Maste
GetOptions()1727435933ddSDimitry Andric Options *GetOptions() override { return &m_options; }
172835617911SEd Maste
DoExecute(llvm::StringRef raw_command_line,CommandReturnObject & result)17294ba319b5SDimitry Andric bool DoExecute(llvm::StringRef raw_command_line,
1730435933ddSDimitry Andric CommandReturnObject &result) override {
1731435933ddSDimitry Andric ExecutionContext exe_ctx = GetCommandInterpreter().GetExecutionContext();
1732435933ddSDimitry Andric m_options.NotifyOptionParsingStarting(&exe_ctx);
173335617911SEd Maste
173435617911SEd Maste
173535617911SEd Maste // Print out an usage syntax on an empty command line.
17364ba319b5SDimitry Andric if (raw_command_line.empty()) {
1737435933ddSDimitry Andric result.GetOutputStream().Printf("%s\n", this->GetSyntax().str().c_str());
173835617911SEd Maste return true;
173935617911SEd Maste }
174035617911SEd Maste
17414ba319b5SDimitry Andric OptionsWithRaw args(raw_command_line);
17424ba319b5SDimitry Andric const char *expr = args.GetRawPart().c_str();
174335617911SEd Maste
17444ba319b5SDimitry Andric if (args.HasArgs())
17454ba319b5SDimitry Andric if (!ParseOptions(args.GetArgs(), result))
174635617911SEd Maste return false;
174735617911SEd Maste
1748435933ddSDimitry Andric PlatformSP platform_sp(
1749435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
17505517e702SDimitry Andric Status error;
1751435933ddSDimitry Andric if (platform_sp) {
17521c3bbb01SEd Maste FileSpec working_dir{};
1753ac7ddfbfSEd Maste std::string output;
1754ac7ddfbfSEd Maste int status = -1;
1755ac7ddfbfSEd Maste int signo = -1;
1756435933ddSDimitry Andric error = (platform_sp->RunShellCommand(expr, working_dir, &status, &signo,
1757435933ddSDimitry Andric &output, m_options.timeout));
1758ac7ddfbfSEd Maste if (!output.empty())
1759435933ddSDimitry Andric result.GetOutputStream().PutCString(output);
1760435933ddSDimitry Andric if (status > 0) {
1761435933ddSDimitry Andric if (signo > 0) {
1762ac7ddfbfSEd Maste const char *signo_cstr = Host::GetSignalAsCString(signo);
1763ac7ddfbfSEd Maste if (signo_cstr)
1764435933ddSDimitry Andric result.GetOutputStream().Printf(
1765435933ddSDimitry Andric "error: command returned with status %i and signal %s\n",
1766435933ddSDimitry Andric status, signo_cstr);
1767ac7ddfbfSEd Maste else
1768435933ddSDimitry Andric result.GetOutputStream().Printf(
1769435933ddSDimitry Andric "error: command returned with status %i and signal %i\n",
1770435933ddSDimitry Andric status, signo);
1771435933ddSDimitry Andric } else
1772435933ddSDimitry Andric result.GetOutputStream().Printf(
1773435933ddSDimitry Andric "error: command returned with status %i\n", status);
1774ac7ddfbfSEd Maste }
1775435933ddSDimitry Andric } else {
1776435933ddSDimitry Andric result.GetOutputStream().Printf(
1777435933ddSDimitry Andric "error: cannot run remote shell commands without a platform\n");
1778435933ddSDimitry Andric error.SetErrorString(
1779435933ddSDimitry Andric "error: cannot run remote shell commands without a platform");
178035617911SEd Maste }
1781ac7ddfbfSEd Maste
1782435933ddSDimitry Andric if (error.Fail()) {
1783ac7ddfbfSEd Maste result.AppendError(error.AsCString());
1784ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1785435933ddSDimitry Andric } else {
1786ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
1787ac7ddfbfSEd Maste }
1788ac7ddfbfSEd Maste return true;
1789ac7ddfbfSEd Maste }
17904bb0738eSEd Maste
179135617911SEd Maste CommandOptions m_options;
179235617911SEd Maste };
179335617911SEd Maste
179435617911SEd Maste //----------------------------------------------------------------------
179535617911SEd Maste // "platform install" - install a target to a remote end
179635617911SEd Maste //----------------------------------------------------------------------
1797435933ddSDimitry Andric class CommandObjectPlatformInstall : public CommandObjectParsed {
179835617911SEd Maste public:
CommandObjectPlatformInstall(CommandInterpreter & interpreter)1799435933ddSDimitry Andric CommandObjectPlatformInstall(CommandInterpreter &interpreter)
1800435933ddSDimitry Andric : CommandObjectParsed(
1801435933ddSDimitry Andric interpreter, "platform target-install",
180235617911SEd Maste "Install a target (bundle or executable file) to the remote end.",
1803435933ddSDimitry Andric "platform target-install <local-thing> <remote-sandbox>", 0) {}
180435617911SEd Maste
18054bb0738eSEd Maste ~CommandObjectPlatformInstall() override = default;
180635617911SEd Maste
DoExecute(Args & args,CommandReturnObject & result)1807435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
1808435933ddSDimitry Andric if (args.GetArgumentCount() != 2) {
180935617911SEd Maste result.AppendError("platform target-install takes two arguments");
181035617911SEd Maste result.SetStatus(eReturnStatusFailed);
181135617911SEd Maste return false;
181235617911SEd Maste }
181335617911SEd Maste // TODO: move the bulk of this code over to the platform itself
1814*b5893f02SDimitry Andric FileSpec src(args.GetArgumentAtIndex(0));
1815*b5893f02SDimitry Andric FileSystem::Instance().Resolve(src);
1816*b5893f02SDimitry Andric FileSpec dst(args.GetArgumentAtIndex(1));
1817*b5893f02SDimitry Andric if (!FileSystem::Instance().Exists(src)) {
181835617911SEd Maste result.AppendError("source location does not exist or is not accessible");
181935617911SEd Maste result.SetStatus(eReturnStatusFailed);
182035617911SEd Maste return false;
182135617911SEd Maste }
1822435933ddSDimitry Andric PlatformSP platform_sp(
1823435933ddSDimitry Andric m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
1824435933ddSDimitry Andric if (!platform_sp) {
182535617911SEd Maste result.AppendError("no platform currently selected");
182635617911SEd Maste result.SetStatus(eReturnStatusFailed);
182735617911SEd Maste return false;
182835617911SEd Maste }
1829b952cd58SEd Maste
18305517e702SDimitry Andric Status error = platform_sp->Install(src, dst);
1831435933ddSDimitry Andric if (error.Success()) {
183235617911SEd Maste result.SetStatus(eReturnStatusSuccessFinishNoResult);
1833435933ddSDimitry Andric } else {
1834b952cd58SEd Maste result.AppendErrorWithFormat("install failed: %s", error.AsCString());
183535617911SEd Maste result.SetStatus(eReturnStatusFailed);
183635617911SEd Maste }
1837b952cd58SEd Maste return result.Succeeded();
183835617911SEd Maste }
1839ac7ddfbfSEd Maste };
1840ac7ddfbfSEd Maste
CommandObjectPlatform(CommandInterpreter & interpreter)18414bb0738eSEd Maste CommandObjectPlatform::CommandObjectPlatform(CommandInterpreter &interpreter)
1842435933ddSDimitry Andric : CommandObjectMultiword(
1843435933ddSDimitry Andric interpreter, "platform", "Commands to manage and create platforms.",
1844435933ddSDimitry Andric "platform [connect|disconnect|info|list|status|select] ...") {
1845435933ddSDimitry Andric LoadSubCommand("select",
1846435933ddSDimitry Andric CommandObjectSP(new CommandObjectPlatformSelect(interpreter)));
1847435933ddSDimitry Andric LoadSubCommand("list",
1848435933ddSDimitry Andric CommandObjectSP(new CommandObjectPlatformList(interpreter)));
1849435933ddSDimitry Andric LoadSubCommand("status",
1850435933ddSDimitry Andric CommandObjectSP(new CommandObjectPlatformStatus(interpreter)));
1851435933ddSDimitry Andric LoadSubCommand("connect", CommandObjectSP(
1852435933ddSDimitry Andric new CommandObjectPlatformConnect(interpreter)));
1853435933ddSDimitry Andric LoadSubCommand(
1854435933ddSDimitry Andric "disconnect",
1855435933ddSDimitry Andric CommandObjectSP(new CommandObjectPlatformDisconnect(interpreter)));
1856435933ddSDimitry Andric LoadSubCommand("settings", CommandObjectSP(new CommandObjectPlatformSettings(
1857435933ddSDimitry Andric interpreter)));
1858435933ddSDimitry Andric LoadSubCommand("mkdir",
1859435933ddSDimitry Andric CommandObjectSP(new CommandObjectPlatformMkDir(interpreter)));
1860435933ddSDimitry Andric LoadSubCommand("file",
1861435933ddSDimitry Andric CommandObjectSP(new CommandObjectPlatformFile(interpreter)));
1862435933ddSDimitry Andric LoadSubCommand("get-file", CommandObjectSP(new CommandObjectPlatformGetFile(
1863435933ddSDimitry Andric interpreter)));
1864435933ddSDimitry Andric LoadSubCommand("get-size", CommandObjectSP(new CommandObjectPlatformGetSize(
1865435933ddSDimitry Andric interpreter)));
1866435933ddSDimitry Andric LoadSubCommand("put-file", CommandObjectSP(new CommandObjectPlatformPutFile(
1867435933ddSDimitry Andric interpreter)));
1868435933ddSDimitry Andric LoadSubCommand("process", CommandObjectSP(
1869435933ddSDimitry Andric new CommandObjectPlatformProcess(interpreter)));
1870435933ddSDimitry Andric LoadSubCommand("shell",
1871435933ddSDimitry Andric CommandObjectSP(new CommandObjectPlatformShell(interpreter)));
1872435933ddSDimitry Andric LoadSubCommand(
1873435933ddSDimitry Andric "target-install",
1874435933ddSDimitry Andric CommandObjectSP(new CommandObjectPlatformInstall(interpreter)));
1875ac7ddfbfSEd Maste }
1876ac7ddfbfSEd Maste
18774bb0738eSEd Maste CommandObjectPlatform::~CommandObjectPlatform() = default;
1878