1 //===-- SBCommandInterpreter.cpp ------------------------------------------===// 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 "lldb/lldb-types.h" 10 11 #include "lldb/Interpreter/CommandInterpreter.h" 12 #include "lldb/Interpreter/CommandObjectMultiword.h" 13 #include "lldb/Interpreter/CommandReturnObject.h" 14 #include "lldb/Target/Target.h" 15 #include "lldb/Utility/Instrumentation.h" 16 #include "lldb/Utility/Listener.h" 17 18 #include "lldb/API/SBBroadcaster.h" 19 #include "lldb/API/SBCommandInterpreter.h" 20 #include "lldb/API/SBCommandInterpreterRunOptions.h" 21 #include "lldb/API/SBCommandReturnObject.h" 22 #include "lldb/API/SBEvent.h" 23 #include "lldb/API/SBExecutionContext.h" 24 #include "lldb/API/SBListener.h" 25 #include "lldb/API/SBProcess.h" 26 #include "lldb/API/SBStream.h" 27 #include "lldb/API/SBStringList.h" 28 #include "lldb/API/SBTarget.h" 29 30 #include <memory> 31 32 using namespace lldb; 33 using namespace lldb_private; 34 35 class CommandPluginInterfaceImplementation : public CommandObjectParsed { 36 public: 37 CommandPluginInterfaceImplementation(CommandInterpreter &interpreter, 38 const char *name, 39 lldb::SBCommandPluginInterface *backend, 40 const char *help = nullptr, 41 const char *syntax = nullptr, 42 uint32_t flags = 0, 43 const char *auto_repeat_command = "") 44 : CommandObjectParsed(interpreter, name, help, syntax, flags), 45 m_backend(backend) { 46 m_auto_repeat_command = 47 auto_repeat_command == nullptr 48 ? llvm::None 49 : llvm::Optional<std::string>(auto_repeat_command); 50 } 51 52 bool IsRemovable() const override { return true; } 53 54 /// More documentation is available in lldb::CommandObject::GetRepeatCommand, 55 /// but in short, if nullptr is returned, the previous command will be 56 /// repeated, and if an empty string is returned, no commands will be 57 /// executed. 58 const char *GetRepeatCommand(Args ¤t_command_args, 59 uint32_t index) override { 60 if (!m_auto_repeat_command) 61 return nullptr; 62 else 63 return m_auto_repeat_command->c_str(); 64 } 65 66 protected: 67 bool DoExecute(Args &command, CommandReturnObject &result) override { 68 SBCommandReturnObject sb_return(result); 69 SBCommandInterpreter sb_interpreter(&m_interpreter); 70 SBDebugger debugger_sb(m_interpreter.GetDebugger().shared_from_this()); 71 bool ret = m_backend->DoExecute( 72 debugger_sb, command.GetArgumentVector(), sb_return); 73 return ret; 74 } 75 std::shared_ptr<lldb::SBCommandPluginInterface> m_backend; 76 llvm::Optional<std::string> m_auto_repeat_command; 77 }; 78 79 SBCommandInterpreter::SBCommandInterpreter(CommandInterpreter *interpreter) 80 : m_opaque_ptr(interpreter) { 81 LLDB_INSTRUMENT_VA(this, interpreter); 82 } 83 84 SBCommandInterpreter::SBCommandInterpreter(const SBCommandInterpreter &rhs) 85 : m_opaque_ptr(rhs.m_opaque_ptr) { 86 LLDB_INSTRUMENT_VA(this, rhs); 87 } 88 89 SBCommandInterpreter::~SBCommandInterpreter() = default; 90 91 const SBCommandInterpreter &SBCommandInterpreter:: 92 operator=(const SBCommandInterpreter &rhs) { 93 LLDB_INSTRUMENT_VA(this, rhs); 94 95 m_opaque_ptr = rhs.m_opaque_ptr; 96 return *this; 97 } 98 99 bool SBCommandInterpreter::IsValid() const { 100 LLDB_INSTRUMENT_VA(this); 101 return this->operator bool(); 102 } 103 SBCommandInterpreter::operator bool() const { 104 LLDB_INSTRUMENT_VA(this); 105 106 return m_opaque_ptr != nullptr; 107 } 108 109 bool SBCommandInterpreter::CommandExists(const char *cmd) { 110 LLDB_INSTRUMENT_VA(this, cmd); 111 112 return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->CommandExists(cmd) 113 : false); 114 } 115 116 bool SBCommandInterpreter::AliasExists(const char *cmd) { 117 LLDB_INSTRUMENT_VA(this, cmd); 118 119 return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->AliasExists(cmd) 120 : false); 121 } 122 123 bool SBCommandInterpreter::IsActive() { 124 LLDB_INSTRUMENT_VA(this); 125 126 return (IsValid() ? m_opaque_ptr->IsActive() : false); 127 } 128 129 bool SBCommandInterpreter::WasInterrupted() const { 130 LLDB_INSTRUMENT_VA(this); 131 132 return (IsValid() ? m_opaque_ptr->WasInterrupted() : false); 133 } 134 135 const char *SBCommandInterpreter::GetIOHandlerControlSequence(char ch) { 136 LLDB_INSTRUMENT_VA(this, ch); 137 138 return (IsValid() 139 ? m_opaque_ptr->GetDebugger() 140 .GetTopIOHandlerControlSequence(ch) 141 .GetCString() 142 : nullptr); 143 } 144 145 lldb::ReturnStatus 146 SBCommandInterpreter::HandleCommand(const char *command_line, 147 SBCommandReturnObject &result, 148 bool add_to_history) { 149 LLDB_INSTRUMENT_VA(this, command_line, result, add_to_history); 150 151 SBExecutionContext sb_exe_ctx; 152 return HandleCommand(command_line, sb_exe_ctx, result, add_to_history); 153 } 154 155 lldb::ReturnStatus SBCommandInterpreter::HandleCommand( 156 const char *command_line, SBExecutionContext &override_context, 157 SBCommandReturnObject &result, bool add_to_history) { 158 LLDB_INSTRUMENT_VA(this, command_line, override_context, result, 159 add_to_history); 160 161 result.Clear(); 162 if (command_line && IsValid()) { 163 result.ref().SetInteractive(false); 164 auto do_add_to_history = add_to_history ? eLazyBoolYes : eLazyBoolNo; 165 if (override_context.get()) 166 m_opaque_ptr->HandleCommand(command_line, do_add_to_history, 167 override_context.get()->Lock(true), 168 result.ref()); 169 else 170 m_opaque_ptr->HandleCommand(command_line, do_add_to_history, 171 result.ref()); 172 } else { 173 result->AppendError( 174 "SBCommandInterpreter or the command line is not valid"); 175 } 176 177 return result.GetStatus(); 178 } 179 180 void SBCommandInterpreter::HandleCommandsFromFile( 181 lldb::SBFileSpec &file, lldb::SBExecutionContext &override_context, 182 lldb::SBCommandInterpreterRunOptions &options, 183 lldb::SBCommandReturnObject result) { 184 LLDB_INSTRUMENT_VA(this, file, override_context, options, result); 185 186 if (!IsValid()) { 187 result->AppendError("SBCommandInterpreter is not valid."); 188 return; 189 } 190 191 if (!file.IsValid()) { 192 SBStream s; 193 file.GetDescription(s); 194 result->AppendErrorWithFormat("File is not valid: %s.", s.GetData()); 195 } 196 197 FileSpec tmp_spec = file.ref(); 198 if (override_context.get()) 199 m_opaque_ptr->HandleCommandsFromFile(tmp_spec, 200 override_context.get()->Lock(true), 201 options.ref(), 202 result.ref()); 203 204 else 205 m_opaque_ptr->HandleCommandsFromFile(tmp_spec, options.ref(), result.ref()); 206 } 207 208 int SBCommandInterpreter::HandleCompletion( 209 const char *current_line, const char *cursor, const char *last_char, 210 int match_start_point, int max_return_elements, SBStringList &matches) { 211 LLDB_INSTRUMENT_VA(this, current_line, cursor, last_char, match_start_point, 212 max_return_elements, matches); 213 214 SBStringList dummy_descriptions; 215 return HandleCompletionWithDescriptions( 216 current_line, cursor, last_char, match_start_point, max_return_elements, 217 matches, dummy_descriptions); 218 } 219 220 int SBCommandInterpreter::HandleCompletionWithDescriptions( 221 const char *current_line, const char *cursor, const char *last_char, 222 int match_start_point, int max_return_elements, SBStringList &matches, 223 SBStringList &descriptions) { 224 LLDB_INSTRUMENT_VA(this, current_line, cursor, last_char, match_start_point, 225 max_return_elements, matches, descriptions); 226 227 // Sanity check the arguments that are passed in: cursor & last_char have to 228 // be within the current_line. 229 if (current_line == nullptr || cursor == nullptr || last_char == nullptr) 230 return 0; 231 232 if (cursor < current_line || last_char < current_line) 233 return 0; 234 235 size_t current_line_size = strlen(current_line); 236 if (cursor - current_line > static_cast<ptrdiff_t>(current_line_size) || 237 last_char - current_line > static_cast<ptrdiff_t>(current_line_size)) 238 return 0; 239 240 if (!IsValid()) 241 return 0; 242 243 lldb_private::StringList lldb_matches, lldb_descriptions; 244 CompletionResult result; 245 CompletionRequest request(current_line, cursor - current_line, result); 246 m_opaque_ptr->HandleCompletion(request); 247 result.GetMatches(lldb_matches); 248 result.GetDescriptions(lldb_descriptions); 249 250 // Make the result array indexed from 1 again by adding the 'common prefix' 251 // of all completions as element 0. This is done to emulate the old API. 252 if (request.GetParsedLine().GetArgumentCount() == 0) { 253 // If we got an empty string, insert nothing. 254 lldb_matches.InsertStringAtIndex(0, ""); 255 lldb_descriptions.InsertStringAtIndex(0, ""); 256 } else { 257 // Now figure out if there is a common substring, and if so put that in 258 // element 0, otherwise put an empty string in element 0. 259 std::string command_partial_str = request.GetCursorArgumentPrefix().str(); 260 261 std::string common_prefix = lldb_matches.LongestCommonPrefix(); 262 const size_t partial_name_len = command_partial_str.size(); 263 common_prefix.erase(0, partial_name_len); 264 265 // If we matched a unique single command, add a space... Only do this if 266 // the completer told us this was a complete word, however... 267 if (lldb_matches.GetSize() == 1) { 268 char quote_char = request.GetParsedArg().GetQuoteChar(); 269 common_prefix = 270 Args::EscapeLLDBCommandArgument(common_prefix, quote_char); 271 if (request.GetParsedArg().IsQuoted()) 272 common_prefix.push_back(quote_char); 273 common_prefix.push_back(' '); 274 } 275 lldb_matches.InsertStringAtIndex(0, common_prefix.c_str()); 276 lldb_descriptions.InsertStringAtIndex(0, ""); 277 } 278 279 SBStringList temp_matches_list(&lldb_matches); 280 matches.AppendList(temp_matches_list); 281 SBStringList temp_descriptions_list(&lldb_descriptions); 282 descriptions.AppendList(temp_descriptions_list); 283 return result.GetNumberOfResults(); 284 } 285 286 int SBCommandInterpreter::HandleCompletionWithDescriptions( 287 const char *current_line, uint32_t cursor_pos, int match_start_point, 288 int max_return_elements, SBStringList &matches, 289 SBStringList &descriptions) { 290 LLDB_INSTRUMENT_VA(this, current_line, cursor_pos, match_start_point, 291 max_return_elements, matches, descriptions); 292 293 const char *cursor = current_line + cursor_pos; 294 const char *last_char = current_line + strlen(current_line); 295 return HandleCompletionWithDescriptions( 296 current_line, cursor, last_char, match_start_point, max_return_elements, 297 matches, descriptions); 298 } 299 300 int SBCommandInterpreter::HandleCompletion(const char *current_line, 301 uint32_t cursor_pos, 302 int match_start_point, 303 int max_return_elements, 304 lldb::SBStringList &matches) { 305 LLDB_INSTRUMENT_VA(this, current_line, cursor_pos, match_start_point, 306 max_return_elements, matches); 307 308 const char *cursor = current_line + cursor_pos; 309 const char *last_char = current_line + strlen(current_line); 310 return HandleCompletion(current_line, cursor, last_char, match_start_point, 311 max_return_elements, matches); 312 } 313 314 bool SBCommandInterpreter::HasCommands() { 315 LLDB_INSTRUMENT_VA(this); 316 317 return (IsValid() ? m_opaque_ptr->HasCommands() : false); 318 } 319 320 bool SBCommandInterpreter::HasAliases() { 321 LLDB_INSTRUMENT_VA(this); 322 323 return (IsValid() ? m_opaque_ptr->HasAliases() : false); 324 } 325 326 bool SBCommandInterpreter::HasAliasOptions() { 327 LLDB_INSTRUMENT_VA(this); 328 329 return (IsValid() ? m_opaque_ptr->HasAliasOptions() : false); 330 } 331 332 SBProcess SBCommandInterpreter::GetProcess() { 333 LLDB_INSTRUMENT_VA(this); 334 335 SBProcess sb_process; 336 ProcessSP process_sp; 337 if (IsValid()) { 338 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); 339 if (target_sp) { 340 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 341 process_sp = target_sp->GetProcessSP(); 342 sb_process.SetSP(process_sp); 343 } 344 } 345 346 return sb_process; 347 } 348 349 SBDebugger SBCommandInterpreter::GetDebugger() { 350 LLDB_INSTRUMENT_VA(this); 351 352 SBDebugger sb_debugger; 353 if (IsValid()) 354 sb_debugger.reset(m_opaque_ptr->GetDebugger().shared_from_this()); 355 356 return sb_debugger; 357 } 358 359 bool SBCommandInterpreter::GetPromptOnQuit() { 360 LLDB_INSTRUMENT_VA(this); 361 362 return (IsValid() ? m_opaque_ptr->GetPromptOnQuit() : false); 363 } 364 365 void SBCommandInterpreter::SetPromptOnQuit(bool b) { 366 LLDB_INSTRUMENT_VA(this, b); 367 368 if (IsValid()) 369 m_opaque_ptr->SetPromptOnQuit(b); 370 } 371 372 void SBCommandInterpreter::AllowExitCodeOnQuit(bool allow) { 373 LLDB_INSTRUMENT_VA(this, allow); 374 375 if (m_opaque_ptr) 376 m_opaque_ptr->AllowExitCodeOnQuit(allow); 377 } 378 379 bool SBCommandInterpreter::HasCustomQuitExitCode() { 380 LLDB_INSTRUMENT_VA(this); 381 382 bool exited = false; 383 if (m_opaque_ptr) 384 m_opaque_ptr->GetQuitExitCode(exited); 385 return exited; 386 } 387 388 int SBCommandInterpreter::GetQuitStatus() { 389 LLDB_INSTRUMENT_VA(this); 390 391 bool exited = false; 392 return (m_opaque_ptr ? m_opaque_ptr->GetQuitExitCode(exited) : 0); 393 } 394 395 void SBCommandInterpreter::ResolveCommand(const char *command_line, 396 SBCommandReturnObject &result) { 397 LLDB_INSTRUMENT_VA(this, command_line, result); 398 399 result.Clear(); 400 if (command_line && IsValid()) { 401 m_opaque_ptr->ResolveCommand(command_line, result.ref()); 402 } else { 403 result->AppendError( 404 "SBCommandInterpreter or the command line is not valid"); 405 } 406 } 407 408 CommandInterpreter *SBCommandInterpreter::get() { return m_opaque_ptr; } 409 410 CommandInterpreter &SBCommandInterpreter::ref() { 411 assert(m_opaque_ptr); 412 return *m_opaque_ptr; 413 } 414 415 void SBCommandInterpreter::reset( 416 lldb_private::CommandInterpreter *interpreter) { 417 m_opaque_ptr = interpreter; 418 } 419 420 void SBCommandInterpreter::SourceInitFileInHomeDirectory( 421 SBCommandReturnObject &result) { 422 LLDB_INSTRUMENT_VA(this, result); 423 424 SourceInitFileInHomeDirectory(result, /*is_repl=*/false); 425 } 426 427 void SBCommandInterpreter::SourceInitFileInHomeDirectory( 428 SBCommandReturnObject &result, bool is_repl) { 429 LLDB_INSTRUMENT_VA(this, result, is_repl); 430 431 result.Clear(); 432 if (IsValid()) { 433 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); 434 std::unique_lock<std::recursive_mutex> lock; 435 if (target_sp) 436 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex()); 437 m_opaque_ptr->SourceInitFileHome(result.ref(), is_repl); 438 } else { 439 result->AppendError("SBCommandInterpreter is not valid"); 440 } 441 } 442 443 void SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory( 444 SBCommandReturnObject &result) { 445 LLDB_INSTRUMENT_VA(this, result); 446 447 result.Clear(); 448 if (IsValid()) { 449 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); 450 std::unique_lock<std::recursive_mutex> lock; 451 if (target_sp) 452 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex()); 453 m_opaque_ptr->SourceInitFileCwd(result.ref()); 454 } else { 455 result->AppendError("SBCommandInterpreter is not valid"); 456 } 457 } 458 459 SBBroadcaster SBCommandInterpreter::GetBroadcaster() { 460 LLDB_INSTRUMENT_VA(this); 461 462 SBBroadcaster broadcaster(m_opaque_ptr, false); 463 464 return broadcaster; 465 } 466 467 const char *SBCommandInterpreter::GetBroadcasterClass() { 468 LLDB_INSTRUMENT(); 469 470 return CommandInterpreter::GetStaticBroadcasterClass().AsCString(); 471 } 472 473 const char *SBCommandInterpreter::GetArgumentTypeAsCString( 474 const lldb::CommandArgumentType arg_type) { 475 LLDB_INSTRUMENT_VA(arg_type); 476 477 return CommandObject::GetArgumentTypeAsCString(arg_type); 478 } 479 480 const char *SBCommandInterpreter::GetArgumentDescriptionAsCString( 481 const lldb::CommandArgumentType arg_type) { 482 LLDB_INSTRUMENT_VA(arg_type); 483 484 return CommandObject::GetArgumentDescriptionAsCString(arg_type); 485 } 486 487 bool SBCommandInterpreter::EventIsCommandInterpreterEvent( 488 const lldb::SBEvent &event) { 489 LLDB_INSTRUMENT_VA(event); 490 491 return event.GetBroadcasterClass() == 492 SBCommandInterpreter::GetBroadcasterClass(); 493 } 494 495 bool SBCommandInterpreter::SetCommandOverrideCallback( 496 const char *command_name, lldb::CommandOverrideCallback callback, 497 void *baton) { 498 LLDB_INSTRUMENT_VA(this, command_name, callback, baton); 499 500 if (command_name && command_name[0] && IsValid()) { 501 llvm::StringRef command_name_str = command_name; 502 CommandObject *cmd_obj = 503 m_opaque_ptr->GetCommandObjectForCommand(command_name_str); 504 if (cmd_obj) { 505 assert(command_name_str.empty()); 506 cmd_obj->SetOverrideCallback(callback, baton); 507 return true; 508 } 509 } 510 return false; 511 } 512 513 lldb::SBCommand SBCommandInterpreter::AddMultiwordCommand(const char *name, 514 const char *help) { 515 LLDB_INSTRUMENT_VA(this, name, help); 516 517 lldb::CommandObjectSP new_command_sp( 518 new CommandObjectMultiword(*m_opaque_ptr, name, help)); 519 new_command_sp->GetAsMultiwordCommand()->SetRemovable(true); 520 Status add_error = m_opaque_ptr->AddUserCommand(name, new_command_sp, true); 521 if (add_error.Success()) 522 return lldb::SBCommand(new_command_sp); 523 return lldb::SBCommand(); 524 } 525 526 lldb::SBCommand SBCommandInterpreter::AddCommand( 527 const char *name, lldb::SBCommandPluginInterface *impl, const char *help) { 528 LLDB_INSTRUMENT_VA(this, name, impl, help); 529 530 return AddCommand(name, impl, help, /*syntax=*/nullptr, 531 /*auto_repeat_command=*/""); 532 } 533 534 lldb::SBCommand 535 SBCommandInterpreter::AddCommand(const char *name, 536 lldb::SBCommandPluginInterface *impl, 537 const char *help, const char *syntax) { 538 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax); 539 return AddCommand(name, impl, help, syntax, /*auto_repeat_command=*/""); 540 } 541 542 lldb::SBCommand SBCommandInterpreter::AddCommand( 543 const char *name, lldb::SBCommandPluginInterface *impl, const char *help, 544 const char *syntax, const char *auto_repeat_command) { 545 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax, auto_repeat_command); 546 547 lldb::CommandObjectSP new_command_sp; 548 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>( 549 *m_opaque_ptr, name, impl, help, syntax, /*flags=*/0, 550 auto_repeat_command); 551 552 Status add_error = m_opaque_ptr->AddUserCommand(name, new_command_sp, true); 553 if (add_error.Success()) 554 return lldb::SBCommand(new_command_sp); 555 return lldb::SBCommand(); 556 } 557 558 SBCommand::SBCommand() { LLDB_INSTRUMENT_VA(this); } 559 560 SBCommand::SBCommand(lldb::CommandObjectSP cmd_sp) : m_opaque_sp(cmd_sp) {} 561 562 bool SBCommand::IsValid() { 563 LLDB_INSTRUMENT_VA(this); 564 return this->operator bool(); 565 } 566 SBCommand::operator bool() const { 567 LLDB_INSTRUMENT_VA(this); 568 569 return m_opaque_sp.get() != nullptr; 570 } 571 572 const char *SBCommand::GetName() { 573 LLDB_INSTRUMENT_VA(this); 574 575 return (IsValid() ? ConstString(m_opaque_sp->GetCommandName()).AsCString() : nullptr); 576 } 577 578 const char *SBCommand::GetHelp() { 579 LLDB_INSTRUMENT_VA(this); 580 581 return (IsValid() ? ConstString(m_opaque_sp->GetHelp()).AsCString() 582 : nullptr); 583 } 584 585 const char *SBCommand::GetHelpLong() { 586 LLDB_INSTRUMENT_VA(this); 587 588 return (IsValid() ? ConstString(m_opaque_sp->GetHelpLong()).AsCString() 589 : nullptr); 590 } 591 592 void SBCommand::SetHelp(const char *help) { 593 LLDB_INSTRUMENT_VA(this, help); 594 595 if (IsValid()) 596 m_opaque_sp->SetHelp(help); 597 } 598 599 void SBCommand::SetHelpLong(const char *help) { 600 LLDB_INSTRUMENT_VA(this, help); 601 602 if (IsValid()) 603 m_opaque_sp->SetHelpLong(help); 604 } 605 606 lldb::SBCommand SBCommand::AddMultiwordCommand(const char *name, 607 const char *help) { 608 LLDB_INSTRUMENT_VA(this, name, help); 609 610 if (!IsValid()) 611 return lldb::SBCommand(); 612 if (!m_opaque_sp->IsMultiwordObject()) 613 return lldb::SBCommand(); 614 CommandObjectMultiword *new_command = new CommandObjectMultiword( 615 m_opaque_sp->GetCommandInterpreter(), name, help); 616 new_command->SetRemovable(true); 617 lldb::CommandObjectSP new_command_sp(new_command); 618 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp)) 619 return lldb::SBCommand(new_command_sp); 620 return lldb::SBCommand(); 621 } 622 623 lldb::SBCommand SBCommand::AddCommand(const char *name, 624 lldb::SBCommandPluginInterface *impl, 625 const char *help) { 626 LLDB_INSTRUMENT_VA(this, name, impl, help); 627 return AddCommand(name, impl, help, /*syntax=*/nullptr, 628 /*auto_repeat_command=*/""); 629 } 630 631 lldb::SBCommand SBCommand::AddCommand(const char *name, 632 lldb::SBCommandPluginInterface *impl, 633 const char *help, const char *syntax) { 634 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax); 635 return AddCommand(name, impl, help, syntax, /*auto_repeat_command=*/""); 636 } 637 638 lldb::SBCommand SBCommand::AddCommand(const char *name, 639 lldb::SBCommandPluginInterface *impl, 640 const char *help, const char *syntax, 641 const char *auto_repeat_command) { 642 LLDB_INSTRUMENT_VA(this, name, impl, help, syntax, auto_repeat_command); 643 644 if (!IsValid()) 645 return lldb::SBCommand(); 646 if (!m_opaque_sp->IsMultiwordObject()) 647 return lldb::SBCommand(); 648 lldb::CommandObjectSP new_command_sp; 649 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>( 650 m_opaque_sp->GetCommandInterpreter(), name, impl, help, syntax, 651 /*flags=*/0, auto_repeat_command); 652 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp)) 653 return lldb::SBCommand(new_command_sp); 654 return lldb::SBCommand(); 655 } 656 657 uint32_t SBCommand::GetFlags() { 658 LLDB_INSTRUMENT_VA(this); 659 660 return (IsValid() ? m_opaque_sp->GetFlags().Get() : 0); 661 } 662 663 void SBCommand::SetFlags(uint32_t flags) { 664 LLDB_INSTRUMENT_VA(this, flags); 665 666 if (IsValid()) 667 m_opaque_sp->GetFlags().Set(flags); 668 } 669