1 //===-- 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 // C Includes 11 // C++ Includes 12 #include <mutex> 13 // Other libraries and framework includes 14 // Project includes 15 #include "CommandObjectPlatform.h" 16 #include "lldb/Core/DataExtractor.h" 17 #include "lldb/Core/Debugger.h" 18 #include "lldb/Core/Module.h" 19 #include "lldb/Core/PluginManager.h" 20 #include "lldb/Host/StringConvert.h" 21 #include "lldb/Interpreter/Args.h" 22 #include "lldb/Interpreter/CommandInterpreter.h" 23 #include "lldb/Interpreter/CommandOptionValidators.h" 24 #include "lldb/Interpreter/CommandReturnObject.h" 25 #include "lldb/Interpreter/OptionGroupFile.h" 26 #include "lldb/Interpreter/OptionGroupPlatform.h" 27 #include "lldb/Target/ExecutionContext.h" 28 #include "lldb/Target/Platform.h" 29 #include "lldb/Target/Process.h" 30 #include "lldb/Utility/Utils.h" 31 32 #include "llvm/ADT/SmallString.h" 33 34 using namespace lldb; 35 using namespace lldb_private; 36 37 static mode_t ParsePermissionString(const char *) = delete; 38 39 static mode_t ParsePermissionString(llvm::StringRef permissions) { 40 if (permissions.size() != 9) 41 return (mode_t)(-1); 42 bool user_r, user_w, user_x, group_r, group_w, group_x, world_r, world_w, 43 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 65 static OptionDefinition g_permissions_options[] = { 66 // clang-format off 67 {LLDB_OPT_SET_ALL, false, "permissions-value", 'v', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePermissionsNumber, "Give out the numeric value for permissions (e.g. 757)"}, 68 {LLDB_OPT_SET_ALL, false, "permissions-string", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePermissionsString, "Give out the string value for permissions (e.g. rwxr-xr--)."}, 69 {LLDB_OPT_SET_ALL, false, "user-read", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Allow user to read."}, 70 {LLDB_OPT_SET_ALL, false, "user-write", 'w', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Allow user to write."}, 71 {LLDB_OPT_SET_ALL, false, "user-exec", 'x', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Allow user to execute."}, 72 {LLDB_OPT_SET_ALL, false, "group-read", 'R', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Allow group to read."}, 73 {LLDB_OPT_SET_ALL, false, "group-write", 'W', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Allow group to write."}, 74 {LLDB_OPT_SET_ALL, false, "group-exec", 'X', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Allow group to execute."}, 75 {LLDB_OPT_SET_ALL, false, "world-read", 'd', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Allow world to read."}, 76 {LLDB_OPT_SET_ALL, false, "world-write", 't', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Allow world to write."}, 77 {LLDB_OPT_SET_ALL, false, "world-exec", 'e', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Allow world to execute."}, 78 // clang-format on 79 }; 80 81 class OptionPermissions : public OptionGroup { 82 public: 83 OptionPermissions() {} 84 85 ~OptionPermissions() override = default; 86 87 lldb_private::Error 88 SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 89 ExecutionContext *execution_context) override { 90 Error error; 91 char short_option = (char)GetDefinitions()[option_idx].short_option; 92 switch (short_option) { 93 case 'v': { 94 if (option_arg.getAsInteger(8, m_permissions)) { 95 m_permissions = 0777; 96 error.SetErrorStringWithFormat("invalid value for permissions: %s", 97 option_arg.str().c_str()); 98 } 99 100 } break; 101 case 's': { 102 mode_t perms = ParsePermissionString(option_arg); 103 if (perms == (mode_t)-1) 104 error.SetErrorStringWithFormat("invalid value for permissions: %s", 105 option_arg.str().c_str()); 106 else 107 m_permissions = perms; 108 } break; 109 case 'r': 110 m_permissions |= lldb::eFilePermissionsUserRead; 111 break; 112 case 'w': 113 m_permissions |= lldb::eFilePermissionsUserWrite; 114 break; 115 case 'x': 116 m_permissions |= lldb::eFilePermissionsUserExecute; 117 break; 118 case 'R': 119 m_permissions |= lldb::eFilePermissionsGroupRead; 120 break; 121 case 'W': 122 m_permissions |= lldb::eFilePermissionsGroupWrite; 123 break; 124 case 'X': 125 m_permissions |= lldb::eFilePermissionsGroupExecute; 126 break; 127 case 'd': 128 m_permissions |= lldb::eFilePermissionsWorldRead; 129 break; 130 case 't': 131 m_permissions |= lldb::eFilePermissionsWorldWrite; 132 break; 133 case 'e': 134 m_permissions |= lldb::eFilePermissionsWorldExecute; 135 break; 136 default: 137 error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); 138 break; 139 } 140 141 return error; 142 } 143 144 void OptionParsingStarting(ExecutionContext *execution_context) override { 145 m_permissions = 0; 146 } 147 148 llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 149 return llvm::makeArrayRef(g_permissions_options); 150 } 151 152 // Instance variables to hold the values for command options. 153 154 uint32_t m_permissions; 155 156 private: 157 DISALLOW_COPY_AND_ASSIGN(OptionPermissions); 158 }; 159 160 //---------------------------------------------------------------------- 161 // "platform select <platform-name>" 162 //---------------------------------------------------------------------- 163 class CommandObjectPlatformSelect : public CommandObjectParsed { 164 public: 165 CommandObjectPlatformSelect(CommandInterpreter &interpreter) 166 : CommandObjectParsed(interpreter, "platform select", 167 "Create a platform if needed and select it as the " 168 "current platform.", 169 "platform select <platform-name>", 0), 170 m_option_group(), 171 m_platform_options( 172 false) // Don't include the "--platform" option by passing false 173 { 174 m_option_group.Append(&m_platform_options, LLDB_OPT_SET_ALL, 1); 175 m_option_group.Finalize(); 176 } 177 178 ~CommandObjectPlatformSelect() override = default; 179 180 int HandleCompletion(Args &input, int &cursor_index, 181 int &cursor_char_position, int match_start_point, 182 int max_return_elements, bool &word_complete, 183 StringList &matches) override { 184 std::string completion_str(input.GetArgumentAtIndex(cursor_index)); 185 completion_str.erase(cursor_char_position); 186 187 CommandCompletions::PlatformPluginNames( 188 GetCommandInterpreter(), completion_str.c_str(), match_start_point, 189 max_return_elements, nullptr, word_complete, matches); 190 return matches.GetSize(); 191 } 192 193 Options *GetOptions() override { return &m_option_group; } 194 195 protected: 196 bool DoExecute(Args &args, CommandReturnObject &result) override { 197 if (args.GetArgumentCount() == 1) { 198 const char *platform_name = args.GetArgumentAtIndex(0); 199 if (platform_name && platform_name[0]) { 200 const bool select = true; 201 m_platform_options.SetPlatformName(platform_name); 202 Error error; 203 ArchSpec platform_arch; 204 PlatformSP platform_sp(m_platform_options.CreatePlatformWithOptions( 205 m_interpreter, ArchSpec(), select, error, platform_arch)); 206 if (platform_sp) { 207 m_interpreter.GetDebugger().GetPlatformList().SetSelectedPlatform( 208 platform_sp); 209 210 platform_sp->GetStatus(result.GetOutputStream()); 211 result.SetStatus(eReturnStatusSuccessFinishResult); 212 } else { 213 result.AppendError(error.AsCString()); 214 result.SetStatus(eReturnStatusFailed); 215 } 216 } else { 217 result.AppendError("invalid platform name"); 218 result.SetStatus(eReturnStatusFailed); 219 } 220 } else { 221 result.AppendError( 222 "platform create takes a platform name as an argument\n"); 223 result.SetStatus(eReturnStatusFailed); 224 } 225 return result.Succeeded(); 226 } 227 228 OptionGroupOptions m_option_group; 229 OptionGroupPlatform m_platform_options; 230 }; 231 232 //---------------------------------------------------------------------- 233 // "platform list" 234 //---------------------------------------------------------------------- 235 class CommandObjectPlatformList : public CommandObjectParsed { 236 public: 237 CommandObjectPlatformList(CommandInterpreter &interpreter) 238 : CommandObjectParsed(interpreter, "platform list", 239 "List all platforms that are available.", nullptr, 240 0) {} 241 242 ~CommandObjectPlatformList() override = default; 243 244 protected: 245 bool DoExecute(Args &args, CommandReturnObject &result) override { 246 Stream &ostrm = result.GetOutputStream(); 247 ostrm.Printf("Available platforms:\n"); 248 249 PlatformSP host_platform_sp(Platform::GetHostPlatform()); 250 ostrm.Printf("%s: %s\n", host_platform_sp->GetPluginName().GetCString(), 251 host_platform_sp->GetDescription()); 252 253 uint32_t idx; 254 for (idx = 0; 1; ++idx) { 255 const char *plugin_name = 256 PluginManager::GetPlatformPluginNameAtIndex(idx); 257 if (plugin_name == nullptr) 258 break; 259 const char *plugin_desc = 260 PluginManager::GetPlatformPluginDescriptionAtIndex(idx); 261 if (plugin_desc == nullptr) 262 break; 263 ostrm.Printf("%s: %s\n", plugin_name, plugin_desc); 264 } 265 266 if (idx == 0) { 267 result.AppendError("no platforms are available\n"); 268 result.SetStatus(eReturnStatusFailed); 269 } else 270 result.SetStatus(eReturnStatusSuccessFinishResult); 271 return result.Succeeded(); 272 } 273 }; 274 275 //---------------------------------------------------------------------- 276 // "platform status" 277 //---------------------------------------------------------------------- 278 class CommandObjectPlatformStatus : public CommandObjectParsed { 279 public: 280 CommandObjectPlatformStatus(CommandInterpreter &interpreter) 281 : CommandObjectParsed(interpreter, "platform status", 282 "Display status for the current platform.", nullptr, 283 0) {} 284 285 ~CommandObjectPlatformStatus() override = default; 286 287 protected: 288 bool DoExecute(Args &args, CommandReturnObject &result) override { 289 Stream &ostrm = result.GetOutputStream(); 290 291 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 292 PlatformSP platform_sp; 293 if (target) { 294 platform_sp = target->GetPlatform(); 295 } 296 if (!platform_sp) { 297 platform_sp = 298 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform(); 299 } 300 if (platform_sp) { 301 platform_sp->GetStatus(ostrm); 302 result.SetStatus(eReturnStatusSuccessFinishResult); 303 } else { 304 result.AppendError("no platform us currently selected\n"); 305 result.SetStatus(eReturnStatusFailed); 306 } 307 return result.Succeeded(); 308 } 309 }; 310 311 //---------------------------------------------------------------------- 312 // "platform connect <connect-url>" 313 //---------------------------------------------------------------------- 314 class CommandObjectPlatformConnect : public CommandObjectParsed { 315 public: 316 CommandObjectPlatformConnect(CommandInterpreter &interpreter) 317 : CommandObjectParsed( 318 interpreter, "platform connect", 319 "Select the current platform by providing a connection URL.", 320 "platform connect <connect-url>", 0) {} 321 322 ~CommandObjectPlatformConnect() override = default; 323 324 protected: 325 bool DoExecute(Args &args, CommandReturnObject &result) override { 326 Stream &ostrm = result.GetOutputStream(); 327 328 PlatformSP platform_sp( 329 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); 330 if (platform_sp) { 331 Error error(platform_sp->ConnectRemote(args)); 332 if (error.Success()) { 333 platform_sp->GetStatus(ostrm); 334 result.SetStatus(eReturnStatusSuccessFinishResult); 335 336 platform_sp->ConnectToWaitingProcesses(m_interpreter.GetDebugger(), 337 error); 338 if (error.Fail()) { 339 result.AppendError(error.AsCString()); 340 result.SetStatus(eReturnStatusFailed); 341 } 342 } else { 343 result.AppendErrorWithFormat("%s\n", error.AsCString()); 344 result.SetStatus(eReturnStatusFailed); 345 } 346 } else { 347 result.AppendError("no platform is currently selected\n"); 348 result.SetStatus(eReturnStatusFailed); 349 } 350 return result.Succeeded(); 351 } 352 353 Options *GetOptions() override { 354 PlatformSP platform_sp( 355 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); 356 OptionGroupOptions *m_platform_options = nullptr; 357 if (platform_sp) { 358 m_platform_options = platform_sp->GetConnectionOptions(m_interpreter); 359 if (m_platform_options != nullptr && !m_platform_options->m_did_finalize) 360 m_platform_options->Finalize(); 361 } 362 return m_platform_options; 363 } 364 }; 365 366 //---------------------------------------------------------------------- 367 // "platform disconnect" 368 //---------------------------------------------------------------------- 369 class CommandObjectPlatformDisconnect : public CommandObjectParsed { 370 public: 371 CommandObjectPlatformDisconnect(CommandInterpreter &interpreter) 372 : CommandObjectParsed(interpreter, "platform disconnect", 373 "Disconnect from the current platform.", 374 "platform disconnect", 0) {} 375 376 ~CommandObjectPlatformDisconnect() override = default; 377 378 protected: 379 bool DoExecute(Args &args, CommandReturnObject &result) override { 380 PlatformSP platform_sp( 381 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); 382 if (platform_sp) { 383 if (args.GetArgumentCount() == 0) { 384 Error error; 385 386 if (platform_sp->IsConnected()) { 387 // Cache the instance name if there is one since we are 388 // about to disconnect and the name might go with it. 389 const char *hostname_cstr = platform_sp->GetHostname(); 390 std::string hostname; 391 if (hostname_cstr) 392 hostname.assign(hostname_cstr); 393 394 error = platform_sp->DisconnectRemote(); 395 if (error.Success()) { 396 Stream &ostrm = result.GetOutputStream(); 397 if (hostname.empty()) 398 ostrm.Printf("Disconnected from \"%s\"\n", 399 platform_sp->GetPluginName().GetCString()); 400 else 401 ostrm.Printf("Disconnected from \"%s\"\n", hostname.c_str()); 402 result.SetStatus(eReturnStatusSuccessFinishResult); 403 } else { 404 result.AppendErrorWithFormat("%s", error.AsCString()); 405 result.SetStatus(eReturnStatusFailed); 406 } 407 } else { 408 // Not connected... 409 result.AppendErrorWithFormat( 410 "not connected to '%s'", 411 platform_sp->GetPluginName().GetCString()); 412 result.SetStatus(eReturnStatusFailed); 413 } 414 } else { 415 // Bad args 416 result.AppendError( 417 "\"platform disconnect\" doesn't take any arguments"); 418 result.SetStatus(eReturnStatusFailed); 419 } 420 } else { 421 result.AppendError("no platform is currently selected"); 422 result.SetStatus(eReturnStatusFailed); 423 } 424 return result.Succeeded(); 425 } 426 }; 427 428 //---------------------------------------------------------------------- 429 // "platform settings" 430 //---------------------------------------------------------------------- 431 class CommandObjectPlatformSettings : public CommandObjectParsed { 432 public: 433 CommandObjectPlatformSettings(CommandInterpreter &interpreter) 434 : CommandObjectParsed(interpreter, "platform settings", 435 "Set settings for the current target's platform, " 436 "or for a platform by name.", 437 "platform settings", 0), 438 m_options(), 439 m_option_working_dir(LLDB_OPT_SET_1, false, "working-dir", 'w', 0, 440 eArgTypePath, 441 "The working directory for the platform.") { 442 m_options.Append(&m_option_working_dir, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); 443 } 444 445 ~CommandObjectPlatformSettings() override = default; 446 447 protected: 448 bool DoExecute(Args &args, CommandReturnObject &result) override { 449 PlatformSP platform_sp( 450 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); 451 if (platform_sp) { 452 if (m_option_working_dir.GetOptionValue().OptionWasSet()) 453 platform_sp->SetWorkingDirectory( 454 m_option_working_dir.GetOptionValue().GetCurrentValue()); 455 } else { 456 result.AppendError("no platform is currently selected"); 457 result.SetStatus(eReturnStatusFailed); 458 } 459 return result.Succeeded(); 460 } 461 462 Options *GetOptions() override { 463 if (!m_options.DidFinalize()) 464 m_options.Finalize(); 465 return &m_options; 466 } 467 468 protected: 469 OptionGroupOptions m_options; 470 OptionGroupFile m_option_working_dir; 471 }; 472 473 //---------------------------------------------------------------------- 474 // "platform mkdir" 475 //---------------------------------------------------------------------- 476 class CommandObjectPlatformMkDir : public CommandObjectParsed { 477 public: 478 CommandObjectPlatformMkDir(CommandInterpreter &interpreter) 479 : CommandObjectParsed(interpreter, "platform mkdir", 480 "Make a new directory on the remote end.", nullptr, 481 0), 482 m_options() {} 483 484 ~CommandObjectPlatformMkDir() override = default; 485 486 bool DoExecute(Args &args, CommandReturnObject &result) override { 487 PlatformSP platform_sp( 488 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); 489 if (platform_sp) { 490 std::string cmd_line; 491 args.GetCommandString(cmd_line); 492 uint32_t mode; 493 const OptionPermissions *options_permissions = 494 (const OptionPermissions *)m_options.GetGroupWithOption('r'); 495 if (options_permissions) 496 mode = options_permissions->m_permissions; 497 else 498 mode = lldb::eFilePermissionsUserRWX | lldb::eFilePermissionsGroupRWX | 499 lldb::eFilePermissionsWorldRX; 500 Error error = platform_sp->MakeDirectory(FileSpec{cmd_line, false}, mode); 501 if (error.Success()) { 502 result.SetStatus(eReturnStatusSuccessFinishResult); 503 } else { 504 result.AppendError(error.AsCString()); 505 result.SetStatus(eReturnStatusFailed); 506 } 507 } else { 508 result.AppendError("no platform currently selected\n"); 509 result.SetStatus(eReturnStatusFailed); 510 } 511 return result.Succeeded(); 512 } 513 514 Options *GetOptions() override { 515 if (!m_options.DidFinalize()) { 516 m_options.Append(new OptionPermissions()); 517 m_options.Finalize(); 518 } 519 return &m_options; 520 } 521 522 OptionGroupOptions m_options; 523 }; 524 525 //---------------------------------------------------------------------- 526 // "platform fopen" 527 //---------------------------------------------------------------------- 528 class CommandObjectPlatformFOpen : public CommandObjectParsed { 529 public: 530 CommandObjectPlatformFOpen(CommandInterpreter &interpreter) 531 : CommandObjectParsed(interpreter, "platform file open", 532 "Open a file on the remote end.", nullptr, 0), 533 m_options() {} 534 535 ~CommandObjectPlatformFOpen() override = default; 536 537 bool DoExecute(Args &args, CommandReturnObject &result) override { 538 PlatformSP platform_sp( 539 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); 540 if (platform_sp) { 541 Error error; 542 std::string cmd_line; 543 args.GetCommandString(cmd_line); 544 mode_t perms; 545 const OptionPermissions *options_permissions = 546 (const OptionPermissions *)m_options.GetGroupWithOption('r'); 547 if (options_permissions) 548 perms = options_permissions->m_permissions; 549 else 550 perms = lldb::eFilePermissionsUserRW | lldb::eFilePermissionsGroupRW | 551 lldb::eFilePermissionsWorldRead; 552 lldb::user_id_t fd = platform_sp->OpenFile( 553 FileSpec(cmd_line, false), 554 File::eOpenOptionRead | File::eOpenOptionWrite | 555 File::eOpenOptionAppend | File::eOpenOptionCanCreate, 556 perms, error); 557 if (error.Success()) { 558 result.AppendMessageWithFormat("File Descriptor = %" PRIu64 "\n", fd); 559 result.SetStatus(eReturnStatusSuccessFinishResult); 560 } else { 561 result.AppendError(error.AsCString()); 562 result.SetStatus(eReturnStatusFailed); 563 } 564 } else { 565 result.AppendError("no platform currently selected\n"); 566 result.SetStatus(eReturnStatusFailed); 567 } 568 return result.Succeeded(); 569 } 570 571 Options *GetOptions() override { 572 if (!m_options.DidFinalize()) { 573 m_options.Append(new OptionPermissions()); 574 m_options.Finalize(); 575 } 576 return &m_options; 577 } 578 579 OptionGroupOptions m_options; 580 }; 581 582 //---------------------------------------------------------------------- 583 // "platform fclose" 584 //---------------------------------------------------------------------- 585 class CommandObjectPlatformFClose : public CommandObjectParsed { 586 public: 587 CommandObjectPlatformFClose(CommandInterpreter &interpreter) 588 : CommandObjectParsed(interpreter, "platform file close", 589 "Close a file on the remote end.", nullptr, 0) {} 590 591 ~CommandObjectPlatformFClose() override = default; 592 593 bool DoExecute(Args &args, CommandReturnObject &result) override { 594 PlatformSP platform_sp( 595 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); 596 if (platform_sp) { 597 std::string cmd_line; 598 args.GetCommandString(cmd_line); 599 const lldb::user_id_t fd = 600 StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX); 601 Error error; 602 bool success = platform_sp->CloseFile(fd, error); 603 if (success) { 604 result.AppendMessageWithFormat("file %" PRIu64 " closed.\n", fd); 605 result.SetStatus(eReturnStatusSuccessFinishResult); 606 } else { 607 result.AppendError(error.AsCString()); 608 result.SetStatus(eReturnStatusFailed); 609 } 610 } else { 611 result.AppendError("no platform currently selected\n"); 612 result.SetStatus(eReturnStatusFailed); 613 } 614 return result.Succeeded(); 615 } 616 }; 617 618 //---------------------------------------------------------------------- 619 // "platform fread" 620 //---------------------------------------------------------------------- 621 622 static OptionDefinition g_platform_fread_options[] = { 623 // clang-format off 624 { LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeIndex, "Offset into the file at which to start reading." }, 625 { LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "Number of bytes to read from the file." }, 626 // clang-format on 627 }; 628 629 class CommandObjectPlatformFRead : public CommandObjectParsed { 630 public: 631 CommandObjectPlatformFRead(CommandInterpreter &interpreter) 632 : CommandObjectParsed(interpreter, "platform file read", 633 "Read data from a file on the remote end.", nullptr, 634 0), 635 m_options() {} 636 637 ~CommandObjectPlatformFRead() override = default; 638 639 bool DoExecute(Args &args, CommandReturnObject &result) override { 640 PlatformSP platform_sp( 641 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); 642 if (platform_sp) { 643 std::string cmd_line; 644 args.GetCommandString(cmd_line); 645 const lldb::user_id_t fd = 646 StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX); 647 std::string buffer(m_options.m_count, 0); 648 Error error; 649 uint32_t retcode = platform_sp->ReadFile( 650 fd, m_options.m_offset, &buffer[0], m_options.m_count, error); 651 result.AppendMessageWithFormat("Return = %d\n", retcode); 652 result.AppendMessageWithFormat("Data = \"%s\"\n", buffer.c_str()); 653 result.SetStatus(eReturnStatusSuccessFinishResult); 654 } else { 655 result.AppendError("no platform currently selected\n"); 656 result.SetStatus(eReturnStatusFailed); 657 } 658 return result.Succeeded(); 659 } 660 661 Options *GetOptions() override { return &m_options; } 662 663 protected: 664 class CommandOptions : public Options { 665 public: 666 CommandOptions() : Options() {} 667 668 ~CommandOptions() override = default; 669 670 Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 671 ExecutionContext *execution_context) override { 672 Error error; 673 char short_option = (char)m_getopt_table[option_idx].val; 674 675 switch (short_option) { 676 case 'o': 677 if (option_arg.getAsInteger(0, m_offset)) 678 error.SetErrorStringWithFormat("invalid offset: '%s'", 679 option_arg.str().c_str()); 680 break; 681 case 'c': 682 if (option_arg.getAsInteger(0, m_count)) 683 error.SetErrorStringWithFormat("invalid offset: '%s'", 684 option_arg.str().c_str()); 685 break; 686 default: 687 error.SetErrorStringWithFormat("unrecognized option '%c'", 688 short_option); 689 break; 690 } 691 692 return error; 693 } 694 695 void OptionParsingStarting(ExecutionContext *execution_context) override { 696 m_offset = 0; 697 m_count = 1; 698 } 699 700 llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 701 return llvm::makeArrayRef(g_platform_fread_options); 702 } 703 704 // Instance variables to hold the values for command options. 705 706 uint32_t m_offset; 707 uint32_t m_count; 708 }; 709 710 CommandOptions m_options; 711 }; 712 713 //---------------------------------------------------------------------- 714 // "platform fwrite" 715 //---------------------------------------------------------------------- 716 717 static OptionDefinition g_platform_fwrite_options[] = { 718 // clang-format off 719 { LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeIndex, "Offset into the file at which to start reading." }, 720 { LLDB_OPT_SET_1, false, "data", 'd', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeValue, "Text to write to the file." }, 721 // clang-format on 722 }; 723 724 class CommandObjectPlatformFWrite : public CommandObjectParsed { 725 public: 726 CommandObjectPlatformFWrite(CommandInterpreter &interpreter) 727 : CommandObjectParsed(interpreter, "platform file write", 728 "Write data to a file on the remote end.", nullptr, 729 0), 730 m_options() {} 731 732 ~CommandObjectPlatformFWrite() override = default; 733 734 bool DoExecute(Args &args, CommandReturnObject &result) override { 735 PlatformSP platform_sp( 736 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); 737 if (platform_sp) { 738 std::string cmd_line; 739 args.GetCommandString(cmd_line); 740 Error error; 741 const lldb::user_id_t fd = 742 StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX); 743 uint32_t retcode = 744 platform_sp->WriteFile(fd, m_options.m_offset, &m_options.m_data[0], 745 m_options.m_data.size(), error); 746 result.AppendMessageWithFormat("Return = %d\n", retcode); 747 result.SetStatus(eReturnStatusSuccessFinishResult); 748 } else { 749 result.AppendError("no platform currently selected\n"); 750 result.SetStatus(eReturnStatusFailed); 751 } 752 return result.Succeeded(); 753 } 754 755 Options *GetOptions() override { return &m_options; } 756 757 protected: 758 class CommandOptions : public Options { 759 public: 760 CommandOptions() : Options() {} 761 762 ~CommandOptions() override = default; 763 764 Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 765 ExecutionContext *execution_context) override { 766 Error error; 767 char short_option = (char)m_getopt_table[option_idx].val; 768 769 switch (short_option) { 770 case 'o': 771 if (option_arg.getAsInteger(0, m_offset)) 772 error.SetErrorStringWithFormat("invalid offset: '%s'", 773 option_arg.str().c_str()); 774 break; 775 case 'd': 776 m_data.assign(option_arg); 777 break; 778 default: 779 error.SetErrorStringWithFormat("unrecognized option '%c'", 780 short_option); 781 break; 782 } 783 784 return error; 785 } 786 787 void OptionParsingStarting(ExecutionContext *execution_context) override { 788 m_offset = 0; 789 m_data.clear(); 790 } 791 792 llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 793 return llvm::makeArrayRef(g_platform_fwrite_options); 794 } 795 796 // Instance variables to hold the values for command options. 797 798 uint32_t m_offset; 799 std::string m_data; 800 }; 801 802 CommandOptions m_options; 803 }; 804 805 class CommandObjectPlatformFile : public CommandObjectMultiword { 806 public: 807 //------------------------------------------------------------------ 808 // Constructors and Destructors 809 //------------------------------------------------------------------ 810 CommandObjectPlatformFile(CommandInterpreter &interpreter) 811 : CommandObjectMultiword( 812 interpreter, "platform file", 813 "Commands to access files on the current platform.", 814 "platform file [open|close|read|write] ...") { 815 LoadSubCommand( 816 "open", CommandObjectSP(new CommandObjectPlatformFOpen(interpreter))); 817 LoadSubCommand( 818 "close", CommandObjectSP(new CommandObjectPlatformFClose(interpreter))); 819 LoadSubCommand( 820 "read", CommandObjectSP(new CommandObjectPlatformFRead(interpreter))); 821 LoadSubCommand( 822 "write", CommandObjectSP(new CommandObjectPlatformFWrite(interpreter))); 823 } 824 825 ~CommandObjectPlatformFile() override = default; 826 827 private: 828 //------------------------------------------------------------------ 829 // For CommandObjectPlatform only 830 //------------------------------------------------------------------ 831 DISALLOW_COPY_AND_ASSIGN(CommandObjectPlatformFile); 832 }; 833 834 //---------------------------------------------------------------------- 835 // "platform get-file remote-file-path host-file-path" 836 //---------------------------------------------------------------------- 837 class CommandObjectPlatformGetFile : public CommandObjectParsed { 838 public: 839 CommandObjectPlatformGetFile(CommandInterpreter &interpreter) 840 : CommandObjectParsed( 841 interpreter, "platform get-file", 842 "Transfer a file from the remote end to the local host.", 843 "platform get-file <remote-file-spec> <local-file-spec>", 0) { 844 SetHelpLong( 845 R"(Examples: 846 847 (lldb) platform get-file /the/remote/file/path /the/local/file/path 848 849 Transfer a file from the remote end with file path /the/remote/file/path to the local host.)"); 850 851 CommandArgumentEntry arg1, arg2; 852 CommandArgumentData file_arg_remote, file_arg_host; 853 854 // Define the first (and only) variant of this arg. 855 file_arg_remote.arg_type = eArgTypeFilename; 856 file_arg_remote.arg_repetition = eArgRepeatPlain; 857 // There is only one variant this argument could be; put it into the 858 // argument entry. 859 arg1.push_back(file_arg_remote); 860 861 // Define the second (and only) variant of this arg. 862 file_arg_host.arg_type = eArgTypeFilename; 863 file_arg_host.arg_repetition = eArgRepeatPlain; 864 // There is only one variant this argument could be; put it into the 865 // argument entry. 866 arg2.push_back(file_arg_host); 867 868 // Push the data for the first and the second arguments into the m_arguments 869 // vector. 870 m_arguments.push_back(arg1); 871 m_arguments.push_back(arg2); 872 } 873 874 ~CommandObjectPlatformGetFile() override = default; 875 876 bool DoExecute(Args &args, CommandReturnObject &result) override { 877 // If the number of arguments is incorrect, issue an error message. 878 if (args.GetArgumentCount() != 2) { 879 result.GetErrorStream().Printf("error: required arguments missing; " 880 "specify both the source and destination " 881 "file paths\n"); 882 result.SetStatus(eReturnStatusFailed); 883 return false; 884 } 885 886 PlatformSP platform_sp( 887 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); 888 if (platform_sp) { 889 const char *remote_file_path = args.GetArgumentAtIndex(0); 890 const char *local_file_path = args.GetArgumentAtIndex(1); 891 Error error = platform_sp->GetFile(FileSpec(remote_file_path, false), 892 FileSpec(local_file_path, false)); 893 if (error.Success()) { 894 result.AppendMessageWithFormat( 895 "successfully get-file from %s (remote) to %s (host)\n", 896 remote_file_path, local_file_path); 897 result.SetStatus(eReturnStatusSuccessFinishResult); 898 } else { 899 result.AppendMessageWithFormat("get-file failed: %s\n", 900 error.AsCString()); 901 result.SetStatus(eReturnStatusFailed); 902 } 903 } else { 904 result.AppendError("no platform currently selected\n"); 905 result.SetStatus(eReturnStatusFailed); 906 } 907 return result.Succeeded(); 908 } 909 }; 910 911 //---------------------------------------------------------------------- 912 // "platform get-size remote-file-path" 913 //---------------------------------------------------------------------- 914 class CommandObjectPlatformGetSize : public CommandObjectParsed { 915 public: 916 CommandObjectPlatformGetSize(CommandInterpreter &interpreter) 917 : CommandObjectParsed(interpreter, "platform get-size", 918 "Get the file size from the remote end.", 919 "platform get-size <remote-file-spec>", 0) { 920 SetHelpLong( 921 R"(Examples: 922 923 (lldb) platform get-size /the/remote/file/path 924 925 Get the file size from the remote end with path /the/remote/file/path.)"); 926 927 CommandArgumentEntry arg1; 928 CommandArgumentData file_arg_remote; 929 930 // Define the first (and only) variant of this arg. 931 file_arg_remote.arg_type = eArgTypeFilename; 932 file_arg_remote.arg_repetition = eArgRepeatPlain; 933 // There is only one variant this argument could be; put it into the 934 // argument entry. 935 arg1.push_back(file_arg_remote); 936 937 // Push the data for the first argument into the m_arguments vector. 938 m_arguments.push_back(arg1); 939 } 940 941 ~CommandObjectPlatformGetSize() override = default; 942 943 bool DoExecute(Args &args, CommandReturnObject &result) override { 944 // If the number of arguments is incorrect, issue an error message. 945 if (args.GetArgumentCount() != 1) { 946 result.GetErrorStream().Printf("error: required argument missing; " 947 "specify the source file path as the only " 948 "argument\n"); 949 result.SetStatus(eReturnStatusFailed); 950 return false; 951 } 952 953 PlatformSP platform_sp( 954 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); 955 if (platform_sp) { 956 std::string remote_file_path(args.GetArgumentAtIndex(0)); 957 user_id_t size = 958 platform_sp->GetFileSize(FileSpec(remote_file_path, false)); 959 if (size != UINT64_MAX) { 960 result.AppendMessageWithFormat("File size of %s (remote): %" PRIu64 961 "\n", 962 remote_file_path.c_str(), size); 963 result.SetStatus(eReturnStatusSuccessFinishResult); 964 } else { 965 result.AppendMessageWithFormat( 966 "Error getting file size of %s (remote)\n", 967 remote_file_path.c_str()); 968 result.SetStatus(eReturnStatusFailed); 969 } 970 } else { 971 result.AppendError("no platform currently selected\n"); 972 result.SetStatus(eReturnStatusFailed); 973 } 974 return result.Succeeded(); 975 } 976 }; 977 978 //---------------------------------------------------------------------- 979 // "platform put-file" 980 //---------------------------------------------------------------------- 981 class CommandObjectPlatformPutFile : public CommandObjectParsed { 982 public: 983 CommandObjectPlatformPutFile(CommandInterpreter &interpreter) 984 : CommandObjectParsed( 985 interpreter, "platform put-file", 986 "Transfer a file from this system to the remote end.", nullptr, 0) { 987 } 988 989 ~CommandObjectPlatformPutFile() override = default; 990 991 bool DoExecute(Args &args, CommandReturnObject &result) override { 992 const char *src = args.GetArgumentAtIndex(0); 993 const char *dst = args.GetArgumentAtIndex(1); 994 995 FileSpec src_fs(src, true); 996 FileSpec dst_fs(dst ? dst : src_fs.GetFilename().GetCString(), false); 997 998 PlatformSP platform_sp( 999 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); 1000 if (platform_sp) { 1001 Error error(platform_sp->PutFile(src_fs, dst_fs)); 1002 if (error.Success()) { 1003 result.SetStatus(eReturnStatusSuccessFinishNoResult); 1004 } else { 1005 result.AppendError(error.AsCString()); 1006 result.SetStatus(eReturnStatusFailed); 1007 } 1008 } else { 1009 result.AppendError("no platform currently selected\n"); 1010 result.SetStatus(eReturnStatusFailed); 1011 } 1012 return result.Succeeded(); 1013 } 1014 }; 1015 1016 //---------------------------------------------------------------------- 1017 // "platform process launch" 1018 //---------------------------------------------------------------------- 1019 class CommandObjectPlatformProcessLaunch : public CommandObjectParsed { 1020 public: 1021 CommandObjectPlatformProcessLaunch(CommandInterpreter &interpreter) 1022 : CommandObjectParsed(interpreter, "platform process launch", 1023 "Launch a new process on a remote platform.", 1024 "platform process launch program", 1025 eCommandRequiresTarget | eCommandTryTargetAPILock), 1026 m_options() {} 1027 1028 ~CommandObjectPlatformProcessLaunch() override = default; 1029 1030 Options *GetOptions() override { return &m_options; } 1031 1032 protected: 1033 bool DoExecute(Args &args, CommandReturnObject &result) override { 1034 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 1035 PlatformSP platform_sp; 1036 if (target) { 1037 platform_sp = target->GetPlatform(); 1038 } 1039 if (!platform_sp) { 1040 platform_sp = 1041 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform(); 1042 } 1043 1044 if (platform_sp) { 1045 Error error; 1046 const size_t argc = args.GetArgumentCount(); 1047 Target *target = m_exe_ctx.GetTargetPtr(); 1048 Module *exe_module = target->GetExecutableModulePointer(); 1049 if (exe_module) { 1050 m_options.launch_info.GetExecutableFile() = exe_module->GetFileSpec(); 1051 llvm::SmallString<PATH_MAX> exe_path; 1052 m_options.launch_info.GetExecutableFile().GetPath(exe_path); 1053 if (!exe_path.empty()) 1054 m_options.launch_info.GetArguments().AppendArgument(exe_path); 1055 m_options.launch_info.GetArchitecture() = exe_module->GetArchitecture(); 1056 } 1057 1058 if (argc > 0) { 1059 if (m_options.launch_info.GetExecutableFile()) { 1060 // We already have an executable file, so we will use this 1061 // and all arguments to this function are extra arguments 1062 m_options.launch_info.GetArguments().AppendArguments(args); 1063 } else { 1064 // We don't have any file yet, so the first argument is our 1065 // executable, and the rest are program arguments 1066 const bool first_arg_is_executable = true; 1067 m_options.launch_info.SetArguments(args, first_arg_is_executable); 1068 } 1069 } 1070 1071 if (m_options.launch_info.GetExecutableFile()) { 1072 Debugger &debugger = m_interpreter.GetDebugger(); 1073 1074 if (argc == 0) 1075 target->GetRunArguments(m_options.launch_info.GetArguments()); 1076 1077 ProcessSP process_sp(platform_sp->DebugProcess( 1078 m_options.launch_info, debugger, target, error)); 1079 if (process_sp && process_sp->IsAlive()) { 1080 result.SetStatus(eReturnStatusSuccessFinishNoResult); 1081 return true; 1082 } 1083 1084 if (error.Success()) 1085 result.AppendError("process launch failed"); 1086 else 1087 result.AppendError(error.AsCString()); 1088 result.SetStatus(eReturnStatusFailed); 1089 } else { 1090 result.AppendError("'platform process launch' uses the current target " 1091 "file and arguments, or the executable and its " 1092 "arguments can be specified in this command"); 1093 result.SetStatus(eReturnStatusFailed); 1094 return false; 1095 } 1096 } else { 1097 result.AppendError("no platform is selected\n"); 1098 } 1099 return result.Succeeded(); 1100 } 1101 1102 protected: 1103 ProcessLaunchCommandOptions m_options; 1104 }; 1105 1106 //---------------------------------------------------------------------- 1107 // "platform process list" 1108 //---------------------------------------------------------------------- 1109 1110 OptionDefinition g_platform_process_list_options[] = { 1111 // clang-format off 1112 { LLDB_OPT_SET_1, false, "pid", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePid, "List the process info for a specific process ID." }, 1113 { LLDB_OPT_SET_2, true, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeProcessName, "Find processes with executable basenames that match a string." }, 1114 { LLDB_OPT_SET_3, true, "ends-with", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeProcessName, "Find processes with executable basenames that end with a string." }, 1115 { LLDB_OPT_SET_4, true, "starts-with", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeProcessName, "Find processes with executable basenames that start with a string." }, 1116 { LLDB_OPT_SET_5, true, "contains", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeProcessName, "Find processes with executable basenames that contain a string." }, 1117 { LLDB_OPT_SET_6, true, "regex", 'r', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, "Find processes with executable basenames that match a regular expression." }, 1118 { LLDB_OPT_SET_FROM_TO(2, 6), false, "parent", 'P', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePid, "Find processes that have a matching parent process ID." }, 1119 { LLDB_OPT_SET_FROM_TO(2, 6), false, "uid", 'u', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Find processes that have a matching user ID." }, 1120 { LLDB_OPT_SET_FROM_TO(2, 6), false, "euid", 'U', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Find processes that have a matching effective user ID." }, 1121 { LLDB_OPT_SET_FROM_TO(2, 6), false, "gid", 'g', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Find processes that have a matching group ID." }, 1122 { LLDB_OPT_SET_FROM_TO(2, 6), false, "egid", 'G', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Find processes that have a matching effective group ID." }, 1123 { LLDB_OPT_SET_FROM_TO(2, 6), false, "arch", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeArchitecture, "Find processes that have a matching architecture." }, 1124 { LLDB_OPT_SET_FROM_TO(1, 6), false, "show-args", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Show process arguments instead of the process executable basename." }, 1125 { LLDB_OPT_SET_FROM_TO(1, 6), false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable verbose output." }, 1126 // clang-format on 1127 }; 1128 1129 class CommandObjectPlatformProcessList : public CommandObjectParsed { 1130 public: 1131 CommandObjectPlatformProcessList(CommandInterpreter &interpreter) 1132 : CommandObjectParsed(interpreter, "platform process list", 1133 "List processes on a remote platform by name, pid, " 1134 "or many other matching attributes.", 1135 "platform process list", 0), 1136 m_options() {} 1137 1138 ~CommandObjectPlatformProcessList() override = default; 1139 1140 Options *GetOptions() override { return &m_options; } 1141 1142 protected: 1143 bool DoExecute(Args &args, CommandReturnObject &result) override { 1144 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 1145 PlatformSP platform_sp; 1146 if (target) { 1147 platform_sp = target->GetPlatform(); 1148 } 1149 if (!platform_sp) { 1150 platform_sp = 1151 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform(); 1152 } 1153 1154 if (platform_sp) { 1155 Error error; 1156 if (args.GetArgumentCount() == 0) { 1157 if (platform_sp) { 1158 Stream &ostrm = result.GetOutputStream(); 1159 1160 lldb::pid_t pid = 1161 m_options.match_info.GetProcessInfo().GetProcessID(); 1162 if (pid != LLDB_INVALID_PROCESS_ID) { 1163 ProcessInstanceInfo proc_info; 1164 if (platform_sp->GetProcessInfo(pid, proc_info)) { 1165 ProcessInstanceInfo::DumpTableHeader(ostrm, platform_sp.get(), 1166 m_options.show_args, 1167 m_options.verbose); 1168 proc_info.DumpAsTableRow(ostrm, platform_sp.get(), 1169 m_options.show_args, m_options.verbose); 1170 result.SetStatus(eReturnStatusSuccessFinishResult); 1171 } else { 1172 result.AppendErrorWithFormat( 1173 "no process found with pid = %" PRIu64 "\n", pid); 1174 result.SetStatus(eReturnStatusFailed); 1175 } 1176 } else { 1177 ProcessInstanceInfoList proc_infos; 1178 const uint32_t matches = 1179 platform_sp->FindProcesses(m_options.match_info, proc_infos); 1180 const char *match_desc = nullptr; 1181 const char *match_name = 1182 m_options.match_info.GetProcessInfo().GetName(); 1183 if (match_name && match_name[0]) { 1184 switch (m_options.match_info.GetNameMatchType()) { 1185 case eNameMatchIgnore: 1186 break; 1187 case eNameMatchEquals: 1188 match_desc = "matched"; 1189 break; 1190 case eNameMatchContains: 1191 match_desc = "contained"; 1192 break; 1193 case eNameMatchStartsWith: 1194 match_desc = "started with"; 1195 break; 1196 case eNameMatchEndsWith: 1197 match_desc = "ended with"; 1198 break; 1199 case eNameMatchRegularExpression: 1200 match_desc = "matched the regular expression"; 1201 break; 1202 } 1203 } 1204 1205 if (matches == 0) { 1206 if (match_desc) 1207 result.AppendErrorWithFormat( 1208 "no processes were found that %s \"%s\" on the \"%s\" " 1209 "platform\n", 1210 match_desc, match_name, 1211 platform_sp->GetPluginName().GetCString()); 1212 else 1213 result.AppendErrorWithFormat( 1214 "no processes were found on the \"%s\" platform\n", 1215 platform_sp->GetPluginName().GetCString()); 1216 result.SetStatus(eReturnStatusFailed); 1217 } else { 1218 result.AppendMessageWithFormat( 1219 "%u matching process%s found on \"%s\"", matches, 1220 matches > 1 ? "es were" : " was", 1221 platform_sp->GetName().GetCString()); 1222 if (match_desc) 1223 result.AppendMessageWithFormat(" whose name %s \"%s\"", 1224 match_desc, match_name); 1225 result.AppendMessageWithFormat("\n"); 1226 ProcessInstanceInfo::DumpTableHeader(ostrm, platform_sp.get(), 1227 m_options.show_args, 1228 m_options.verbose); 1229 for (uint32_t i = 0; i < matches; ++i) { 1230 proc_infos.GetProcessInfoAtIndex(i).DumpAsTableRow( 1231 ostrm, platform_sp.get(), m_options.show_args, 1232 m_options.verbose); 1233 } 1234 } 1235 } 1236 } 1237 } else { 1238 result.AppendError("invalid args: process list takes only options\n"); 1239 result.SetStatus(eReturnStatusFailed); 1240 } 1241 } else { 1242 result.AppendError("no platform is selected\n"); 1243 result.SetStatus(eReturnStatusFailed); 1244 } 1245 return result.Succeeded(); 1246 } 1247 1248 class CommandOptions : public Options { 1249 public: 1250 CommandOptions() 1251 : Options(), match_info(), show_args(false), verbose(false) { 1252 static std::once_flag g_once_flag; 1253 std::call_once(g_once_flag, []() { 1254 PosixPlatformCommandOptionValidator *posix_validator = 1255 new PosixPlatformCommandOptionValidator(); 1256 for (auto &Option : g_platform_process_list_options) { 1257 switch (Option.short_option) { 1258 case 'u': 1259 case 'U': 1260 case 'g': 1261 case 'G': 1262 Option.validator = posix_validator; 1263 break; 1264 default: 1265 break; 1266 } 1267 } 1268 }); 1269 } 1270 1271 ~CommandOptions() override = default; 1272 1273 Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1274 ExecutionContext *execution_context) override { 1275 Error error; 1276 const int short_option = m_getopt_table[option_idx].val; 1277 bool success = false; 1278 1279 uint32_t id = LLDB_INVALID_PROCESS_ID; 1280 success = !option_arg.getAsInteger(0, id); 1281 switch (short_option) { 1282 case 'p': { 1283 match_info.GetProcessInfo().SetProcessID(id); 1284 if (!success) 1285 error.SetErrorStringWithFormat("invalid process ID string: '%s'", 1286 option_arg.str().c_str()); 1287 break; 1288 } 1289 case 'P': 1290 match_info.GetProcessInfo().SetParentProcessID(id); 1291 if (!success) 1292 error.SetErrorStringWithFormat( 1293 "invalid parent process ID string: '%s'", 1294 option_arg.str().c_str()); 1295 break; 1296 1297 case 'u': 1298 match_info.GetProcessInfo().SetUserID(success ? id : UINT32_MAX); 1299 if (!success) 1300 error.SetErrorStringWithFormat("invalid user ID string: '%s'", 1301 option_arg.str().c_str()); 1302 break; 1303 1304 case 'U': 1305 match_info.GetProcessInfo().SetEffectiveUserID(success ? id 1306 : UINT32_MAX); 1307 if (!success) 1308 error.SetErrorStringWithFormat( 1309 "invalid effective user ID string: '%s'", 1310 option_arg.str().c_str()); 1311 break; 1312 1313 case 'g': 1314 match_info.GetProcessInfo().SetGroupID(success ? id : UINT32_MAX); 1315 if (!success) 1316 error.SetErrorStringWithFormat("invalid group ID string: '%s'", 1317 option_arg.str().c_str()); 1318 break; 1319 1320 case 'G': 1321 match_info.GetProcessInfo().SetEffectiveGroupID(success ? id 1322 : UINT32_MAX); 1323 if (!success) 1324 error.SetErrorStringWithFormat( 1325 "invalid effective group ID string: '%s'", 1326 option_arg.str().c_str()); 1327 break; 1328 1329 case 'a': { 1330 TargetSP target_sp = 1331 execution_context ? execution_context->GetTargetSP() : TargetSP(); 1332 DebuggerSP debugger_sp = 1333 target_sp ? target_sp->GetDebugger().shared_from_this() 1334 : DebuggerSP(); 1335 PlatformSP platform_sp = 1336 debugger_sp ? debugger_sp->GetPlatformList().GetSelectedPlatform() 1337 : PlatformSP(); 1338 match_info.GetProcessInfo().GetArchitecture().SetTriple( 1339 option_arg, platform_sp.get()); 1340 } break; 1341 1342 case 'n': 1343 match_info.GetProcessInfo().GetExecutableFile().SetFile(option_arg, 1344 false); 1345 match_info.SetNameMatchType(eNameMatchEquals); 1346 break; 1347 1348 case 'e': 1349 match_info.GetProcessInfo().GetExecutableFile().SetFile(option_arg, 1350 false); 1351 match_info.SetNameMatchType(eNameMatchEndsWith); 1352 break; 1353 1354 case 's': 1355 match_info.GetProcessInfo().GetExecutableFile().SetFile(option_arg, 1356 false); 1357 match_info.SetNameMatchType(eNameMatchStartsWith); 1358 break; 1359 1360 case 'c': 1361 match_info.GetProcessInfo().GetExecutableFile().SetFile(option_arg, 1362 false); 1363 match_info.SetNameMatchType(eNameMatchContains); 1364 break; 1365 1366 case 'r': 1367 match_info.GetProcessInfo().GetExecutableFile().SetFile(option_arg, 1368 false); 1369 match_info.SetNameMatchType(eNameMatchRegularExpression); 1370 break; 1371 1372 case 'A': 1373 show_args = true; 1374 break; 1375 1376 case 'v': 1377 verbose = true; 1378 break; 1379 1380 default: 1381 error.SetErrorStringWithFormat("unrecognized option '%c'", 1382 short_option); 1383 break; 1384 } 1385 1386 return error; 1387 } 1388 1389 void OptionParsingStarting(ExecutionContext *execution_context) override { 1390 match_info.Clear(); 1391 show_args = false; 1392 verbose = false; 1393 } 1394 1395 llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 1396 return llvm::makeArrayRef(g_platform_process_list_options); 1397 } 1398 1399 // Instance variables to hold the values for command options. 1400 1401 ProcessInstanceInfoMatch match_info; 1402 bool show_args; 1403 bool verbose; 1404 }; 1405 1406 CommandOptions m_options; 1407 }; 1408 1409 //---------------------------------------------------------------------- 1410 // "platform process info" 1411 //---------------------------------------------------------------------- 1412 class CommandObjectPlatformProcessInfo : public CommandObjectParsed { 1413 public: 1414 CommandObjectPlatformProcessInfo(CommandInterpreter &interpreter) 1415 : CommandObjectParsed( 1416 interpreter, "platform process info", 1417 "Get detailed information for one or more process by process ID.", 1418 "platform process info <pid> [<pid> <pid> ...]", 0) { 1419 CommandArgumentEntry arg; 1420 CommandArgumentData pid_args; 1421 1422 // Define the first (and only) variant of this arg. 1423 pid_args.arg_type = eArgTypePid; 1424 pid_args.arg_repetition = eArgRepeatStar; 1425 1426 // There is only one variant this argument could be; put it into the 1427 // argument entry. 1428 arg.push_back(pid_args); 1429 1430 // Push the data for the first argument into the m_arguments vector. 1431 m_arguments.push_back(arg); 1432 } 1433 1434 ~CommandObjectPlatformProcessInfo() override = default; 1435 1436 protected: 1437 bool DoExecute(Args &args, CommandReturnObject &result) override { 1438 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 1439 PlatformSP platform_sp; 1440 if (target) { 1441 platform_sp = target->GetPlatform(); 1442 } 1443 if (!platform_sp) { 1444 platform_sp = 1445 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform(); 1446 } 1447 1448 if (platform_sp) { 1449 const size_t argc = args.GetArgumentCount(); 1450 if (argc > 0) { 1451 Error error; 1452 1453 if (platform_sp->IsConnected()) { 1454 Stream &ostrm = result.GetOutputStream(); 1455 for (auto &entry : args.entries()) { 1456 lldb::pid_t pid; 1457 if (entry.ref.getAsInteger(0, pid)) { 1458 result.AppendErrorWithFormat("invalid process ID argument '%s'", 1459 entry.ref.str().c_str()); 1460 result.SetStatus(eReturnStatusFailed); 1461 break; 1462 } else { 1463 ProcessInstanceInfo proc_info; 1464 if (platform_sp->GetProcessInfo(pid, proc_info)) { 1465 ostrm.Printf("Process information for process %" PRIu64 ":\n", 1466 pid); 1467 proc_info.Dump(ostrm, platform_sp.get()); 1468 } else { 1469 ostrm.Printf("error: no process information is available for " 1470 "process %" PRIu64 "\n", 1471 pid); 1472 } 1473 ostrm.EOL(); 1474 } 1475 } 1476 } else { 1477 // Not connected... 1478 result.AppendErrorWithFormat( 1479 "not connected to '%s'", 1480 platform_sp->GetPluginName().GetCString()); 1481 result.SetStatus(eReturnStatusFailed); 1482 } 1483 } else { 1484 // No args 1485 result.AppendError("one or more process id(s) must be specified"); 1486 result.SetStatus(eReturnStatusFailed); 1487 } 1488 } else { 1489 result.AppendError("no platform is currently selected"); 1490 result.SetStatus(eReturnStatusFailed); 1491 } 1492 return result.Succeeded(); 1493 } 1494 }; 1495 1496 static OptionDefinition g_platform_process_attach_options[] = { 1497 // clang-format off 1498 { LLDB_OPT_SET_ALL, false, "plugin", 'P', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePlugin, "Name of the process plugin you want to use." }, 1499 { LLDB_OPT_SET_1, false, "pid", 'p', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePid, "The process ID of an existing process to attach to." }, 1500 { LLDB_OPT_SET_2, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeProcessName, "The name of the process to attach to." }, 1501 { LLDB_OPT_SET_2, false, "waitfor", 'w', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Wait for the process with <process-name> to launch." }, 1502 // clang-format on 1503 }; 1504 1505 class CommandObjectPlatformProcessAttach : public CommandObjectParsed { 1506 public: 1507 class CommandOptions : public Options { 1508 public: 1509 CommandOptions() : Options() { 1510 // Keep default values of all options in one place: OptionParsingStarting 1511 // () 1512 OptionParsingStarting(nullptr); 1513 } 1514 1515 ~CommandOptions() override = default; 1516 1517 Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1518 ExecutionContext *execution_context) override { 1519 Error error; 1520 char short_option = (char)m_getopt_table[option_idx].val; 1521 switch (short_option) { 1522 case 'p': { 1523 lldb::pid_t pid = LLDB_INVALID_PROCESS_ID; 1524 if (option_arg.getAsInteger(0, pid)) { 1525 error.SetErrorStringWithFormat("invalid process ID '%s'", 1526 option_arg.str().c_str()); 1527 } else { 1528 attach_info.SetProcessID(pid); 1529 } 1530 } break; 1531 1532 case 'P': 1533 attach_info.SetProcessPluginName(option_arg); 1534 break; 1535 1536 case 'n': 1537 attach_info.GetExecutableFile().SetFile(option_arg, false); 1538 break; 1539 1540 case 'w': 1541 attach_info.SetWaitForLaunch(true); 1542 break; 1543 1544 default: 1545 error.SetErrorStringWithFormat("invalid short option character '%c'", 1546 short_option); 1547 break; 1548 } 1549 return error; 1550 } 1551 1552 void OptionParsingStarting(ExecutionContext *execution_context) override { 1553 attach_info.Clear(); 1554 } 1555 1556 llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 1557 return llvm::makeArrayRef(g_platform_process_attach_options); 1558 } 1559 1560 bool HandleOptionArgumentCompletion( 1561 Args &input, int cursor_index, int char_pos, 1562 OptionElementVector &opt_element_vector, int opt_element_index, 1563 int match_start_point, int max_return_elements, 1564 CommandInterpreter &interpreter, bool &word_complete, 1565 StringList &matches) override { 1566 int opt_arg_pos = opt_element_vector[opt_element_index].opt_arg_pos; 1567 int opt_defs_index = opt_element_vector[opt_element_index].opt_defs_index; 1568 1569 // We are only completing the name option for now... 1570 1571 if (GetDefinitions()[opt_defs_index].short_option == 'n') { 1572 // Are we in the name? 1573 1574 // Look to see if there is a -P argument provided, and if so use that 1575 // plugin, otherwise 1576 // use the default plugin. 1577 1578 const char *partial_name = nullptr; 1579 partial_name = input.GetArgumentAtIndex(opt_arg_pos); 1580 1581 PlatformSP platform_sp(interpreter.GetPlatform(true)); 1582 if (platform_sp) { 1583 ProcessInstanceInfoList process_infos; 1584 ProcessInstanceInfoMatch match_info; 1585 if (partial_name) { 1586 match_info.GetProcessInfo().GetExecutableFile().SetFile( 1587 partial_name, false); 1588 match_info.SetNameMatchType(eNameMatchStartsWith); 1589 } 1590 platform_sp->FindProcesses(match_info, process_infos); 1591 const uint32_t num_matches = process_infos.GetSize(); 1592 if (num_matches > 0) { 1593 for (uint32_t i = 0; i < num_matches; ++i) { 1594 matches.AppendString( 1595 process_infos.GetProcessNameAtIndex(i), 1596 process_infos.GetProcessNameLengthAtIndex(i)); 1597 } 1598 } 1599 } 1600 } 1601 1602 return false; 1603 } 1604 1605 // Options table: Required for subclasses of Options. 1606 1607 static OptionDefinition g_option_table[]; 1608 1609 // Instance variables to hold the values for command options. 1610 1611 ProcessAttachInfo attach_info; 1612 }; 1613 1614 CommandObjectPlatformProcessAttach(CommandInterpreter &interpreter) 1615 : CommandObjectParsed(interpreter, "platform process attach", 1616 "Attach to a process.", 1617 "platform process attach <cmd-options>"), 1618 m_options() {} 1619 1620 ~CommandObjectPlatformProcessAttach() override = default; 1621 1622 bool DoExecute(Args &command, CommandReturnObject &result) override { 1623 PlatformSP platform_sp( 1624 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); 1625 if (platform_sp) { 1626 Error err; 1627 ProcessSP remote_process_sp = platform_sp->Attach( 1628 m_options.attach_info, m_interpreter.GetDebugger(), nullptr, err); 1629 if (err.Fail()) { 1630 result.AppendError(err.AsCString()); 1631 result.SetStatus(eReturnStatusFailed); 1632 } else if (!remote_process_sp) { 1633 result.AppendError("could not attach: unknown reason"); 1634 result.SetStatus(eReturnStatusFailed); 1635 } else 1636 result.SetStatus(eReturnStatusSuccessFinishResult); 1637 } else { 1638 result.AppendError("no platform is currently selected"); 1639 result.SetStatus(eReturnStatusFailed); 1640 } 1641 return result.Succeeded(); 1642 } 1643 1644 Options *GetOptions() override { return &m_options; } 1645 1646 protected: 1647 CommandOptions m_options; 1648 }; 1649 1650 class CommandObjectPlatformProcess : public CommandObjectMultiword { 1651 public: 1652 //------------------------------------------------------------------ 1653 // Constructors and Destructors 1654 //------------------------------------------------------------------ 1655 CommandObjectPlatformProcess(CommandInterpreter &interpreter) 1656 : CommandObjectMultiword(interpreter, "platform process", 1657 "Commands to query, launch and attach to " 1658 "processes on the current platform.", 1659 "platform process [attach|launch|list] ...") { 1660 LoadSubCommand( 1661 "attach", 1662 CommandObjectSP(new CommandObjectPlatformProcessAttach(interpreter))); 1663 LoadSubCommand( 1664 "launch", 1665 CommandObjectSP(new CommandObjectPlatformProcessLaunch(interpreter))); 1666 LoadSubCommand("info", CommandObjectSP(new CommandObjectPlatformProcessInfo( 1667 interpreter))); 1668 LoadSubCommand("list", CommandObjectSP(new CommandObjectPlatformProcessList( 1669 interpreter))); 1670 } 1671 1672 ~CommandObjectPlatformProcess() override = default; 1673 1674 private: 1675 //------------------------------------------------------------------ 1676 // For CommandObjectPlatform only 1677 //------------------------------------------------------------------ 1678 DISALLOW_COPY_AND_ASSIGN(CommandObjectPlatformProcess); 1679 }; 1680 1681 //---------------------------------------------------------------------- 1682 // "platform shell" 1683 //---------------------------------------------------------------------- 1684 static OptionDefinition g_platform_shell_options[] = { 1685 // clang-format off 1686 { LLDB_OPT_SET_ALL, false, "timeout", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeValue, "Seconds to wait for the remote host to finish running the command." }, 1687 // clang-format on 1688 }; 1689 1690 class CommandObjectPlatformShell : public CommandObjectRaw { 1691 public: 1692 class CommandOptions : public Options { 1693 public: 1694 CommandOptions() : Options(), timeout(10) {} 1695 1696 ~CommandOptions() override = default; 1697 1698 llvm::ArrayRef<OptionDefinition> GetDefinitions() override { 1699 return llvm::makeArrayRef(g_platform_shell_options); 1700 } 1701 1702 Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, 1703 ExecutionContext *execution_context) override { 1704 Error error; 1705 1706 const char short_option = (char)GetDefinitions()[option_idx].short_option; 1707 1708 switch (short_option) { 1709 case 't': 1710 timeout = 10; 1711 if (option_arg.getAsInteger(10, timeout)) 1712 error.SetErrorStringWithFormat( 1713 "could not convert \"%s\" to a numeric value.", 1714 option_arg.str().c_str()); 1715 break; 1716 default: 1717 error.SetErrorStringWithFormat("invalid short option character '%c'", 1718 short_option); 1719 break; 1720 } 1721 1722 return error; 1723 } 1724 1725 void OptionParsingStarting(ExecutionContext *execution_context) override {} 1726 1727 uint32_t timeout; 1728 }; 1729 1730 CommandObjectPlatformShell(CommandInterpreter &interpreter) 1731 : CommandObjectRaw(interpreter, "platform shell", 1732 "Run a shell command on the current platform.", 1733 "platform shell <shell-command>", 0), 1734 m_options() {} 1735 1736 ~CommandObjectPlatformShell() override = default; 1737 1738 Options *GetOptions() override { return &m_options; } 1739 1740 bool DoExecute(const char *raw_command_line, 1741 CommandReturnObject &result) override { 1742 ExecutionContext exe_ctx = GetCommandInterpreter().GetExecutionContext(); 1743 m_options.NotifyOptionParsingStarting(&exe_ctx); 1744 1745 const char *expr = nullptr; 1746 1747 // Print out an usage syntax on an empty command line. 1748 if (raw_command_line[0] == '\0') { 1749 result.GetOutputStream().Printf("%s\n", this->GetSyntax().str().c_str()); 1750 return true; 1751 } 1752 1753 if (raw_command_line[0] == '-') { 1754 // We have some options and these options MUST end with --. 1755 const char *end_options = nullptr; 1756 const char *s = raw_command_line; 1757 while (s && s[0]) { 1758 end_options = ::strstr(s, "--"); 1759 if (end_options) { 1760 end_options += 2; // Get past the "--" 1761 if (::isspace(end_options[0])) { 1762 expr = end_options; 1763 while (::isspace(*expr)) 1764 ++expr; 1765 break; 1766 } 1767 } 1768 s = end_options; 1769 } 1770 1771 if (end_options) { 1772 Args args( 1773 llvm::StringRef(raw_command_line, end_options - raw_command_line)); 1774 if (!ParseOptions(args, result)) 1775 return false; 1776 } 1777 } 1778 1779 if (expr == nullptr) 1780 expr = raw_command_line; 1781 1782 PlatformSP platform_sp( 1783 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); 1784 Error error; 1785 if (platform_sp) { 1786 FileSpec working_dir{}; 1787 std::string output; 1788 int status = -1; 1789 int signo = -1; 1790 error = (platform_sp->RunShellCommand(expr, working_dir, &status, &signo, 1791 &output, m_options.timeout)); 1792 if (!output.empty()) 1793 result.GetOutputStream().PutCString(output); 1794 if (status > 0) { 1795 if (signo > 0) { 1796 const char *signo_cstr = Host::GetSignalAsCString(signo); 1797 if (signo_cstr) 1798 result.GetOutputStream().Printf( 1799 "error: command returned with status %i and signal %s\n", 1800 status, signo_cstr); 1801 else 1802 result.GetOutputStream().Printf( 1803 "error: command returned with status %i and signal %i\n", 1804 status, signo); 1805 } else 1806 result.GetOutputStream().Printf( 1807 "error: command returned with status %i\n", status); 1808 } 1809 } else { 1810 result.GetOutputStream().Printf( 1811 "error: cannot run remote shell commands without a platform\n"); 1812 error.SetErrorString( 1813 "error: cannot run remote shell commands without a platform"); 1814 } 1815 1816 if (error.Fail()) { 1817 result.AppendError(error.AsCString()); 1818 result.SetStatus(eReturnStatusFailed); 1819 } else { 1820 result.SetStatus(eReturnStatusSuccessFinishResult); 1821 } 1822 return true; 1823 } 1824 1825 CommandOptions m_options; 1826 }; 1827 1828 //---------------------------------------------------------------------- 1829 // "platform install" - install a target to a remote end 1830 //---------------------------------------------------------------------- 1831 class CommandObjectPlatformInstall : public CommandObjectParsed { 1832 public: 1833 CommandObjectPlatformInstall(CommandInterpreter &interpreter) 1834 : CommandObjectParsed( 1835 interpreter, "platform target-install", 1836 "Install a target (bundle or executable file) to the remote end.", 1837 "platform target-install <local-thing> <remote-sandbox>", 0) {} 1838 1839 ~CommandObjectPlatformInstall() override = default; 1840 1841 bool DoExecute(Args &args, CommandReturnObject &result) override { 1842 if (args.GetArgumentCount() != 2) { 1843 result.AppendError("platform target-install takes two arguments"); 1844 result.SetStatus(eReturnStatusFailed); 1845 return false; 1846 } 1847 // TODO: move the bulk of this code over to the platform itself 1848 FileSpec src(args.GetArgumentAtIndex(0), true); 1849 FileSpec dst(args.GetArgumentAtIndex(1), false); 1850 if (!src.Exists()) { 1851 result.AppendError("source location does not exist or is not accessible"); 1852 result.SetStatus(eReturnStatusFailed); 1853 return false; 1854 } 1855 PlatformSP platform_sp( 1856 m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform()); 1857 if (!platform_sp) { 1858 result.AppendError("no platform currently selected"); 1859 result.SetStatus(eReturnStatusFailed); 1860 return false; 1861 } 1862 1863 Error error = platform_sp->Install(src, dst); 1864 if (error.Success()) { 1865 result.SetStatus(eReturnStatusSuccessFinishNoResult); 1866 } else { 1867 result.AppendErrorWithFormat("install failed: %s", error.AsCString()); 1868 result.SetStatus(eReturnStatusFailed); 1869 } 1870 return result.Succeeded(); 1871 } 1872 }; 1873 1874 CommandObjectPlatform::CommandObjectPlatform(CommandInterpreter &interpreter) 1875 : CommandObjectMultiword( 1876 interpreter, "platform", "Commands to manage and create platforms.", 1877 "platform [connect|disconnect|info|list|status|select] ...") { 1878 LoadSubCommand("select", 1879 CommandObjectSP(new CommandObjectPlatformSelect(interpreter))); 1880 LoadSubCommand("list", 1881 CommandObjectSP(new CommandObjectPlatformList(interpreter))); 1882 LoadSubCommand("status", 1883 CommandObjectSP(new CommandObjectPlatformStatus(interpreter))); 1884 LoadSubCommand("connect", CommandObjectSP( 1885 new CommandObjectPlatformConnect(interpreter))); 1886 LoadSubCommand( 1887 "disconnect", 1888 CommandObjectSP(new CommandObjectPlatformDisconnect(interpreter))); 1889 LoadSubCommand("settings", CommandObjectSP(new CommandObjectPlatformSettings( 1890 interpreter))); 1891 LoadSubCommand("mkdir", 1892 CommandObjectSP(new CommandObjectPlatformMkDir(interpreter))); 1893 LoadSubCommand("file", 1894 CommandObjectSP(new CommandObjectPlatformFile(interpreter))); 1895 LoadSubCommand("get-file", CommandObjectSP(new CommandObjectPlatformGetFile( 1896 interpreter))); 1897 LoadSubCommand("get-size", CommandObjectSP(new CommandObjectPlatformGetSize( 1898 interpreter))); 1899 LoadSubCommand("put-file", CommandObjectSP(new CommandObjectPlatformPutFile( 1900 interpreter))); 1901 LoadSubCommand("process", CommandObjectSP( 1902 new CommandObjectPlatformProcess(interpreter))); 1903 LoadSubCommand("shell", 1904 CommandObjectSP(new CommandObjectPlatformShell(interpreter))); 1905 LoadSubCommand( 1906 "target-install", 1907 CommandObjectSP(new CommandObjectPlatformInstall(interpreter))); 1908 } 1909 1910 CommandObjectPlatform::~CommandObjectPlatform() = default; 1911