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