blob: 8ac2c51e12fe9dfc94076524b1815867bdd68976 [file] [log] [blame]
Johnny Chen0eca5442011-07-18 22:11:53 +00001//===-- 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
10namespace lldb {
11
12%feature("docstring",
13"SBDebugger is the primordial object that creates SBTargets and provides
14access to them. It also manages the overall debugging experiences.
15
16For example (from example/disasm.py),
17
18import lldb
19import os
20import sys
21
22def disassemble_instructions (insts):
23 for i in insts:
24 print i
25
26...
27
28# Create a new debugger instance
29debugger = 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.
33debugger.SetAsync (False)
34
35# Create a target from a file and arch
Zachary Turner5f3fd802015-10-16 17:52:32 +000036print('Creating a target for \'%s\'' % exe)
Johnny Chen0eca5442011-07-18 22:11:53 +000037
38target = debugger.CreateTargetWithFileAndArch (exe, lldb.LLDB_ARCH_DEFAULT)
39
40if 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 Turner5f3fd802015-10-16 17:52:32 +000085 print('Frame registers (size of register set = %d):' % registerList.GetSize())
Johnny Chen0eca5442011-07-18 22:11:53 +000086 for value in registerList:
87 #print value
Zachary Turner5f3fd802015-10-16 17:52:32 +000088 print('%s (number of children = %d):' % (value.GetName(), value.GetNumChildren()))
Johnny Chen0eca5442011-07-18 22:11:53 +000089 for child in value:
Zachary Turner5f3fd802015-10-16 17:52:32 +000090 print('Name: ', child.GetName(), ' Value: ', child.GetValue())
Johnny Chen0eca5442011-07-18 22:11:53 +000091
Zachary Turner5f3fd802015-10-16 17:52:32 +000092 print('Hit the breakpoint at main, enter to continue and wait for program to exit or \'Ctrl-D\'/\'quit\' to terminate the program')
Johnny Chen0eca5442011-07-18 22:11:53 +000093 next = sys.stdin.readline()
94 if not next or next.rstrip('\n') == 'quit':
Zachary Turner5f3fd802015-10-16 17:52:32 +000095 print('Terminating the inferior process...')
Johnny Chen0eca5442011-07-18 22:11:53 +000096 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 Turner5f3fd802015-10-16 17:52:32 +0000104 print('Didn\'t hit the breakpoint at main, program has exited...')
Johnny Chen0eca5442011-07-18 22:11:53 +0000105 else:
Zachary Turner5f3fd802015-10-16 17:52:32 +0000106 print('Unexpected process state: %s, killing process...' % debugger.StateAsCString (state))
Johnny Chen0eca5442011-07-18 22:11:53 +0000107 process.Kill()
Jim Ingham5c94f292016-02-01 20:05:37 +0000108
109Sometimes you need to create an empty target that will get filled in later. The most common use for this
110is to attach to a process by name or pid where you don't know the executable up front. The most convenient way
111to do this is:
112
113target = debugger.CreateTarget('')
114error = lldb.SBError()
115process = target.AttachToProcessWithName(debugger.GetListener(), 'PROCESS_NAME', False, error)
116
117or the equivalent arguments for AttachToProcessWithID.
Johnny Chen0eca5442011-07-18 22:11:53 +0000118") SBDebugger;
119class SBDebugger
120{
121public:
122
123 static void
124 Initialize();
125
126 static void
127 Terminate();
128
129 static lldb::SBDebugger
130 Create();
131
Jim Ingham228063c2012-02-21 02:23:08 +0000132 static lldb::SBDebugger
133 Create(bool source_init_files);
134
Filipe Cabecinhasc5041912012-08-25 00:29:07 +0000135 static lldb::SBDebugger
136 Create(bool source_init_files, lldb::LogOutputCallback log_callback, void *baton);
137
Johnny Chen0eca5442011-07-18 22:11:53 +0000138 static void
139 Destroy (lldb::SBDebugger &debugger);
140
Greg Claytonf9322412011-12-15 04:38:41 +0000141 static void
142 MemoryPressureDetected();
143
Johnny Chen0eca5442011-07-18 22:11:53 +0000144 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 Inghame64f0dc2011-09-13 23:25:31 +0000158
159 bool
160 GetAsync ();
Johnny Chen0eca5442011-07-18 22:11:53 +0000161
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 Claytoncac9c5f2011-09-24 00:52:29 +0000199 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 Chen0eca5442011-07-18 22:11:53 +0000206 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 Inghamb842f2e2017-09-14 20:22:49 +0000217 "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 Chen0eca5442011-07-18 22:11:53 +0000222 "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 Ingham8499e1a2012-05-08 23:06:07 +0000230 uint32_t
231 GetIndexOfTarget (lldb::SBTarget target);
232
Johnny Chen0eca5442011-07-18 22:11:53 +0000233 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 Inghame64f0dc2011-09-13 23:25:31 +0000246 void
247 SetSelectedTarget (lldb::SBTarget &target);
248
Greg Claytonfbb76342013-11-20 21:07:01 +0000249 lldb::SBPlatform
250 GetSelectedPlatform();
251
252 void
253 SetSelectedPlatform(lldb::SBPlatform &platform);
254
Vadim Macagonc10e34d2017-08-09 09:20:40 +0000255 %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 Inghame37d6052011-09-13 00:29:56 +0000283 lldb::SBSourceManager
Johnny Chen0eca5442011-07-18 22:11:53 +0000284 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 Mitchener832a28c2015-02-26 17:46:16 +0000302 bool
303 SetUseColor (bool use_color);
304
305 bool
306 GetUseColor () const;
307
Johnny Chen0eca5442011-07-18 22:11:53 +0000308 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 Labathf1389e92018-02-19 15:06:28 +0000323 static SBStructuredData GetBuildConfiguration();
324
Johnny Chen0eca5442011-07-18 22:11:53 +0000325 static bool
326 StateIsRunningState (lldb::StateType state);
327
328 static bool
329 StateIsStoppedState (lldb::StateType state);
330
Jim Ingham228063c2012-02-21 02:23:08 +0000331 bool
332 EnableLog (const char *channel, const char ** types);
333
Johnny Chen0eca5442011-07-18 22:11:53 +0000334 void
Filipe Cabecinhasc5041912012-08-25 00:29:07 +0000335 SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton);
336
337 void
Filipe Cabecinhasc3019992012-08-20 16:21:04 +0000338 DispatchInput (const void *data, size_t data_len);
Johnny Chen0eca5442011-07-18 22:11:53 +0000339
340 void
341 DispatchInputInterrupt ();
342
343 void
344 DispatchInputEndOfFile ();
345
Johnny Chen0eca5442011-07-18 22:11:53 +0000346 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 Granata061858c2012-02-15 02:34:21 +0000387
388 lldb::SBTypeCategory
389 GetCategory (const char* category_name);
390
Enrico Granatae2426242015-12-18 21:25:24 +0000391 SBTypeCategory
392 GetCategory (lldb::LanguageType lang_type);
393
Enrico Granata061858c2012-02-15 02:34:21 +0000394 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 Ingham26c7bf92014-10-11 00:38:27 +0000420
Greg Clayton44d93782014-01-27 23:43:24 +0000421 void
422 RunCommandInterpreter (bool auto_handle_events,
Jim Ingham26c7bf92014-10-11 00:38:27 +0000423 bool spawn_thread,
424 SBCommandInterpreterRunOptions &options,
425 int &num_errors,
Jim Inghamffc9f1d2014-10-14 01:20:07 +0000426 bool &quit_requested,
427 bool &stopped_for_crash);
Sean Callanan3e7e9152015-10-20 00:23:46 +0000428
429 lldb::SBError
430 RunREPL (lldb::LanguageType language, const char *repl_options);
Johnny Chen0eca5442011-07-18 22:11:53 +0000431}; // class SBDebugger
432
433} // namespace lldb