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 return ret; 171 } 172 std::shared_ptr<lldb::SBCommandPluginInterface> m_backend; 173 }; 174 175 SBCommandInterpreter::SBCommandInterpreter(CommandInterpreter *interpreter) 176 : m_opaque_ptr(interpreter) { 177 LLDB_RECORD_CONSTRUCTOR(SBCommandInterpreter, 178 (lldb_private::CommandInterpreter *), interpreter); 179 180 } 181 182 SBCommandInterpreter::SBCommandInterpreter(const SBCommandInterpreter &rhs) 183 : m_opaque_ptr(rhs.m_opaque_ptr) { 184 LLDB_RECORD_CONSTRUCTOR(SBCommandInterpreter, 185 (const lldb::SBCommandInterpreter &), rhs); 186 } 187 188 SBCommandInterpreter::~SBCommandInterpreter() = default; 189 190 const SBCommandInterpreter &SBCommandInterpreter:: 191 operator=(const SBCommandInterpreter &rhs) { 192 LLDB_RECORD_METHOD( 193 const lldb::SBCommandInterpreter &, 194 SBCommandInterpreter, operator=,(const lldb::SBCommandInterpreter &), 195 rhs); 196 197 m_opaque_ptr = rhs.m_opaque_ptr; 198 return LLDB_RECORD_RESULT(*this); 199 } 200 201 bool SBCommandInterpreter::IsValid() const { 202 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreter, IsValid); 203 return this->operator bool(); 204 } 205 SBCommandInterpreter::operator bool() const { 206 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreter, operator bool); 207 208 return m_opaque_ptr != nullptr; 209 } 210 211 bool SBCommandInterpreter::CommandExists(const char *cmd) { 212 LLDB_RECORD_METHOD(bool, SBCommandInterpreter, CommandExists, (const char *), 213 cmd); 214 215 return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->CommandExists(cmd) 216 : false); 217 } 218 219 bool SBCommandInterpreter::AliasExists(const char *cmd) { 220 LLDB_RECORD_METHOD(bool, SBCommandInterpreter, AliasExists, (const char *), 221 cmd); 222 223 return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->AliasExists(cmd) 224 : false); 225 } 226 227 bool SBCommandInterpreter::IsActive() { 228 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, IsActive); 229 230 return (IsValid() ? m_opaque_ptr->IsActive() : false); 231 } 232 233 bool SBCommandInterpreter::WasInterrupted() const { 234 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommandInterpreter, WasInterrupted); 235 236 return (IsValid() ? m_opaque_ptr->WasInterrupted() : false); 237 } 238 239 const char *SBCommandInterpreter::GetIOHandlerControlSequence(char ch) { 240 LLDB_RECORD_METHOD(const char *, SBCommandInterpreter, 241 GetIOHandlerControlSequence, (char), ch); 242 243 return (IsValid() 244 ? m_opaque_ptr->GetDebugger() 245 .GetTopIOHandlerControlSequence(ch) 246 .GetCString() 247 : nullptr); 248 } 249 250 lldb::ReturnStatus 251 SBCommandInterpreter::HandleCommand(const char *command_line, 252 SBCommandReturnObject &result, 253 bool add_to_history) { 254 LLDB_RECORD_METHOD(lldb::ReturnStatus, SBCommandInterpreter, HandleCommand, 255 (const char *, lldb::SBCommandReturnObject &, bool), 256 command_line, result, add_to_history); 257 258 SBExecutionContext sb_exe_ctx; 259 return HandleCommand(command_line, sb_exe_ctx, result, add_to_history); 260 } 261 262 lldb::ReturnStatus SBCommandInterpreter::HandleCommand( 263 const char *command_line, SBExecutionContext &override_context, 264 SBCommandReturnObject &result, bool add_to_history) { 265 LLDB_RECORD_METHOD(lldb::ReturnStatus, SBCommandInterpreter, HandleCommand, 266 (const char *, lldb::SBExecutionContext &, 267 lldb::SBCommandReturnObject &, bool), 268 command_line, override_context, result, add_to_history); 269 270 271 ExecutionContext ctx, *ctx_ptr; 272 if (override_context.get()) { 273 ctx = override_context.get()->Lock(true); 274 ctx_ptr = &ctx; 275 } else 276 ctx_ptr = nullptr; 277 278 result.Clear(); 279 if (command_line && IsValid()) { 280 result.ref().SetInteractive(false); 281 m_opaque_ptr->HandleCommand(command_line, 282 add_to_history ? eLazyBoolYes : eLazyBoolNo, 283 result.ref(), ctx_ptr); 284 } else { 285 result->AppendError( 286 "SBCommandInterpreter or the command line is not valid"); 287 result->SetStatus(eReturnStatusFailed); 288 } 289 290 291 return result.GetStatus(); 292 } 293 294 void SBCommandInterpreter::HandleCommandsFromFile( 295 lldb::SBFileSpec &file, lldb::SBExecutionContext &override_context, 296 lldb::SBCommandInterpreterRunOptions &options, 297 lldb::SBCommandReturnObject result) { 298 LLDB_RECORD_METHOD(void, SBCommandInterpreter, HandleCommandsFromFile, 299 (lldb::SBFileSpec &, lldb::SBExecutionContext &, 300 lldb::SBCommandInterpreterRunOptions &, 301 lldb::SBCommandReturnObject), 302 file, override_context, options, result); 303 304 if (!IsValid()) { 305 result->AppendError("SBCommandInterpreter is not valid."); 306 result->SetStatus(eReturnStatusFailed); 307 return; 308 } 309 310 if (!file.IsValid()) { 311 SBStream s; 312 file.GetDescription(s); 313 result->AppendErrorWithFormat("File is not valid: %s.", s.GetData()); 314 result->SetStatus(eReturnStatusFailed); 315 } 316 317 FileSpec tmp_spec = file.ref(); 318 ExecutionContext ctx, *ctx_ptr; 319 if (override_context.get()) { 320 ctx = override_context.get()->Lock(true); 321 ctx_ptr = &ctx; 322 } else 323 ctx_ptr = nullptr; 324 325 m_opaque_ptr->HandleCommandsFromFile(tmp_spec, ctx_ptr, options.ref(), 326 result.ref()); 327 } 328 329 int SBCommandInterpreter::HandleCompletion( 330 const char *current_line, const char *cursor, const char *last_char, 331 int match_start_point, int max_return_elements, SBStringList &matches) { 332 LLDB_RECORD_METHOD(int, SBCommandInterpreter, HandleCompletion, 333 (const char *, const char *, const char *, int, int, 334 lldb::SBStringList &), 335 current_line, cursor, last_char, match_start_point, 336 max_return_elements, matches); 337 338 SBStringList dummy_descriptions; 339 return HandleCompletionWithDescriptions( 340 current_line, cursor, last_char, match_start_point, max_return_elements, 341 matches, dummy_descriptions); 342 } 343 344 int SBCommandInterpreter::HandleCompletionWithDescriptions( 345 const char *current_line, const char *cursor, const char *last_char, 346 int match_start_point, int max_return_elements, SBStringList &matches, 347 SBStringList &descriptions) { 348 LLDB_RECORD_METHOD(int, SBCommandInterpreter, 349 HandleCompletionWithDescriptions, 350 (const char *, const char *, const char *, int, int, 351 lldb::SBStringList &, lldb::SBStringList &), 352 current_line, cursor, last_char, match_start_point, 353 max_return_elements, matches, descriptions); 354 355 // Sanity check the arguments that are passed in: cursor & last_char have to 356 // be within the current_line. 357 if (current_line == nullptr || cursor == nullptr || last_char == nullptr) 358 return 0; 359 360 if (cursor < current_line || last_char < current_line) 361 return 0; 362 363 size_t current_line_size = strlen(current_line); 364 if (cursor - current_line > static_cast<ptrdiff_t>(current_line_size) || 365 last_char - current_line > static_cast<ptrdiff_t>(current_line_size)) 366 return 0; 367 368 if (!IsValid()) 369 return 0; 370 371 lldb_private::StringList lldb_matches, lldb_descriptions; 372 CompletionResult result; 373 CompletionRequest request(current_line, cursor - current_line, result); 374 m_opaque_ptr->HandleCompletion(request); 375 result.GetMatches(lldb_matches); 376 result.GetDescriptions(lldb_descriptions); 377 378 // Make the result array indexed from 1 again by adding the 'common prefix' 379 // of all completions as element 0. This is done to emulate the old API. 380 if (request.GetParsedLine().GetArgumentCount() == 0) { 381 // If we got an empty string, insert nothing. 382 lldb_matches.InsertStringAtIndex(0, ""); 383 lldb_descriptions.InsertStringAtIndex(0, ""); 384 } else { 385 // Now figure out if there is a common substring, and if so put that in 386 // element 0, otherwise put an empty string in element 0. 387 std::string command_partial_str = request.GetCursorArgumentPrefix().str(); 388 389 std::string common_prefix = lldb_matches.LongestCommonPrefix(); 390 const size_t partial_name_len = command_partial_str.size(); 391 common_prefix.erase(0, partial_name_len); 392 393 // If we matched a unique single command, add a space... Only do this if 394 // the completer told us this was a complete word, however... 395 if (lldb_matches.GetSize() == 1) { 396 char quote_char = request.GetParsedArg().GetQuoteChar(); 397 common_prefix = 398 Args::EscapeLLDBCommandArgument(common_prefix, quote_char); 399 if (request.GetParsedArg().IsQuoted()) 400 common_prefix.push_back(quote_char); 401 common_prefix.push_back(' '); 402 } 403 lldb_matches.InsertStringAtIndex(0, common_prefix.c_str()); 404 lldb_descriptions.InsertStringAtIndex(0, ""); 405 } 406 407 SBStringList temp_matches_list(&lldb_matches); 408 matches.AppendList(temp_matches_list); 409 SBStringList temp_descriptions_list(&lldb_descriptions); 410 descriptions.AppendList(temp_descriptions_list); 411 return result.GetNumberOfResults(); 412 } 413 414 int SBCommandInterpreter::HandleCompletionWithDescriptions( 415 const char *current_line, uint32_t cursor_pos, int match_start_point, 416 int max_return_elements, SBStringList &matches, 417 SBStringList &descriptions) { 418 LLDB_RECORD_METHOD(int, SBCommandInterpreter, 419 HandleCompletionWithDescriptions, 420 (const char *, uint32_t, int, int, lldb::SBStringList &, 421 lldb::SBStringList &), 422 current_line, cursor_pos, match_start_point, 423 max_return_elements, matches, descriptions); 424 425 const char *cursor = current_line + cursor_pos; 426 const char *last_char = current_line + strlen(current_line); 427 return HandleCompletionWithDescriptions( 428 current_line, cursor, last_char, match_start_point, max_return_elements, 429 matches, descriptions); 430 } 431 432 int SBCommandInterpreter::HandleCompletion(const char *current_line, 433 uint32_t cursor_pos, 434 int match_start_point, 435 int max_return_elements, 436 lldb::SBStringList &matches) { 437 LLDB_RECORD_METHOD(int, SBCommandInterpreter, HandleCompletion, 438 (const char *, uint32_t, int, int, lldb::SBStringList &), 439 current_line, cursor_pos, match_start_point, 440 max_return_elements, matches); 441 442 const char *cursor = current_line + cursor_pos; 443 const char *last_char = current_line + strlen(current_line); 444 return HandleCompletion(current_line, cursor, last_char, match_start_point, 445 max_return_elements, matches); 446 } 447 448 bool SBCommandInterpreter::HasCommands() { 449 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasCommands); 450 451 return (IsValid() ? m_opaque_ptr->HasCommands() : false); 452 } 453 454 bool SBCommandInterpreter::HasAliases() { 455 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasAliases); 456 457 return (IsValid() ? m_opaque_ptr->HasAliases() : false); 458 } 459 460 bool SBCommandInterpreter::HasAliasOptions() { 461 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasAliasOptions); 462 463 return (IsValid() ? m_opaque_ptr->HasAliasOptions() : false); 464 } 465 466 SBProcess SBCommandInterpreter::GetProcess() { 467 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBProcess, SBCommandInterpreter, GetProcess); 468 469 SBProcess sb_process; 470 ProcessSP process_sp; 471 if (IsValid()) { 472 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); 473 if (target_sp) { 474 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); 475 process_sp = target_sp->GetProcessSP(); 476 sb_process.SetSP(process_sp); 477 } 478 } 479 480 return LLDB_RECORD_RESULT(sb_process); 481 } 482 483 SBDebugger SBCommandInterpreter::GetDebugger() { 484 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBDebugger, SBCommandInterpreter, 485 GetDebugger); 486 487 SBDebugger sb_debugger; 488 if (IsValid()) 489 sb_debugger.reset(m_opaque_ptr->GetDebugger().shared_from_this()); 490 491 return LLDB_RECORD_RESULT(sb_debugger); 492 } 493 494 bool SBCommandInterpreter::GetPromptOnQuit() { 495 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, GetPromptOnQuit); 496 497 return (IsValid() ? m_opaque_ptr->GetPromptOnQuit() : false); 498 } 499 500 void SBCommandInterpreter::SetPromptOnQuit(bool b) { 501 LLDB_RECORD_METHOD(void, SBCommandInterpreter, SetPromptOnQuit, (bool), b); 502 503 if (IsValid()) 504 m_opaque_ptr->SetPromptOnQuit(b); 505 } 506 507 void SBCommandInterpreter::AllowExitCodeOnQuit(bool allow) { 508 LLDB_RECORD_METHOD(void, SBCommandInterpreter, AllowExitCodeOnQuit, (bool), 509 allow); 510 511 if (m_opaque_ptr) 512 m_opaque_ptr->AllowExitCodeOnQuit(allow); 513 } 514 515 bool SBCommandInterpreter::HasCustomQuitExitCode() { 516 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommandInterpreter, HasCustomQuitExitCode); 517 518 bool exited = false; 519 if (m_opaque_ptr) 520 m_opaque_ptr->GetQuitExitCode(exited); 521 return exited; 522 } 523 524 int SBCommandInterpreter::GetQuitStatus() { 525 LLDB_RECORD_METHOD_NO_ARGS(int, SBCommandInterpreter, GetQuitStatus); 526 527 bool exited = false; 528 return (m_opaque_ptr ? m_opaque_ptr->GetQuitExitCode(exited) : 0); 529 } 530 531 void SBCommandInterpreter::ResolveCommand(const char *command_line, 532 SBCommandReturnObject &result) { 533 LLDB_RECORD_METHOD(void, SBCommandInterpreter, ResolveCommand, 534 (const char *, lldb::SBCommandReturnObject &), 535 command_line, result); 536 537 result.Clear(); 538 if (command_line && IsValid()) { 539 m_opaque_ptr->ResolveCommand(command_line, result.ref()); 540 } else { 541 result->AppendError( 542 "SBCommandInterpreter or the command line is not valid"); 543 result->SetStatus(eReturnStatusFailed); 544 } 545 } 546 547 CommandInterpreter *SBCommandInterpreter::get() { return m_opaque_ptr; } 548 549 CommandInterpreter &SBCommandInterpreter::ref() { 550 assert(m_opaque_ptr); 551 return *m_opaque_ptr; 552 } 553 554 void SBCommandInterpreter::reset( 555 lldb_private::CommandInterpreter *interpreter) { 556 m_opaque_ptr = interpreter; 557 } 558 559 void SBCommandInterpreter::SourceInitFileInHomeDirectory( 560 SBCommandReturnObject &result) { 561 LLDB_RECORD_METHOD(void, SBCommandInterpreter, SourceInitFileInHomeDirectory, 562 (lldb::SBCommandReturnObject &), result); 563 564 result.Clear(); 565 if (IsValid()) { 566 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); 567 std::unique_lock<std::recursive_mutex> lock; 568 if (target_sp) 569 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex()); 570 m_opaque_ptr->SourceInitFileHome(result.ref()); 571 } else { 572 result->AppendError("SBCommandInterpreter is not valid"); 573 result->SetStatus(eReturnStatusFailed); 574 } 575 } 576 577 void SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory( 578 SBCommandReturnObject &result) { 579 LLDB_RECORD_METHOD(void, SBCommandInterpreter, 580 SourceInitFileInCurrentWorkingDirectory, 581 (lldb::SBCommandReturnObject &), result); 582 583 result.Clear(); 584 if (IsValid()) { 585 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); 586 std::unique_lock<std::recursive_mutex> lock; 587 if (target_sp) 588 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex()); 589 m_opaque_ptr->SourceInitFileCwd(result.ref()); 590 } else { 591 result->AppendError("SBCommandInterpreter is not valid"); 592 result->SetStatus(eReturnStatusFailed); 593 } 594 } 595 596 SBBroadcaster SBCommandInterpreter::GetBroadcaster() { 597 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBBroadcaster, SBCommandInterpreter, 598 GetBroadcaster); 599 600 601 SBBroadcaster broadcaster(m_opaque_ptr, false); 602 603 604 return LLDB_RECORD_RESULT(broadcaster); 605 } 606 607 const char *SBCommandInterpreter::GetBroadcasterClass() { 608 LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBCommandInterpreter, 609 GetBroadcasterClass); 610 611 return CommandInterpreter::GetStaticBroadcasterClass().AsCString(); 612 } 613 614 const char *SBCommandInterpreter::GetArgumentTypeAsCString( 615 const lldb::CommandArgumentType arg_type) { 616 LLDB_RECORD_STATIC_METHOD(const char *, SBCommandInterpreter, 617 GetArgumentTypeAsCString, 618 (const lldb::CommandArgumentType), arg_type); 619 620 return CommandObject::GetArgumentTypeAsCString(arg_type); 621 } 622 623 const char *SBCommandInterpreter::GetArgumentDescriptionAsCString( 624 const lldb::CommandArgumentType arg_type) { 625 LLDB_RECORD_STATIC_METHOD(const char *, SBCommandInterpreter, 626 GetArgumentDescriptionAsCString, 627 (const lldb::CommandArgumentType), arg_type); 628 629 return CommandObject::GetArgumentDescriptionAsCString(arg_type); 630 } 631 632 bool SBCommandInterpreter::EventIsCommandInterpreterEvent( 633 const lldb::SBEvent &event) { 634 LLDB_RECORD_STATIC_METHOD(bool, SBCommandInterpreter, 635 EventIsCommandInterpreterEvent, 636 (const lldb::SBEvent &), event); 637 638 return event.GetBroadcasterClass() == 639 SBCommandInterpreter::GetBroadcasterClass(); 640 } 641 642 bool SBCommandInterpreter::SetCommandOverrideCallback( 643 const char *command_name, lldb::CommandOverrideCallback callback, 644 void *baton) { 645 LLDB_RECORD_DUMMY(bool, SBCommandInterpreter, SetCommandOverrideCallback, 646 (const char *, lldb::CommandOverrideCallback, void *), 647 command_name, callback, baton); 648 649 if (command_name && command_name[0] && IsValid()) { 650 llvm::StringRef command_name_str = command_name; 651 CommandObject *cmd_obj = 652 m_opaque_ptr->GetCommandObjectForCommand(command_name_str); 653 if (cmd_obj) { 654 assert(command_name_str.empty()); 655 cmd_obj->SetOverrideCallback(callback, baton); 656 return true; 657 } 658 } 659 return false; 660 } 661 662 lldb::SBCommand SBCommandInterpreter::AddMultiwordCommand(const char *name, 663 const char *help) { 664 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommandInterpreter, AddMultiwordCommand, 665 (const char *, const char *), name, help); 666 667 CommandObjectMultiword *new_command = 668 new CommandObjectMultiword(*m_opaque_ptr, name, help); 669 new_command->SetRemovable(true); 670 lldb::CommandObjectSP new_command_sp(new_command); 671 if (new_command_sp && 672 m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) 673 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 674 return LLDB_RECORD_RESULT(lldb::SBCommand()); 675 } 676 677 lldb::SBCommand SBCommandInterpreter::AddCommand( 678 const char *name, lldb::SBCommandPluginInterface *impl, const char *help) { 679 LLDB_RECORD_METHOD( 680 lldb::SBCommand, SBCommandInterpreter, AddCommand, 681 (const char *, lldb::SBCommandPluginInterface *, const char *), name, 682 impl, help); 683 684 lldb::CommandObjectSP new_command_sp; 685 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>( 686 *m_opaque_ptr, name, impl, help); 687 688 if (new_command_sp && 689 m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) 690 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 691 return LLDB_RECORD_RESULT(lldb::SBCommand()); 692 } 693 694 lldb::SBCommand 695 SBCommandInterpreter::AddCommand(const char *name, 696 lldb::SBCommandPluginInterface *impl, 697 const char *help, const char *syntax) { 698 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommandInterpreter, AddCommand, 699 (const char *, lldb::SBCommandPluginInterface *, 700 const char *, const char *), 701 name, impl, help, syntax); 702 703 lldb::CommandObjectSP new_command_sp; 704 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>( 705 *m_opaque_ptr, name, impl, help, syntax); 706 707 if (new_command_sp && 708 m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) 709 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 710 return LLDB_RECORD_RESULT(lldb::SBCommand()); 711 } 712 713 SBCommand::SBCommand() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBCommand); } 714 715 SBCommand::SBCommand(lldb::CommandObjectSP cmd_sp) : m_opaque_sp(cmd_sp) {} 716 717 bool SBCommand::IsValid() { 718 LLDB_RECORD_METHOD_NO_ARGS(bool, SBCommand, IsValid); 719 return this->operator bool(); 720 } 721 SBCommand::operator bool() const { 722 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCommand, operator bool); 723 724 return m_opaque_sp.get() != nullptr; 725 } 726 727 const char *SBCommand::GetName() { 728 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBCommand, GetName); 729 730 return (IsValid() ? ConstString(m_opaque_sp->GetCommandName()).AsCString() : nullptr); 731 } 732 733 const char *SBCommand::GetHelp() { 734 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBCommand, GetHelp); 735 736 return (IsValid() ? ConstString(m_opaque_sp->GetHelp()).AsCString() 737 : nullptr); 738 } 739 740 const char *SBCommand::GetHelpLong() { 741 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBCommand, GetHelpLong); 742 743 return (IsValid() ? ConstString(m_opaque_sp->GetHelpLong()).AsCString() 744 : nullptr); 745 } 746 747 void SBCommand::SetHelp(const char *help) { 748 LLDB_RECORD_METHOD(void, SBCommand, SetHelp, (const char *), help); 749 750 if (IsValid()) 751 m_opaque_sp->SetHelp(help); 752 } 753 754 void SBCommand::SetHelpLong(const char *help) { 755 LLDB_RECORD_METHOD(void, SBCommand, SetHelpLong, (const char *), help); 756 757 if (IsValid()) 758 m_opaque_sp->SetHelpLong(help); 759 } 760 761 lldb::SBCommand SBCommand::AddMultiwordCommand(const char *name, 762 const char *help) { 763 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommand, AddMultiwordCommand, 764 (const char *, const char *), name, help); 765 766 if (!IsValid()) 767 return LLDB_RECORD_RESULT(lldb::SBCommand()); 768 if (!m_opaque_sp->IsMultiwordObject()) 769 return LLDB_RECORD_RESULT(lldb::SBCommand()); 770 CommandObjectMultiword *new_command = new CommandObjectMultiword( 771 m_opaque_sp->GetCommandInterpreter(), name, help); 772 new_command->SetRemovable(true); 773 lldb::CommandObjectSP new_command_sp(new_command); 774 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp)) 775 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 776 return LLDB_RECORD_RESULT(lldb::SBCommand()); 777 } 778 779 lldb::SBCommand SBCommand::AddCommand(const char *name, 780 lldb::SBCommandPluginInterface *impl, 781 const char *help) { 782 LLDB_RECORD_METHOD( 783 lldb::SBCommand, SBCommand, AddCommand, 784 (const char *, lldb::SBCommandPluginInterface *, const char *), name, 785 impl, help); 786 787 if (!IsValid()) 788 return LLDB_RECORD_RESULT(lldb::SBCommand()); 789 if (!m_opaque_sp->IsMultiwordObject()) 790 return LLDB_RECORD_RESULT(lldb::SBCommand()); 791 lldb::CommandObjectSP new_command_sp; 792 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>( 793 m_opaque_sp->GetCommandInterpreter(), name, impl, help); 794 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp)) 795 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 796 return LLDB_RECORD_RESULT(lldb::SBCommand()); 797 } 798 799 lldb::SBCommand SBCommand::AddCommand(const char *name, 800 lldb::SBCommandPluginInterface *impl, 801 const char *help, const char *syntax) { 802 LLDB_RECORD_METHOD(lldb::SBCommand, SBCommand, AddCommand, 803 (const char *, lldb::SBCommandPluginInterface *, 804 const char *, const char *), 805 name, impl, help, syntax); 806 807 if (!IsValid()) 808 return LLDB_RECORD_RESULT(lldb::SBCommand()); 809 if (!m_opaque_sp->IsMultiwordObject()) 810 return LLDB_RECORD_RESULT(lldb::SBCommand()); 811 lldb::CommandObjectSP new_command_sp; 812 new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>( 813 m_opaque_sp->GetCommandInterpreter(), name, impl, help, syntax); 814 if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp)) 815 return LLDB_RECORD_RESULT(lldb::SBCommand(new_command_sp)); 816 return LLDB_RECORD_RESULT(lldb::SBCommand()); 817 } 818 819 uint32_t SBCommand::GetFlags() { 820 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBCommand, GetFlags); 821 822 return (IsValid() ? m_opaque_sp->GetFlags().Get() : 0); 823 } 824 825 void SBCommand::SetFlags(uint32_t flags) { 826 LLDB_RECORD_METHOD(void, SBCommand, SetFlags, (uint32_t), flags); 827 828 if (IsValid()) 829 m_opaque_sp->GetFlags().Set(flags); 830 } 831 832 namespace lldb_private { 833 namespace repro { 834 835 template <> 836 void RegisterMethods<SBCommandInterpreterRunOptions>(Registry &R) { 837 LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreterRunOptions, ()); 838 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 839 GetStopOnContinue, ()); 840 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, 841 SetStopOnContinue, (bool)); 842 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 843 GetStopOnError, ()); 844 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetStopOnError, 845 (bool)); 846 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 847 GetStopOnCrash, ()); 848 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetStopOnCrash, 849 (bool)); 850 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 851 GetEchoCommands, ()); 852 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetEchoCommands, 853 (bool)); 854 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 855 GetEchoCommentCommands, ()); 856 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, 857 SetEchoCommentCommands, (bool)); 858 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 859 GetPrintResults, ()); 860 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetPrintResults, 861 (bool)); 862 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreterRunOptions, 863 GetAddToHistory, ()); 864 LLDB_REGISTER_METHOD(void, SBCommandInterpreterRunOptions, SetAddToHistory, 865 (bool)); 866 LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreter, 867 (lldb_private::CommandInterpreter *)); 868 LLDB_REGISTER_CONSTRUCTOR(SBCommandInterpreter, 869 (const lldb::SBCommandInterpreter &)); 870 LLDB_REGISTER_METHOD( 871 const lldb::SBCommandInterpreter &, 872 SBCommandInterpreter, operator=,(const lldb::SBCommandInterpreter &)); 873 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreter, IsValid, ()); 874 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreter, operator bool, ()); 875 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, CommandExists, 876 (const char *)); 877 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, AliasExists, 878 (const char *)); 879 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, IsActive, ()); 880 LLDB_REGISTER_METHOD_CONST(bool, SBCommandInterpreter, WasInterrupted, ()); 881 LLDB_REGISTER_METHOD(const char *, SBCommandInterpreter, 882 GetIOHandlerControlSequence, (char)); 883 LLDB_REGISTER_METHOD(lldb::ReturnStatus, SBCommandInterpreter, 884 HandleCommand, 885 (const char *, lldb::SBCommandReturnObject &, bool)); 886 LLDB_REGISTER_METHOD(lldb::ReturnStatus, SBCommandInterpreter, 887 HandleCommand, 888 (const char *, lldb::SBExecutionContext &, 889 lldb::SBCommandReturnObject &, bool)); 890 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, HandleCommandsFromFile, 891 (lldb::SBFileSpec &, lldb::SBExecutionContext &, 892 lldb::SBCommandInterpreterRunOptions &, 893 lldb::SBCommandReturnObject)); 894 LLDB_REGISTER_METHOD(int, SBCommandInterpreter, HandleCompletion, 895 (const char *, const char *, const char *, int, int, 896 lldb::SBStringList &)); 897 LLDB_REGISTER_METHOD(int, SBCommandInterpreter, 898 HandleCompletionWithDescriptions, 899 (const char *, const char *, const char *, int, int, 900 lldb::SBStringList &, lldb::SBStringList &)); 901 LLDB_REGISTER_METHOD(int, SBCommandInterpreter, 902 HandleCompletionWithDescriptions, 903 (const char *, uint32_t, int, int, 904 lldb::SBStringList &, lldb::SBStringList &)); 905 LLDB_REGISTER_METHOD( 906 int, SBCommandInterpreter, HandleCompletion, 907 (const char *, uint32_t, int, int, lldb::SBStringList &)); 908 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasCommands, ()); 909 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasAliases, ()); 910 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasAliasOptions, ()); 911 LLDB_REGISTER_METHOD(lldb::SBProcess, SBCommandInterpreter, GetProcess, ()); 912 LLDB_REGISTER_METHOD(lldb::SBDebugger, SBCommandInterpreter, GetDebugger, 913 ()); 914 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, GetPromptOnQuit, ()); 915 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, SetPromptOnQuit, (bool)); 916 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, AllowExitCodeOnQuit, 917 (bool)); 918 LLDB_REGISTER_METHOD(bool, SBCommandInterpreter, HasCustomQuitExitCode, ()); 919 LLDB_REGISTER_METHOD(int, SBCommandInterpreter, GetQuitStatus, ()); 920 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, ResolveCommand, 921 (const char *, lldb::SBCommandReturnObject &)); 922 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, 923 SourceInitFileInHomeDirectory, 924 (lldb::SBCommandReturnObject &)); 925 LLDB_REGISTER_METHOD(void, SBCommandInterpreter, 926 SourceInitFileInCurrentWorkingDirectory, 927 (lldb::SBCommandReturnObject &)); 928 LLDB_REGISTER_METHOD(lldb::SBBroadcaster, SBCommandInterpreter, 929 GetBroadcaster, ()); 930 LLDB_REGISTER_STATIC_METHOD(const char *, SBCommandInterpreter, 931 GetBroadcasterClass, ()); 932 LLDB_REGISTER_STATIC_METHOD(const char *, SBCommandInterpreter, 933 GetArgumentTypeAsCString, 934 (const lldb::CommandArgumentType)); 935 LLDB_REGISTER_STATIC_METHOD(const char *, SBCommandInterpreter, 936 GetArgumentDescriptionAsCString, 937 (const lldb::CommandArgumentType)); 938 LLDB_REGISTER_STATIC_METHOD(bool, SBCommandInterpreter, 939 EventIsCommandInterpreterEvent, 940 (const lldb::SBEvent &)); 941 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommandInterpreter, 942 AddMultiwordCommand, (const char *, const char *)); 943 LLDB_REGISTER_METHOD( 944 lldb::SBCommand, SBCommandInterpreter, AddCommand, 945 (const char *, lldb::SBCommandPluginInterface *, const char *)); 946 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommandInterpreter, AddCommand, 947 (const char *, lldb::SBCommandPluginInterface *, 948 const char *, const char *)); 949 LLDB_REGISTER_CONSTRUCTOR(SBCommand, ()); 950 LLDB_REGISTER_METHOD(bool, SBCommand, IsValid, ()); 951 LLDB_REGISTER_METHOD_CONST(bool, SBCommand, operator bool, ()); 952 LLDB_REGISTER_METHOD(const char *, SBCommand, GetName, ()); 953 LLDB_REGISTER_METHOD(const char *, SBCommand, GetHelp, ()); 954 LLDB_REGISTER_METHOD(const char *, SBCommand, GetHelpLong, ()); 955 LLDB_REGISTER_METHOD(void, SBCommand, SetHelp, (const char *)); 956 LLDB_REGISTER_METHOD(void, SBCommand, SetHelpLong, (const char *)); 957 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommand, AddMultiwordCommand, 958 (const char *, const char *)); 959 LLDB_REGISTER_METHOD( 960 lldb::SBCommand, SBCommand, AddCommand, 961 (const char *, lldb::SBCommandPluginInterface *, const char *)); 962 LLDB_REGISTER_METHOD(lldb::SBCommand, SBCommand, AddCommand, 963 (const char *, lldb::SBCommandPluginInterface *, 964 const char *, const char *)); 965 LLDB_REGISTER_METHOD(uint32_t, SBCommand, GetFlags, ()); 966 LLDB_REGISTER_METHOD(void, SBCommand, SetFlags, (uint32_t)); 967 } 968 969 } 970 } 971