Johnny Chen | 6cf1bc3 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 1 | //===-- SWIG Interface for SBDebugger ---------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | namespace lldb { |
| 11 | |
| 12 | %feature("docstring", |
| 13 | "SBDebugger is the primordial object that creates SBTargets and provides |
| 14 | access to them. It also manages the overall debugging experiences. |
| 15 | |
| 16 | For example (from example/disasm.py), |
| 17 | |
| 18 | import lldb |
| 19 | import os |
| 20 | import sys |
| 21 | |
| 22 | def disassemble_instructions (insts): |
| 23 | for i in insts: |
| 24 | print i |
| 25 | |
| 26 | ... |
| 27 | |
| 28 | # Create a new debugger instance |
| 29 | debugger = lldb.SBDebugger.Create() |
| 30 | |
| 31 | # When we step or continue, don't return from the function until the process |
| 32 | # stops. We do this by setting the async mode to false. |
| 33 | debugger.SetAsync (False) |
| 34 | |
| 35 | # Create a target from a file and arch |
| 36 | print 'Creating a target for \'%s\'' % exe |
| 37 | |
| 38 | target = debugger.CreateTargetWithFileAndArch (exe, lldb.LLDB_ARCH_DEFAULT) |
| 39 | |
| 40 | if target: |
| 41 | # If the target is valid set a breakpoint at main |
| 42 | main_bp = target.BreakpointCreateByName (fname, target.GetExecutable().GetFilename()); |
| 43 | |
| 44 | print main_bp |
| 45 | |
| 46 | # Launch the process. Since we specified synchronous mode, we won't return |
| 47 | # from this function until we hit the breakpoint at main |
| 48 | process = target.LaunchSimple (None, None, os.getcwd()) |
| 49 | |
| 50 | # Make sure the launch went ok |
| 51 | if process: |
| 52 | # Print some simple process info |
| 53 | state = process.GetState () |
| 54 | print process |
| 55 | if state == lldb.eStateStopped: |
| 56 | # Get the first thread |
| 57 | thread = process.GetThreadAtIndex (0) |
| 58 | if thread: |
| 59 | # Print some simple thread info |
| 60 | print thread |
| 61 | # Get the first frame |
| 62 | frame = thread.GetFrameAtIndex (0) |
| 63 | if frame: |
| 64 | # Print some simple frame info |
| 65 | print frame |
| 66 | function = frame.GetFunction() |
| 67 | # See if we have debug info (a function) |
| 68 | if function: |
| 69 | # We do have a function, print some info for the function |
| 70 | print function |
| 71 | # Now get all instructions for this function and print them |
| 72 | insts = function.GetInstructions(target) |
| 73 | disassemble_instructions (insts) |
| 74 | else: |
| 75 | # See if we have a symbol in the symbol table for where we stopped |
| 76 | symbol = frame.GetSymbol(); |
| 77 | if symbol: |
| 78 | # We do have a symbol, print some info for the symbol |
| 79 | print symbol |
| 80 | # Now get all instructions for this symbol and print them |
| 81 | insts = symbol.GetInstructions(target) |
| 82 | disassemble_instructions (insts) |
| 83 | |
| 84 | registerList = frame.GetRegisters() |
| 85 | print 'Frame registers (size of register set = %d):' % registerList.GetSize() |
| 86 | for value in registerList: |
| 87 | #print value |
| 88 | print '%s (number of children = %d):' % (value.GetName(), value.GetNumChildren()) |
| 89 | for child in value: |
| 90 | print 'Name: ', child.GetName(), ' Value: ', child.GetValue(frame) |
| 91 | |
| 92 | print 'Hit the breakpoint at main, enter to continue and wait for program to exit or \'Ctrl-D\'/\'quit\' to terminate the program' |
| 93 | next = sys.stdin.readline() |
| 94 | if not next or next.rstrip('\n') == 'quit': |
| 95 | print 'Terminating the inferior process...' |
| 96 | process.Kill() |
| 97 | else: |
| 98 | # Now continue to the program exit |
| 99 | process.Continue() |
| 100 | # When we return from the above function we will hopefully be at the |
| 101 | # program exit. Print out some process info |
| 102 | print process |
| 103 | elif state == lldb.eStateExited: |
| 104 | print 'Didn\'t hit the breakpoint at main, program has exited...' |
| 105 | else: |
| 106 | print 'Unexpected process state: %s, killing process...' % debugger.StateAsCString (state) |
| 107 | process.Kill() |
| 108 | ") SBDebugger; |
| 109 | class SBDebugger |
| 110 | { |
| 111 | public: |
| 112 | |
| 113 | static void |
| 114 | Initialize(); |
| 115 | |
| 116 | static void |
| 117 | Terminate(); |
| 118 | |
| 119 | static lldb::SBDebugger |
| 120 | Create(); |
| 121 | |
| 122 | static void |
| 123 | Destroy (lldb::SBDebugger &debugger); |
| 124 | |
| 125 | SBDebugger(); |
| 126 | |
| 127 | SBDebugger(const lldb::SBDebugger &rhs); |
| 128 | |
| 129 | ~SBDebugger(); |
| 130 | |
| 131 | bool |
| 132 | IsValid() const; |
| 133 | |
| 134 | void |
| 135 | Clear (); |
| 136 | |
| 137 | void |
| 138 | SetAsync (bool b); |
| 139 | |
| 140 | void |
| 141 | SkipLLDBInitFiles (bool b); |
| 142 | |
| 143 | void |
| 144 | SetInputFileHandle (FILE *f, bool transfer_ownership); |
| 145 | |
| 146 | void |
| 147 | SetOutputFileHandle (FILE *f, bool transfer_ownership); |
| 148 | |
| 149 | void |
| 150 | SetErrorFileHandle (FILE *f, bool transfer_ownership); |
| 151 | |
| 152 | FILE * |
| 153 | GetInputFileHandle (); |
| 154 | |
| 155 | FILE * |
| 156 | GetOutputFileHandle (); |
| 157 | |
| 158 | FILE * |
| 159 | GetErrorFileHandle (); |
| 160 | |
| 161 | lldb::SBCommandInterpreter |
| 162 | GetCommandInterpreter (); |
| 163 | |
| 164 | void |
| 165 | HandleCommand (const char *command); |
| 166 | |
| 167 | lldb::SBListener |
| 168 | GetListener (); |
| 169 | |
| 170 | void |
| 171 | HandleProcessEvent (const lldb::SBProcess &process, |
| 172 | const lldb::SBEvent &event, |
| 173 | FILE *out, |
| 174 | FILE *err); |
| 175 | |
| 176 | lldb::SBTarget |
| 177 | CreateTargetWithFileAndTargetTriple (const char *filename, |
| 178 | const char *target_triple); |
| 179 | |
| 180 | lldb::SBTarget |
| 181 | CreateTargetWithFileAndArch (const char *filename, |
| 182 | const char *archname); |
| 183 | |
| 184 | lldb::SBTarget |
| 185 | CreateTarget (const char *filename); |
| 186 | |
| 187 | %feature("docstring", |
| 188 | "Return true if target is deleted from the target list of the debugger." |
| 189 | ) DeleteTarget; |
| 190 | bool |
| 191 | DeleteTarget (lldb::SBTarget &target); |
| 192 | |
| 193 | lldb::SBTarget |
| 194 | GetTargetAtIndex (uint32_t idx); |
| 195 | |
| 196 | lldb::SBTarget |
| 197 | FindTargetWithProcessID (pid_t pid); |
| 198 | |
| 199 | lldb::SBTarget |
| 200 | FindTargetWithFileAndArch (const char *filename, |
| 201 | const char *arch); |
| 202 | |
| 203 | uint32_t |
| 204 | GetNumTargets (); |
| 205 | |
| 206 | lldb::SBTarget |
| 207 | GetSelectedTarget (); |
| 208 | |
| 209 | lldb::SBSourceManager & |
| 210 | GetSourceManager (); |
| 211 | |
| 212 | // REMOVE: just for a quick fix, need to expose platforms through |
| 213 | // SBPlatform from this class. |
| 214 | lldb::SBError |
| 215 | SetCurrentPlatform (const char *platform_name); |
| 216 | |
| 217 | bool |
| 218 | SetCurrentPlatformSDKRoot (const char *sysroot); |
| 219 | |
| 220 | // FIXME: Once we get the set show stuff in place, the driver won't need |
| 221 | // an interface to the Set/Get UseExternalEditor. |
| 222 | bool |
| 223 | SetUseExternalEditor (bool input); |
| 224 | |
| 225 | bool |
| 226 | GetUseExternalEditor (); |
| 227 | |
| 228 | static bool |
| 229 | GetDefaultArchitecture (char *arch_name, size_t arch_name_len); |
| 230 | |
| 231 | static bool |
| 232 | SetDefaultArchitecture (const char *arch_name); |
| 233 | |
| 234 | lldb::ScriptLanguage |
| 235 | GetScriptingLanguage (const char *script_language_name); |
| 236 | |
| 237 | static const char * |
| 238 | GetVersionString (); |
| 239 | |
| 240 | static const char * |
| 241 | StateAsCString (lldb::StateType state); |
| 242 | |
| 243 | static bool |
| 244 | StateIsRunningState (lldb::StateType state); |
| 245 | |
| 246 | static bool |
| 247 | StateIsStoppedState (lldb::StateType state); |
| 248 | |
| 249 | void |
| 250 | DispatchInput (void *baton, const void *data, size_t data_len); |
| 251 | |
| 252 | void |
| 253 | DispatchInputInterrupt (); |
| 254 | |
| 255 | void |
| 256 | DispatchInputEndOfFile (); |
| 257 | |
| 258 | void |
| 259 | PushInputReader (lldb::SBInputReader &reader); |
| 260 | |
| 261 | void |
| 262 | NotifyTopInputReader (lldb::InputReaderAction notification); |
| 263 | |
| 264 | bool |
| 265 | InputReaderIsTopReader (const lldb::SBInputReader &reader); |
| 266 | |
| 267 | const char * |
| 268 | GetInstanceName (); |
| 269 | |
| 270 | static SBDebugger |
| 271 | FindDebuggerWithID (int id); |
| 272 | |
| 273 | static lldb::SBError |
| 274 | SetInternalVariable (const char *var_name, const char *value, const char *debugger_instance_name); |
| 275 | |
| 276 | static lldb::SBStringList |
| 277 | GetInternalVariableValue (const char *var_name, const char *debugger_instance_name); |
| 278 | |
| 279 | bool |
| 280 | GetDescription (lldb::SBStream &description); |
| 281 | |
| 282 | uint32_t |
| 283 | GetTerminalWidth () const; |
| 284 | |
| 285 | void |
| 286 | SetTerminalWidth (uint32_t term_width); |
| 287 | |
| 288 | lldb::user_id_t |
| 289 | GetID (); |
| 290 | |
| 291 | const char * |
| 292 | GetPrompt() const; |
| 293 | |
| 294 | void |
| 295 | SetPrompt (const char *prompt); |
| 296 | |
| 297 | lldb::ScriptLanguage |
| 298 | GetScriptLanguage() const; |
| 299 | |
| 300 | void |
| 301 | SetScriptLanguage (lldb::ScriptLanguage script_lang); |
| 302 | |
| 303 | bool |
| 304 | GetCloseInputOnEOF () const; |
| 305 | |
| 306 | void |
| 307 | SetCloseInputOnEOF (bool b); |
| 308 | }; // class SBDebugger |
| 309 | |
| 310 | } // namespace lldb |