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, match_start_point, max_return_elements, 376 lldb_matches, lldb_descriptions); 377 378 SBStringList temp_matches_list(&lldb_matches); 379 matches.AppendList(temp_matches_list); 380 SBStringList temp_descriptions_list(&lldb_descriptions); 381 descriptions.AppendList(temp_descriptions_list); 382 } 383 384 return num_completions; 385 } 386 387 int SBCommandInterpreter::HandleCompletionWithDescriptions( 388 const char *current_line, uint32_t cursor_pos, int match_start_point, 389 int max_return_elements, SBStringList &matches, 390 SBStringList &descriptions) { 391 LLDB_RECORD_METHOD(int, SBCommandInterpreter, 392 HandleCompletionWithDescriptions, 393 (const char *, uint32_t, int, int, lldb::SBStringList &, 394 lldb::SBStringList &), 395 current_line, cursor_pos, match_start_point, 396 max_return_elements, matches, descriptions); 397 398 const char *cursor = current_line + cursor_pos; 399 const char *last_char = current_line + strlen(current_line); 400 return HandleCompletionWithDescriptions( 401 current_line, cursor, last_char, match_start_point, max_return_elements, 402 matches, descriptions); 403 } 404 405 int SBCommandInterpreter::HandleCompletion(const char *current_line, 406 uint32_t cursor_pos, 407 int match_start_point, 408 int max_return_elements, 409 lldb::SBStringList &matches) { 410 LLDB_RECORD_METHOD(int, SBCommandInterpreter, HandleCompletion, 411 (const char *, uint32_t, int, int, lldb::SBStringList &), 412 current_line, cursor_pos, match_start_point, 413 max_return_elements, matches); 414 415 const char *cursor = current_line + cursor_pos; 416 const char *last_char = current_line + strlen(current_line); 417 return HandleCompletion(current_line, cursor, last_char, match_start_point, 418 max_return_elements, matches); 419 } 420 421 bool SBCommandInterpreter::HasCommands() { 422 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasCommands); 423 424 return (IsValid() ? m_opaque_ptr->HasCommands() : false); 425 } 426 427 bool SBCommandInterpreter::HasAliases() { 428 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasAliases); 429 430 return (IsValid() ? m_opaque_ptr->HasAliases() : false); 431 } 432 433 bool SBCommandInterpreter::HasAliasOptions() { 434 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasAliasOptions); 435 436 return (IsValid() ? m_opaque_ptr->HasAliasOptions() : false); 437 } 438 439 SBProcess SBCommandInterpreter::GetProcess() { 440 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBProcess, SBCommandInterpreter, GetProcess); 441 442 SBProcess sb_process; 443 ProcessSP process_sp; 444 if (IsValid()) { 445 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); 446 if (target_sp) { 447 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 448 process_sp = target_sp->GetProcessSP(); 449 sb_process.SetSP(process_sp); 450 } 451 } 452 453 return LLDB_RECORD_RESULT(sb_process); 454 } 455 456 SBDebugger SBCommandInterpreter::GetDebugger() { 457 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBDebugger, SBCommandInterpreter, 458 GetDebugger); 459 460 SBDebugger sb_debugger; 461 if (IsValid()) 462 sb_debugger.reset(m_opaque_ptr->GetDebugger().shared_from_this()); 463 464 return LLDB_RECORD_RESULT(sb_debugger); 465 } 466 467 bool SBCommandInterpreter::GetPromptOnQuit() { 468 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, GetPromptOnQuit); 469 470 return (IsValid() ? m_opaque_ptr->GetPromptOnQuit() : false); 471 } 472 473 void SBCommandInterpreter::SetPromptOnQuit(bool b) { 474 LLDB_RECORD_METHOD(void, SBCommandInterpreter, SetPromptOnQuit, (bool), b); 475 476 if (IsValid()) 477 m_opaque_ptr->SetPromptOnQuit(b); 478 } 479 480 void SBCommandInterpreter::AllowExitCodeOnQuit(bool allow) { 481 LLDB_RECORD_METHOD(void, SBCommandInterpreter, AllowExitCodeOnQuit, (bool), 482 allow); 483 484 if (m_opaque_ptr) 485 m_opaque_ptr->AllowExitCodeOnQuit(allow); 486 } 487 488 bool SBCommandInterpreter::HasCustomQuitExitCode() { 489 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasCustomQuitExitCode); 490 491 bool exited = false; 492 if (m_opaque_ptr) 493 m_opaque_ptr->GetQuitExitCode(exited); 494 return exited; 495 } 496 497 int SBCommandInterpreter::GetQuitStatus() { 498 LLDB_RECORD_METHOD_NO_ARGS(int, SBCommandInterpreter, GetQuitStatus); 499 500 bool exited = false; 501 return (m_opaque_ptr ? m_opaque_ptr->GetQuitExitCode(exited) : 0); 502 } 503 504 void SBCommandInterpreter::ResolveCommand(const char *command_line, 505 SBCommandReturnObject &result) { 506 LLDB_RECORD_METHOD(void, SBCommandInterpreter, ResolveCommand, 507 (const char *, lldb::SBCommandReturnObject &), 508 command_line, result); 509 510 result.Clear(); 511 if (command_line && IsValid()) { 512 m_opaque_ptr->ResolveCommand(command_line, result.ref()); 513 } else { 514 result->AppendError( 515 "SBCommandInterpreter or the command line is not valid"); 516 result->SetStatus(eReturnStatusFailed); 517 } 518 } 519 520 CommandInterpreter *SBCommandInterpreter::get() { return m_opaque_ptr; } 521 522 CommandInterpreter &SBCommandInterpreter::ref() { 523 assert(m_opaque_ptr); 524 return *m_opaque_ptr; 525 } 526 527 void SBCommandInterpreter::reset( 528 lldb_private::CommandInterpreter *interpreter) { 529 m_opaque_ptr = interpreter; 530 } 531 532 void SBCommandInterpreter::SourceInitFileInHomeDirectory( 533 SBCommandReturnObject &result) { 534 LLDB_RECORD_METHOD(void, SBCommandInterpreter, SourceInitFileInHomeDirectory, 535 (lldb::SBCommandReturnObject &), result); 536 537 result.Clear(); 538 if (IsValid()) { 539 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); 540 std::unique_lock<std::recursive_mutex> lock; 541 if (target_sp) 542 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex()); 543 m_opaque_ptr->SourceInitFileHome(result.ref()); 544 } else { 545 result->AppendError("SBCommandInterpreter is not valid"); 546 result->SetStatus(eReturnStatusFailed); 547 } 548 } 549 550 void SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory( 551 SBCommandReturnObject &result) { 552 LLDB_RECORD_METHOD(void, SBCommandInterpreter, 553 SourceInitFileInCurrentWorkingDirectory, 554 (lldb::SBCommandReturnObject &), result); 555 556 result.Clear(); 557 if (IsValid()) { 558 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); 559 std::unique_lock<std::recursive_mutex> lock; 560 if (target_sp) 561 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex()); 562 m_opaque_ptr->SourceInitFileCwd(result.ref()); 563 } else { 564 result->AppendError("SBCommandInterpreter is not valid"); 565 result->SetStatus(eReturnStatusFailed); 566 } 567 } 568 569 SBBroadcaster SBCommandInterpreter::GetBroadcaster() { 570 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBBroadcaster, SBCommandInterpreter, 571 GetBroadcaster); 572 573 574 SBBroadcaster broadcaster(m_opaque_ptr, false); 575 576 577 return LLDB_RECORD_RESULT(broadcaster); 578 } 579 580 const char *SBCommandInterpreter::GetBroadcasterClass() { 581 LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBCommandInterpreter, 582 GetBroadcasterClass); 583 584 return CommandInterpreter::GetStaticBroadcasterClass().AsCString(); 585 } 586 587 const char *SBCommandInterpreter::GetArgumentTypeAsCString( 588 const lldb::CommandArgumentType arg_type) { 589 LLDB_RECORD_STATIC_METHOD(const char *, SBCommandInterpreter, 590 GetArgumentTypeAsCString, 591 (const lldb::CommandArgumentType), arg_type); 592 593 return CommandObject::GetArgumentTypeAsCString(arg_type); 594 } 595 596 const char *SBCommandInterpreter::GetArgumentDescriptionAsCString( 597 const lldb::CommandArgumentType arg_type) { 598 LLDB_RECORD_STATIC_METHOD(const char *, SBCommandInterpreter, 599 GetArgumentDescriptionAsCString, 600 (const lldb::CommandArgumentType), arg_type); 601 602 return CommandObject::GetArgumentDescriptionAsCString(arg_type); 603 } 604 605 bool SBCommandInterpreter::EventIsCommandInterpreterEvent( 606 const lldb::SBEvent &event) { 607 LLDB_RECORD_STATIC_METHOD(bool, SBCommandInterpreter, 608 EventIsCommandInterpreterEvent, 609 (const lldb::SBEvent &), event); 610 611 return event.GetBroadcasterClass() == 612 SBCommandInterpreter::GetBroadcasterClass(); 613 } 614 615 bool SBCommandInterpreter::SetCommandOverrideCallback( 616 const char *command_name, lldb::CommandOverrideCallback callback, 617 void *baton) { 618 LLDB_RECORD_DUMMY(bool, SBCommandInterpreter, SetCommandOverrideCallback, 619 (const char *, lldb::CommandOverrideCallback, void *), 620 command_name, callback, baton); 621 622 if (command_name && command_name[0] && IsValid()) { 623 llvm::StringRef command_name_str = command_name; 624 CommandObject *cmd_obj = 625 m_opaque_ptr->GetCommandObjectForCommand(command_name_str); 626 if (cmd_obj) { 627 assert(command_name_str.empty()); 628 cmd_obj->SetOverrideCallback(callback, baton); 629 return true; 630 } 631 } 632 return false; 633 } 634 635 lldb::SBCommand SBCommandInterpreter::AddMultiwordCommand(const char *name, 636 const char *help) { 637 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommandInterpreter, AddMultiwordCommand, 638 (const char *, const char *), name, help); 639 640 CommandObjectMultiword *new_command = 641 new CommandObjectMultiword(*m_opaque_ptr, name, help); 642 new_command->SetRemovable(true); 643 lldb::CommandObjectSP new_command_sp(new_command); 644 if (new_command_sp && 645 m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) 646 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 647 return LLDB_RECORD_RESULT(lldb::SBCommand()); 648 } 649 650 lldb::SBCommand SBCommandInterpreter::AddCommand( 651 const char *name, lldb::SBCommandPluginInterface *impl, const char *help) { 652 LLDB_RECORD_METHOD( 653 lldb::SBCommand, SBCommandInterpreter, AddCommand, 654 (const char *, lldb::SBCommandPluginInterface *, const char *), name, 655 impl, help); 656 657 lldb::CommandObjectSP new_command_sp; 658 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>( 659 *m_opaque_ptr, name, impl, help); 660 661 if (new_command_sp && 662 m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) 663 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 664 return LLDB_RECORD_RESULT(lldb::SBCommand()); 665 } 666 667 lldb::SBCommand 668 SBCommandInterpreter::AddCommand(const char *name, 669 lldb::SBCommandPluginInterface *impl, 670 const char *help, const char *syntax) { 671 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommandInterpreter, AddCommand, 672 (const char *, lldb::SBCommandPluginInterface *, 673 const char *, const char *), 674 name, impl, help, syntax); 675 676 lldb::CommandObjectSP new_command_sp; 677 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>( 678 *m_opaque_ptr, name, impl, help, syntax); 679 680 if (new_command_sp && 681 m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) 682 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 683 return LLDB_RECORD_RESULT(lldb::SBCommand()); 684 } 685 686 SBCommand::SBCommand() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBCommand); } 687 688 SBCommand::SBCommand(lldb::CommandObjectSP cmd_sp) : m_opaque_sp(cmd_sp) {} 689 690 bool SBCommand::IsValid() { 691 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommand, IsValid); 692 return this->operator bool(); 693 } 694 SBCommand::operator bool() const { 695 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommand, operator bool); 696 697 return m_opaque_sp.get() != nullptr; 698 } 699 700 const char *SBCommand::GetName() { 701 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBCommand, GetName); 702 703 return (IsValid() ? ConstString(m_opaque_sp->GetCommandName()).AsCString() : nullptr); 704 } 705 706 const char *SBCommand::GetHelp() { 707 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBCommand, GetHelp); 708 709 return (IsValid() ? ConstString(m_opaque_sp->GetHelp()).AsCString() 710 : nullptr); 711 } 712 713 const char *SBCommand::GetHelpLong() { 714 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBCommand, GetHelpLong); 715 716 return (IsValid() ? ConstString(m_opaque_sp->GetHelpLong()).AsCString() 717 : nullptr); 718 } 719 720 void SBCommand::SetHelp(const char *help) { 721 LLDB_RECORD_METHOD(void, SBCommand, SetHelp, (const char *), help); 722 723 if (IsValid()) 724 m_opaque_sp->SetHelp(help); 725 } 726 727 void SBCommand::SetHelpLong(const char *help) { 728 LLDB_RECORD_METHOD(void, SBCommand, SetHelpLong, (const char *), help); 729 730 if (IsValid()) 731 m_opaque_sp->SetHelpLong(help); 732 } 733 734 lldb::SBCommand SBCommand::AddMultiwordCommand(const char *name, 735 const char *help) { 736 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommand, AddMultiwordCommand, 737 (const char *, const char *), name, help); 738 739 if (!IsValid()) 740 return LLDB_RECORD_RESULT(lldb::SBCommand()); 741 if (!m_opaque_sp->IsMultiwordObject()) 742 return LLDB_RECORD_RESULT(lldb::SBCommand()); 743 CommandObjectMultiword *new_command = new CommandObjectMultiword( 744 m_opaque_sp->GetCommandInterpreter(), name, help); 745 new_command->SetRemovable(true); 746 lldb::CommandObjectSP new_command_sp(new_command); 747 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp)) 748 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 749 return LLDB_RECORD_RESULT(lldb::SBCommand()); 750 } 751 752 lldb::SBCommand SBCommand::AddCommand(const char *name, 753 lldb::SBCommandPluginInterface *impl, 754 const char *help) { 755 LLDB_RECORD_METHOD( 756 lldb::SBCommand, SBCommand, AddCommand, 757 (const char *, lldb::SBCommandPluginInterface *, const char *), name, 758 impl, help); 759 760 if (!IsValid()) 761 return LLDB_RECORD_RESULT(lldb::SBCommand()); 762 if (!m_opaque_sp->IsMultiwordObject()) 763 return LLDB_RECORD_RESULT(lldb::SBCommand()); 764 lldb::CommandObjectSP new_command_sp; 765 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>( 766 m_opaque_sp->GetCommandInterpreter(), name, impl, help); 767 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp)) 768 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 769 return LLDB_RECORD_RESULT(lldb::SBCommand()); 770 } 771 772 lldb::SBCommand SBCommand::AddCommand(const char *name, 773 lldb::SBCommandPluginInterface *impl, 774 const char *help, const char *syntax) { 775 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommand, AddCommand, 776 (const char *, lldb::SBCommandPluginInterface *, 777 const char *, const char *), 778 name, impl, help, syntax); 779 780 if (!IsValid()) 781 return LLDB_RECORD_RESULT(lldb::SBCommand()); 782 if (!m_opaque_sp->IsMultiwordObject()) 783 return LLDB_RECORD_RESULT(lldb::SBCommand()); 784 lldb::CommandObjectSP new_command_sp; 785 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>( 786 m_opaque_sp->GetCommandInterpreter(), name, impl, help, syntax); 787 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp)) 788 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 789 return LLDB_RECORD_RESULT(lldb::SBCommand()); 790 } 791 792 uint32_t SBCommand::GetFlags() { 793 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBCommand, GetFlags); 794 795 return (IsValid() ? m_opaque_sp->GetFlags().Get() : 0); 796 } 797 798 void SBCommand::SetFlags(uint32_t flags) { 799 LLDB_RECORD_METHOD(void, SBCommand, SetFlags, (uint32_t), flags); 800 801 if (IsValid()) 802 m_opaque_sp->GetFlags().Set(flags); 803 } 804 805 namespace lldb_private { 806 namespace repro { 807 808 template <> 809 void RegisterMethods<SBCommandInterpreterRunOptions>(Registry &R) { 810 LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreterRunOptions, ()); 811 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 812 GetStopOnContinue, ()); 813 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, 814 SetStopOnContinue, (bool)); 815 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 816 GetStopOnError, ()); 817 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetStopOnError, 818 (bool)); 819 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 820 GetStopOnCrash, ()); 821 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetStopOnCrash, 822 (bool)); 823 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 824 GetEchoCommands, ()); 825 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetEchoCommands, 826 (bool)); 827 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 828 GetEchoCommentCommands, ()); 829 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, 830 SetEchoCommentCommands, (bool)); 831 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 832 GetPrintResults, ()); 833 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetPrintResults, 834 (bool)); 835 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 836 GetAddToHistory, ()); 837 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetAddToHistory, 838 (bool)); 839 LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreter, 840 (lldb_private::CommandInterpreter *)); 841 LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreter, 842 (const lldb::SBCommandInterpreter &)); 843 LLDB_REGISTER_METHOD( 844 const lldb::SBCommandInterpreter &, 845 SBCommandInterpreter, operator=,(const lldb::SBCommandInterpreter &)); 846 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreter, IsValid, ()); 847 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreter, operator bool, ()); 848 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, CommandExists, 849 (const char *)); 850 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, AliasExists, 851 (const char *)); 852 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, IsActive, ()); 853 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreter, WasInterrupted, ()); 854 LLDB_REGISTER_METHOD(const char *, SBCommandInterpreter, 855 GetIOHandlerControlSequence, (char)); 856 LLDB_REGISTER_METHOD(lldb::ReturnStatus, SBCommandInterpreter, 857 HandleCommand, 858 (const char *, lldb::SBCommandReturnObject &, bool)); 859 LLDB_REGISTER_METHOD(lldb::ReturnStatus, SBCommandInterpreter, 860 HandleCommand, 861 (const char *, lldb::SBExecutionContext &, 862 lldb::SBCommandReturnObject &, bool)); 863 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, HandleCommandsFromFile, 864 (lldb::SBFileSpec &, lldb::SBExecutionContext &, 865 lldb::SBCommandInterpreterRunOptions &, 866 lldb::SBCommandReturnObject)); 867 LLDB_REGISTER_METHOD(int, SBCommandInterpreter, HandleCompletion, 868 (const char *, const char *, const char *, int, int, 869 lldb::SBStringList &)); 870 LLDB_REGISTER_METHOD(int, SBCommandInterpreter, 871 HandleCompletionWithDescriptions, 872 (const char *, const char *, const char *, int, int, 873 lldb::SBStringList &, lldb::SBStringList &)); 874 LLDB_REGISTER_METHOD(int, SBCommandInterpreter, 875 HandleCompletionWithDescriptions, 876 (const char *, uint32_t, int, int, 877 lldb::SBStringList &, lldb::SBStringList &)); 878 LLDB_REGISTER_METHOD( 879 int, SBCommandInterpreter, HandleCompletion, 880 (const char *, uint32_t, int, int, lldb::SBStringList &)); 881 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasCommands, ()); 882 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasAliases, ()); 883 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasAliasOptions, ()); 884 LLDB_REGISTER_METHOD(lldb::SBProcess, SBCommandInterpreter, GetProcess, ()); 885 LLDB_REGISTER_METHOD(lldb::SBDebugger, SBCommandInterpreter, GetDebugger, 886 ()); 887 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, GetPromptOnQuit, ()); 888 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, SetPromptOnQuit, (bool)); 889 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, AllowExitCodeOnQuit, 890 (bool)); 891 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasCustomQuitExitCode, ()); 892 LLDB_REGISTER_METHOD(int, SBCommandInterpreter, GetQuitStatus, ()); 893 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, ResolveCommand, 894 (const char *, lldb::SBCommandReturnObject &)); 895 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, 896 SourceInitFileInHomeDirectory, 897 (lldb::SBCommandReturnObject &)); 898 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, 899 SourceInitFileInCurrentWorkingDirectory, 900 (lldb::SBCommandReturnObject &)); 901 LLDB_REGISTER_METHOD(lldb::SBBroadcaster, SBCommandInterpreter, 902 GetBroadcaster, ()); 903 LLDB_REGISTER_STATIC_METHOD(const char *, SBCommandInterpreter, 904 GetBroadcasterClass, ()); 905 LLDB_REGISTER_STATIC_METHOD(const char *, SBCommandInterpreter, 906 GetArgumentTypeAsCString, 907 (const lldb::CommandArgumentType)); 908 LLDB_REGISTER_STATIC_METHOD(const char *, SBCommandInterpreter, 909 GetArgumentDescriptionAsCString, 910 (const lldb::CommandArgumentType)); 911 LLDB_REGISTER_STATIC_METHOD(bool, SBCommandInterpreter, 912 EventIsCommandInterpreterEvent, 913 (const lldb::SBEvent &)); 914 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommandInterpreter, 915 AddMultiwordCommand, (const char *, const char *)); 916 LLDB_REGISTER_METHOD( 917 lldb::SBCommand, SBCommandInterpreter, AddCommand, 918 (const char *, lldb::SBCommandPluginInterface *, const char *)); 919 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommandInterpreter, AddCommand, 920 (const char *, lldb::SBCommandPluginInterface *, 921 const char *, const char *)); 922 LLDB_REGISTER_CONSTRUCTOR(SBCommand, ()); 923 LLDB_REGISTER_METHOD(bool, SBCommand, IsValid, ()); 924 LLDB_REGISTER_METHOD_CONST(bool, SBCommand, operator bool, ()); 925 LLDB_REGISTER_METHOD(const char *, SBCommand, GetName, ()); 926 LLDB_REGISTER_METHOD(const char *, SBCommand, GetHelp, ()); 927 LLDB_REGISTER_METHOD(const char *, SBCommand, GetHelpLong, ()); 928 LLDB_REGISTER_METHOD(void, SBCommand, SetHelp, (const char *)); 929 LLDB_REGISTER_METHOD(void, SBCommand, SetHelpLong, (const char *)); 930 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommand, AddMultiwordCommand, 931 (const char *, const char *)); 932 LLDB_REGISTER_METHOD( 933 lldb::SBCommand, SBCommand, AddCommand, 934 (const char *, lldb::SBCommandPluginInterface *, const char *)); 935 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommand, AddCommand, 936 (const char *, lldb::SBCommandPluginInterface *, 937 const char *, const char *)); 938 LLDB_REGISTER_METHOD(uint32_t, SBCommand, GetFlags, ()); 939 LLDB_REGISTER_METHOD(void, SBCommand, SetFlags, (uint32_t)); 940 } 941 942 } 943 } 944