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