blob: a72b0db4d143a0b1c86bd517fb5470e5102cf7a5 [file] [log] [blame]
Greg Claytonb1888f22011-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
10#include "CommandObjectPlatform.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Core/DataExtractor.h"
17#include "lldb/Core/Debugger.h"
18#include "lldb/Core/PluginManager.h"
19#include "lldb/Interpreter/Args.h"
20#include "lldb/Interpreter/CommandInterpreter.h"
21#include "lldb/Interpreter/CommandReturnObject.h"
Greg Claytonf15996e2011-04-07 22:46:35 +000022#include "lldb/Interpreter/Options.h"
Greg Claytonb1888f22011-03-19 01:12:21 +000023#include "lldb/Target/ExecutionContext.h"
24#include "lldb/Target/Platform.h"
Greg Claytonf15996e2011-04-07 22:46:35 +000025#include "lldb/Target/Process.h"
Greg Claytonb1888f22011-03-19 01:12:21 +000026
27using namespace lldb;
28using namespace lldb_private;
29
30//----------------------------------------------------------------------
31// "platform create <platform-name>"
32//----------------------------------------------------------------------
33class CommandObjectPlatformCreate : public CommandObject
34{
35public:
36 CommandObjectPlatformCreate (CommandInterpreter &interpreter) :
37 CommandObject (interpreter,
38 "platform create",
39 "Create a platform instance by name and select it as the current platform.",
40 "platform create <platform-name>",
Greg Claytonf15996e2011-04-07 22:46:35 +000041 0),
42 m_options (interpreter)
Greg Claytonb1888f22011-03-19 01:12:21 +000043 {
44 }
45
46 virtual
47 ~CommandObjectPlatformCreate ()
48 {
49 }
50
51 virtual bool
52 Execute (Args& args, CommandReturnObject &result)
53 {
54 Error error;
55 if (args.GetArgumentCount() == 1)
56 {
57 PlatformSP platform_sp (Platform::Create (args.GetArgumentAtIndex (0), error));
58
59 if (platform_sp)
60 {
61 m_interpreter.GetDebugger().GetPlatformList().Append (platform_sp, true);
62 if (m_options.os_version_major != UINT32_MAX)
63 {
64 platform_sp->SetOSVersion (m_options.os_version_major,
65 m_options.os_version_minor,
66 m_options.os_version_update);
67 }
68
69 platform_sp->GetStatus (result.GetOutputStream());
70 }
71 }
72 else
73 {
Greg Clayton24bc5d92011-03-30 18:16:51 +000074 result.AppendError ("platform create takes a platform name as an argument\n");
Greg Claytonb1888f22011-03-19 01:12:21 +000075 result.SetStatus (eReturnStatusFailed);
76 }
77 return result.Succeeded();
78 }
79
80 virtual Options *
81 GetOptions ()
82 {
83 return &m_options;
84 }
85
86protected:
87
88 class CommandOptions : public Options
89 {
90 public:
91
Greg Claytonf15996e2011-04-07 22:46:35 +000092 CommandOptions (CommandInterpreter &interpreter) :
93 Options (interpreter),
Greg Claytonb1888f22011-03-19 01:12:21 +000094 os_version_major (UINT32_MAX),
95 os_version_minor (UINT32_MAX),
96 os_version_update (UINT32_MAX)
97 {
98 }
99
100 virtual
101 ~CommandOptions ()
102 {
103 }
104
105 virtual Error
106 SetOptionValue (int option_idx, const char *option_arg)
107 {
108 Error error;
109 char short_option = (char) m_getopt_table[option_idx].val;
110
111 switch (short_option)
112 {
113 case 'v':
114 if (Args::StringToVersion (option_arg,
115 os_version_major,
116 os_version_minor,
117 os_version_update) == option_arg)
118 {
119 error.SetErrorStringWithFormat ("invalid version string '%s'", option_arg);
120 }
121 break;
122
123 default:
124 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
125 break;
126 }
127
128 return error;
129 }
130
131 void
132 ResetOptionValues ()
133 {
134 os_version_major = UINT32_MAX;
135 os_version_minor = UINT32_MAX;
136 os_version_update = UINT32_MAX;
137 }
138
Greg Claytonb3448432011-03-24 21:19:54 +0000139 const OptionDefinition*
Greg Claytonb1888f22011-03-19 01:12:21 +0000140 GetDefinitions ()
141 {
142 return g_option_table;
143 }
144
145 // Options table: Required for subclasses of Options.
146
Greg Claytonb3448432011-03-24 21:19:54 +0000147 static OptionDefinition g_option_table[];
Greg Claytonb1888f22011-03-19 01:12:21 +0000148
149 // Instance variables to hold the values for command options.
150
151 uint32_t os_version_major;
152 uint32_t os_version_minor;
153 uint32_t os_version_update;
154 };
155 CommandOptions m_options;
156};
157
Greg Claytonb3448432011-03-24 21:19:54 +0000158OptionDefinition
Greg Claytonb1888f22011-03-19 01:12:21 +0000159CommandObjectPlatformCreate::CommandOptions::g_option_table[] =
160{
161 { LLDB_OPT_SET_ALL, false, "sdk-version", 'v', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting." },
162 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
163};
164
165//----------------------------------------------------------------------
166// "platform list"
167//----------------------------------------------------------------------
168class CommandObjectPlatformList : public CommandObject
169{
170public:
171 CommandObjectPlatformList (CommandInterpreter &interpreter) :
172 CommandObject (interpreter,
173 "platform list",
174 "List all platforms that are available.",
175 NULL,
176 0)
177 {
178 }
179
180 virtual
181 ~CommandObjectPlatformList ()
182 {
183 }
184
185 virtual bool
186 Execute (Args& args, CommandReturnObject &result)
187 {
188 Stream &ostrm = result.GetOutputStream();
189 ostrm.Printf("Available platforms:\n");
190
191 PlatformSP host_platform_sp (Platform::GetDefaultPlatform());
192 ostrm.Printf ("%s: %s\n",
193 host_platform_sp->GetShortPluginName(),
194 host_platform_sp->GetDescription());
195
196 uint32_t idx;
197 for (idx = 0; 1; ++idx)
198 {
199 const char *plugin_name = PluginManager::GetPlatformPluginNameAtIndex (idx);
200 if (plugin_name == NULL)
201 break;
202 const char *plugin_desc = PluginManager::GetPlatformPluginDescriptionAtIndex (idx);
203 if (plugin_desc == NULL)
204 break;
205 ostrm.Printf("%s: %s\n", plugin_name, plugin_desc);
206 }
207
208 if (idx == 0)
209 {
Greg Clayton58e26e02011-03-24 04:28:38 +0000210 result.AppendError ("no platforms are available\n");
Greg Claytonb1888f22011-03-19 01:12:21 +0000211 result.SetStatus (eReturnStatusFailed);
212 }
Johnny Chen08150312011-03-30 21:19:59 +0000213 else
214 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytonb1888f22011-03-19 01:12:21 +0000215 return result.Succeeded();
216 }
217};
218
219//----------------------------------------------------------------------
220// "platform status"
221//----------------------------------------------------------------------
222class CommandObjectPlatformStatus : public CommandObject
223{
224public:
225 CommandObjectPlatformStatus (CommandInterpreter &interpreter) :
226 CommandObject (interpreter,
227 "platform status",
228 "Display status for the currently selected platform.",
229 NULL,
230 0)
231 {
232 }
233
234 virtual
235 ~CommandObjectPlatformStatus ()
236 {
237 }
238
239 virtual bool
240 Execute (Args& args, CommandReturnObject &result)
241 {
242 Stream &ostrm = result.GetOutputStream();
243
Greg Claytonff39f742011-04-01 00:29:43 +0000244 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
245 if (platform_sp)
Greg Claytonb1888f22011-03-19 01:12:21 +0000246 {
Greg Claytonff39f742011-04-01 00:29:43 +0000247 platform_sp->GetStatus (ostrm);
Greg Claytonb1888f22011-03-19 01:12:21 +0000248 result.SetStatus (eReturnStatusSuccessFinishResult);
249 }
250 else
251 {
Greg Clayton58e26e02011-03-24 04:28:38 +0000252 result.AppendError ("no platform us currently selected\n");
Greg Claytonb1888f22011-03-19 01:12:21 +0000253 result.SetStatus (eReturnStatusFailed);
254 }
255 return result.Succeeded();
256 }
257};
258
259
260//----------------------------------------------------------------------
261// "platform select <platform-name>"
262//----------------------------------------------------------------------
263class CommandObjectPlatformSelect : public CommandObject
264{
265public:
266 CommandObjectPlatformSelect (CommandInterpreter &interpreter) :
267 CommandObject (interpreter,
268 "platform select",
269 "Select a platform by name to be the currently selected platform.",
270 "platform select <platform-name>",
271 0)
272 {
273 }
274
275 virtual
276 ~CommandObjectPlatformSelect ()
277 {
278 }
279
280 virtual bool
281 Execute (Args& args, CommandReturnObject &result)
282 {
Greg Clayton58e26e02011-03-24 04:28:38 +0000283 result.AppendError ("command not implemented\n");
Greg Claytonb1888f22011-03-19 01:12:21 +0000284 result.SetStatus (eReturnStatusFailed);
285 return result.Succeeded();
286 }
287};
288
289
Greg Claytoncb8977d2011-03-23 00:09:55 +0000290//----------------------------------------------------------------------
291// "platform connect <connect-url>"
292//----------------------------------------------------------------------
293class CommandObjectPlatformConnect : public CommandObject
294{
295public:
296 CommandObjectPlatformConnect (CommandInterpreter &interpreter) :
297 CommandObject (interpreter,
298 "platform connect",
299 "Connect a platform by name to be the currently selected platform.",
300 "platform connect <connect-url>",
301 0)
302 {
303 }
304
305 virtual
306 ~CommandObjectPlatformConnect ()
307 {
308 }
309
310 virtual bool
311 Execute (Args& args, CommandReturnObject &result)
312 {
313 Stream &ostrm = result.GetOutputStream();
314
Greg Claytonff39f742011-04-01 00:29:43 +0000315 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
316 if (platform_sp)
Greg Claytoncb8977d2011-03-23 00:09:55 +0000317 {
Greg Claytonff39f742011-04-01 00:29:43 +0000318 Error error (platform_sp->ConnectRemote (args));
Greg Claytoncb8977d2011-03-23 00:09:55 +0000319 if (error.Success())
320 {
Greg Claytonff39f742011-04-01 00:29:43 +0000321 platform_sp->GetStatus (ostrm);
Greg Claytoncb8977d2011-03-23 00:09:55 +0000322 result.SetStatus (eReturnStatusSuccessFinishResult);
323 }
324 else
325 {
Greg Clayton58e26e02011-03-24 04:28:38 +0000326 result.AppendErrorWithFormat ("%s\n", error.AsCString());
Greg Claytoncb8977d2011-03-23 00:09:55 +0000327 result.SetStatus (eReturnStatusFailed);
328 }
329 }
330 else
331 {
Greg Clayton58e26e02011-03-24 04:28:38 +0000332 result.AppendError ("no platform us currently selected\n");
Greg Claytoncb8977d2011-03-23 00:09:55 +0000333 result.SetStatus (eReturnStatusFailed);
334 }
335 return result.Succeeded();
336 }
337};
338
339//----------------------------------------------------------------------
340// "platform disconnect"
341//----------------------------------------------------------------------
342class CommandObjectPlatformDisconnect : public CommandObject
343{
344public:
345 CommandObjectPlatformDisconnect (CommandInterpreter &interpreter) :
346 CommandObject (interpreter,
347 "platform disconnect",
348 "Disconnect a platform by name to be the currently selected platform.",
349 "platform disconnect",
350 0)
351 {
352 }
353
354 virtual
355 ~CommandObjectPlatformDisconnect ()
356 {
357 }
358
359 virtual bool
360 Execute (Args& args, CommandReturnObject &result)
361 {
Greg Claytonff39f742011-04-01 00:29:43 +0000362 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
363 if (platform_sp)
Greg Claytoncb8977d2011-03-23 00:09:55 +0000364 {
365 if (args.GetArgumentCount() == 0)
366 {
367 Error error;
368
Greg Claytonff39f742011-04-01 00:29:43 +0000369 if (platform_sp->IsConnected())
Greg Claytoncb8977d2011-03-23 00:09:55 +0000370 {
371 // Cache the instance name if there is one since we are
372 // about to disconnect and the name might go with it.
Greg Claytonff39f742011-04-01 00:29:43 +0000373 const char *hostname_cstr = platform_sp->GetHostname();
Greg Clayton58e26e02011-03-24 04:28:38 +0000374 std::string hostname;
375 if (hostname_cstr)
376 hostname.assign (hostname_cstr);
Greg Claytoncb8977d2011-03-23 00:09:55 +0000377
Greg Claytonff39f742011-04-01 00:29:43 +0000378 error = platform_sp->DisconnectRemote ();
Greg Claytoncb8977d2011-03-23 00:09:55 +0000379 if (error.Success())
380 {
381 Stream &ostrm = result.GetOutputStream();
Greg Clayton58e26e02011-03-24 04:28:38 +0000382 if (hostname.empty())
Greg Claytonff39f742011-04-01 00:29:43 +0000383 ostrm.Printf ("Disconnected from \"%s\"\n", platform_sp->GetShortPluginName());
Greg Claytoncb8977d2011-03-23 00:09:55 +0000384 else
Greg Clayton58e26e02011-03-24 04:28:38 +0000385 ostrm.Printf ("Disconnected from \"%s\"\n", hostname.c_str());
Greg Claytoncb8977d2011-03-23 00:09:55 +0000386 result.SetStatus (eReturnStatusSuccessFinishResult);
387 }
388 else
389 {
Greg Clayton58e26e02011-03-24 04:28:38 +0000390 result.AppendErrorWithFormat ("%s", error.AsCString());
Greg Claytoncb8977d2011-03-23 00:09:55 +0000391 result.SetStatus (eReturnStatusFailed);
392 }
393 }
394 else
395 {
396 // Not connected...
Greg Claytonff39f742011-04-01 00:29:43 +0000397 result.AppendErrorWithFormat ("not connected to '%s'", platform_sp->GetShortPluginName());
Greg Claytoncb8977d2011-03-23 00:09:55 +0000398 result.SetStatus (eReturnStatusFailed);
399 }
400 }
401 else
402 {
403 // Bad args
404 result.AppendError ("\"platform disconnect\" doesn't take any arguments");
405 result.SetStatus (eReturnStatusFailed);
406 }
407 }
408 else
409 {
Greg Clayton58e26e02011-03-24 04:28:38 +0000410 result.AppendError ("no platform is currently selected");
Greg Claytoncb8977d2011-03-23 00:09:55 +0000411 result.SetStatus (eReturnStatusFailed);
412 }
413 return result.Succeeded();
414 }
415};
416
417
Greg Clayton24bc5d92011-03-30 18:16:51 +0000418//----------------------------------------------------------------------
419// "platform process list"
420//----------------------------------------------------------------------
421class CommandObjectPlatformProcessList : public CommandObject
422{
423public:
424 CommandObjectPlatformProcessList (CommandInterpreter &interpreter) :
Greg Claytonf15996e2011-04-07 22:46:35 +0000425 CommandObject (interpreter,
426 "platform process list",
427 "List processes on a remote platform by name, pid, or many other matching attributes.",
428 "platform process list",
429 0),
430 m_options (interpreter)
Greg Clayton24bc5d92011-03-30 18:16:51 +0000431 {
432 }
433
434 virtual
435 ~CommandObjectPlatformProcessList ()
436 {
437 }
438
439 virtual bool
440 Execute (Args& args, CommandReturnObject &result)
441 {
442 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
443
444 if (platform_sp)
445 {
446 Error error;
447 if (args.GetArgumentCount() == 0)
448 {
449
450 if (platform_sp)
451 {
Greg Claytonff39f742011-04-01 00:29:43 +0000452 Stream &ostrm = result.GetOutputStream();
453
Greg Clayton24bc5d92011-03-30 18:16:51 +0000454 lldb::pid_t pid = m_options.match_info.GetProcessInfo().GetProcessID();
455 if (pid != LLDB_INVALID_PROCESS_ID)
456 {
457 ProcessInfo proc_info;
458 if (platform_sp->GetProcessInfo (pid, proc_info))
459 {
Greg Claytonff39f742011-04-01 00:29:43 +0000460 ProcessInfo::DumpTableHeader (ostrm, platform_sp.get());
461 proc_info.DumpAsTableRow(ostrm, platform_sp.get());
Greg Clayton24bc5d92011-03-30 18:16:51 +0000462 result.SetStatus (eReturnStatusSuccessFinishResult);
463 }
464 else
465 {
466 result.AppendErrorWithFormat ("no process found with pid = %i\n", pid);
467 result.SetStatus (eReturnStatusFailed);
468 }
469 }
470 else
471 {
472 ProcessInfoList proc_infos;
473 const uint32_t matches = platform_sp->FindProcesses (m_options.match_info, proc_infos);
474 if (matches == 0)
475 {
476 const char *match_desc = NULL;
477 const char *match_name = m_options.match_info.GetProcessInfo().GetName();
478 if (match_name && match_name[0])
479 {
480 switch (m_options.match_info.GetNameMatchType())
481 {
482 case eNameMatchIgnore: break;
483 case eNameMatchEquals: match_desc = "match"; break;
484 case eNameMatchContains: match_desc = "contains"; break;
485 case eNameMatchStartsWith: match_desc = "starts with"; break;
486 case eNameMatchEndsWith: match_desc = "end with"; break;
487 case eNameMatchRegularExpression: match_desc = "match the regular expression"; break;
488 }
489 }
490 if (match_desc)
491 result.AppendErrorWithFormat ("no processes were found that %s \"%s\" on the \"%s\" platform\n",
492 match_desc,
493 match_name,
494 platform_sp->GetShortPluginName());
495 else
496 result.AppendErrorWithFormat ("no processes were found on the \"%s\" platform\n", platform_sp->GetShortPluginName());
497 result.SetStatus (eReturnStatusFailed);
498 }
499 else
500 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000501
502 ProcessInfo::DumpTableHeader (ostrm, platform_sp.get());
503 for (uint32_t i=0; i<matches; ++i)
504 {
505 proc_infos.GetProcessInfoAtIndex(i).DumpAsTableRow(ostrm, platform_sp.get());
506 }
507 }
508 }
509 }
510 }
511 else
512 {
513 result.AppendError ("invalid args: process list takes only options\n");
514 result.SetStatus (eReturnStatusFailed);
515 }
516 }
517 else
518 {
519 result.AppendError ("no platform is selected\n");
520 result.SetStatus (eReturnStatusFailed);
521 }
522 return result.Succeeded();
523 }
524
525 virtual Options *
526 GetOptions ()
527 {
528 return &m_options;
529 }
530
531protected:
532
533 class CommandOptions : public Options
534 {
535 public:
536
Greg Claytonf15996e2011-04-07 22:46:35 +0000537 CommandOptions (CommandInterpreter &interpreter) :
538 Options (interpreter),
Greg Clayton24bc5d92011-03-30 18:16:51 +0000539 match_info ()
540 {
541 }
542
543 virtual
544 ~CommandOptions ()
545 {
546 }
547
548 virtual Error
549 SetOptionValue (int option_idx, const char *option_arg)
550 {
551 Error error;
552 char short_option = (char) m_getopt_table[option_idx].val;
553 bool success = false;
554
555 switch (short_option)
556 {
557 case 'p':
558 match_info.GetProcessInfo().SetProcessID (Args::StringToUInt32 (option_arg, LLDB_INVALID_PROCESS_ID, 0, &success));
559 if (!success)
560 error.SetErrorStringWithFormat("invalid process ID string: '%s'", option_arg);
561 break;
562
563 case 'P':
564 match_info.GetProcessInfo().SetParentProcessID (Args::StringToUInt32 (option_arg, LLDB_INVALID_PROCESS_ID, 0, &success));
565 if (!success)
566 error.SetErrorStringWithFormat("invalid parent process ID string: '%s'", option_arg);
567 break;
568
569 case 'u':
570 match_info.GetProcessInfo().SetRealUserID (Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success));
571 if (!success)
572 error.SetErrorStringWithFormat("invalid user ID string: '%s'", option_arg);
573 break;
574
575 case 'U':
576 match_info.GetProcessInfo().SetEffectiveUserID (Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success));
577 if (!success)
578 error.SetErrorStringWithFormat("invalid effective user ID string: '%s'", option_arg);
579 break;
580
581 case 'g':
582 match_info.GetProcessInfo().SetRealGroupID (Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success));
583 if (!success)
584 error.SetErrorStringWithFormat("invalid group ID string: '%s'", option_arg);
585 break;
586
587 case 'G':
588 match_info.GetProcessInfo().SetEffectiveGroupID (Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success));
589 if (!success)
590 error.SetErrorStringWithFormat("invalid effective group ID string: '%s'", option_arg);
591 break;
592
593 case 'a':
Greg Claytonf15996e2011-04-07 22:46:35 +0000594 match_info.GetProcessInfo().GetArchitecture().SetTriple (option_arg, m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform().get());
Greg Clayton24bc5d92011-03-30 18:16:51 +0000595 break;
596
597 case 'n':
598 match_info.GetProcessInfo().SetName (option_arg);
599 if (match_info.GetNameMatchType() == eNameMatchIgnore)
600 match_info.SetNameMatchType (eNameMatchEquals);
601 break;
602
603 case 'e':
604 match_info.SetNameMatchType (eNameMatchEndsWith);
605 break;
606
607 case 's':
608 match_info.SetNameMatchType (eNameMatchStartsWith);
609 break;
610
611 case 'c':
612 match_info.SetNameMatchType (eNameMatchContains);
613 break;
614
615 case 'r':
616 match_info.SetNameMatchType (eNameMatchRegularExpression);
617 break;
618
619 default:
620 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
621 break;
622 }
623
624 return error;
625 }
626
627 void
628 ResetOptionValues ()
629 {
630 match_info.Clear();
631 }
632
633 const OptionDefinition*
634 GetDefinitions ()
635 {
636 return g_option_table;
637 }
638
639 // Options table: Required for subclasses of Options.
640
641 static OptionDefinition g_option_table[];
642
643 // Instance variables to hold the values for command options.
644
645 ProcessInfoMatch match_info;
646 };
647 CommandOptions m_options;
648};
649
650OptionDefinition
651CommandObjectPlatformProcessList::CommandOptions::g_option_table[] =
652{
653{ LLDB_OPT_SET_1, false, "pid" , 'p', required_argument, NULL, 0, eArgTypePid , "List the process info for a specific process ID." },
654{ LLDB_OPT_SET_2|
655 LLDB_OPT_SET_3|
656 LLDB_OPT_SET_4|
657 LLDB_OPT_SET_5, true , "name" , 'n', required_argument, NULL, 0, eArgTypeProcessName , "Find processes that match the supplied name." },
658{ LLDB_OPT_SET_2, false, "ends-with" , 'e', no_argument , NULL, 0, eArgTypeNone , "Process names must end with the name supplied with the --name option." },
659{ LLDB_OPT_SET_3, false, "starts-with" , 's', no_argument , NULL, 0, eArgTypeNone , "Process names must start with the name supplied with the --name option." },
660{ LLDB_OPT_SET_4, false, "contains" , 'c', no_argument , NULL, 0, eArgTypeNone , "Process names must contain the name supplied with the --name option." },
661{ LLDB_OPT_SET_5, false, "regex" , 'r', no_argument , NULL, 0, eArgTypeNone , "Process names must match name supplied with the --name option as a regular expression." },
662{ LLDB_OPT_SET_2|
663 LLDB_OPT_SET_3|
664 LLDB_OPT_SET_4|
665 LLDB_OPT_SET_5|
666 LLDB_OPT_SET_6, false, "parent" , 'P', required_argument, NULL, 0, eArgTypePid , "Find processes that have a matching parent process ID." },
667{ LLDB_OPT_SET_2|
668 LLDB_OPT_SET_3|
669 LLDB_OPT_SET_4|
670 LLDB_OPT_SET_5|
671 LLDB_OPT_SET_6, false, "uid" , 'u', required_argument, NULL, 0, eArgTypeNone , "Find processes that have a matching user ID." },
672{ LLDB_OPT_SET_2|
673 LLDB_OPT_SET_3|
674 LLDB_OPT_SET_4|
675 LLDB_OPT_SET_5|
676 LLDB_OPT_SET_6, false, "euid" , 'U', required_argument, NULL, 0, eArgTypeNone , "Find processes that have a matching effective user ID." },
677{ LLDB_OPT_SET_2|
678 LLDB_OPT_SET_3|
679 LLDB_OPT_SET_4|
680 LLDB_OPT_SET_5|
681 LLDB_OPT_SET_6, false, "gid" , 'g', required_argument, NULL, 0, eArgTypeNone , "Find processes that have a matching group ID." },
682{ LLDB_OPT_SET_2|
683 LLDB_OPT_SET_3|
684 LLDB_OPT_SET_4|
685 LLDB_OPT_SET_5|
686 LLDB_OPT_SET_6, false, "egid" , 'G', required_argument, NULL, 0, eArgTypeNone , "Find processes that have a matching effective group ID." },
687{ LLDB_OPT_SET_2|
688 LLDB_OPT_SET_3|
689 LLDB_OPT_SET_4|
690 LLDB_OPT_SET_5|
691 LLDB_OPT_SET_6, false, "arch" , 'a', required_argument, NULL, 0, eArgTypeArchitecture , "Find processes that have a matching architecture." },
692{ 0 , false, NULL , 0 , 0 , NULL, 0, eArgTypeNone , NULL }
693};
694
Greg Claytonff39f742011-04-01 00:29:43 +0000695
696//----------------------------------------------------------------------
697// "platform process info"
698//----------------------------------------------------------------------
699class CommandObjectPlatformProcessInfo : public CommandObject
700{
701public:
702 CommandObjectPlatformProcessInfo (CommandInterpreter &interpreter) :
703 CommandObject (interpreter,
704 "platform process info",
705 "Get detailed information for one or more process by process ID.",
706 "platform process info <pid> [<pid> <pid> ...]",
707 0)
708 {
709 CommandArgumentEntry arg;
710 CommandArgumentData pid_args;
711
712 // Define the first (and only) variant of this arg.
713 pid_args.arg_type = eArgTypePid;
714 pid_args.arg_repetition = eArgRepeatStar;
715
716 // There is only one variant this argument could be; put it into the argument entry.
717 arg.push_back (pid_args);
718
719 // Push the data for the first argument into the m_arguments vector.
720 m_arguments.push_back (arg);
721 }
722
723 virtual
724 ~CommandObjectPlatformProcessInfo ()
725 {
726 }
727
728 virtual bool
729 Execute (Args& args, CommandReturnObject &result)
730 {
731 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
732 if (platform_sp)
733 {
734 const size_t argc = args.GetArgumentCount();
735 if (argc > 0)
736 {
737 Error error;
738
739 if (platform_sp->IsConnected())
740 {
741 Stream &ostrm = result.GetOutputStream();
742 bool success;
743 for (size_t i=0; i<argc; ++ i)
744 {
745 const char *arg = args.GetArgumentAtIndex(i);
746 lldb::pid_t pid = Args::StringToUInt32 (arg, LLDB_INVALID_PROCESS_ID, 0, &success);
747 if (success)
748 {
749 ProcessInfo proc_info;
750 if (platform_sp->GetProcessInfo (pid, proc_info))
751 {
752 ostrm.Printf ("Process information for process %i:\n", pid);
753 proc_info.Dump (ostrm, platform_sp.get());
754 }
755 else
756 {
757 ostrm.Printf ("error: no process information is available for process %i\n", pid);
758 }
759 ostrm.EOL();
760 }
761 else
762 {
763 result.AppendErrorWithFormat ("invalid process ID argument '%s'", arg);
764 result.SetStatus (eReturnStatusFailed);
765 break;
766 }
767 }
768 }
769 else
770 {
771 // Not connected...
772 result.AppendErrorWithFormat ("not connected to '%s'", platform_sp->GetShortPluginName());
773 result.SetStatus (eReturnStatusFailed);
774 }
775 }
776 else
777 {
778 // Bad args
779 result.AppendError ("\"platform disconnect\" doesn't take any arguments");
780 result.SetStatus (eReturnStatusFailed);
781 }
782 }
783 else
784 {
785 result.AppendError ("no platform is currently selected");
786 result.SetStatus (eReturnStatusFailed);
787 }
788 return result.Succeeded();
789 }
790};
791
792
793
794
Greg Clayton24bc5d92011-03-30 18:16:51 +0000795class CommandObjectPlatformProcess : public CommandObjectMultiword
796{
797public:
798 //------------------------------------------------------------------
799 // Constructors and Destructors
800 //------------------------------------------------------------------
801 CommandObjectPlatformProcess (CommandInterpreter &interpreter) :
802 CommandObjectMultiword (interpreter,
803 "platform process",
804 "A set of commands to query, launch and attach to platform processes",
805 "platform process [attach|launch|list] ...")
806 {
807// LoadSubCommand ("attach", CommandObjectSP (new CommandObjectPlatformProcessAttach (interpreter)));
808// LoadSubCommand ("launch", CommandObjectSP (new CommandObjectPlatformProcessLaunch (interpreter)));
Greg Claytonff39f742011-04-01 00:29:43 +0000809 LoadSubCommand ("info" , CommandObjectSP (new CommandObjectPlatformProcessInfo (interpreter)));
Greg Clayton24bc5d92011-03-30 18:16:51 +0000810 LoadSubCommand ("list" , CommandObjectSP (new CommandObjectPlatformProcessList (interpreter)));
811
812 }
813
814 virtual
815 ~CommandObjectPlatformProcess ()
816 {
817 }
818
819private:
820 //------------------------------------------------------------------
821 // For CommandObjectPlatform only
822 //------------------------------------------------------------------
823 DISALLOW_COPY_AND_ASSIGN (CommandObjectPlatformProcess);
824};
Greg Claytonb1888f22011-03-19 01:12:21 +0000825
826//----------------------------------------------------------------------
827// CommandObjectPlatform constructor
828//----------------------------------------------------------------------
829CommandObjectPlatform::CommandObjectPlatform(CommandInterpreter &interpreter) :
830 CommandObjectMultiword (interpreter,
831 "platform",
832 "A set of commands to manage and create platforms.",
Greg Claytonff39f742011-04-01 00:29:43 +0000833 "platform [connect|create|disconnect|info|list|status|select] ...")
Greg Claytonb1888f22011-03-19 01:12:21 +0000834{
835 LoadSubCommand ("create", CommandObjectSP (new CommandObjectPlatformCreate (interpreter)));
836 LoadSubCommand ("list" , CommandObjectSP (new CommandObjectPlatformList (interpreter)));
837 LoadSubCommand ("select", CommandObjectSP (new CommandObjectPlatformSelect (interpreter)));
838 LoadSubCommand ("status", CommandObjectSP (new CommandObjectPlatformStatus (interpreter)));
Greg Claytoncb8977d2011-03-23 00:09:55 +0000839 LoadSubCommand ("connect", CommandObjectSP (new CommandObjectPlatformConnect (interpreter)));
840 LoadSubCommand ("disconnect", CommandObjectSP (new CommandObjectPlatformDisconnect (interpreter)));
Greg Clayton24bc5d92011-03-30 18:16:51 +0000841 LoadSubCommand ("process", CommandObjectSP (new CommandObjectPlatformProcess (interpreter)));
Greg Claytonb1888f22011-03-19 01:12:21 +0000842}
843
844
845//----------------------------------------------------------------------
846// Destructor
847//----------------------------------------------------------------------
848CommandObjectPlatform::~CommandObjectPlatform()
849{
850}