1 //===-- SBCommandInterpreter.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 "lldb/lldb-types.h" 10 11 #include "SBReproducerPrivate.h" 12 #include "lldb/Interpreter/CommandInterpreter.h" 13 #include "lldb/Interpreter/CommandObjectMultiword.h" 14 #include "lldb/Interpreter/CommandReturnObject.h" 15 #include "lldb/Target/Target.h" 16 #include "lldb/Utility/Listener.h" 17 18 #include "lldb/API/SBBroadcaster.h" 19 #include "lldb/API/SBCommandInterpreter.h" 20 #include "lldb/API/SBCommandReturnObject.h" 21 #include "lldb/API/SBEvent.h" 22 #include "lldb/API/SBExecutionContext.h" 23 #include "lldb/API/SBListener.h" 24 #include "lldb/API/SBProcess.h" 25 #include "lldb/API/SBStream.h" 26 #include "lldb/API/SBStringList.h" 27 #include "lldb/API/SBTarget.h" 28 29 #include <memory> 30 31 using namespace lldb; 32 using namespace lldb_private; 33 34 SBCommandInterpreterRunOptions::SBCommandInterpreterRunOptions() { 35 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBCommandInterpreterRunOptions); 36 37 m_opaque_up.reset(new CommandInterpreterRunOptions()); 38 } 39 40 SBCommandInterpreterRunOptions::~SBCommandInterpreterRunOptions() = default; 41 42 bool SBCommandInterpreterRunOptions::GetStopOnContinue() const { 43 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions, 44 GetStopOnContinue); 45 46 return m_opaque_up->GetStopOnContinue(); 47 } 48 49 void SBCommandInterpreterRunOptions::SetStopOnContinue(bool stop_on_continue) { 50 LLDB_RECORD_METHOD(void, SBCommandInterpreterRunOptions, SetStopOnContinue, 51 (bool), stop_on_continue); 52 53 m_opaque_up->SetStopOnContinue(stop_on_continue); 54 } 55 56 bool SBCommandInterpreterRunOptions::GetStopOnError() const { 57 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions, 58 GetStopOnError); 59 60 return m_opaque_up->GetStopOnError(); 61 } 62 63 void SBCommandInterpreterRunOptions::SetStopOnError(bool stop_on_error) { 64 LLDB_RECORD_METHOD(void, SBCommandInterpreterRunOptions, SetStopOnError, 65 (bool), stop_on_error); 66 67 m_opaque_up->SetStopOnError(stop_on_error); 68 } 69 70 bool SBCommandInterpreterRunOptions::GetStopOnCrash() const { 71 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions, 72 GetStopOnCrash); 73 74 return m_opaque_up->GetStopOnCrash(); 75 } 76 77 void SBCommandInterpreterRunOptions::SetStopOnCrash(bool stop_on_crash) { 78 LLDB_RECORD_METHOD(void, SBCommandInterpreterRunOptions, SetStopOnCrash, 79 (bool), stop_on_crash); 80 81 m_opaque_up->SetStopOnCrash(stop_on_crash); 82 } 83 84 bool SBCommandInterpreterRunOptions::GetEchoCommands() const { 85 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions, 86 GetEchoCommands); 87 88 return m_opaque_up->GetEchoCommands(); 89 } 90 91 void SBCommandInterpreterRunOptions::SetEchoCommands(bool echo_commands) { 92 LLDB_RECORD_METHOD(void, SBCommandInterpreterRunOptions, SetEchoCommands, 93 (bool), echo_commands); 94 95 m_opaque_up->SetEchoCommands(echo_commands); 96 } 97 98 bool SBCommandInterpreterRunOptions::GetEchoCommentCommands() const { 99 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions, 100 GetEchoCommentCommands); 101 102 return m_opaque_up->GetEchoCommentCommands(); 103 } 104 105 void SBCommandInterpreterRunOptions::SetEchoCommentCommands(bool echo) { 106 LLDB_RECORD_METHOD(void, SBCommandInterpreterRunOptions, 107 SetEchoCommentCommands, (bool), echo); 108 109 m_opaque_up->SetEchoCommentCommands(echo); 110 } 111 112 bool SBCommandInterpreterRunOptions::GetPrintResults() const { 113 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions, 114 GetPrintResults); 115 116 return m_opaque_up->GetPrintResults(); 117 } 118 119 void SBCommandInterpreterRunOptions::SetPrintResults(bool print_results) { 120 LLDB_RECORD_METHOD(void, SBCommandInterpreterRunOptions, SetPrintResults, 121 (bool), print_results); 122 123 m_opaque_up->SetPrintResults(print_results); 124 } 125 126 bool SBCommandInterpreterRunOptions::GetAddToHistory() const { 127 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreterRunOptions, 128 GetAddToHistory); 129 130 return m_opaque_up->GetAddToHistory(); 131 } 132 133 void SBCommandInterpreterRunOptions::SetAddToHistory(bool add_to_history) { 134 LLDB_RECORD_METHOD(void, SBCommandInterpreterRunOptions, SetAddToHistory, 135 (bool), add_to_history); 136 137 m_opaque_up->SetAddToHistory(add_to_history); 138 } 139 140 lldb_private::CommandInterpreterRunOptions * 141 SBCommandInterpreterRunOptions::get() const { 142 return m_opaque_up.get(); 143 } 144 145 lldb_private::CommandInterpreterRunOptions & 146 SBCommandInterpreterRunOptions::ref() const { 147 return *m_opaque_up; 148 } 149 150 class CommandPluginInterfaceImplementation : public CommandObjectParsed { 151 public: 152 CommandPluginInterfaceImplementation(CommandInterpreter &interpreter, 153 const char *name, 154 lldb::SBCommandPluginInterface *backend, 155 const char *help = nullptr, 156 const char *syntax = nullptr, 157 uint32_t flags = 0) 158 : CommandObjectParsed(interpreter, name, help, syntax, flags), 159 m_backend(backend) {} 160 161 bool IsRemovable() const override { return true; } 162 163 protected: 164 bool DoExecute(Args &command, CommandReturnObject &result) override { 165 SBCommandReturnObject sb_return(&result); 166 SBCommandInterpreter sb_interpreter(&m_interpreter); 167 SBDebugger debugger_sb(m_interpreter.GetDebugger().shared_from_this()); 168 bool ret = m_backend->DoExecute( 169 debugger_sb, (char **)command.GetArgumentVector(), sb_return); 170 sb_return.Release(); 171 return ret; 172 } 173 std::shared_ptr<lldb::SBCommandPluginInterface> m_backend; 174 }; 175 176 SBCommandInterpreter::SBCommandInterpreter(CommandInterpreter *interpreter) 177 : m_opaque_ptr(interpreter) { 178 LLDB_RECORD_CONSTRUCTOR(SBCommandInterpreter, 179 (lldb_private::CommandInterpreter *), interpreter); 180 181 } 182 183 SBCommandInterpreter::SBCommandInterpreter(const SBCommandInterpreter &rhs) 184 : m_opaque_ptr(rhs.m_opaque_ptr) { 185 LLDB_RECORD_CONSTRUCTOR(SBCommandInterpreter, 186 (const lldb::SBCommandInterpreter &), rhs); 187 } 188 189 SBCommandInterpreter::~SBCommandInterpreter() = default; 190 191 const SBCommandInterpreter &SBCommandInterpreter:: 192 operator=(const SBCommandInterpreter &rhs) { 193 LLDB_RECORD_METHOD( 194 const lldb::SBCommandInterpreter &, 195 SBCommandInterpreter, operator=,(const lldb::SBCommandInterpreter &), 196 rhs); 197 198 m_opaque_ptr = rhs.m_opaque_ptr; 199 return LLDB_RECORD_RESULT(*this); 200 } 201 202 bool SBCommandInterpreter::IsValid() const { 203 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreter, IsValid); 204 return this->operator bool(); 205 } 206 SBCommandInterpreter::operator bool() const { 207 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreter, operator bool); 208 209 return m_opaque_ptr != nullptr; 210 } 211 212 bool SBCommandInterpreter::CommandExists(const char *cmd) { 213 LLDB_RECORD_METHOD(bool, SBCommandInterpreter, CommandExists, (const char *), 214 cmd); 215 216 return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->CommandExists(cmd) 217 : false); 218 } 219 220 bool SBCommandInterpreter::AliasExists(const char *cmd) { 221 LLDB_RECORD_METHOD(bool, SBCommandInterpreter, AliasExists, (const char *), 222 cmd); 223 224 return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->AliasExists(cmd) 225 : false); 226 } 227 228 bool SBCommandInterpreter::IsActive() { 229 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, IsActive); 230 231 return (IsValid() ? m_opaque_ptr->IsActive() : false); 232 } 233 234 bool SBCommandInterpreter::WasInterrupted() const { 235 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreter, WasInterrupted); 236 237 return (IsValid() ? m_opaque_ptr->WasInterrupted() : false); 238 } 239 240 const char *SBCommandInterpreter::GetIOHandlerControlSequence(char ch) { 241 LLDB_RECORD_METHOD(const char *, SBCommandInterpreter, 242 GetIOHandlerControlSequence, (char), ch); 243 244 return (IsValid() 245 ? m_opaque_ptr->GetDebugger() 246 .GetTopIOHandlerControlSequence(ch) 247 .GetCString() 248 : nullptr); 249 } 250 251 lldb::ReturnStatus 252 SBCommandInterpreter::HandleCommand(const char *command_line, 253 SBCommandReturnObject &result, 254 bool add_to_history) { 255 LLDB_RECORD_METHOD(lldb::ReturnStatus, SBCommandInterpreter, HandleCommand, 256 (const char *, lldb::SBCommandReturnObject &, bool), 257 command_line, result, add_to_history); 258 259 SBExecutionContext sb_exe_ctx; 260 return HandleCommand(command_line, sb_exe_ctx, result, add_to_history); 261 } 262 263 lldb::ReturnStatus SBCommandInterpreter::HandleCommand( 264 const char *command_line, SBExecutionContext &override_context, 265 SBCommandReturnObject &result, bool add_to_history) { 266 LLDB_RECORD_METHOD(lldb::ReturnStatus, SBCommandInterpreter, HandleCommand, 267 (const char *, lldb::SBExecutionContext &, 268 lldb::SBCommandReturnObject &, bool), 269 command_line, override_context, result, add_to_history); 270 271 272 ExecutionContext ctx, *ctx_ptr; 273 if (override_context.get()) { 274 ctx = override_context.get()->Lock(true); 275 ctx_ptr = &ctx; 276 } else 277 ctx_ptr = nullptr; 278 279 result.Clear(); 280 if (command_line && IsValid()) { 281 result.ref().SetInteractive(false); 282 m_opaque_ptr->HandleCommand(command_line, 283 add_to_history ? eLazyBoolYes : eLazyBoolNo, 284 result.ref(), ctx_ptr); 285 } else { 286 result->AppendError( 287 "SBCommandInterpreter or the command line is not valid"); 288 result->SetStatus(eReturnStatusFailed); 289 } 290 291 292 return result.GetStatus(); 293 } 294 295 void SBCommandInterpreter::HandleCommandsFromFile( 296 lldb::SBFileSpec &file, lldb::SBExecutionContext &override_context, 297 lldb::SBCommandInterpreterRunOptions &options, 298 lldb::SBCommandReturnObject result) { 299 LLDB_RECORD_METHOD(void, SBCommandInterpreter, HandleCommandsFromFile, 300 (lldb::SBFileSpec &, lldb::SBExecutionContext &, 301 lldb::SBCommandInterpreterRunOptions &, 302 lldb::SBCommandReturnObject), 303 file, override_context, options, result); 304 305 if (!IsValid()) { 306 result->AppendError("SBCommandInterpreter is not valid."); 307 result->SetStatus(eReturnStatusFailed); 308 return; 309 } 310 311 if (!file.IsValid()) { 312 SBStream s; 313 file.GetDescription(s); 314 result->AppendErrorWithFormat("File is not valid: %s.", s.GetData()); 315 result->SetStatus(eReturnStatusFailed); 316 } 317 318 FileSpec tmp_spec = file.ref(); 319 ExecutionContext ctx, *ctx_ptr; 320 if (override_context.get()) { 321 ctx = override_context.get()->Lock(true); 322 ctx_ptr = &ctx; 323 } else 324 ctx_ptr = nullptr; 325 326 m_opaque_ptr->HandleCommandsFromFile(tmp_spec, ctx_ptr, options.ref(), 327 result.ref()); 328 } 329 330 int SBCommandInterpreter::HandleCompletion( 331 const char *current_line, const char *cursor, const char *last_char, 332 int match_start_point, int max_return_elements, SBStringList &matches) { 333 LLDB_RECORD_METHOD(int, SBCommandInterpreter, HandleCompletion, 334 (const char *, const char *, const char *, int, int, 335 lldb::SBStringList &), 336 current_line, cursor, last_char, match_start_point, 337 max_return_elements, matches); 338 339 SBStringList dummy_descriptions; 340 return HandleCompletionWithDescriptions( 341 current_line, cursor, last_char, match_start_point, max_return_elements, 342 matches, dummy_descriptions); 343 } 344 345 int SBCommandInterpreter::HandleCompletionWithDescriptions( 346 const char *current_line, const char *cursor, const char *last_char, 347 int match_start_point, int max_return_elements, SBStringList &matches, 348 SBStringList &descriptions) { 349 LLDB_RECORD_METHOD(int, SBCommandInterpreter, 350 HandleCompletionWithDescriptions, 351 (const char *, const char *, const char *, int, int, 352 lldb::SBStringList &, lldb::SBStringList &), 353 current_line, cursor, last_char, match_start_point, 354 max_return_elements, matches, descriptions); 355 356 int num_completions = 0; 357 358 // Sanity check the arguments that are passed in: cursor & last_char have to 359 // be within the current_line. 360 if (current_line == nullptr || cursor == nullptr || last_char == nullptr) 361 return 0; 362 363 if (cursor < current_line || last_char < current_line) 364 return 0; 365 366 size_t current_line_size = strlen(current_line); 367 if (cursor - current_line > static_cast<ptrdiff_t>(current_line_size) || 368 last_char - current_line > static_cast<ptrdiff_t>(current_line_size)) 369 return 0; 370 371 372 if (IsValid()) { 373 lldb_private::StringList lldb_matches, lldb_descriptions; 374 num_completions = m_opaque_ptr->HandleCompletion( 375 current_line, cursor, last_char, lldb_matches, lldb_descriptions); 376 377 SBStringList temp_matches_list(&lldb_matches); 378 matches.AppendList(temp_matches_list); 379 SBStringList temp_descriptions_list(&lldb_descriptions); 380 descriptions.AppendList(temp_descriptions_list); 381 } 382 383 return num_completions; 384 } 385 386 int SBCommandInterpreter::HandleCompletionWithDescriptions( 387 const char *current_line, uint32_t cursor_pos, int match_start_point, 388 int max_return_elements, SBStringList &matches, 389 SBStringList &descriptions) { 390 LLDB_RECORD_METHOD(int, SBCommandInterpreter, 391 HandleCompletionWithDescriptions, 392 (const char *, uint32_t, int, int, lldb::SBStringList &, 393 lldb::SBStringList &), 394 current_line, cursor_pos, match_start_point, 395 max_return_elements, matches, descriptions); 396 397 const char *cursor = current_line + cursor_pos; 398 const char *last_char = current_line + strlen(current_line); 399 return HandleCompletionWithDescriptions( 400 current_line, cursor, last_char, match_start_point, max_return_elements, 401 matches, descriptions); 402 } 403 404 int SBCommandInterpreter::HandleCompletion(const char *current_line, 405 uint32_t cursor_pos, 406 int match_start_point, 407 int max_return_elements, 408 lldb::SBStringList &matches) { 409 LLDB_RECORD_METHOD(int, SBCommandInterpreter, HandleCompletion, 410 (const char *, uint32_t, int, int, lldb::SBStringList &), 411 current_line, cursor_pos, match_start_point, 412 max_return_elements, matches); 413 414 const char *cursor = current_line + cursor_pos; 415 const char *last_char = current_line + strlen(current_line); 416 return HandleCompletion(current_line, cursor, last_char, match_start_point, 417 max_return_elements, matches); 418 } 419 420 bool SBCommandInterpreter::HasCommands() { 421 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasCommands); 422 423 return (IsValid() ? m_opaque_ptr->HasCommands() : false); 424 } 425 426 bool SBCommandInterpreter::HasAliases() { 427 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasAliases); 428 429 return (IsValid() ? m_opaque_ptr->HasAliases() : false); 430 } 431 432 bool SBCommandInterpreter::HasAliasOptions() { 433 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasAliasOptions); 434 435 return (IsValid() ? m_opaque_ptr->HasAliasOptions() : false); 436 } 437 438 SBProcess SBCommandInterpreter::GetProcess() { 439 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBProcess, SBCommandInterpreter, GetProcess); 440 441 SBProcess sb_process; 442 ProcessSP process_sp; 443 if (IsValid()) { 444 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); 445 if (target_sp) { 446 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 447 process_sp = target_sp->GetProcessSP(); 448 sb_process.SetSP(process_sp); 449 } 450 } 451 452 return LLDB_RECORD_RESULT(sb_process); 453 } 454 455 SBDebugger SBCommandInterpreter::GetDebugger() { 456 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBDebugger, SBCommandInterpreter, 457 GetDebugger); 458 459 SBDebugger sb_debugger; 460 if (IsValid()) 461 sb_debugger.reset(m_opaque_ptr->GetDebugger().shared_from_this()); 462 463 return LLDB_RECORD_RESULT(sb_debugger); 464 } 465 466 bool SBCommandInterpreter::GetPromptOnQuit() { 467 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, GetPromptOnQuit); 468 469 return (IsValid() ? m_opaque_ptr->GetPromptOnQuit() : false); 470 } 471 472 void SBCommandInterpreter::SetPromptOnQuit(bool b) { 473 LLDB_RECORD_METHOD(void, SBCommandInterpreter, SetPromptOnQuit, (bool), b); 474 475 if (IsValid()) 476 m_opaque_ptr->SetPromptOnQuit(b); 477 } 478 479 void SBCommandInterpreter::AllowExitCodeOnQuit(bool allow) { 480 LLDB_RECORD_METHOD(void, SBCommandInterpreter, AllowExitCodeOnQuit, (bool), 481 allow); 482 483 if (m_opaque_ptr) 484 m_opaque_ptr->AllowExitCodeOnQuit(allow); 485 } 486 487 bool SBCommandInterpreter::HasCustomQuitExitCode() { 488 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasCustomQuitExitCode); 489 490 bool exited = false; 491 if (m_opaque_ptr) 492 m_opaque_ptr->GetQuitExitCode(exited); 493 return exited; 494 } 495 496 int SBCommandInterpreter::GetQuitStatus() { 497 LLDB_RECORD_METHOD_NO_ARGS(int, SBCommandInterpreter, GetQuitStatus); 498 499 bool exited = false; 500 return (m_opaque_ptr ? m_opaque_ptr->GetQuitExitCode(exited) : 0); 501 } 502 503 void SBCommandInterpreter::ResolveCommand(const char *command_line, 504 SBCommandReturnObject &result) { 505 LLDB_RECORD_METHOD(void, SBCommandInterpreter, ResolveCommand, 506 (const char *, lldb::SBCommandReturnObject &), 507 command_line, result); 508 509 result.Clear(); 510 if (command_line && IsValid()) { 511 m_opaque_ptr->ResolveCommand(command_line, result.ref()); 512 } else { 513 result->AppendError( 514 "SBCommandInterpreter or the command line is not valid"); 515 result->SetStatus(eReturnStatusFailed); 516 } 517 } 518 519 CommandInterpreter *SBCommandInterpreter::get() { return m_opaque_ptr; } 520 521 CommandInterpreter &SBCommandInterpreter::ref() { 522 assert(m_opaque_ptr); 523 return *m_opaque_ptr; 524 } 525 526 void SBCommandInterpreter::reset( 527 lldb_private::CommandInterpreter *interpreter) { 528 m_opaque_ptr = interpreter; 529 } 530 531 void SBCommandInterpreter::SourceInitFileInHomeDirectory( 532 SBCommandReturnObject &result) { 533 LLDB_RECORD_METHOD(void, SBCommandInterpreter, SourceInitFileInHomeDirectory, 534 (lldb::SBCommandReturnObject &), result); 535 536 result.Clear(); 537 if (IsValid()) { 538 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); 539 std::unique_lock<std::recursive_mutex> lock; 540 if (target_sp) 541 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex()); 542 m_opaque_ptr->SourceInitFileHome(result.ref()); 543 } else { 544 result->AppendError("SBCommandInterpreter is not valid"); 545 result->SetStatus(eReturnStatusFailed); 546 } 547 } 548 549 void SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory( 550 SBCommandReturnObject &result) { 551 LLDB_RECORD_METHOD(void, SBCommandInterpreter, 552 SourceInitFileInCurrentWorkingDirectory, 553 (lldb::SBCommandReturnObject &), result); 554 555 result.Clear(); 556 if (IsValid()) { 557 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); 558 std::unique_lock<std::recursive_mutex> lock; 559 if (target_sp) 560 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex()); 561 m_opaque_ptr->SourceInitFileCwd(result.ref()); 562 } else { 563 result->AppendError("SBCommandInterpreter is not valid"); 564 result->SetStatus(eReturnStatusFailed); 565 } 566 } 567 568 SBBroadcaster SBCommandInterpreter::GetBroadcaster() { 569 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBBroadcaster, SBCommandInterpreter, 570 GetBroadcaster); 571 572 573 SBBroadcaster broadcaster(m_opaque_ptr, false); 574 575 576 return LLDB_RECORD_RESULT(broadcaster); 577 } 578 579 const char *SBCommandInterpreter::GetBroadcasterClass() { 580 LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBCommandInterpreter, 581 GetBroadcasterClass); 582 583 return CommandInterpreter::GetStaticBroadcasterClass().AsCString(); 584 } 585 586 const char *SBCommandInterpreter::GetArgumentTypeAsCString( 587 const lldb::CommandArgumentType arg_type) { 588 LLDB_RECORD_STATIC_METHOD(const char *, SBCommandInterpreter, 589 GetArgumentTypeAsCString, 590 (const lldb::CommandArgumentType), arg_type); 591 592 return CommandObject::GetArgumentTypeAsCString(arg_type); 593 } 594 595 const char *SBCommandInterpreter::GetArgumentDescriptionAsCString( 596 const lldb::CommandArgumentType arg_type) { 597 LLDB_RECORD_STATIC_METHOD(const char *, SBCommandInterpreter, 598 GetArgumentDescriptionAsCString, 599 (const lldb::CommandArgumentType), arg_type); 600 601 return CommandObject::GetArgumentDescriptionAsCString(arg_type); 602 } 603 604 bool SBCommandInterpreter::EventIsCommandInterpreterEvent( 605 const lldb::SBEvent &event) { 606 LLDB_RECORD_STATIC_METHOD(bool, SBCommandInterpreter, 607 EventIsCommandInterpreterEvent, 608 (const lldb::SBEvent &), event); 609 610 return event.GetBroadcasterClass() == 611 SBCommandInterpreter::GetBroadcasterClass(); 612 } 613 614 bool SBCommandInterpreter::SetCommandOverrideCallback( 615 const char *command_name, lldb::CommandOverrideCallback callback, 616 void *baton) { 617 LLDB_RECORD_DUMMY(bool, SBCommandInterpreter, SetCommandOverrideCallback, 618 (const char *, lldb::CommandOverrideCallback, void *), 619 command_name, callback, baton); 620 621 if (command_name && command_name[0] && IsValid()) { 622 llvm::StringRef command_name_str = command_name; 623 CommandObject *cmd_obj = 624 m_opaque_ptr->GetCommandObjectForCommand(command_name_str); 625 if (cmd_obj) { 626 assert(command_name_str.empty()); 627 cmd_obj->SetOverrideCallback(callback, baton); 628 return true; 629 } 630 } 631 return false; 632 } 633 634 lldb::SBCommand SBCommandInterpreter::AddMultiwordCommand(const char *name, 635 const char *help) { 636 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommandInterpreter, AddMultiwordCommand, 637 (const char *, const char *), name, help); 638 639 CommandObjectMultiword *new_command = 640 new CommandObjectMultiword(*m_opaque_ptr, name, help); 641 new_command->SetRemovable(true); 642 lldb::CommandObjectSP new_command_sp(new_command); 643 if (new_command_sp && 644 m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) 645 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 646 return LLDB_RECORD_RESULT(lldb::SBCommand()); 647 } 648 649 lldb::SBCommand SBCommandInterpreter::AddCommand( 650 const char *name, lldb::SBCommandPluginInterface *impl, const char *help) { 651 LLDB_RECORD_METHOD( 652 lldb::SBCommand, SBCommandInterpreter, AddCommand, 653 (const char *, lldb::SBCommandPluginInterface *, const char *), name, 654 impl, help); 655 656 lldb::CommandObjectSP new_command_sp; 657 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>( 658 *m_opaque_ptr, name, impl, help); 659 660 if (new_command_sp && 661 m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) 662 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 663 return LLDB_RECORD_RESULT(lldb::SBCommand()); 664 } 665 666 lldb::SBCommand 667 SBCommandInterpreter::AddCommand(const char *name, 668 lldb::SBCommandPluginInterface *impl, 669 const char *help, const char *syntax) { 670 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommandInterpreter, AddCommand, 671 (const char *, lldb::SBCommandPluginInterface *, 672 const char *, const char *), 673 name, impl, help, syntax); 674 675 lldb::CommandObjectSP new_command_sp; 676 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>( 677 *m_opaque_ptr, name, impl, help, syntax); 678 679 if (new_command_sp && 680 m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) 681 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 682 return LLDB_RECORD_RESULT(lldb::SBCommand()); 683 } 684 685 SBCommand::SBCommand() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBCommand); } 686 687 SBCommand::SBCommand(lldb::CommandObjectSP cmd_sp) : m_opaque_sp(cmd_sp) {} 688 689 bool SBCommand::IsValid() { 690 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommand, IsValid); 691 return this->operator bool(); 692 } 693 SBCommand::operator bool() const { 694 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommand, operator bool); 695 696 return m_opaque_sp.get() != nullptr; 697 } 698 699 const char *SBCommand::GetName() { 700 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBCommand, GetName); 701 702 return (IsValid() ? ConstString(m_opaque_sp->GetCommandName()).AsCString() : nullptr); 703 } 704 705 const char *SBCommand::GetHelp() { 706 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBCommand, GetHelp); 707 708 return (IsValid() ? ConstString(m_opaque_sp->GetHelp()).AsCString() 709 : nullptr); 710 } 711 712 const char *SBCommand::GetHelpLong() { 713 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBCommand, GetHelpLong); 714 715 return (IsValid() ? ConstString(m_opaque_sp->GetHelpLong()).AsCString() 716 : nullptr); 717 } 718 719 void SBCommand::SetHelp(const char *help) { 720 LLDB_RECORD_METHOD(void, SBCommand, SetHelp, (const char *), help); 721 722 if (IsValid()) 723 m_opaque_sp->SetHelp(help); 724 } 725 726 void SBCommand::SetHelpLong(const char *help) { 727 LLDB_RECORD_METHOD(void, SBCommand, SetHelpLong, (const char *), help); 728 729 if (IsValid()) 730 m_opaque_sp->SetHelpLong(help); 731 } 732 733 lldb::SBCommand SBCommand::AddMultiwordCommand(const char *name, 734 const char *help) { 735 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommand, AddMultiwordCommand, 736 (const char *, const char *), name, help); 737 738 if (!IsValid()) 739 return LLDB_RECORD_RESULT(lldb::SBCommand()); 740 if (!m_opaque_sp->IsMultiwordObject()) 741 return LLDB_RECORD_RESULT(lldb::SBCommand()); 742 CommandObjectMultiword *new_command = new CommandObjectMultiword( 743 m_opaque_sp->GetCommandInterpreter(), name, help); 744 new_command->SetRemovable(true); 745 lldb::CommandObjectSP new_command_sp(new_command); 746 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp)) 747 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 748 return LLDB_RECORD_RESULT(lldb::SBCommand()); 749 } 750 751 lldb::SBCommand SBCommand::AddCommand(const char *name, 752 lldb::SBCommandPluginInterface *impl, 753 const char *help) { 754 LLDB_RECORD_METHOD( 755 lldb::SBCommand, SBCommand, AddCommand, 756 (const char *, lldb::SBCommandPluginInterface *, const char *), name, 757 impl, help); 758 759 if (!IsValid()) 760 return LLDB_RECORD_RESULT(lldb::SBCommand()); 761 if (!m_opaque_sp->IsMultiwordObject()) 762 return LLDB_RECORD_RESULT(lldb::SBCommand()); 763 lldb::CommandObjectSP new_command_sp; 764 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>( 765 m_opaque_sp->GetCommandInterpreter(), name, impl, help); 766 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp)) 767 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 768 return LLDB_RECORD_RESULT(lldb::SBCommand()); 769 } 770 771 lldb::SBCommand SBCommand::AddCommand(const char *name, 772 lldb::SBCommandPluginInterface *impl, 773 const char *help, const char *syntax) { 774 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommand, AddCommand, 775 (const char *, lldb::SBCommandPluginInterface *, 776 const char *, const char *), 777 name, impl, help, syntax); 778 779 if (!IsValid()) 780 return LLDB_RECORD_RESULT(lldb::SBCommand()); 781 if (!m_opaque_sp->IsMultiwordObject()) 782 return LLDB_RECORD_RESULT(lldb::SBCommand()); 783 lldb::CommandObjectSP new_command_sp; 784 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>( 785 m_opaque_sp->GetCommandInterpreter(), name, impl, help, syntax); 786 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp)) 787 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 788 return LLDB_RECORD_RESULT(lldb::SBCommand()); 789 } 790 791 uint32_t SBCommand::GetFlags() { 792 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBCommand, GetFlags); 793 794 return (IsValid() ? m_opaque_sp->GetFlags().Get() : 0); 795 } 796 797 void SBCommand::SetFlags(uint32_t flags) { 798 LLDB_RECORD_METHOD(void, SBCommand, SetFlags, (uint32_t), flags); 799 800 if (IsValid()) 801 m_opaque_sp->GetFlags().Set(flags); 802 } 803 804 namespace lldb_private { 805 namespace repro { 806 807 template <> 808 void RegisterMethods<SBCommandInterpreterRunOptions>(Registry &R) { 809 LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreterRunOptions, ()); 810 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 811 GetStopOnContinue, ()); 812 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, 813 SetStopOnContinue, (bool)); 814 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 815 GetStopOnError, ()); 816 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetStopOnError, 817 (bool)); 818 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 819 GetStopOnCrash, ()); 820 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetStopOnCrash, 821 (bool)); 822 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 823 GetEchoCommands, ()); 824 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetEchoCommands, 825 (bool)); 826 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 827 GetEchoCommentCommands, ()); 828 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, 829 SetEchoCommentCommands, (bool)); 830 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 831 GetPrintResults, ()); 832 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetPrintResults, 833 (bool)); 834 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 835 GetAddToHistory, ()); 836 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetAddToHistory, 837 (bool)); 838 LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreter, 839 (lldb_private::CommandInterpreter *)); 840 LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreter, 841 (const lldb::SBCommandInterpreter &)); 842 LLDB_REGISTER_METHOD( 843 const lldb::SBCommandInterpreter &, 844 SBCommandInterpreter, operator=,(const lldb::SBCommandInterpreter &)); 845 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreter, IsValid, ()); 846 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreter, operator bool, ()); 847 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, CommandExists, 848 (const char *)); 849 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, AliasExists, 850 (const char *)); 851 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, IsActive, ()); 852 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreter, WasInterrupted, ()); 853 LLDB_REGISTER_METHOD(const char *, SBCommandInterpreter, 854 GetIOHandlerControlSequence, (char)); 855 LLDB_REGISTER_METHOD(lldb::ReturnStatus, SBCommandInterpreter, 856 HandleCommand, 857 (const char *, lldb::SBCommandReturnObject &, bool)); 858 LLDB_REGISTER_METHOD(lldb::ReturnStatus, SBCommandInterpreter, 859 HandleCommand, 860 (const char *, lldb::SBExecutionContext &, 861 lldb::SBCommandReturnObject &, bool)); 862 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, HandleCommandsFromFile, 863 (lldb::SBFileSpec &, lldb::SBExecutionContext &, 864 lldb::SBCommandInterpreterRunOptions &, 865 lldb::SBCommandReturnObject)); 866 LLDB_REGISTER_METHOD(int, SBCommandInterpreter, HandleCompletion, 867 (const char *, const char *, const char *, int, int, 868 lldb::SBStringList &)); 869 LLDB_REGISTER_METHOD(int, SBCommandInterpreter, 870 HandleCompletionWithDescriptions, 871 (const char *, const char *, const char *, int, int, 872 lldb::SBStringList &, lldb::SBStringList &)); 873 LLDB_REGISTER_METHOD(int, SBCommandInterpreter, 874 HandleCompletionWithDescriptions, 875 (const char *, uint32_t, int, int, 876 lldb::SBStringList &, lldb::SBStringList &)); 877 LLDB_REGISTER_METHOD( 878 int, SBCommandInterpreter, HandleCompletion, 879 (const char *, uint32_t, int, int, lldb::SBStringList &)); 880 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasCommands, ()); 881 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasAliases, ()); 882 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasAliasOptions, ()); 883 LLDB_REGISTER_METHOD(lldb::SBProcess, SBCommandInterpreter, GetProcess, ()); 884 LLDB_REGISTER_METHOD(lldb::SBDebugger, SBCommandInterpreter, GetDebugger, 885 ()); 886 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, GetPromptOnQuit, ()); 887 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, SetPromptOnQuit, (bool)); 888 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, AllowExitCodeOnQuit, 889 (bool)); 890 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasCustomQuitExitCode, ()); 891 LLDB_REGISTER_METHOD(int, SBCommandInterpreter, GetQuitStatus, ()); 892 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, ResolveCommand, 893 (const char *, lldb::SBCommandReturnObject &)); 894 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, 895 SourceInitFileInHomeDirectory, 896 (lldb::SBCommandReturnObject &)); 897 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, 898 SourceInitFileInCurrentWorkingDirectory, 899 (lldb::SBCommandReturnObject &)); 900 LLDB_REGISTER_METHOD(lldb::SBBroadcaster, SBCommandInterpreter, 901 GetBroadcaster, ()); 902 LLDB_REGISTER_STATIC_METHOD(const char *, SBCommandInterpreter, 903 GetBroadcasterClass, ()); 904 LLDB_REGISTER_STATIC_METHOD(const char *, SBCommandInterpreter, 905 GetArgumentTypeAsCString, 906 (const lldb::CommandArgumentType)); 907 LLDB_REGISTER_STATIC_METHOD(const char *, SBCommandInterpreter, 908 GetArgumentDescriptionAsCString, 909 (const lldb::CommandArgumentType)); 910 LLDB_REGISTER_STATIC_METHOD(bool, SBCommandInterpreter, 911 EventIsCommandInterpreterEvent, 912 (const lldb::SBEvent &)); 913 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommandInterpreter, 914 AddMultiwordCommand, (const char *, const char *)); 915 LLDB_REGISTER_METHOD( 916 lldb::SBCommand, SBCommandInterpreter, AddCommand, 917 (const char *, lldb::SBCommandPluginInterface *, const char *)); 918 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommandInterpreter, AddCommand, 919 (const char *, lldb::SBCommandPluginInterface *, 920 const char *, const char *)); 921 LLDB_REGISTER_CONSTRUCTOR(SBCommand, ()); 922 LLDB_REGISTER_METHOD(bool, SBCommand, IsValid, ()); 923 LLDB_REGISTER_METHOD_CONST(bool, SBCommand, operator bool, ()); 924 LLDB_REGISTER_METHOD(const char *, SBCommand, GetName, ()); 925 LLDB_REGISTER_METHOD(const char *, SBCommand, GetHelp, ()); 926 LLDB_REGISTER_METHOD(const char *, SBCommand, GetHelpLong, ()); 927 LLDB_REGISTER_METHOD(void, SBCommand, SetHelp, (const char *)); 928 LLDB_REGISTER_METHOD(void, SBCommand, SetHelpLong, (const char *)); 929 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommand, AddMultiwordCommand, 930 (const char *, const char *)); 931 LLDB_REGISTER_METHOD( 932 lldb::SBCommand, SBCommand, AddCommand, 933 (const char *, lldb::SBCommandPluginInterface *, const char *)); 934 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommand, AddCommand, 935 (const char *, lldb::SBCommandPluginInterface *, 936 const char *, const char *)); 937 LLDB_REGISTER_METHOD(uint32_t, SBCommand, GetFlags, ()); 938 LLDB_REGISTER_METHOD(void, SBCommand, SetFlags, (uint32_t)); 939 } 940 941 } 942 } 943