blob: 9998dbdccdad0ddaa9d1db8826fd23fd35b06d85 [file] [log] [blame]
Greg Claytonded470d2011-03-19 01:12:21 +00001//===-- CommandObjectPlatform.cpp -------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Greg Claytonded470d2011-03-19 01:12:21 +000012#include "CommandObjectPlatform.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
18#include "lldb/Core/DataExtractor.h"
19#include "lldb/Core/Debugger.h"
Greg Clayton1f746072012-08-29 21:13:06 +000020#include "lldb/Core/Module.h"
Greg Claytonded470d2011-03-19 01:12:21 +000021#include "lldb/Core/PluginManager.h"
22#include "lldb/Interpreter/Args.h"
23#include "lldb/Interpreter/CommandInterpreter.h"
Zachary Turnerd37221d2014-07-09 16:31:49 +000024#include "lldb/Interpreter/CommandOptionValidators.h"
Greg Claytonded470d2011-03-19 01:12:21 +000025#include "lldb/Interpreter/CommandReturnObject.h"
Greg Claytonfbb76342013-11-20 21:07:01 +000026#include "lldb/Interpreter/OptionGroupFile.h"
Greg Clayton7260f622011-04-18 08:33:37 +000027#include "lldb/Interpreter/OptionGroupPlatform.h"
Greg Claytonded470d2011-03-19 01:12:21 +000028#include "lldb/Target/ExecutionContext.h"
29#include "lldb/Target/Platform.h"
Greg Claytoneb0103f2011-04-07 22:46:35 +000030#include "lldb/Target/Process.h"
Daniel Maleae0f8f572013-08-26 23:57:52 +000031#include "lldb/Utility/Utils.h"
Greg Claytonded470d2011-03-19 01:12:21 +000032
33using namespace lldb;
34using namespace lldb_private;
35
Daniel Maleae0f8f572013-08-26 23:57:52 +000036static mode_t
37ParsePermissionString(const char* permissions)
38{
39 if (strlen(permissions) != 9)
40 return (mode_t)(-1);
41 bool user_r,user_w,user_x,
42 group_r,group_w,group_x,
43 world_r,world_w,world_x;
44
45 user_r = (permissions[0] == 'r');
46 user_w = (permissions[1] == 'w');
47 user_x = (permissions[2] == 'x');
48
49 group_r = (permissions[3] == 'r');
50 group_w = (permissions[4] == 'w');
51 group_x = (permissions[5] == 'x');
52
53 world_r = (permissions[6] == 'r');
54 world_w = (permissions[7] == 'w');
55 world_x = (permissions[8] == 'x');
56
57 mode_t user,group,world;
58 user = (user_r ? 4 : 0) | (user_w ? 2 : 0) | (user_x ? 1 : 0);
59 group = (group_r ? 4 : 0) | (group_w ? 2 : 0) | (group_x ? 1 : 0);
60 world = (world_r ? 4 : 0) | (world_w ? 2 : 0) | (world_x ? 1 : 0);
61
62 return user | group | world;
63}
64
65static OptionDefinition
66g_permissions_options[] =
67{
Zachary Turnerd37221d2014-07-09 16:31:49 +000068 { LLDB_OPT_SET_ALL, false, "permissions-value", 'v', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePermissionsNumber , "Give out the numeric value for permissions (e.g. 757)" },
69 { LLDB_OPT_SET_ALL, false, "permissions-string", 's', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePermissionsString , "Give out the string value for permissions (e.g. rwxr-xr--)." },
70 { LLDB_OPT_SET_ALL, false, "user-read", 'r', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Allow user to read." },
71 { LLDB_OPT_SET_ALL, false, "user-write", 'w', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Allow user to write." },
72 { LLDB_OPT_SET_ALL, false, "user-exec", 'x', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Allow user to execute." },
Daniel Maleae0f8f572013-08-26 23:57:52 +000073
Zachary Turnerd37221d2014-07-09 16:31:49 +000074 { LLDB_OPT_SET_ALL, false, "group-read", 'R', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Allow group to read." },
75 { LLDB_OPT_SET_ALL, false, "group-write", 'W', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Allow group to write." },
76 { LLDB_OPT_SET_ALL, false, "group-exec", 'X', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Allow group to execute." },
Daniel Maleae0f8f572013-08-26 23:57:52 +000077
Zachary Turnerd37221d2014-07-09 16:31:49 +000078 { LLDB_OPT_SET_ALL, false, "world-read", 'd', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Allow world to read." },
79 { LLDB_OPT_SET_ALL, false, "world-write", 't', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Allow world to write." },
80 { LLDB_OPT_SET_ALL, false, "world-exec", 'e', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Allow world to execute." },
Daniel Maleae0f8f572013-08-26 23:57:52 +000081};
82
83class OptionPermissions : public lldb_private::OptionGroup
84{
85public:
86 OptionPermissions ()
87 {
88 }
89
90 virtual
91 ~OptionPermissions ()
92 {
93 }
94
95 virtual lldb_private::Error
96 SetOptionValue (CommandInterpreter &interpreter,
97 uint32_t option_idx,
98 const char *option_arg)
99 {
100 Error error;
101 char short_option = (char) GetDefinitions()[option_idx].short_option;
102 switch (short_option)
103 {
104 case 'v':
105 {
106 bool ok;
107 uint32_t perms = Args::StringToUInt32(option_arg, 777, 8, &ok);
108 if (!ok)
109 error.SetErrorStringWithFormat("invalid value for permissions: %s", option_arg);
110 else
111 m_permissions = perms;
112 }
113 break;
114 case 's':
115 {
116 mode_t perms = ParsePermissionString(option_arg);
117 if (perms == (mode_t)-1)
118 error.SetErrorStringWithFormat("invalid value for permissions: %s", option_arg);
119 else
120 m_permissions = perms;
121 }
122 case 'r':
Greg Claytonfbb76342013-11-20 21:07:01 +0000123 m_permissions |= lldb::eFilePermissionsUserRead;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000124 break;
125 case 'w':
Greg Claytonfbb76342013-11-20 21:07:01 +0000126 m_permissions |= lldb::eFilePermissionsUserWrite;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000127 break;
128 case 'x':
Greg Claytonfbb76342013-11-20 21:07:01 +0000129 m_permissions |= lldb::eFilePermissionsUserExecute;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000130 break;
131 case 'R':
Greg Claytonfbb76342013-11-20 21:07:01 +0000132 m_permissions |= lldb::eFilePermissionsGroupRead;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000133 break;
134 case 'W':
Greg Claytonfbb76342013-11-20 21:07:01 +0000135 m_permissions |= lldb::eFilePermissionsGroupWrite;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000136 break;
137 case 'X':
Greg Claytonfbb76342013-11-20 21:07:01 +0000138 m_permissions |= lldb::eFilePermissionsGroupExecute;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000139 break;
140 case 'd':
Greg Claytonfbb76342013-11-20 21:07:01 +0000141 m_permissions |= lldb::eFilePermissionsWorldRead;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000142 break;
143 case 't':
Greg Claytonfbb76342013-11-20 21:07:01 +0000144 m_permissions |= lldb::eFilePermissionsWorldWrite;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000145 break;
146 case 'e':
Greg Claytonfbb76342013-11-20 21:07:01 +0000147 m_permissions |= lldb::eFilePermissionsWorldExecute;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000148 break;
149
150 default:
151 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
152 break;
153 }
154
155 return error;
156 }
157
158 void
159 OptionParsingStarting (CommandInterpreter &interpreter)
160 {
161 m_permissions = 0;
162 }
163
164 virtual uint32_t
165 GetNumDefinitions ()
166 {
167 return llvm::array_lengthof(g_permissions_options);
168 }
169
170 const lldb_private::OptionDefinition*
171 GetDefinitions ()
172 {
173 return g_permissions_options;
174 }
175
176 // Instance variables to hold the values for command options.
177
178 uint32_t m_permissions;
179private:
180 DISALLOW_COPY_AND_ASSIGN(OptionPermissions);
181};
Greg Claytonf6b8b582011-04-13 00:18:08 +0000182
Greg Claytonded470d2011-03-19 01:12:21 +0000183//----------------------------------------------------------------------
Greg Clayton7260f622011-04-18 08:33:37 +0000184// "platform select <platform-name>"
Greg Claytonded470d2011-03-19 01:12:21 +0000185//----------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +0000186class CommandObjectPlatformSelect : public CommandObjectParsed
Greg Claytonded470d2011-03-19 01:12:21 +0000187{
188public:
Greg Claytonf6b8b582011-04-13 00:18:08 +0000189 CommandObjectPlatformSelect (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000190 CommandObjectParsed (interpreter,
191 "platform select",
192 "Create a platform if needed and select it as the current platform.",
193 "platform select <platform-name>",
194 0),
Greg Claytonf6b8b582011-04-13 00:18:08 +0000195 m_option_group (interpreter),
196 m_platform_options (false) // Don't include the "--platform" option by passing false
Greg Claytonded470d2011-03-19 01:12:21 +0000197 {
Greg Claytonab65b342011-04-13 22:47:15 +0000198 m_option_group.Append (&m_platform_options, LLDB_OPT_SET_ALL, 1);
Greg Claytonf6b8b582011-04-13 00:18:08 +0000199 m_option_group.Finalize();
Greg Claytonded470d2011-03-19 01:12:21 +0000200 }
201
202 virtual
Greg Claytonf6b8b582011-04-13 00:18:08 +0000203 ~CommandObjectPlatformSelect ()
Greg Claytonded470d2011-03-19 01:12:21 +0000204 {
205 }
206
Jim Ingham5a988412012-06-08 21:56:10 +0000207 virtual int
208 HandleCompletion (Args &input,
209 int &cursor_index,
210 int &cursor_char_position,
211 int match_start_point,
212 int max_return_elements,
213 bool &word_complete,
214 StringList &matches)
215 {
216 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
217 completion_str.erase (cursor_char_position);
218
219 CommandCompletions::PlatformPluginNames (m_interpreter,
220 completion_str.c_str(),
221 match_start_point,
222 max_return_elements,
223 NULL,
224 word_complete,
225 matches);
226 return matches.GetSize();
227 }
228
229 virtual Options *
230 GetOptions ()
231 {
232 return &m_option_group;
233 }
234
235protected:
Greg Claytonded470d2011-03-19 01:12:21 +0000236 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +0000237 DoExecute (Args& args, CommandReturnObject &result)
Greg Claytonded470d2011-03-19 01:12:21 +0000238 {
Greg Claytonded470d2011-03-19 01:12:21 +0000239 if (args.GetArgumentCount() == 1)
240 {
Greg Claytonab65b342011-04-13 22:47:15 +0000241 const char *platform_name = args.GetArgumentAtIndex (0);
242 if (platform_name && platform_name[0])
243 {
244 const bool select = true;
Greg Clayton7260f622011-04-18 08:33:37 +0000245 m_platform_options.SetPlatformName (platform_name);
Greg Claytonab65b342011-04-13 22:47:15 +0000246 Error error;
Greg Clayton70512312012-05-08 01:45:38 +0000247 ArchSpec platform_arch;
248 PlatformSP platform_sp (m_platform_options.CreatePlatformWithOptions (m_interpreter, ArchSpec(), select, error, platform_arch));
Greg Claytonab65b342011-04-13 22:47:15 +0000249 if (platform_sp)
250 {
251 platform_sp->GetStatus (result.GetOutputStream());
252 result.SetStatus (eReturnStatusSuccessFinishResult);
253 }
254 else
255 {
256 result.AppendError(error.AsCString());
257 result.SetStatus (eReturnStatusFailed);
258 }
259 }
260 else
261 {
262 result.AppendError ("invalid platform name");
263 result.SetStatus (eReturnStatusFailed);
264 }
Greg Claytonded470d2011-03-19 01:12:21 +0000265 }
266 else
267 {
Greg Clayton32e0a752011-03-30 18:16:51 +0000268 result.AppendError ("platform create takes a platform name as an argument\n");
Greg Claytonded470d2011-03-19 01:12:21 +0000269 result.SetStatus (eReturnStatusFailed);
270 }
271 return result.Succeeded();
272 }
Greg Clayton7260f622011-04-18 08:33:37 +0000273
Greg Claytonf6b8b582011-04-13 00:18:08 +0000274 OptionGroupOptions m_option_group;
Greg Clayton7260f622011-04-18 08:33:37 +0000275 OptionGroupPlatform m_platform_options;
Greg Claytonded470d2011-03-19 01:12:21 +0000276};
277
278//----------------------------------------------------------------------
279// "platform list"
280//----------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +0000281class CommandObjectPlatformList : public CommandObjectParsed
Greg Claytonded470d2011-03-19 01:12:21 +0000282{
283public:
284 CommandObjectPlatformList (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000285 CommandObjectParsed (interpreter,
286 "platform list",
287 "List all platforms that are available.",
288 NULL,
289 0)
Greg Claytonded470d2011-03-19 01:12:21 +0000290 {
291 }
292
293 virtual
294 ~CommandObjectPlatformList ()
295 {
296 }
297
Jim Ingham5a988412012-06-08 21:56:10 +0000298protected:
Greg Claytonded470d2011-03-19 01:12:21 +0000299 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +0000300 DoExecute (Args& args, CommandReturnObject &result)
Greg Claytonded470d2011-03-19 01:12:21 +0000301 {
302 Stream &ostrm = result.GetOutputStream();
303 ostrm.Printf("Available platforms:\n");
304
305 PlatformSP host_platform_sp (Platform::GetDefaultPlatform());
306 ostrm.Printf ("%s: %s\n",
Greg Clayton57abc5d2013-05-10 21:47:16 +0000307 host_platform_sp->GetPluginName().GetCString(),
Greg Claytonded470d2011-03-19 01:12:21 +0000308 host_platform_sp->GetDescription());
309
310 uint32_t idx;
311 for (idx = 0; 1; ++idx)
312 {
313 const char *plugin_name = PluginManager::GetPlatformPluginNameAtIndex (idx);
314 if (plugin_name == NULL)
315 break;
316 const char *plugin_desc = PluginManager::GetPlatformPluginDescriptionAtIndex (idx);
317 if (plugin_desc == NULL)
318 break;
319 ostrm.Printf("%s: %s\n", plugin_name, plugin_desc);
320 }
321
322 if (idx == 0)
323 {
Greg Clayton1cb64962011-03-24 04:28:38 +0000324 result.AppendError ("no platforms are available\n");
Greg Claytonded470d2011-03-19 01:12:21 +0000325 result.SetStatus (eReturnStatusFailed);
326 }
Johnny Chenc6401792011-03-30 21:19:59 +0000327 else
328 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytonded470d2011-03-19 01:12:21 +0000329 return result.Succeeded();
330 }
331};
332
333//----------------------------------------------------------------------
334// "platform status"
335//----------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +0000336class CommandObjectPlatformStatus : public CommandObjectParsed
Greg Claytonded470d2011-03-19 01:12:21 +0000337{
338public:
339 CommandObjectPlatformStatus (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000340 CommandObjectParsed (interpreter,
341 "platform status",
342 "Display status for the currently selected platform.",
343 NULL,
344 0)
Greg Claytonded470d2011-03-19 01:12:21 +0000345 {
346 }
347
348 virtual
349 ~CommandObjectPlatformStatus ()
350 {
351 }
352
Jim Ingham5a988412012-06-08 21:56:10 +0000353protected:
Greg Claytonded470d2011-03-19 01:12:21 +0000354 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +0000355 DoExecute (Args& args, CommandReturnObject &result)
Greg Claytonded470d2011-03-19 01:12:21 +0000356 {
357 Stream &ostrm = result.GetOutputStream();
358
Jason Molenda8c1157c2013-04-05 02:59:09 +0000359 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
360 PlatformSP platform_sp;
361 if (target)
362 {
363 platform_sp = target->GetPlatform();
364 }
365 if (!platform_sp)
366 {
367 platform_sp = m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform();
368 }
Greg Clayton95bf0fd2011-04-01 00:29:43 +0000369 if (platform_sp)
Greg Claytonded470d2011-03-19 01:12:21 +0000370 {
Greg Clayton95bf0fd2011-04-01 00:29:43 +0000371 platform_sp->GetStatus (ostrm);
Greg Claytonded470d2011-03-19 01:12:21 +0000372 result.SetStatus (eReturnStatusSuccessFinishResult);
373 }
374 else
375 {
Greg Clayton1cb64962011-03-24 04:28:38 +0000376 result.AppendError ("no platform us currently selected\n");
Greg Claytonded470d2011-03-19 01:12:21 +0000377 result.SetStatus (eReturnStatusFailed);
378 }
379 return result.Succeeded();
380 }
381};
382
Greg Claytond314e812011-03-23 00:09:55 +0000383//----------------------------------------------------------------------
384// "platform connect <connect-url>"
385//----------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +0000386class CommandObjectPlatformConnect : public CommandObjectParsed
Greg Claytond314e812011-03-23 00:09:55 +0000387{
388public:
389 CommandObjectPlatformConnect (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000390 CommandObjectParsed (interpreter,
391 "platform connect",
392 "Connect a platform by name to be the currently selected platform.",
393 "platform connect <connect-url>",
394 0)
Greg Claytond314e812011-03-23 00:09:55 +0000395 {
396 }
397
398 virtual
399 ~CommandObjectPlatformConnect ()
400 {
401 }
402
Jim Ingham5a988412012-06-08 21:56:10 +0000403protected:
Greg Claytond314e812011-03-23 00:09:55 +0000404 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +0000405 DoExecute (Args& args, CommandReturnObject &result)
Greg Claytond314e812011-03-23 00:09:55 +0000406 {
407 Stream &ostrm = result.GetOutputStream();
408
Greg Clayton95bf0fd2011-04-01 00:29:43 +0000409 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
410 if (platform_sp)
Greg Claytond314e812011-03-23 00:09:55 +0000411 {
Greg Clayton95bf0fd2011-04-01 00:29:43 +0000412 Error error (platform_sp->ConnectRemote (args));
Greg Claytond314e812011-03-23 00:09:55 +0000413 if (error.Success())
414 {
Greg Clayton95bf0fd2011-04-01 00:29:43 +0000415 platform_sp->GetStatus (ostrm);
Greg Claytond314e812011-03-23 00:09:55 +0000416 result.SetStatus (eReturnStatusSuccessFinishResult);
417 }
418 else
419 {
Greg Clayton1cb64962011-03-24 04:28:38 +0000420 result.AppendErrorWithFormat ("%s\n", error.AsCString());
Greg Claytond314e812011-03-23 00:09:55 +0000421 result.SetStatus (eReturnStatusFailed);
422 }
423 }
424 else
425 {
Daniel Maleae0f8f572013-08-26 23:57:52 +0000426 result.AppendError ("no platform is currently selected\n");
Greg Claytond314e812011-03-23 00:09:55 +0000427 result.SetStatus (eReturnStatusFailed);
428 }
429 return result.Succeeded();
430 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000431
432 virtual Options *
433 GetOptions ()
434 {
435 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
436 OptionGroupOptions* m_platform_options = NULL;
437 if (platform_sp)
438 {
439 m_platform_options = platform_sp->GetConnectionOptions(m_interpreter);
440 if (m_platform_options != NULL && !m_platform_options->m_did_finalize)
441 m_platform_options->Finalize();
442 }
443 return m_platform_options;
444 }
445
Greg Claytond314e812011-03-23 00:09:55 +0000446};
447
448//----------------------------------------------------------------------
449// "platform disconnect"
450//----------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +0000451class CommandObjectPlatformDisconnect : public CommandObjectParsed
Greg Claytond314e812011-03-23 00:09:55 +0000452{
453public:
454 CommandObjectPlatformDisconnect (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000455 CommandObjectParsed (interpreter,
456 "platform disconnect",
457 "Disconnect a platform by name to be the currently selected platform.",
458 "platform disconnect",
459 0)
Greg Claytond314e812011-03-23 00:09:55 +0000460 {
461 }
462
463 virtual
464 ~CommandObjectPlatformDisconnect ()
465 {
466 }
467
Jim Ingham5a988412012-06-08 21:56:10 +0000468protected:
Greg Claytond314e812011-03-23 00:09:55 +0000469 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +0000470 DoExecute (Args& args, CommandReturnObject &result)
Greg Claytond314e812011-03-23 00:09:55 +0000471 {
Greg Clayton95bf0fd2011-04-01 00:29:43 +0000472 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
473 if (platform_sp)
Greg Claytond314e812011-03-23 00:09:55 +0000474 {
475 if (args.GetArgumentCount() == 0)
476 {
477 Error error;
478
Greg Clayton95bf0fd2011-04-01 00:29:43 +0000479 if (platform_sp->IsConnected())
Greg Claytond314e812011-03-23 00:09:55 +0000480 {
481 // Cache the instance name if there is one since we are
482 // about to disconnect and the name might go with it.
Greg Clayton95bf0fd2011-04-01 00:29:43 +0000483 const char *hostname_cstr = platform_sp->GetHostname();
Greg Clayton1cb64962011-03-24 04:28:38 +0000484 std::string hostname;
485 if (hostname_cstr)
486 hostname.assign (hostname_cstr);
Greg Claytond314e812011-03-23 00:09:55 +0000487
Greg Clayton95bf0fd2011-04-01 00:29:43 +0000488 error = platform_sp->DisconnectRemote ();
Greg Claytond314e812011-03-23 00:09:55 +0000489 if (error.Success())
490 {
491 Stream &ostrm = result.GetOutputStream();
Greg Clayton1cb64962011-03-24 04:28:38 +0000492 if (hostname.empty())
Greg Clayton57abc5d2013-05-10 21:47:16 +0000493 ostrm.Printf ("Disconnected from \"%s\"\n", platform_sp->GetPluginName().GetCString());
Greg Claytond314e812011-03-23 00:09:55 +0000494 else
Greg Clayton1cb64962011-03-24 04:28:38 +0000495 ostrm.Printf ("Disconnected from \"%s\"\n", hostname.c_str());
Greg Claytond314e812011-03-23 00:09:55 +0000496 result.SetStatus (eReturnStatusSuccessFinishResult);
497 }
498 else
499 {
Greg Clayton1cb64962011-03-24 04:28:38 +0000500 result.AppendErrorWithFormat ("%s", error.AsCString());
Greg Claytond314e812011-03-23 00:09:55 +0000501 result.SetStatus (eReturnStatusFailed);
502 }
503 }
504 else
505 {
506 // Not connected...
Greg Clayton57abc5d2013-05-10 21:47:16 +0000507 result.AppendErrorWithFormat ("not connected to '%s'", platform_sp->GetPluginName().GetCString());
Greg Claytond314e812011-03-23 00:09:55 +0000508 result.SetStatus (eReturnStatusFailed);
509 }
510 }
511 else
512 {
513 // Bad args
514 result.AppendError ("\"platform disconnect\" doesn't take any arguments");
515 result.SetStatus (eReturnStatusFailed);
516 }
517 }
518 else
519 {
Greg Clayton1cb64962011-03-24 04:28:38 +0000520 result.AppendError ("no platform is currently selected");
Greg Claytond314e812011-03-23 00:09:55 +0000521 result.SetStatus (eReturnStatusFailed);
522 }
523 return result.Succeeded();
524 }
525};
Daniel Maleae0f8f572013-08-26 23:57:52 +0000526
527//----------------------------------------------------------------------
Greg Claytonfbb76342013-11-20 21:07:01 +0000528// "platform settings"
529//----------------------------------------------------------------------
530class CommandObjectPlatformSettings : public CommandObjectParsed
531{
532public:
533 CommandObjectPlatformSettings (CommandInterpreter &interpreter) :
534 CommandObjectParsed (interpreter,
535 "platform settings",
536 "Set settings for the current target's platform, or for a platform by name.",
537 "platform settings",
538 0),
539 m_options (interpreter),
540 m_option_working_dir (LLDB_OPT_SET_1, false, "working-dir", 'w', 0, eArgTypePath, "The working directory for the platform.")
541 {
542 m_options.Append (&m_option_working_dir, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
543 }
544
545 virtual
546 ~CommandObjectPlatformSettings ()
547 {
548 }
549
550protected:
551 virtual bool
552 DoExecute (Args& args, CommandReturnObject &result)
553 {
554 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
555 if (platform_sp)
556 {
557 if (m_option_working_dir.GetOptionValue().OptionWasSet())
558 platform_sp->SetWorkingDirectory (ConstString(m_option_working_dir.GetOptionValue().GetCurrentValue().GetPath().c_str()));
559 }
560 else
561 {
562 result.AppendError ("no platform is currently selected");
563 result.SetStatus (eReturnStatusFailed);
564 }
565 return result.Succeeded();
566 }
567
568 virtual Options *
569 GetOptions ()
570 {
571 if (m_options.DidFinalize() == false)
572 {
573 m_options.Append(new OptionPermissions());
574 m_options.Finalize();
575 }
576 return &m_options;
577 }
578protected:
579
580 OptionGroupOptions m_options;
581 OptionGroupFile m_option_working_dir;
582
583};
584
585
586//----------------------------------------------------------------------
Daniel Maleae0f8f572013-08-26 23:57:52 +0000587// "platform mkdir"
588//----------------------------------------------------------------------
589class CommandObjectPlatformMkDir : public CommandObjectParsed
590{
591public:
592 CommandObjectPlatformMkDir (CommandInterpreter &interpreter) :
593 CommandObjectParsed (interpreter,
Enrico Granatafff25892013-09-09 22:35:18 +0000594 "platform mkdir",
Daniel Maleae0f8f572013-08-26 23:57:52 +0000595 "Make a new directory on the remote end.",
596 NULL,
597 0),
598 m_options(interpreter)
599 {
600 }
601
602 virtual
603 ~CommandObjectPlatformMkDir ()
604 {
605 }
606
607 virtual bool
608 DoExecute (Args& args, CommandReturnObject &result)
609 {
610 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
611 if (platform_sp)
612 {
613 std::string cmd_line;
614 args.GetCommandString(cmd_line);
Greg Claytonfbb76342013-11-20 21:07:01 +0000615 uint32_t mode;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000616 const OptionPermissions* options_permissions = (OptionPermissions*)m_options.GetGroupWithOption('r');
617 if (options_permissions)
Greg Claytonfbb76342013-11-20 21:07:01 +0000618 mode = options_permissions->m_permissions;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000619 else
Greg Claytonfbb76342013-11-20 21:07:01 +0000620 mode = lldb::eFilePermissionsUserRWX | lldb::eFilePermissionsGroupRWX | lldb::eFilePermissionsWorldRX;
621 Error error = platform_sp->MakeDirectory(cmd_line.c_str(), mode);
622 if (error.Success())
623 {
624 result.SetStatus (eReturnStatusSuccessFinishResult);
625 }
626 else
627 {
628 result.AppendError(error.AsCString());
629 result.SetStatus (eReturnStatusFailed);
630 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000631 }
632 else
633 {
634 result.AppendError ("no platform currently selected\n");
635 result.SetStatus (eReturnStatusFailed);
636 }
637 return result.Succeeded();
638 }
639
640 virtual Options *
641 GetOptions ()
642 {
643 if (m_options.DidFinalize() == false)
644 {
645 m_options.Append(new OptionPermissions());
646 m_options.Finalize();
647 }
648 return &m_options;
649 }
650 OptionGroupOptions m_options;
651
652};
653
654//----------------------------------------------------------------------
655// "platform fopen"
656//----------------------------------------------------------------------
657class CommandObjectPlatformFOpen : public CommandObjectParsed
658{
659public:
660 CommandObjectPlatformFOpen (CommandInterpreter &interpreter) :
661 CommandObjectParsed (interpreter,
662 "platform file open",
663 "Open a file on the remote end.",
664 NULL,
665 0),
666 m_options(interpreter)
667 {
668 }
669
670 virtual
671 ~CommandObjectPlatformFOpen ()
672 {
673 }
674
675 virtual bool
676 DoExecute (Args& args, CommandReturnObject &result)
677 {
678 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
679 if (platform_sp)
680 {
681 Error error;
682 std::string cmd_line;
683 args.GetCommandString(cmd_line);
684 mode_t perms;
685 const OptionPermissions* options_permissions = (OptionPermissions*)m_options.GetGroupWithOption('r');
686 if (options_permissions)
687 perms = options_permissions->m_permissions;
688 else
Greg Claytonfbb76342013-11-20 21:07:01 +0000689 perms = lldb::eFilePermissionsUserRW | lldb::eFilePermissionsGroupRW | lldb::eFilePermissionsWorldRead;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000690 lldb::user_id_t fd = platform_sp->OpenFile(FileSpec(cmd_line.c_str(),false),
691 File::eOpenOptionRead | File::eOpenOptionWrite |
692 File::eOpenOptionAppend | File::eOpenOptionCanCreate,
693 perms,
694 error);
695 if (error.Success())
696 {
697 result.AppendMessageWithFormat("File Descriptor = %" PRIu64 "\n",fd);
698 result.SetStatus (eReturnStatusSuccessFinishResult);
699 }
700 else
701 {
702 result.AppendError(error.AsCString());
703 result.SetStatus (eReturnStatusFailed);
704 }
705 }
706 else
707 {
708 result.AppendError ("no platform currently selected\n");
709 result.SetStatus (eReturnStatusFailed);
710 }
711 return result.Succeeded();
712 }
713 virtual Options *
714 GetOptions ()
715 {
716 if (m_options.DidFinalize() == false)
717 {
718 m_options.Append(new OptionPermissions());
719 m_options.Finalize();
720 }
721 return &m_options;
722 }
723 OptionGroupOptions m_options;
724};
725
726//----------------------------------------------------------------------
727// "platform fclose"
728//----------------------------------------------------------------------
729class CommandObjectPlatformFClose : public CommandObjectParsed
730{
731public:
732 CommandObjectPlatformFClose (CommandInterpreter &interpreter) :
733 CommandObjectParsed (interpreter,
734 "platform file close",
735 "Close a file on the remote end.",
736 NULL,
737 0)
738 {
739 }
740
741 virtual
742 ~CommandObjectPlatformFClose ()
743 {
744 }
745
746 virtual bool
747 DoExecute (Args& args, CommandReturnObject &result)
748 {
749 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
750 if (platform_sp)
751 {
752 std::string cmd_line;
753 args.GetCommandString(cmd_line);
754 const lldb::user_id_t fd = Args::StringToUInt64(cmd_line.c_str(), UINT64_MAX);
755 Error error;
756 bool success = platform_sp->CloseFile(fd, error);
757 if (success)
758 {
759 result.AppendMessageWithFormat("file %" PRIu64 " closed.\n", fd);
760 result.SetStatus (eReturnStatusSuccessFinishResult);
761 }
762 else
763 {
764 result.AppendError(error.AsCString());
765 result.SetStatus (eReturnStatusFailed);
766 }
767 }
768 else
769 {
770 result.AppendError ("no platform currently selected\n");
771 result.SetStatus (eReturnStatusFailed);
772 }
773 return result.Succeeded();
774 }
775};
776
777//----------------------------------------------------------------------
778// "platform fread"
779//----------------------------------------------------------------------
780class CommandObjectPlatformFRead : public CommandObjectParsed
781{
782public:
783 CommandObjectPlatformFRead (CommandInterpreter &interpreter) :
784 CommandObjectParsed (interpreter,
785 "platform file read",
786 "Read data from a file on the remote end.",
787 NULL,
788 0),
789 m_options (interpreter)
790 {
791 }
792
793 virtual
794 ~CommandObjectPlatformFRead ()
795 {
796 }
797
798 virtual bool
799 DoExecute (Args& args, CommandReturnObject &result)
800 {
801 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
802 if (platform_sp)
803 {
804 std::string cmd_line;
805 args.GetCommandString(cmd_line);
806 const lldb::user_id_t fd = Args::StringToUInt64(cmd_line.c_str(), UINT64_MAX);
807 std::string buffer(m_options.m_count,0);
808 Error error;
809 uint32_t retcode = platform_sp->ReadFile(fd, m_options.m_offset, &buffer[0], m_options.m_count, error);
810 result.AppendMessageWithFormat("Return = %d\n",retcode);
811 result.AppendMessageWithFormat("Data = \"%s\"\n",buffer.c_str());
812 result.SetStatus (eReturnStatusSuccessFinishResult);
813 }
814 else
815 {
816 result.AppendError ("no platform currently selected\n");
817 result.SetStatus (eReturnStatusFailed);
818 }
819 return result.Succeeded();
820 }
821 virtual Options *
822 GetOptions ()
823 {
824 return &m_options;
825 }
826
827protected:
828 class CommandOptions : public Options
829 {
830 public:
831
832 CommandOptions (CommandInterpreter &interpreter) :
833 Options (interpreter)
834 {
835 }
836
837 virtual
838 ~CommandOptions ()
839 {
840 }
841
842 virtual Error
843 SetOptionValue (uint32_t option_idx, const char *option_arg)
844 {
845 Error error;
846 char short_option = (char) m_getopt_table[option_idx].val;
847 bool success = false;
848
849 switch (short_option)
850 {
851 case 'o':
852 m_offset = Args::StringToUInt32(option_arg, 0, 0, &success);
853 if (!success)
854 error.SetErrorStringWithFormat("invalid offset: '%s'", option_arg);
855 break;
856 case 'c':
857 m_count = Args::StringToUInt32(option_arg, 0, 0, &success);
858 if (!success)
859 error.SetErrorStringWithFormat("invalid offset: '%s'", option_arg);
860 break;
861
862 default:
863 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
864 break;
865 }
866
867 return error;
868 }
869
870 void
871 OptionParsingStarting ()
872 {
873 m_offset = 0;
874 m_count = 1;
875 }
876
877 const OptionDefinition*
878 GetDefinitions ()
879 {
880 return g_option_table;
881 }
882
883 // Options table: Required for subclasses of Options.
884
885 static OptionDefinition g_option_table[];
886
887 // Instance variables to hold the values for command options.
888
889 uint32_t m_offset;
890 uint32_t m_count;
891 };
892 CommandOptions m_options;
893};
894OptionDefinition
895CommandObjectPlatformFRead::CommandOptions::g_option_table[] =
896{
Zachary Turnerd37221d2014-07-09 16:31:49 +0000897 { LLDB_OPT_SET_1, false, "offset" , 'o', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeIndex , "Offset into the file at which to start reading." },
898 { LLDB_OPT_SET_1, false, "count" , 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCount , "Number of bytes to read from the file." },
899 { 0 , false, NULL , 0 , 0 , NULL, NULL, 0, eArgTypeNone , NULL }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000900};
901
902
903//----------------------------------------------------------------------
904// "platform fwrite"
905//----------------------------------------------------------------------
906class CommandObjectPlatformFWrite : public CommandObjectParsed
907{
908public:
909 CommandObjectPlatformFWrite (CommandInterpreter &interpreter) :
910 CommandObjectParsed (interpreter,
911 "platform file write",
912 "Write data to a file on the remote end.",
913 NULL,
914 0),
915 m_options (interpreter)
916 {
917 }
918
919 virtual
920 ~CommandObjectPlatformFWrite ()
921 {
922 }
923
924 virtual bool
925 DoExecute (Args& args, CommandReturnObject &result)
926 {
927 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
928 if (platform_sp)
929 {
930 std::string cmd_line;
931 args.GetCommandString(cmd_line);
932 Error error;
933 const lldb::user_id_t fd = Args::StringToUInt64(cmd_line.c_str(), UINT64_MAX);
934 uint32_t retcode = platform_sp->WriteFile (fd,
935 m_options.m_offset,
936 &m_options.m_data[0],
937 m_options.m_data.size(),
938 error);
939 result.AppendMessageWithFormat("Return = %d\n",retcode);
940 result.SetStatus (eReturnStatusSuccessFinishResult);
941 }
942 else
943 {
944 result.AppendError ("no platform currently selected\n");
945 result.SetStatus (eReturnStatusFailed);
946 }
947 return result.Succeeded();
948 }
949 virtual Options *
950 GetOptions ()
951 {
952 return &m_options;
953 }
954
955protected:
956 class CommandOptions : public Options
957 {
958 public:
959
960 CommandOptions (CommandInterpreter &interpreter) :
961 Options (interpreter)
962 {
963 }
964
965 virtual
966 ~CommandOptions ()
967 {
968 }
969
970 virtual Error
971 SetOptionValue (uint32_t option_idx, const char *option_arg)
972 {
973 Error error;
974 char short_option = (char) m_getopt_table[option_idx].val;
975 bool success = false;
976
977 switch (short_option)
978 {
979 case 'o':
980 m_offset = Args::StringToUInt32(option_arg, 0, 0, &success);
981 if (!success)
982 error.SetErrorStringWithFormat("invalid offset: '%s'", option_arg);
983 break;
984 case 'd':
985 m_data.assign(option_arg);
986 break;
987
988 default:
989 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
990 break;
991 }
992
993 return error;
994 }
995
996 void
997 OptionParsingStarting ()
998 {
999 m_offset = 0;
1000 m_data.clear();
1001 }
1002
1003 const OptionDefinition*
1004 GetDefinitions ()
1005 {
1006 return g_option_table;
1007 }
1008
1009 // Options table: Required for subclasses of Options.
1010
1011 static OptionDefinition g_option_table[];
1012
1013 // Instance variables to hold the values for command options.
1014
1015 uint32_t m_offset;
1016 std::string m_data;
1017 };
1018 CommandOptions m_options;
1019};
1020OptionDefinition
1021CommandObjectPlatformFWrite::CommandOptions::g_option_table[] =
1022{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001023 { LLDB_OPT_SET_1, false, "offset" , 'o', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeIndex , "Offset into the file at which to start reading." },
1024 { LLDB_OPT_SET_1, false, "data" , 'd', OptionParser::eRequiredArgument , NULL, NULL, 0, eArgTypeValue , "Text to write to the file." },
1025 { 0 , false, NULL , 0 , 0 , NULL, NULL, 0, eArgTypeNone , NULL }
Daniel Maleae0f8f572013-08-26 23:57:52 +00001026};
1027
1028class CommandObjectPlatformFile : public CommandObjectMultiword
1029{
1030public:
1031 //------------------------------------------------------------------
1032 // Constructors and Destructors
1033 //------------------------------------------------------------------
1034 CommandObjectPlatformFile (CommandInterpreter &interpreter) :
1035 CommandObjectMultiword (interpreter,
1036 "platform file",
1037 "A set of commands to manage file access through a platform",
1038 "platform file [open|close|read|write] ...")
1039 {
1040 LoadSubCommand ("open", CommandObjectSP (new CommandObjectPlatformFOpen (interpreter)));
1041 LoadSubCommand ("close", CommandObjectSP (new CommandObjectPlatformFClose (interpreter)));
1042 LoadSubCommand ("read", CommandObjectSP (new CommandObjectPlatformFRead (interpreter)));
1043 LoadSubCommand ("write", CommandObjectSP (new CommandObjectPlatformFWrite (interpreter)));
1044 }
1045
1046 virtual
1047 ~CommandObjectPlatformFile ()
1048 {
1049 }
1050
1051private:
1052 //------------------------------------------------------------------
1053 // For CommandObjectPlatform only
1054 //------------------------------------------------------------------
1055 DISALLOW_COPY_AND_ASSIGN (CommandObjectPlatformFile);
1056};
1057
1058//----------------------------------------------------------------------
1059// "platform get-file remote-file-path host-file-path"
1060//----------------------------------------------------------------------
1061class CommandObjectPlatformGetFile : public CommandObjectParsed
1062{
1063public:
1064 CommandObjectPlatformGetFile (CommandInterpreter &interpreter) :
1065 CommandObjectParsed (interpreter,
1066 "platform get-file",
1067 "Transfer a file from the remote end to the local host.",
1068 "platform get-file <remote-file-spec> <local-file-spec>",
1069 0)
1070 {
1071 SetHelpLong(
1072"Examples: \n\
1073\n\
1074 platform get-file /the/remote/file/path /the/local/file/path\n\
1075 # Transfer a file from the remote end with file path /the/remote/file/path to the local host.\n");
1076
1077 CommandArgumentEntry arg1, arg2;
1078 CommandArgumentData file_arg_remote, file_arg_host;
1079
1080 // Define the first (and only) variant of this arg.
1081 file_arg_remote.arg_type = eArgTypeFilename;
1082 file_arg_remote.arg_repetition = eArgRepeatPlain;
1083 // There is only one variant this argument could be; put it into the argument entry.
1084 arg1.push_back (file_arg_remote);
1085
1086 // Define the second (and only) variant of this arg.
1087 file_arg_host.arg_type = eArgTypeFilename;
1088 file_arg_host.arg_repetition = eArgRepeatPlain;
1089 // There is only one variant this argument could be; put it into the argument entry.
1090 arg2.push_back (file_arg_host);
1091
1092 // Push the data for the first and the second arguments into the m_arguments vector.
1093 m_arguments.push_back (arg1);
1094 m_arguments.push_back (arg2);
1095 }
1096
1097 virtual
1098 ~CommandObjectPlatformGetFile ()
1099 {
1100 }
1101
1102 virtual bool
1103 DoExecute (Args& args, CommandReturnObject &result)
1104 {
1105 // If the number of arguments is incorrect, issue an error message.
1106 if (args.GetArgumentCount() != 2)
1107 {
1108 result.GetErrorStream().Printf("error: required arguments missing; specify both the source and destination file paths\n");
1109 result.SetStatus(eReturnStatusFailed);
1110 return false;
1111 }
1112
1113 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
1114 if (platform_sp)
1115 {
1116 const char *remote_file_path = args.GetArgumentAtIndex(0);
1117 const char *local_file_path = args.GetArgumentAtIndex(1);
1118 Error error = platform_sp->GetFile(FileSpec(remote_file_path, false),
1119 FileSpec(local_file_path, false));
1120 if (error.Success())
1121 {
1122 result.AppendMessageWithFormat("successfully get-file from %s (remote) to %s (host)\n",
1123 remote_file_path, local_file_path);
1124 result.SetStatus (eReturnStatusSuccessFinishResult);
1125 }
1126 else
1127 {
1128 result.AppendMessageWithFormat("get-file failed: %s\n", error.AsCString());
1129 result.SetStatus (eReturnStatusFailed);
1130 }
1131 }
1132 else
1133 {
1134 result.AppendError ("no platform currently selected\n");
1135 result.SetStatus (eReturnStatusFailed);
1136 }
1137 return result.Succeeded();
1138 }
1139};
1140
1141//----------------------------------------------------------------------
1142// "platform get-size remote-file-path"
1143//----------------------------------------------------------------------
1144class CommandObjectPlatformGetSize : public CommandObjectParsed
1145{
1146public:
1147 CommandObjectPlatformGetSize (CommandInterpreter &interpreter) :
1148 CommandObjectParsed (interpreter,
1149 "platform get-size",
1150 "Get the file size from the remote end.",
1151 "platform get-size <remote-file-spec>",
1152 0)
1153 {
1154 SetHelpLong(
1155"Examples: \n\
1156\n\
1157 platform get-size /the/remote/file/path\n\
1158 # Get the file size from the remote end with path /the/remote/file/path.\n");
1159
1160 CommandArgumentEntry arg1;
1161 CommandArgumentData file_arg_remote;
1162
1163 // Define the first (and only) variant of this arg.
1164 file_arg_remote.arg_type = eArgTypeFilename;
1165 file_arg_remote.arg_repetition = eArgRepeatPlain;
1166 // There is only one variant this argument could be; put it into the argument entry.
1167 arg1.push_back (file_arg_remote);
1168
1169 // Push the data for the first argument into the m_arguments vector.
1170 m_arguments.push_back (arg1);
1171 }
1172
1173 virtual
1174 ~CommandObjectPlatformGetSize ()
1175 {
1176 }
1177
1178 virtual bool
1179 DoExecute (Args& args, CommandReturnObject &result)
1180 {
1181 // If the number of arguments is incorrect, issue an error message.
1182 if (args.GetArgumentCount() != 1)
1183 {
1184 result.GetErrorStream().Printf("error: required argument missing; specify the source file path as the only argument\n");
1185 result.SetStatus(eReturnStatusFailed);
1186 return false;
1187 }
1188
1189 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
1190 if (platform_sp)
1191 {
1192 std::string remote_file_path(args.GetArgumentAtIndex(0));
1193 user_id_t size = platform_sp->GetFileSize(FileSpec(remote_file_path.c_str(), false));
1194 if (size != UINT64_MAX)
1195 {
1196 result.AppendMessageWithFormat("File size of %s (remote): %" PRIu64 "\n", remote_file_path.c_str(), size);
1197 result.SetStatus (eReturnStatusSuccessFinishResult);
1198 }
1199 else
1200 {
1201 result.AppendMessageWithFormat("Eroor getting file size of %s (remote)\n", remote_file_path.c_str());
1202 result.SetStatus (eReturnStatusFailed);
1203 }
1204 }
1205 else
1206 {
1207 result.AppendError ("no platform currently selected\n");
1208 result.SetStatus (eReturnStatusFailed);
1209 }
1210 return result.Succeeded();
1211 }
1212};
1213
1214//----------------------------------------------------------------------
1215// "platform put-file"
1216//----------------------------------------------------------------------
1217class CommandObjectPlatformPutFile : public CommandObjectParsed
1218{
1219public:
1220 CommandObjectPlatformPutFile (CommandInterpreter &interpreter) :
1221 CommandObjectParsed (interpreter,
1222 "platform put-file",
1223 "Transfer a file from this system to the remote end.",
1224 NULL,
1225 0)
1226 {
1227 }
1228
1229 virtual
1230 ~CommandObjectPlatformPutFile ()
1231 {
1232 }
1233
1234 virtual bool
1235 DoExecute (Args& args, CommandReturnObject &result)
1236 {
1237 const char* src = args.GetArgumentAtIndex(0);
1238 const char* dst = args.GetArgumentAtIndex(1);
1239
1240 FileSpec src_fs(src, true);
1241 FileSpec dst_fs(dst, false);
1242
1243 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
1244 if (platform_sp)
1245 {
1246 Error error (platform_sp->PutFile(src_fs, dst_fs));
1247 if (error.Success())
1248 {
1249 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1250 }
1251 else
1252 {
1253 result.AppendError (error.AsCString());
1254 result.SetStatus (eReturnStatusFailed);
1255 }
1256 }
1257 else
1258 {
1259 result.AppendError ("no platform currently selected\n");
1260 result.SetStatus (eReturnStatusFailed);
1261 }
1262 return result.Succeeded();
1263 }
1264};
1265
Greg Clayton8b82f082011-04-12 05:54:46 +00001266//----------------------------------------------------------------------
1267// "platform process launch"
1268//----------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +00001269class CommandObjectPlatformProcessLaunch : public CommandObjectParsed
Greg Clayton8b82f082011-04-12 05:54:46 +00001270{
1271public:
1272 CommandObjectPlatformProcessLaunch (CommandInterpreter &interpreter) :
Greg Claytonf9fc6092013-01-09 19:44:40 +00001273 CommandObjectParsed (interpreter,
Jim Ingham5a988412012-06-08 21:56:10 +00001274 "platform process launch",
1275 "Launch a new process on a remote platform.",
1276 "platform process launch program",
Greg Claytonf9fc6092013-01-09 19:44:40 +00001277 eFlagRequiresTarget | eFlagTryTargetAPILock),
Greg Clayton8b82f082011-04-12 05:54:46 +00001278 m_options (interpreter)
1279 {
1280 }
1281
1282 virtual
1283 ~CommandObjectPlatformProcessLaunch ()
1284 {
1285 }
1286
Jim Ingham5a988412012-06-08 21:56:10 +00001287 virtual Options *
1288 GetOptions ()
1289 {
1290 return &m_options;
1291 }
1292
1293protected:
Greg Clayton8b82f082011-04-12 05:54:46 +00001294 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00001295 DoExecute (Args& args, CommandReturnObject &result)
Greg Clayton8b82f082011-04-12 05:54:46 +00001296 {
Jason Molenda8c1157c2013-04-05 02:59:09 +00001297 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1298 PlatformSP platform_sp;
1299 if (target)
1300 {
1301 platform_sp = target->GetPlatform();
1302 }
1303 if (!platform_sp)
1304 {
1305 platform_sp = m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform();
1306 }
1307
Greg Clayton8b82f082011-04-12 05:54:46 +00001308 if (platform_sp)
1309 {
1310 Error error;
Greg Claytonc7bece562013-01-25 18:06:21 +00001311 const size_t argc = args.GetArgumentCount();
Greg Claytonf9fc6092013-01-09 19:44:40 +00001312 Target *target = m_exe_ctx.GetTargetPtr();
Greg Clayton1d885962011-11-08 02:43:13 +00001313 Module *exe_module = target->GetExecutableModulePointer();
1314 if (exe_module)
1315 {
1316 m_options.launch_info.GetExecutableFile () = exe_module->GetFileSpec();
1317 char exe_path[PATH_MAX];
1318 if (m_options.launch_info.GetExecutableFile ().GetPath (exe_path, sizeof(exe_path)))
1319 m_options.launch_info.GetArguments().AppendArgument (exe_path);
1320 m_options.launch_info.GetArchitecture() = exe_module->GetArchitecture();
Greg Clayton8b82f082011-04-12 05:54:46 +00001321 }
1322
1323 if (argc > 0)
1324 {
1325 if (m_options.launch_info.GetExecutableFile ())
1326 {
1327 // We already have an executable file, so we will use this
1328 // and all arguments to this function are extra arguments
1329 m_options.launch_info.GetArguments().AppendArguments (args);
1330 }
1331 else
1332 {
1333 // We don't have any file yet, so the first argument is our
1334 // executable, and the rest are program arguments
1335 const bool first_arg_is_executable = true;
Greg Clayton45392552012-10-17 22:57:12 +00001336 m_options.launch_info.SetArguments (args, first_arg_is_executable);
Greg Clayton8b82f082011-04-12 05:54:46 +00001337 }
1338 }
1339
1340 if (m_options.launch_info.GetExecutableFile ())
1341 {
1342 Debugger &debugger = m_interpreter.GetDebugger();
1343
1344 if (argc == 0)
Greg Clayton67cc0632012-08-22 17:17:09 +00001345 target->GetRunArguments(m_options.launch_info.GetArguments());
Greg Clayton8b82f082011-04-12 05:54:46 +00001346
1347 ProcessSP process_sp (platform_sp->DebugProcess (m_options.launch_info,
1348 debugger,
1349 target,
1350 debugger.GetListener(),
1351 error));
1352 if (process_sp && process_sp->IsAlive())
1353 {
1354 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1355 return true;
1356 }
1357
1358 if (error.Success())
1359 result.AppendError ("process launch failed");
1360 else
1361 result.AppendError (error.AsCString());
1362 result.SetStatus (eReturnStatusFailed);
1363 }
1364 else
1365 {
1366 result.AppendError ("'platform process launch' uses the current target file and arguments, or the executable and its arguments can be specified in this command");
1367 result.SetStatus (eReturnStatusFailed);
1368 return false;
1369 }
1370 }
1371 else
1372 {
1373 result.AppendError ("no platform is selected\n");
1374 }
1375 return result.Succeeded();
1376 }
1377
Greg Clayton8b82f082011-04-12 05:54:46 +00001378protected:
1379 ProcessLaunchCommandOptions m_options;
1380};
1381
Greg Claytond314e812011-03-23 00:09:55 +00001382
1383
Greg Clayton32e0a752011-03-30 18:16:51 +00001384//----------------------------------------------------------------------
1385// "platform process list"
1386//----------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +00001387class CommandObjectPlatformProcessList : public CommandObjectParsed
Greg Clayton32e0a752011-03-30 18:16:51 +00001388{
1389public:
1390 CommandObjectPlatformProcessList (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001391 CommandObjectParsed (interpreter,
1392 "platform process list",
1393 "List processes on a remote platform by name, pid, or many other matching attributes.",
1394 "platform process list",
1395 0),
Greg Claytoneb0103f2011-04-07 22:46:35 +00001396 m_options (interpreter)
Greg Clayton32e0a752011-03-30 18:16:51 +00001397 {
1398 }
1399
1400 virtual
1401 ~CommandObjectPlatformProcessList ()
1402 {
1403 }
1404
Jim Ingham5a988412012-06-08 21:56:10 +00001405 virtual Options *
1406 GetOptions ()
1407 {
1408 return &m_options;
1409 }
1410
1411protected:
Greg Clayton32e0a752011-03-30 18:16:51 +00001412 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00001413 DoExecute (Args& args, CommandReturnObject &result)
Greg Clayton32e0a752011-03-30 18:16:51 +00001414 {
Jason Molenda8c1157c2013-04-05 02:59:09 +00001415 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1416 PlatformSP platform_sp;
1417 if (target)
1418 {
1419 platform_sp = target->GetPlatform();
1420 }
1421 if (!platform_sp)
1422 {
1423 platform_sp = m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform();
1424 }
Greg Clayton32e0a752011-03-30 18:16:51 +00001425
1426 if (platform_sp)
1427 {
1428 Error error;
1429 if (args.GetArgumentCount() == 0)
1430 {
1431
1432 if (platform_sp)
1433 {
Greg Clayton95bf0fd2011-04-01 00:29:43 +00001434 Stream &ostrm = result.GetOutputStream();
1435
Greg Clayton32e0a752011-03-30 18:16:51 +00001436 lldb::pid_t pid = m_options.match_info.GetProcessInfo().GetProcessID();
1437 if (pid != LLDB_INVALID_PROCESS_ID)
1438 {
Greg Clayton8b82f082011-04-12 05:54:46 +00001439 ProcessInstanceInfo proc_info;
Greg Clayton32e0a752011-03-30 18:16:51 +00001440 if (platform_sp->GetProcessInfo (pid, proc_info))
1441 {
Greg Clayton8b82f082011-04-12 05:54:46 +00001442 ProcessInstanceInfo::DumpTableHeader (ostrm, platform_sp.get(), m_options.show_args, m_options.verbose);
1443 proc_info.DumpAsTableRow(ostrm, platform_sp.get(), m_options.show_args, m_options.verbose);
Greg Clayton32e0a752011-03-30 18:16:51 +00001444 result.SetStatus (eReturnStatusSuccessFinishResult);
1445 }
1446 else
1447 {
Daniel Malead01b2952012-11-29 21:49:15 +00001448 result.AppendErrorWithFormat ("no process found with pid = %" PRIu64 "\n", pid);
Greg Clayton32e0a752011-03-30 18:16:51 +00001449 result.SetStatus (eReturnStatusFailed);
1450 }
1451 }
1452 else
1453 {
Greg Clayton8b82f082011-04-12 05:54:46 +00001454 ProcessInstanceInfoList proc_infos;
Greg Clayton32e0a752011-03-30 18:16:51 +00001455 const uint32_t matches = platform_sp->FindProcesses (m_options.match_info, proc_infos);
Greg Clayton8b82f082011-04-12 05:54:46 +00001456 const char *match_desc = NULL;
1457 const char *match_name = m_options.match_info.GetProcessInfo().GetName();
1458 if (match_name && match_name[0])
1459 {
1460 switch (m_options.match_info.GetNameMatchType())
1461 {
1462 case eNameMatchIgnore: break;
1463 case eNameMatchEquals: match_desc = "matched"; break;
1464 case eNameMatchContains: match_desc = "contained"; break;
1465 case eNameMatchStartsWith: match_desc = "started with"; break;
1466 case eNameMatchEndsWith: match_desc = "ended with"; break;
1467 case eNameMatchRegularExpression: match_desc = "matched the regular expression"; break;
1468 }
1469 }
1470
Greg Clayton32e0a752011-03-30 18:16:51 +00001471 if (matches == 0)
1472 {
Greg Clayton32e0a752011-03-30 18:16:51 +00001473 if (match_desc)
1474 result.AppendErrorWithFormat ("no processes were found that %s \"%s\" on the \"%s\" platform\n",
1475 match_desc,
1476 match_name,
Greg Clayton57abc5d2013-05-10 21:47:16 +00001477 platform_sp->GetPluginName().GetCString());
Greg Clayton32e0a752011-03-30 18:16:51 +00001478 else
Greg Clayton57abc5d2013-05-10 21:47:16 +00001479 result.AppendErrorWithFormat ("no processes were found on the \"%s\" platform\n", platform_sp->GetPluginName().GetCString());
Greg Clayton32e0a752011-03-30 18:16:51 +00001480 result.SetStatus (eReturnStatusFailed);
1481 }
1482 else
1483 {
Greg Clayton8b82f082011-04-12 05:54:46 +00001484 result.AppendMessageWithFormat ("%u matching process%s found on \"%s\"",
1485 matches,
1486 matches > 1 ? "es were" : " was",
Greg Clayton57abc5d2013-05-10 21:47:16 +00001487 platform_sp->GetName().GetCString());
Greg Clayton8b82f082011-04-12 05:54:46 +00001488 if (match_desc)
1489 result.AppendMessageWithFormat (" whose name %s \"%s\"",
1490 match_desc,
1491 match_name);
1492 result.AppendMessageWithFormat ("\n");
1493 ProcessInstanceInfo::DumpTableHeader (ostrm, platform_sp.get(), m_options.show_args, m_options.verbose);
Greg Clayton32e0a752011-03-30 18:16:51 +00001494 for (uint32_t i=0; i<matches; ++i)
1495 {
Greg Clayton8b82f082011-04-12 05:54:46 +00001496 proc_infos.GetProcessInfoAtIndex(i).DumpAsTableRow(ostrm, platform_sp.get(), m_options.show_args, m_options.verbose);
Greg Clayton32e0a752011-03-30 18:16:51 +00001497 }
1498 }
1499 }
1500 }
1501 }
1502 else
1503 {
1504 result.AppendError ("invalid args: process list takes only options\n");
1505 result.SetStatus (eReturnStatusFailed);
1506 }
1507 }
1508 else
1509 {
1510 result.AppendError ("no platform is selected\n");
1511 result.SetStatus (eReturnStatusFailed);
1512 }
1513 return result.Succeeded();
1514 }
1515
Greg Clayton32e0a752011-03-30 18:16:51 +00001516 class CommandOptions : public Options
1517 {
1518 public:
1519
Greg Claytoneb0103f2011-04-07 22:46:35 +00001520 CommandOptions (CommandInterpreter &interpreter) :
1521 Options (interpreter),
Greg Clayton32e0a752011-03-30 18:16:51 +00001522 match_info ()
1523 {
1524 }
1525
1526 virtual
1527 ~CommandOptions ()
1528 {
1529 }
1530
1531 virtual Error
Greg Claytonf6b8b582011-04-13 00:18:08 +00001532 SetOptionValue (uint32_t option_idx, const char *option_arg)
Greg Clayton32e0a752011-03-30 18:16:51 +00001533 {
1534 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00001535 const int short_option = m_getopt_table[option_idx].val;
Greg Clayton32e0a752011-03-30 18:16:51 +00001536 bool success = false;
1537
1538 switch (short_option)
1539 {
1540 case 'p':
1541 match_info.GetProcessInfo().SetProcessID (Args::StringToUInt32 (option_arg, LLDB_INVALID_PROCESS_ID, 0, &success));
1542 if (!success)
1543 error.SetErrorStringWithFormat("invalid process ID string: '%s'", option_arg);
1544 break;
1545
1546 case 'P':
1547 match_info.GetProcessInfo().SetParentProcessID (Args::StringToUInt32 (option_arg, LLDB_INVALID_PROCESS_ID, 0, &success));
1548 if (!success)
1549 error.SetErrorStringWithFormat("invalid parent process ID string: '%s'", option_arg);
1550 break;
1551
1552 case 'u':
Greg Clayton8b82f082011-04-12 05:54:46 +00001553 match_info.GetProcessInfo().SetUserID (Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success));
Greg Clayton32e0a752011-03-30 18:16:51 +00001554 if (!success)
1555 error.SetErrorStringWithFormat("invalid user ID string: '%s'", option_arg);
1556 break;
1557
1558 case 'U':
1559 match_info.GetProcessInfo().SetEffectiveUserID (Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success));
1560 if (!success)
1561 error.SetErrorStringWithFormat("invalid effective user ID string: '%s'", option_arg);
1562 break;
1563
1564 case 'g':
Greg Clayton8b82f082011-04-12 05:54:46 +00001565 match_info.GetProcessInfo().SetGroupID (Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success));
Greg Clayton32e0a752011-03-30 18:16:51 +00001566 if (!success)
1567 error.SetErrorStringWithFormat("invalid group ID string: '%s'", option_arg);
1568 break;
1569
1570 case 'G':
1571 match_info.GetProcessInfo().SetEffectiveGroupID (Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success));
1572 if (!success)
1573 error.SetErrorStringWithFormat("invalid effective group ID string: '%s'", option_arg);
1574 break;
1575
1576 case 'a':
Greg Claytoneb0103f2011-04-07 22:46:35 +00001577 match_info.GetProcessInfo().GetArchitecture().SetTriple (option_arg, m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform().get());
Greg Clayton32e0a752011-03-30 18:16:51 +00001578 break;
1579
1580 case 'n':
Greg Clayton144f3a92011-11-15 03:53:30 +00001581 match_info.GetProcessInfo().GetExecutableFile().SetFile (option_arg, false);
Greg Clayton8b82f082011-04-12 05:54:46 +00001582 match_info.SetNameMatchType (eNameMatchEquals);
Greg Clayton32e0a752011-03-30 18:16:51 +00001583 break;
1584
1585 case 'e':
Greg Clayton144f3a92011-11-15 03:53:30 +00001586 match_info.GetProcessInfo().GetExecutableFile().SetFile (option_arg, false);
Greg Clayton32e0a752011-03-30 18:16:51 +00001587 match_info.SetNameMatchType (eNameMatchEndsWith);
1588 break;
1589
1590 case 's':
Greg Clayton144f3a92011-11-15 03:53:30 +00001591 match_info.GetProcessInfo().GetExecutableFile().SetFile (option_arg, false);
Greg Clayton32e0a752011-03-30 18:16:51 +00001592 match_info.SetNameMatchType (eNameMatchStartsWith);
1593 break;
1594
1595 case 'c':
Greg Clayton144f3a92011-11-15 03:53:30 +00001596 match_info.GetProcessInfo().GetExecutableFile().SetFile (option_arg, false);
Greg Clayton32e0a752011-03-30 18:16:51 +00001597 match_info.SetNameMatchType (eNameMatchContains);
1598 break;
1599
1600 case 'r':
Greg Clayton144f3a92011-11-15 03:53:30 +00001601 match_info.GetProcessInfo().GetExecutableFile().SetFile (option_arg, false);
Greg Clayton32e0a752011-03-30 18:16:51 +00001602 match_info.SetNameMatchType (eNameMatchRegularExpression);
1603 break;
1604
Greg Clayton8b82f082011-04-12 05:54:46 +00001605 case 'A':
1606 show_args = true;
1607 break;
1608
1609 case 'v':
1610 verbose = true;
1611 break;
1612
Greg Clayton32e0a752011-03-30 18:16:51 +00001613 default:
1614 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1615 break;
1616 }
1617
1618 return error;
1619 }
1620
1621 void
Greg Claytonf6b8b582011-04-13 00:18:08 +00001622 OptionParsingStarting ()
Greg Clayton32e0a752011-03-30 18:16:51 +00001623 {
1624 match_info.Clear();
Greg Clayton8b82f082011-04-12 05:54:46 +00001625 show_args = false;
1626 verbose = false;
Greg Clayton32e0a752011-03-30 18:16:51 +00001627 }
1628
1629 const OptionDefinition*
1630 GetDefinitions ()
1631 {
1632 return g_option_table;
1633 }
1634
1635 // Options table: Required for subclasses of Options.
1636
1637 static OptionDefinition g_option_table[];
1638
1639 // Instance variables to hold the values for command options.
1640
Greg Clayton8b82f082011-04-12 05:54:46 +00001641 ProcessInstanceInfoMatch match_info;
1642 bool show_args;
1643 bool verbose;
Greg Clayton32e0a752011-03-30 18:16:51 +00001644 };
1645 CommandOptions m_options;
1646};
1647
Zachary Turnerd37221d2014-07-09 16:31:49 +00001648namespace
1649{
1650 PosixPlatformCommandOptionValidator g_posix_validator;
1651}
1652
Greg Clayton32e0a752011-03-30 18:16:51 +00001653OptionDefinition
1654CommandObjectPlatformProcessList::CommandOptions::g_option_table[] =
1655{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001656{ LLDB_OPT_SET_1 , false, "pid" , 'p', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePid , "List the process info for a specific process ID." },
1657{ LLDB_OPT_SET_2 , true , "name" , 'n', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeProcessName , "Find processes with executable basenames that match a string." },
1658{ LLDB_OPT_SET_3 , true , "ends-with" , 'e', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeProcessName , "Find processes with executable basenames that end with a string." },
1659{ LLDB_OPT_SET_4 , true , "starts-with", 's', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeProcessName , "Find processes with executable basenames that start with a string." },
1660{ LLDB_OPT_SET_5 , true , "contains" , 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeProcessName , "Find processes with executable basenames that contain a string." },
1661{ LLDB_OPT_SET_6 , true , "regex" , 'r', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeRegularExpression, "Find processes with executable basenames that match a regular expression." },
1662{ LLDB_OPT_SET_FROM_TO(2, 6), false, "parent" , 'P', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePid , "Find processes that have a matching parent process ID." },
1663{ LLDB_OPT_SET_FROM_TO(2, 6), false, "uid" , 'u', OptionParser::eRequiredArgument, &g_posix_validator, NULL, 0, eArgTypeUnsignedInteger , "Find processes that have a matching user ID." },
1664{ LLDB_OPT_SET_FROM_TO(2, 6), false, "euid" , 'U', OptionParser::eRequiredArgument, &g_posix_validator, NULL, 0, eArgTypeUnsignedInteger , "Find processes that have a matching effective user ID." },
1665{ LLDB_OPT_SET_FROM_TO(2, 6), false, "gid" , 'g', OptionParser::eRequiredArgument, &g_posix_validator, NULL, 0, eArgTypeUnsignedInteger , "Find processes that have a matching group ID." },
1666{ LLDB_OPT_SET_FROM_TO(2, 6), false, "egid" , 'G', OptionParser::eRequiredArgument, &g_posix_validator, NULL, 0, eArgTypeUnsignedInteger , "Find processes that have a matching effective group ID." },
1667{ LLDB_OPT_SET_FROM_TO(2, 6), false, "arch" , 'a', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeArchitecture , "Find processes that have a matching architecture." },
1668{ LLDB_OPT_SET_FROM_TO(1, 6), false, "show-args" , 'A', OptionParser::eNoArgument , NULL, NULL, 0, eArgTypeNone , "Show process arguments instead of the process executable basename." },
1669{ LLDB_OPT_SET_FROM_TO(1, 6), false, "verbose" , 'v', OptionParser::eNoArgument , NULL, NULL, 0, eArgTypeNone , "Enable verbose output." },
1670{ 0 , false, NULL , 0 , 0 , NULL, NULL, 0, eArgTypeNone , NULL }
Greg Clayton32e0a752011-03-30 18:16:51 +00001671};
1672
Greg Clayton95bf0fd2011-04-01 00:29:43 +00001673//----------------------------------------------------------------------
1674// "platform process info"
1675//----------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +00001676class CommandObjectPlatformProcessInfo : public CommandObjectParsed
Greg Clayton95bf0fd2011-04-01 00:29:43 +00001677{
1678public:
1679 CommandObjectPlatformProcessInfo (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001680 CommandObjectParsed (interpreter,
1681 "platform process info",
1682 "Get detailed information for one or more process by process ID.",
1683 "platform process info <pid> [<pid> <pid> ...]",
1684 0)
Greg Clayton95bf0fd2011-04-01 00:29:43 +00001685 {
1686 CommandArgumentEntry arg;
1687 CommandArgumentData pid_args;
1688
1689 // Define the first (and only) variant of this arg.
1690 pid_args.arg_type = eArgTypePid;
1691 pid_args.arg_repetition = eArgRepeatStar;
1692
1693 // There is only one variant this argument could be; put it into the argument entry.
1694 arg.push_back (pid_args);
1695
1696 // Push the data for the first argument into the m_arguments vector.
1697 m_arguments.push_back (arg);
1698 }
1699
1700 virtual
1701 ~CommandObjectPlatformProcessInfo ()
1702 {
1703 }
1704
Jim Ingham5a988412012-06-08 21:56:10 +00001705protected:
Greg Clayton95bf0fd2011-04-01 00:29:43 +00001706 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00001707 DoExecute (Args& args, CommandReturnObject &result)
Greg Clayton95bf0fd2011-04-01 00:29:43 +00001708 {
Jason Molenda8c1157c2013-04-05 02:59:09 +00001709 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1710 PlatformSP platform_sp;
1711 if (target)
1712 {
1713 platform_sp = target->GetPlatform();
1714 }
1715 if (!platform_sp)
1716 {
1717 platform_sp = m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform();
1718 }
1719
Greg Clayton95bf0fd2011-04-01 00:29:43 +00001720 if (platform_sp)
1721 {
1722 const size_t argc = args.GetArgumentCount();
1723 if (argc > 0)
1724 {
1725 Error error;
1726
1727 if (platform_sp->IsConnected())
1728 {
1729 Stream &ostrm = result.GetOutputStream();
1730 bool success;
1731 for (size_t i=0; i<argc; ++ i)
1732 {
1733 const char *arg = args.GetArgumentAtIndex(i);
1734 lldb::pid_t pid = Args::StringToUInt32 (arg, LLDB_INVALID_PROCESS_ID, 0, &success);
1735 if (success)
1736 {
Greg Clayton8b82f082011-04-12 05:54:46 +00001737 ProcessInstanceInfo proc_info;
Greg Clayton95bf0fd2011-04-01 00:29:43 +00001738 if (platform_sp->GetProcessInfo (pid, proc_info))
1739 {
Daniel Malead01b2952012-11-29 21:49:15 +00001740 ostrm.Printf ("Process information for process %" PRIu64 ":\n", pid);
Greg Clayton95bf0fd2011-04-01 00:29:43 +00001741 proc_info.Dump (ostrm, platform_sp.get());
1742 }
1743 else
1744 {
Daniel Malead01b2952012-11-29 21:49:15 +00001745 ostrm.Printf ("error: no process information is available for process %" PRIu64 "\n", pid);
Greg Clayton95bf0fd2011-04-01 00:29:43 +00001746 }
1747 ostrm.EOL();
1748 }
1749 else
1750 {
1751 result.AppendErrorWithFormat ("invalid process ID argument '%s'", arg);
1752 result.SetStatus (eReturnStatusFailed);
1753 break;
1754 }
1755 }
1756 }
1757 else
1758 {
1759 // Not connected...
Greg Clayton57abc5d2013-05-10 21:47:16 +00001760 result.AppendErrorWithFormat ("not connected to '%s'", platform_sp->GetPluginName().GetCString());
Greg Clayton95bf0fd2011-04-01 00:29:43 +00001761 result.SetStatus (eReturnStatusFailed);
1762 }
1763 }
1764 else
1765 {
Johnny Chen3173e272011-05-09 19:05:46 +00001766 // No args
1767 result.AppendError ("one or more process id(s) must be specified");
Greg Clayton95bf0fd2011-04-01 00:29:43 +00001768 result.SetStatus (eReturnStatusFailed);
1769 }
1770 }
1771 else
1772 {
1773 result.AppendError ("no platform is currently selected");
1774 result.SetStatus (eReturnStatusFailed);
1775 }
1776 return result.Succeeded();
1777 }
1778};
1779
Daniel Maleae0f8f572013-08-26 23:57:52 +00001780class CommandObjectPlatformProcessAttach : public CommandObjectParsed
1781{
1782public:
1783
1784 class CommandOptions : public Options
1785 {
1786 public:
1787
1788 CommandOptions (CommandInterpreter &interpreter) :
1789 Options(interpreter)
1790 {
1791 // Keep default values of all options in one place: OptionParsingStarting ()
1792 OptionParsingStarting ();
1793 }
1794
1795 ~CommandOptions ()
1796 {
1797 }
1798
1799 Error
1800 SetOptionValue (uint32_t option_idx, const char *option_arg)
1801 {
1802 Error error;
1803 char short_option = (char) m_getopt_table[option_idx].val;
1804 bool success = false;
1805 switch (short_option)
1806 {
1807 case 'p':
1808 {
1809 lldb::pid_t pid = Args::StringToUInt32 (option_arg, LLDB_INVALID_PROCESS_ID, 0, &success);
1810 if (!success || pid == LLDB_INVALID_PROCESS_ID)
1811 {
1812 error.SetErrorStringWithFormat("invalid process ID '%s'", option_arg);
1813 }
1814 else
1815 {
1816 attach_info.SetProcessID (pid);
1817 }
1818 }
1819 break;
1820
1821 case 'P':
1822 attach_info.SetProcessPluginName (option_arg);
1823 break;
1824
1825 case 'n':
1826 attach_info.GetExecutableFile().SetFile(option_arg, false);
1827 break;
1828
1829 case 'w':
1830 attach_info.SetWaitForLaunch(true);
1831 break;
1832
1833 default:
1834 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
1835 break;
1836 }
1837 return error;
1838 }
1839
1840 void
1841 OptionParsingStarting ()
1842 {
1843 attach_info.Clear();
1844 }
1845
1846 const OptionDefinition*
1847 GetDefinitions ()
1848 {
1849 return g_option_table;
1850 }
1851
1852 virtual bool
1853 HandleOptionArgumentCompletion (Args &input,
1854 int cursor_index,
1855 int char_pos,
1856 OptionElementVector &opt_element_vector,
1857 int opt_element_index,
1858 int match_start_point,
1859 int max_return_elements,
1860 bool &word_complete,
1861 StringList &matches)
1862 {
1863 int opt_arg_pos = opt_element_vector[opt_element_index].opt_arg_pos;
1864 int opt_defs_index = opt_element_vector[opt_element_index].opt_defs_index;
1865
1866 // We are only completing the name option for now...
1867
1868 const OptionDefinition *opt_defs = GetDefinitions();
1869 if (opt_defs[opt_defs_index].short_option == 'n')
1870 {
1871 // Are we in the name?
1872
1873 // Look to see if there is a -P argument provided, and if so use that plugin, otherwise
1874 // use the default plugin.
1875
1876 const char *partial_name = NULL;
1877 partial_name = input.GetArgumentAtIndex(opt_arg_pos);
1878
1879 PlatformSP platform_sp (m_interpreter.GetPlatform (true));
1880 if (platform_sp)
1881 {
1882 ProcessInstanceInfoList process_infos;
1883 ProcessInstanceInfoMatch match_info;
1884 if (partial_name)
1885 {
1886 match_info.GetProcessInfo().GetExecutableFile().SetFile(partial_name, false);
1887 match_info.SetNameMatchType(eNameMatchStartsWith);
1888 }
1889 platform_sp->FindProcesses (match_info, process_infos);
1890 const uint32_t num_matches = process_infos.GetSize();
1891 if (num_matches > 0)
1892 {
1893 for (uint32_t i=0; i<num_matches; ++i)
1894 {
1895 matches.AppendString (process_infos.GetProcessNameAtIndex(i),
1896 process_infos.GetProcessNameLengthAtIndex(i));
1897 }
1898 }
1899 }
1900 }
1901
1902 return false;
1903 }
1904
1905 // Options table: Required for subclasses of Options.
1906
1907 static OptionDefinition g_option_table[];
1908
1909 // Instance variables to hold the values for command options.
1910
1911 ProcessAttachInfo attach_info;
1912 };
1913
1914 CommandObjectPlatformProcessAttach (CommandInterpreter &interpreter) :
1915 CommandObjectParsed (interpreter,
1916 "platform process attach",
1917 "Attach to a process.",
1918 "platform process attach <cmd-options>"),
1919 m_options (interpreter)
1920 {
1921 }
1922
1923 ~CommandObjectPlatformProcessAttach ()
1924 {
1925 }
1926
1927 bool
1928 DoExecute (Args& command,
1929 CommandReturnObject &result)
1930 {
1931 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
1932 if (platform_sp)
1933 {
1934 Error err;
1935 ProcessSP remote_process_sp =
1936 platform_sp->Attach(m_options.attach_info, m_interpreter.GetDebugger(), NULL, m_interpreter.GetDebugger().GetListener(), err);
1937 if (err.Fail())
1938 {
1939 result.AppendError(err.AsCString());
1940 result.SetStatus (eReturnStatusFailed);
1941 }
1942 else if (remote_process_sp.get() == NULL)
1943 {
1944 result.AppendError("could not attach: unknown reason");
1945 result.SetStatus (eReturnStatusFailed);
1946 }
1947 else
1948 result.SetStatus (eReturnStatusSuccessFinishResult);
1949 }
1950 else
1951 {
1952 result.AppendError ("no platform is currently selected");
1953 result.SetStatus (eReturnStatusFailed);
1954 }
1955 return result.Succeeded();
1956 }
1957
1958 Options *
1959 GetOptions ()
1960 {
1961 return &m_options;
1962 }
1963
1964protected:
1965
1966 CommandOptions m_options;
1967};
Greg Clayton95bf0fd2011-04-01 00:29:43 +00001968
1969
Daniel Maleae0f8f572013-08-26 23:57:52 +00001970OptionDefinition
1971CommandObjectPlatformProcessAttach::CommandOptions::g_option_table[] =
1972{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001973 { LLDB_OPT_SET_ALL, false, "plugin", 'P' , OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."},
1974 { LLDB_OPT_SET_1, false, "pid", 'p' , OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePid, "The process ID of an existing process to attach to."},
1975 { LLDB_OPT_SET_2, false, "name", 'n' , OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeProcessName, "The name of the process to attach to."},
1976 { LLDB_OPT_SET_2, false, "waitfor", 'w' , OptionParser::eNoArgument , NULL, NULL, 0, eArgTypeNone, "Wait for the the process with <process-name> to launch."},
1977 { 0, false, NULL , 0 , 0 , NULL, NULL, 0, eArgTypeNone, NULL }
Daniel Maleae0f8f572013-08-26 23:57:52 +00001978};
1979
Greg Clayton95bf0fd2011-04-01 00:29:43 +00001980
Greg Clayton32e0a752011-03-30 18:16:51 +00001981class CommandObjectPlatformProcess : public CommandObjectMultiword
1982{
1983public:
1984 //------------------------------------------------------------------
1985 // Constructors and Destructors
1986 //------------------------------------------------------------------
1987 CommandObjectPlatformProcess (CommandInterpreter &interpreter) :
1988 CommandObjectMultiword (interpreter,
1989 "platform process",
1990 "A set of commands to query, launch and attach to platform processes",
1991 "platform process [attach|launch|list] ...")
1992 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00001993 LoadSubCommand ("attach", CommandObjectSP (new CommandObjectPlatformProcessAttach (interpreter)));
Greg Clayton8b82f082011-04-12 05:54:46 +00001994 LoadSubCommand ("launch", CommandObjectSP (new CommandObjectPlatformProcessLaunch (interpreter)));
Greg Clayton95bf0fd2011-04-01 00:29:43 +00001995 LoadSubCommand ("info" , CommandObjectSP (new CommandObjectPlatformProcessInfo (interpreter)));
Greg Clayton32e0a752011-03-30 18:16:51 +00001996 LoadSubCommand ("list" , CommandObjectSP (new CommandObjectPlatformProcessList (interpreter)));
1997
1998 }
1999
2000 virtual
2001 ~CommandObjectPlatformProcess ()
2002 {
2003 }
2004
2005private:
2006 //------------------------------------------------------------------
2007 // For CommandObjectPlatform only
2008 //------------------------------------------------------------------
2009 DISALLOW_COPY_AND_ASSIGN (CommandObjectPlatformProcess);
2010};
Greg Claytonded470d2011-03-19 01:12:21 +00002011
Daniel Maleae0f8f572013-08-26 23:57:52 +00002012//----------------------------------------------------------------------
2013// "platform shell"
2014//----------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +00002015class CommandObjectPlatformShell : public CommandObjectRaw
Greg Claytond1cf11a2012-04-14 01:42:46 +00002016{
2017public:
Daniel Maleae0f8f572013-08-26 23:57:52 +00002018
2019 class CommandOptions : public Options
2020 {
2021 public:
2022
2023 CommandOptions (CommandInterpreter &interpreter) :
Daniel Maleabb247fb2013-08-27 21:01:01 +00002024 Options(interpreter),
2025 timeout(10)
Daniel Maleae0f8f572013-08-26 23:57:52 +00002026 {
2027 }
2028
2029 virtual
2030 ~CommandOptions ()
2031 {
2032 }
2033
2034 virtual uint32_t
2035 GetNumDefinitions ()
2036 {
2037 return 1;
2038 }
2039
2040 virtual const OptionDefinition*
2041 GetDefinitions ()
2042 {
2043 return g_option_table;
2044 }
2045
2046 virtual Error
2047 SetOptionValue (uint32_t option_idx,
2048 const char *option_value)
2049 {
2050 Error error;
2051
2052 const char short_option = (char) g_option_table[option_idx].short_option;
2053
2054 switch (short_option)
2055 {
2056 case 't':
2057 {
2058 bool success;
2059 timeout = Args::StringToUInt32(option_value, 10, 10, &success);
2060 if (!success)
2061 error.SetErrorStringWithFormat("could not convert \"%s\" to a numeric value.", option_value);
2062 break;
2063 }
2064 default:
2065 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
2066 break;
2067 }
2068
2069 return error;
2070 }
2071
2072 virtual void
2073 OptionParsingStarting ()
2074 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00002075 }
2076
2077 // Options table: Required for subclasses of Options.
2078
2079 static OptionDefinition g_option_table[];
2080 uint32_t timeout;
2081 };
2082
Greg Claytond1cf11a2012-04-14 01:42:46 +00002083 CommandObjectPlatformShell (CommandInterpreter &interpreter) :
Daniel Maleae0f8f572013-08-26 23:57:52 +00002084 CommandObjectRaw (interpreter,
2085 "platform shell",
2086 "Run a shell command on a the selected platform.",
2087 "platform shell <shell-command>",
2088 0),
2089 m_options(interpreter)
Greg Claytond1cf11a2012-04-14 01:42:46 +00002090 {
2091 }
2092
2093 virtual
2094 ~CommandObjectPlatformShell ()
2095 {
2096 }
2097
Enrico Granatafff25892013-09-09 22:35:18 +00002098 virtual
2099 Options *
2100 GetOptions ()
2101 {
2102 return &m_options;
2103 }
2104
Greg Claytond1cf11a2012-04-14 01:42:46 +00002105 virtual bool
Jim Ingham5a988412012-06-08 21:56:10 +00002106 DoExecute (const char *raw_command_line, CommandReturnObject &result)
Greg Claytond1cf11a2012-04-14 01:42:46 +00002107 {
Enrico Granatafff25892013-09-09 22:35:18 +00002108 m_options.NotifyOptionParsingStarting();
2109
Daniel Maleae0f8f572013-08-26 23:57:52 +00002110 const char* expr = NULL;
2111
2112 // Print out an usage syntax on an empty command line.
2113 if (raw_command_line[0] == '\0')
Greg Claytond1cf11a2012-04-14 01:42:46 +00002114 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00002115 result.GetOutputStream().Printf("%s\n", this->GetSyntax());
2116 return true;
2117 }
2118
2119 if (raw_command_line[0] == '-')
2120 {
2121 // We have some options and these options MUST end with --.
2122 const char *end_options = NULL;
2123 const char *s = raw_command_line;
2124 while (s && s[0])
Greg Claytond1cf11a2012-04-14 01:42:46 +00002125 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00002126 end_options = ::strstr (s, "--");
2127 if (end_options)
2128 {
2129 end_options += 2; // Get past the "--"
2130 if (::isspace (end_options[0]))
2131 {
2132 expr = end_options;
2133 while (::isspace (*expr))
2134 ++expr;
2135 break;
2136 }
2137 }
2138 s = end_options;
Greg Claytond1cf11a2012-04-14 01:42:46 +00002139 }
Daniel Maleae0f8f572013-08-26 23:57:52 +00002140
2141 if (end_options)
2142 {
2143 Args args (raw_command_line, end_options - raw_command_line);
2144 if (!ParseOptions (args, result))
2145 return false;
2146 }
2147 }
2148
2149 if (expr == NULL)
2150 expr = raw_command_line;
2151
2152 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
2153 Error error;
2154 if (platform_sp)
2155 {
2156 const char *working_dir = NULL;
2157 std::string output;
2158 int status = -1;
2159 int signo = -1;
2160 error = (platform_sp->RunShellCommand (expr, working_dir, &status, &signo, &output, m_options.timeout));
2161 if (!output.empty())
2162 result.GetOutputStream().PutCString(output.c_str());
2163 if (status > 0)
2164 {
2165 if (signo > 0)
2166 {
2167 const char *signo_cstr = Host::GetSignalAsCString(signo);
2168 if (signo_cstr)
2169 result.GetOutputStream().Printf("error: command returned with status %i and signal %s\n", status, signo_cstr);
2170 else
2171 result.GetOutputStream().Printf("error: command returned with status %i and signal %i\n", status, signo);
2172 }
2173 else
2174 result.GetOutputStream().Printf("error: command returned with status %i\n", status);
2175 }
2176 }
2177 else
2178 {
2179 result.GetOutputStream().Printf("error: cannot run remote shell commands without a platform\n");
2180 error.SetErrorString("error: cannot run remote shell commands without a platform");
Greg Claytond1cf11a2012-04-14 01:42:46 +00002181 }
2182
2183 if (error.Fail())
2184 {
2185 result.AppendError(error.AsCString());
2186 result.SetStatus (eReturnStatusFailed);
2187 }
2188 else
2189 {
2190 result.SetStatus (eReturnStatusSuccessFinishResult);
2191 }
2192 return true;
2193 }
Daniel Maleae0f8f572013-08-26 23:57:52 +00002194 CommandOptions m_options;
2195};
2196
2197OptionDefinition
2198CommandObjectPlatformShell::CommandOptions::g_option_table[] =
2199{
Zachary Turnerd37221d2014-07-09 16:31:49 +00002200 { LLDB_OPT_SET_ALL, false, "timeout", 't', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeValue, "Seconds to wait for the remote host to finish running the command."},
2201 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Daniel Maleae0f8f572013-08-26 23:57:52 +00002202};
2203
Daniel Maleae0f8f572013-08-26 23:57:52 +00002204
2205//----------------------------------------------------------------------
2206// "platform install" - install a target to a remote end
2207//----------------------------------------------------------------------
2208class CommandObjectPlatformInstall : public CommandObjectParsed
2209{
2210public:
2211 CommandObjectPlatformInstall (CommandInterpreter &interpreter) :
2212 CommandObjectParsed (interpreter,
2213 "platform target-install",
2214 "Install a target (bundle or executable file) to the remote end.",
2215 "platform target-install <local-thing> <remote-sandbox>",
2216 0)
2217 {
2218 }
2219
2220 virtual
2221 ~CommandObjectPlatformInstall ()
2222 {
2223 }
2224
2225 virtual bool
2226 DoExecute (Args& args, CommandReturnObject &result)
2227 {
2228 if (args.GetArgumentCount() != 2)
2229 {
2230 result.AppendError("platform target-install takes two arguments");
2231 result.SetStatus(eReturnStatusFailed);
2232 return false;
2233 }
2234 // TODO: move the bulk of this code over to the platform itself
Greg Claytonfbb76342013-11-20 21:07:01 +00002235 FileSpec src(args.GetArgumentAtIndex(0), true);
2236 FileSpec dst(args.GetArgumentAtIndex(1), false);
2237 if (src.Exists() == false)
Daniel Maleae0f8f572013-08-26 23:57:52 +00002238 {
2239 result.AppendError("source location does not exist or is not accessible");
2240 result.SetStatus(eReturnStatusFailed);
2241 return false;
2242 }
2243 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
2244 if (!platform_sp)
2245 {
2246 result.AppendError ("no platform currently selected");
2247 result.SetStatus (eReturnStatusFailed);
2248 return false;
2249 }
Greg Claytonfbb76342013-11-20 21:07:01 +00002250
2251 Error error = platform_sp->Install(src, dst);
2252 if (error.Success())
Daniel Maleae0f8f572013-08-26 23:57:52 +00002253 {
Greg Claytonfbb76342013-11-20 21:07:01 +00002254 result.SetStatus(eReturnStatusSuccessFinishNoResult);
Daniel Maleae0f8f572013-08-26 23:57:52 +00002255 }
2256 else
2257 {
Greg Claytonfbb76342013-11-20 21:07:01 +00002258 result.AppendErrorWithFormat("install failed: %s", error.AsCString());
Daniel Maleae0f8f572013-08-26 23:57:52 +00002259 result.SetStatus(eReturnStatusFailed);
Daniel Maleae0f8f572013-08-26 23:57:52 +00002260 }
Greg Claytonfbb76342013-11-20 21:07:01 +00002261 return result.Succeeded();
Daniel Maleae0f8f572013-08-26 23:57:52 +00002262 }
2263private:
Greg Claytonfbb76342013-11-20 21:07:01 +00002264
Greg Claytond1cf11a2012-04-14 01:42:46 +00002265};
2266
Greg Claytonded470d2011-03-19 01:12:21 +00002267//----------------------------------------------------------------------
2268// CommandObjectPlatform constructor
2269//----------------------------------------------------------------------
2270CommandObjectPlatform::CommandObjectPlatform(CommandInterpreter &interpreter) :
2271 CommandObjectMultiword (interpreter,
2272 "platform",
2273 "A set of commands to manage and create platforms.",
Greg Claytonf6b8b582011-04-13 00:18:08 +00002274 "platform [connect|disconnect|info|list|status|select] ...")
Greg Claytonded470d2011-03-19 01:12:21 +00002275{
Greg Claytonfbb76342013-11-20 21:07:01 +00002276 LoadSubCommand ("select", CommandObjectSP (new CommandObjectPlatformSelect (interpreter)));
2277 LoadSubCommand ("list" , CommandObjectSP (new CommandObjectPlatformList (interpreter)));
2278 LoadSubCommand ("status", CommandObjectSP (new CommandObjectPlatformStatus (interpreter)));
2279 LoadSubCommand ("connect", CommandObjectSP (new CommandObjectPlatformConnect (interpreter)));
2280 LoadSubCommand ("disconnect", CommandObjectSP (new CommandObjectPlatformDisconnect (interpreter)));
2281 LoadSubCommand ("settings", CommandObjectSP (new CommandObjectPlatformSettings (interpreter)));
Daniel Maleae0f8f572013-08-26 23:57:52 +00002282#ifdef LLDB_CONFIGURATION_DEBUG
Greg Claytonfbb76342013-11-20 21:07:01 +00002283 LoadSubCommand ("mkdir", CommandObjectSP (new CommandObjectPlatformMkDir (interpreter)));
2284 LoadSubCommand ("file", CommandObjectSP (new CommandObjectPlatformFile (interpreter)));
2285 LoadSubCommand ("get-file", CommandObjectSP (new CommandObjectPlatformGetFile (interpreter)));
2286 LoadSubCommand ("get-size", CommandObjectSP (new CommandObjectPlatformGetSize (interpreter)));
2287 LoadSubCommand ("put-file", CommandObjectSP (new CommandObjectPlatformPutFile (interpreter)));
Daniel Maleae0f8f572013-08-26 23:57:52 +00002288#endif
Greg Claytonfbb76342013-11-20 21:07:01 +00002289 LoadSubCommand ("process", CommandObjectSP (new CommandObjectPlatformProcess (interpreter)));
2290 LoadSubCommand ("shell", CommandObjectSP (new CommandObjectPlatformShell (interpreter)));
2291 LoadSubCommand ("target-install", CommandObjectSP (new CommandObjectPlatformInstall (interpreter)));
Greg Claytonded470d2011-03-19 01:12:21 +00002292}
2293
2294
2295//----------------------------------------------------------------------
2296// Destructor
2297//----------------------------------------------------------------------
2298CommandObjectPlatform::~CommandObjectPlatform()
2299{
2300}