Johnny Chen | 0eca544 | 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 |
Zachary Turner | 5f3fd80 | 2015-10-16 17:52:32 +0000 | [diff] [blame] | 36 | print('Creating a target for \'%s\'' % exe) |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 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() |
Zachary Turner | 5f3fd80 | 2015-10-16 17:52:32 +0000 | [diff] [blame] | 85 | print('Frame registers (size of register set = %d):' % registerList.GetSize()) |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 86 | for value in registerList: |
| 87 | #print value |
Zachary Turner | 5f3fd80 | 2015-10-16 17:52:32 +0000 | [diff] [blame] | 88 | print('%s (number of children = %d):' % (value.GetName(), value.GetNumChildren())) |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 89 | for child in value: |
Zachary Turner | 5f3fd80 | 2015-10-16 17:52:32 +0000 | [diff] [blame] | 90 | print('Name: ', child.GetName(), ' Value: ', child.GetValue()) |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 91 | |
Zachary Turner | 5f3fd80 | 2015-10-16 17:52:32 +0000 | [diff] [blame] | 92 | print('Hit the breakpoint at main, enter to continue and wait for program to exit or \'Ctrl-D\'/\'quit\' to terminate the program') |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 93 | next = sys.stdin.readline() |
| 94 | if not next or next.rstrip('\n') == 'quit': |
Zachary Turner | 5f3fd80 | 2015-10-16 17:52:32 +0000 | [diff] [blame] | 95 | print('Terminating the inferior process...') |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 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: |
Zachary Turner | 5f3fd80 | 2015-10-16 17:52:32 +0000 | [diff] [blame] | 104 | print('Didn\'t hit the breakpoint at main, program has exited...') |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 105 | else: |
Zachary Turner | 5f3fd80 | 2015-10-16 17:52:32 +0000 | [diff] [blame] | 106 | print('Unexpected process state: %s, killing process...' % debugger.StateAsCString (state)) |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 107 | process.Kill() |
Jim Ingham | 5c94f29 | 2016-02-01 20:05:37 +0000 | [diff] [blame] | 108 | |
| 109 | Sometimes you need to create an empty target that will get filled in later. The most common use for this |
| 110 | is to attach to a process by name or pid where you don't know the executable up front. The most convenient way |
| 111 | to do this is: |
| 112 | |
| 113 | target = debugger.CreateTarget('') |
| 114 | error = lldb.SBError() |
| 115 | process = target.AttachToProcessWithName(debugger.GetListener(), 'PROCESS_NAME', False, error) |
| 116 | |
| 117 | or the equivalent arguments for AttachToProcessWithID. |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 118 | ") SBDebugger; |
| 119 | class SBDebugger |
| 120 | { |
| 121 | public: |
| 122 | |
| 123 | static void |
| 124 | Initialize(); |
| 125 | |
| 126 | static void |
| 127 | Terminate(); |
| 128 | |
| 129 | static lldb::SBDebugger |
| 130 | Create(); |
| 131 | |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 132 | static lldb::SBDebugger |
| 133 | Create(bool source_init_files); |
| 134 | |
Filipe Cabecinhas | c504191 | 2012-08-25 00:29:07 +0000 | [diff] [blame] | 135 | static lldb::SBDebugger |
| 136 | Create(bool source_init_files, lldb::LogOutputCallback log_callback, void *baton); |
| 137 | |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 138 | static void |
| 139 | Destroy (lldb::SBDebugger &debugger); |
| 140 | |
Greg Clayton | f932241 | 2011-12-15 04:38:41 +0000 | [diff] [blame] | 141 | static void |
| 142 | MemoryPressureDetected(); |
| 143 | |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 144 | SBDebugger(); |
| 145 | |
| 146 | SBDebugger(const lldb::SBDebugger &rhs); |
| 147 | |
| 148 | ~SBDebugger(); |
| 149 | |
| 150 | bool |
| 151 | IsValid() const; |
| 152 | |
| 153 | void |
| 154 | Clear (); |
| 155 | |
| 156 | void |
| 157 | SetAsync (bool b); |
Jim Ingham | e64f0dc | 2011-09-13 23:25:31 +0000 | [diff] [blame] | 158 | |
| 159 | bool |
| 160 | GetAsync (); |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 161 | |
| 162 | void |
| 163 | SkipLLDBInitFiles (bool b); |
| 164 | |
| 165 | void |
| 166 | SetInputFileHandle (FILE *f, bool transfer_ownership); |
| 167 | |
| 168 | void |
| 169 | SetOutputFileHandle (FILE *f, bool transfer_ownership); |
| 170 | |
| 171 | void |
| 172 | SetErrorFileHandle (FILE *f, bool transfer_ownership); |
| 173 | |
| 174 | FILE * |
| 175 | GetInputFileHandle (); |
| 176 | |
| 177 | FILE * |
| 178 | GetOutputFileHandle (); |
| 179 | |
| 180 | FILE * |
| 181 | GetErrorFileHandle (); |
| 182 | |
| 183 | lldb::SBCommandInterpreter |
| 184 | GetCommandInterpreter (); |
| 185 | |
| 186 | void |
| 187 | HandleCommand (const char *command); |
| 188 | |
| 189 | lldb::SBListener |
| 190 | GetListener (); |
| 191 | |
| 192 | void |
| 193 | HandleProcessEvent (const lldb::SBProcess &process, |
| 194 | const lldb::SBEvent &event, |
| 195 | FILE *out, |
| 196 | FILE *err); |
| 197 | |
| 198 | lldb::SBTarget |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 199 | CreateTarget (const char *filename, |
| 200 | const char *target_triple, |
| 201 | const char *platform_name, |
| 202 | bool add_dependent_modules, |
| 203 | lldb::SBError& sb_error); |
| 204 | |
| 205 | lldb::SBTarget |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 206 | CreateTargetWithFileAndTargetTriple (const char *filename, |
| 207 | const char *target_triple); |
| 208 | |
| 209 | lldb::SBTarget |
| 210 | CreateTargetWithFileAndArch (const char *filename, |
| 211 | const char *archname); |
| 212 | |
| 213 | lldb::SBTarget |
| 214 | CreateTarget (const char *filename); |
| 215 | |
| 216 | %feature("docstring", |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 217 | "The dummy target holds breakpoints and breakpoint names that will prime newly created targets." |
| 218 | ) GetDummyTarget; |
| 219 | lldb::SBTarget GetDummyTarget(); |
| 220 | |
| 221 | %feature("docstring", |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 222 | "Return true if target is deleted from the target list of the debugger." |
| 223 | ) DeleteTarget; |
| 224 | bool |
| 225 | DeleteTarget (lldb::SBTarget &target); |
| 226 | |
| 227 | lldb::SBTarget |
| 228 | GetTargetAtIndex (uint32_t idx); |
| 229 | |
Jim Ingham | 8499e1a | 2012-05-08 23:06:07 +0000 | [diff] [blame] | 230 | uint32_t |
| 231 | GetIndexOfTarget (lldb::SBTarget target); |
| 232 | |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 233 | lldb::SBTarget |
| 234 | FindTargetWithProcessID (pid_t pid); |
| 235 | |
| 236 | lldb::SBTarget |
| 237 | FindTargetWithFileAndArch (const char *filename, |
| 238 | const char *arch); |
| 239 | |
| 240 | uint32_t |
| 241 | GetNumTargets (); |
| 242 | |
| 243 | lldb::SBTarget |
| 244 | GetSelectedTarget (); |
| 245 | |
Jim Ingham | e64f0dc | 2011-09-13 23:25:31 +0000 | [diff] [blame] | 246 | void |
| 247 | SetSelectedTarget (lldb::SBTarget &target); |
| 248 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 249 | lldb::SBPlatform |
| 250 | GetSelectedPlatform(); |
| 251 | |
| 252 | void |
| 253 | SetSelectedPlatform(lldb::SBPlatform &platform); |
| 254 | |
Vadim Macagon | c10e34d | 2017-08-09 09:20:40 +0000 | [diff] [blame] | 255 | %feature("docstring", |
| 256 | "Get the number of currently active platforms." |
| 257 | ) GetNumPlatforms; |
| 258 | uint32_t |
| 259 | GetNumPlatforms (); |
| 260 | |
| 261 | %feature("docstring", |
| 262 | "Get one of the currently active platforms." |
| 263 | ) GetPlatformAtIndex; |
| 264 | lldb::SBPlatform |
| 265 | GetPlatformAtIndex (uint32_t idx); |
| 266 | |
| 267 | %feature("docstring", |
| 268 | "Get the number of available platforms." |
| 269 | ) GetNumAvailablePlatforms; |
| 270 | uint32_t |
| 271 | GetNumAvailablePlatforms (); |
| 272 | |
| 273 | %feature("docstring", " |
| 274 | Get the name and description of one of the available platforms. |
| 275 | |
| 276 | @param idx Zero-based index of the platform for which info should be |
| 277 | retrieved, must be less than the value returned by |
| 278 | GetNumAvailablePlatforms(). |
| 279 | ") GetAvailablePlatformInfoAtIndex; |
| 280 | lldb::SBStructuredData |
| 281 | GetAvailablePlatformInfoAtIndex (uint32_t idx); |
| 282 | |
Jim Ingham | e37d605 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 283 | lldb::SBSourceManager |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 284 | GetSourceManager (); |
| 285 | |
| 286 | // REMOVE: just for a quick fix, need to expose platforms through |
| 287 | // SBPlatform from this class. |
| 288 | lldb::SBError |
| 289 | SetCurrentPlatform (const char *platform_name); |
| 290 | |
| 291 | bool |
| 292 | SetCurrentPlatformSDKRoot (const char *sysroot); |
| 293 | |
| 294 | // FIXME: Once we get the set show stuff in place, the driver won't need |
| 295 | // an interface to the Set/Get UseExternalEditor. |
| 296 | bool |
| 297 | SetUseExternalEditor (bool input); |
| 298 | |
| 299 | bool |
| 300 | GetUseExternalEditor (); |
| 301 | |
Bruce Mitchener | 832a28c | 2015-02-26 17:46:16 +0000 | [diff] [blame] | 302 | bool |
| 303 | SetUseColor (bool use_color); |
| 304 | |
| 305 | bool |
| 306 | GetUseColor () const; |
| 307 | |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 308 | static bool |
| 309 | GetDefaultArchitecture (char *arch_name, size_t arch_name_len); |
| 310 | |
| 311 | static bool |
| 312 | SetDefaultArchitecture (const char *arch_name); |
| 313 | |
| 314 | lldb::ScriptLanguage |
| 315 | GetScriptingLanguage (const char *script_language_name); |
| 316 | |
| 317 | static const char * |
| 318 | GetVersionString (); |
| 319 | |
| 320 | static const char * |
| 321 | StateAsCString (lldb::StateType state); |
| 322 | |
Pavel Labath | f1389e9 | 2018-02-19 15:06:28 +0000 | [diff] [blame] | 323 | static SBStructuredData GetBuildConfiguration(); |
| 324 | |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 325 | static bool |
| 326 | StateIsRunningState (lldb::StateType state); |
| 327 | |
| 328 | static bool |
| 329 | StateIsStoppedState (lldb::StateType state); |
| 330 | |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 331 | bool |
| 332 | EnableLog (const char *channel, const char ** types); |
| 333 | |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 334 | void |
Filipe Cabecinhas | c504191 | 2012-08-25 00:29:07 +0000 | [diff] [blame] | 335 | SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton); |
| 336 | |
| 337 | void |
Filipe Cabecinhas | c301999 | 2012-08-20 16:21:04 +0000 | [diff] [blame] | 338 | DispatchInput (const void *data, size_t data_len); |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 339 | |
| 340 | void |
| 341 | DispatchInputInterrupt (); |
| 342 | |
| 343 | void |
| 344 | DispatchInputEndOfFile (); |
| 345 | |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 346 | const char * |
| 347 | GetInstanceName (); |
| 348 | |
| 349 | static SBDebugger |
| 350 | FindDebuggerWithID (int id); |
| 351 | |
| 352 | static lldb::SBError |
| 353 | SetInternalVariable (const char *var_name, const char *value, const char *debugger_instance_name); |
| 354 | |
| 355 | static lldb::SBStringList |
| 356 | GetInternalVariableValue (const char *var_name, const char *debugger_instance_name); |
| 357 | |
| 358 | bool |
| 359 | GetDescription (lldb::SBStream &description); |
| 360 | |
| 361 | uint32_t |
| 362 | GetTerminalWidth () const; |
| 363 | |
| 364 | void |
| 365 | SetTerminalWidth (uint32_t term_width); |
| 366 | |
| 367 | lldb::user_id_t |
| 368 | GetID (); |
| 369 | |
| 370 | const char * |
| 371 | GetPrompt() const; |
| 372 | |
| 373 | void |
| 374 | SetPrompt (const char *prompt); |
| 375 | |
| 376 | lldb::ScriptLanguage |
| 377 | GetScriptLanguage() const; |
| 378 | |
| 379 | void |
| 380 | SetScriptLanguage (lldb::ScriptLanguage script_lang); |
| 381 | |
| 382 | bool |
| 383 | GetCloseInputOnEOF () const; |
| 384 | |
| 385 | void |
| 386 | SetCloseInputOnEOF (bool b); |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 387 | |
| 388 | lldb::SBTypeCategory |
| 389 | GetCategory (const char* category_name); |
| 390 | |
Enrico Granata | e242624 | 2015-12-18 21:25:24 +0000 | [diff] [blame] | 391 | SBTypeCategory |
| 392 | GetCategory (lldb::LanguageType lang_type); |
| 393 | |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 394 | lldb::SBTypeCategory |
| 395 | CreateCategory (const char* category_name); |
| 396 | |
| 397 | bool |
| 398 | DeleteCategory (const char* category_name); |
| 399 | |
| 400 | uint32_t |
| 401 | GetNumCategories (); |
| 402 | |
| 403 | lldb::SBTypeCategory |
| 404 | GetCategoryAtIndex (uint32_t); |
| 405 | |
| 406 | lldb::SBTypeCategory |
| 407 | GetDefaultCategory(); |
| 408 | |
| 409 | lldb::SBTypeFormat |
| 410 | GetFormatForType (lldb::SBTypeNameSpecifier); |
| 411 | |
| 412 | lldb::SBTypeSummary |
| 413 | GetSummaryForType (lldb::SBTypeNameSpecifier); |
| 414 | |
| 415 | lldb::SBTypeFilter |
| 416 | GetFilterForType (lldb::SBTypeNameSpecifier); |
| 417 | |
| 418 | lldb::SBTypeSynthetic |
| 419 | GetSyntheticForType (lldb::SBTypeNameSpecifier); |
Jim Ingham | 26c7bf9 | 2014-10-11 00:38:27 +0000 | [diff] [blame] | 420 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 421 | void |
| 422 | RunCommandInterpreter (bool auto_handle_events, |
Jim Ingham | 26c7bf9 | 2014-10-11 00:38:27 +0000 | [diff] [blame] | 423 | bool spawn_thread, |
| 424 | SBCommandInterpreterRunOptions &options, |
| 425 | int &num_errors, |
Jim Ingham | ffc9f1d | 2014-10-14 01:20:07 +0000 | [diff] [blame] | 426 | bool &quit_requested, |
| 427 | bool &stopped_for_crash); |
Sean Callanan | 3e7e915 | 2015-10-20 00:23:46 +0000 | [diff] [blame] | 428 | |
| 429 | lldb::SBError |
| 430 | RunREPL (lldb::LanguageType language, const char *repl_options); |
Johnny Chen | 0eca544 | 2011-07-18 22:11:53 +0000 | [diff] [blame] | 431 | }; // class SBDebugger |
| 432 | |
| 433 | } // namespace lldb |