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