blob: de58f7115b826dc4eacb07b2608a97702490ba76 [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()
108") SBDebugger;
109class SBDebugger
110{
111public:
112
113 static void
114 Initialize();
115
116 static void
117 Terminate();
118
119 static lldb::SBDebugger
120 Create();
121
Jim Ingham228063c2012-02-21 02:23:08 +0000122 static lldb::SBDebugger
123 Create(bool source_init_files);
124
Filipe Cabecinhasc5041912012-08-25 00:29:07 +0000125 static lldb::SBDebugger
126 Create(bool source_init_files, lldb::LogOutputCallback log_callback, void *baton);
127
Johnny Chen0eca5442011-07-18 22:11:53 +0000128 static void
129 Destroy (lldb::SBDebugger &debugger);
130
Greg Claytonf9322412011-12-15 04:38:41 +0000131 static void
132 MemoryPressureDetected();
133
Johnny Chen0eca5442011-07-18 22:11:53 +0000134 SBDebugger();
135
136 SBDebugger(const lldb::SBDebugger &rhs);
137
138 ~SBDebugger();
139
140 bool
141 IsValid() const;
142
143 void
144 Clear ();
145
146 void
147 SetAsync (bool b);
Jim Inghame64f0dc2011-09-13 23:25:31 +0000148
149 bool
150 GetAsync ();
Johnny Chen0eca5442011-07-18 22:11:53 +0000151
152 void
153 SkipLLDBInitFiles (bool b);
154
155 void
156 SetInputFileHandle (FILE *f, bool transfer_ownership);
157
158 void
159 SetOutputFileHandle (FILE *f, bool transfer_ownership);
160
161 void
162 SetErrorFileHandle (FILE *f, bool transfer_ownership);
163
164 FILE *
165 GetInputFileHandle ();
166
167 FILE *
168 GetOutputFileHandle ();
169
170 FILE *
171 GetErrorFileHandle ();
172
173 lldb::SBCommandInterpreter
174 GetCommandInterpreter ();
175
176 void
177 HandleCommand (const char *command);
178
179 lldb::SBListener
180 GetListener ();
181
182 void
183 HandleProcessEvent (const lldb::SBProcess &process,
184 const lldb::SBEvent &event,
185 FILE *out,
186 FILE *err);
187
188 lldb::SBTarget
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000189 CreateTarget (const char *filename,
190 const char *target_triple,
191 const char *platform_name,
192 bool add_dependent_modules,
193 lldb::SBError& sb_error);
194
195 lldb::SBTarget
Johnny Chen0eca5442011-07-18 22:11:53 +0000196 CreateTargetWithFileAndTargetTriple (const char *filename,
197 const char *target_triple);
198
199 lldb::SBTarget
200 CreateTargetWithFileAndArch (const char *filename,
201 const char *archname);
202
203 lldb::SBTarget
204 CreateTarget (const char *filename);
205
206 %feature("docstring",
207 "Return true if target is deleted from the target list of the debugger."
208 ) DeleteTarget;
209 bool
210 DeleteTarget (lldb::SBTarget &target);
211
212 lldb::SBTarget
213 GetTargetAtIndex (uint32_t idx);
214
Jim Ingham8499e1a2012-05-08 23:06:07 +0000215 uint32_t
216 GetIndexOfTarget (lldb::SBTarget target);
217
Johnny Chen0eca5442011-07-18 22:11:53 +0000218 lldb::SBTarget
219 FindTargetWithProcessID (pid_t pid);
220
221 lldb::SBTarget
222 FindTargetWithFileAndArch (const char *filename,
223 const char *arch);
224
225 uint32_t
226 GetNumTargets ();
227
228 lldb::SBTarget
229 GetSelectedTarget ();
230
Jim Inghame64f0dc2011-09-13 23:25:31 +0000231 void
232 SetSelectedTarget (lldb::SBTarget &target);
233
Greg Claytonfbb76342013-11-20 21:07:01 +0000234 lldb::SBPlatform
235 GetSelectedPlatform();
236
237 void
238 SetSelectedPlatform(lldb::SBPlatform &platform);
239
Jim Inghame37d6052011-09-13 00:29:56 +0000240 lldb::SBSourceManager
Johnny Chen0eca5442011-07-18 22:11:53 +0000241 GetSourceManager ();
242
243 // REMOVE: just for a quick fix, need to expose platforms through
244 // SBPlatform from this class.
245 lldb::SBError
246 SetCurrentPlatform (const char *platform_name);
247
248 bool
249 SetCurrentPlatformSDKRoot (const char *sysroot);
250
251 // FIXME: Once we get the set show stuff in place, the driver won't need
252 // an interface to the Set/Get UseExternalEditor.
253 bool
254 SetUseExternalEditor (bool input);
255
256 bool
257 GetUseExternalEditor ();
258
Bruce Mitchener832a28c2015-02-26 17:46:16 +0000259 bool
260 SetUseColor (bool use_color);
261
262 bool
263 GetUseColor () const;
264
Johnny Chen0eca5442011-07-18 22:11:53 +0000265 static bool
266 GetDefaultArchitecture (char *arch_name, size_t arch_name_len);
267
268 static bool
269 SetDefaultArchitecture (const char *arch_name);
270
271 lldb::ScriptLanguage
272 GetScriptingLanguage (const char *script_language_name);
273
274 static const char *
275 GetVersionString ();
276
277 static const char *
278 StateAsCString (lldb::StateType state);
279
280 static bool
281 StateIsRunningState (lldb::StateType state);
282
283 static bool
284 StateIsStoppedState (lldb::StateType state);
285
Jim Ingham228063c2012-02-21 02:23:08 +0000286 bool
287 EnableLog (const char *channel, const char ** types);
288
Johnny Chen0eca5442011-07-18 22:11:53 +0000289 void
Filipe Cabecinhasc5041912012-08-25 00:29:07 +0000290 SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton);
291
292 void
Filipe Cabecinhasc3019992012-08-20 16:21:04 +0000293 DispatchInput (const void *data, size_t data_len);
Johnny Chen0eca5442011-07-18 22:11:53 +0000294
295 void
296 DispatchInputInterrupt ();
297
298 void
299 DispatchInputEndOfFile ();
300
Johnny Chen0eca5442011-07-18 22:11:53 +0000301 const char *
302 GetInstanceName ();
303
304 static SBDebugger
305 FindDebuggerWithID (int id);
306
307 static lldb::SBError
308 SetInternalVariable (const char *var_name, const char *value, const char *debugger_instance_name);
309
310 static lldb::SBStringList
311 GetInternalVariableValue (const char *var_name, const char *debugger_instance_name);
312
313 bool
314 GetDescription (lldb::SBStream &description);
315
316 uint32_t
317 GetTerminalWidth () const;
318
319 void
320 SetTerminalWidth (uint32_t term_width);
321
322 lldb::user_id_t
323 GetID ();
324
325 const char *
326 GetPrompt() const;
327
328 void
329 SetPrompt (const char *prompt);
330
331 lldb::ScriptLanguage
332 GetScriptLanguage() const;
333
334 void
335 SetScriptLanguage (lldb::ScriptLanguage script_lang);
336
337 bool
338 GetCloseInputOnEOF () const;
339
340 void
341 SetCloseInputOnEOF (bool b);
Enrico Granata061858c2012-02-15 02:34:21 +0000342
343 lldb::SBTypeCategory
344 GetCategory (const char* category_name);
345
346 lldb::SBTypeCategory
347 CreateCategory (const char* category_name);
348
349 bool
350 DeleteCategory (const char* category_name);
351
352 uint32_t
353 GetNumCategories ();
354
355 lldb::SBTypeCategory
356 GetCategoryAtIndex (uint32_t);
357
358 lldb::SBTypeCategory
359 GetDefaultCategory();
360
361 lldb::SBTypeFormat
362 GetFormatForType (lldb::SBTypeNameSpecifier);
363
364 lldb::SBTypeSummary
365 GetSummaryForType (lldb::SBTypeNameSpecifier);
366
367 lldb::SBTypeFilter
368 GetFilterForType (lldb::SBTypeNameSpecifier);
369
370 lldb::SBTypeSynthetic
371 GetSyntheticForType (lldb::SBTypeNameSpecifier);
Jim Ingham26c7bf92014-10-11 00:38:27 +0000372
Greg Clayton44d93782014-01-27 23:43:24 +0000373 void
374 RunCommandInterpreter (bool auto_handle_events,
Jim Ingham26c7bf92014-10-11 00:38:27 +0000375 bool spawn_thread,
376 SBCommandInterpreterRunOptions &options,
377 int &num_errors,
Jim Inghamffc9f1d2014-10-14 01:20:07 +0000378 bool &quit_requested,
379 bool &stopped_for_crash);
Johnny Chen0eca5442011-07-18 22:11:53 +0000380}; // class SBDebugger
381
382} // namespace lldb