1 //===-- SWIG Interface for SBCommandInterpreter -----------------*- 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 namespace lldb { 10 11 %feature("docstring", 12 "SBCommandInterpreter handles/interprets commands for lldb. You get the 13 command interpreter from the SBDebugger instance. For example (from test/ 14 python_api/interpreter/TestCommandInterpreterAPI.py), 15 16 def command_interpreter_api(self): 17 '''Test the SBCommandInterpreter APIs.''' 18 exe = os.path.join(os.getcwd(), 'a.out') 19 20 # Create a target by the debugger. 21 target = self.dbg.CreateTarget(exe) 22 self.assertTrue(target, VALID_TARGET) 23 24 # Retrieve the associated command interpreter from our debugger. 25 ci = self.dbg.GetCommandInterpreter() 26 self.assertTrue(ci, VALID_COMMAND_INTERPRETER) 27 28 # Exercise some APIs.... 29 30 self.assertTrue(ci.HasCommands()) 31 self.assertTrue(ci.HasAliases()) 32 self.assertTrue(ci.HasAliasOptions()) 33 self.assertTrue(ci.CommandExists('breakpoint')) 34 self.assertTrue(ci.CommandExists('target')) 35 self.assertTrue(ci.CommandExists('platform')) 36 self.assertTrue(ci.AliasExists('file')) 37 self.assertTrue(ci.AliasExists('run')) 38 self.assertTrue(ci.AliasExists('bt')) 39 40 res = lldb.SBCommandReturnObject() 41 ci.HandleCommand('breakpoint set -f main.c -l %d' % self.line, res) 42 self.assertTrue(res.Succeeded()) 43 ci.HandleCommand('process launch', res) 44 self.assertTrue(res.Succeeded()) 45 46 process = ci.GetProcess() 47 self.assertTrue(process) 48 49 ... 50 51 The HandleCommand() instance method takes two args: the command string and 52 an SBCommandReturnObject instance which encapsulates the result of command 53 execution.") SBCommandInterpreter; 54 class SBCommandInterpreter 55 { 56 public: 57 enum 58 { 59 eBroadcastBitThreadShouldExit = (1 << 0), 60 eBroadcastBitResetPrompt = (1 << 1), 61 eBroadcastBitQuitCommandReceived = (1 << 2), // User entered quit 62 eBroadcastBitAsynchronousOutputData = (1 << 3), 63 eBroadcastBitAsynchronousErrorData = (1 << 4) 64 }; 65 66 SBCommandInterpreter (const lldb::SBCommandInterpreter &rhs); 67 68 ~SBCommandInterpreter (); 69 70 static const char * 71 GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type); 72 73 static const char * 74 GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type); 75 76 static bool 77 EventIsCommandInterpreterEvent (const lldb::SBEvent &event); 78 79 bool 80 IsValid() const; 81 82 explicit operator bool() const; 83 84 const char * 85 GetIOHandlerControlSequence(char ch); 86 87 bool 88 GetPromptOnQuit(); 89 90 void 91 SetPromptOnQuit(bool b); 92 93 void 94 AllowExitCodeOnQuit(bool b); 95 96 bool 97 HasCustomQuitExitCode(); 98 99 int 100 GetQuitStatus(); 101 102 void 103 ResolveCommand(const char *command_line, SBCommandReturnObject &result); 104 105 bool 106 CommandExists (const char *cmd); 107 108 bool 109 AliasExists (const char *cmd); 110 111 lldb::SBBroadcaster 112 GetBroadcaster (); 113 114 static const char * 115 GetBroadcasterClass (); 116 117 bool 118 HasCommands (); 119 120 bool 121 HasAliases (); 122 123 bool 124 HasAliasOptions (); 125 126 lldb::SBProcess 127 GetProcess (); 128 129 lldb::SBDebugger 130 GetDebugger (); 131 132 void 133 SourceInitFileInHomeDirectory (lldb::SBCommandReturnObject &result); 134 135 void 136 SourceInitFileInCurrentWorkingDirectory (lldb::SBCommandReturnObject &result); 137 138 lldb::ReturnStatus 139 HandleCommand (const char *command_line, lldb::SBCommandReturnObject &result, bool add_to_history = false); 140 141 lldb::ReturnStatus 142 HandleCommand (const char *command_line, SBExecutionContext &exe_ctx, SBCommandReturnObject &result, bool add_to_history = false); 143 144 void 145 HandleCommandsFromFile (lldb::SBFileSpec &file, 146 lldb::SBExecutionContext &override_context, 147 lldb::SBCommandInterpreterRunOptions &options, 148 lldb::SBCommandReturnObject result); 149 150 int 151 HandleCompletion (const char *current_line, 152 uint32_t cursor_pos, 153 int match_start_point, 154 int max_return_elements, 155 lldb::SBStringList &matches); 156 157 int 158 HandleCompletionWithDescriptions (const char *current_line, 159 uint32_t cursor_pos, 160 int match_start_point, 161 int max_return_elements, 162 lldb::SBStringList &matches, 163 lldb::SBStringList &descriptions); 164 bool 165 IsActive (); 166 167 bool 168 WasInterrupted () const; 169 }; 170 171 } // namespace lldb 172