blob: 2fabc452fb9450be5450c2364fcb5b26185ad28d [file] [log] [blame]
Johnny Chen6cf1bc32011-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
36print 'Creating a target for \'%s\'' % exe
37
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()
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;
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 Ingham6c530f22012-02-21 02:23:08 +0000122 static lldb::SBDebugger
123 Create(bool source_init_files);
124
Johnny Chen6cf1bc32011-07-18 22:11:53 +0000125 static void
126 Destroy (lldb::SBDebugger &debugger);
127
Greg Claytonc5486872011-12-15 04:38:41 +0000128 static void
129 MemoryPressureDetected();
130
Johnny Chen6cf1bc32011-07-18 22:11:53 +0000131 SBDebugger();
132
133 SBDebugger(const lldb::SBDebugger &rhs);
134
135 ~SBDebugger();
136
137 bool
138 IsValid() const;
139
140 void
141 Clear ();
142
143 void
144 SetAsync (bool b);
Jim Ingham83dd2032011-09-13 23:25:31 +0000145
146 bool
147 GetAsync ();
Johnny Chen6cf1bc32011-07-18 22:11:53 +0000148
149 void
150 SkipLLDBInitFiles (bool b);
151
152 void
153 SetInputFileHandle (FILE *f, bool transfer_ownership);
154
155 void
156 SetOutputFileHandle (FILE *f, bool transfer_ownership);
157
158 void
159 SetErrorFileHandle (FILE *f, bool transfer_ownership);
160
161 FILE *
162 GetInputFileHandle ();
163
164 FILE *
165 GetOutputFileHandle ();
166
167 FILE *
168 GetErrorFileHandle ();
169
170 lldb::SBCommandInterpreter
171 GetCommandInterpreter ();
172
173 void
174 HandleCommand (const char *command);
175
176 lldb::SBListener
177 GetListener ();
178
179 void
180 HandleProcessEvent (const lldb::SBProcess &process,
181 const lldb::SBEvent &event,
182 FILE *out,
183 FILE *err);
184
185 lldb::SBTarget
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000186 CreateTarget (const char *filename,
187 const char *target_triple,
188 const char *platform_name,
189 bool add_dependent_modules,
190 lldb::SBError& sb_error);
191
192 lldb::SBTarget
Johnny Chen6cf1bc32011-07-18 22:11:53 +0000193 CreateTargetWithFileAndTargetTriple (const char *filename,
194 const char *target_triple);
195
196 lldb::SBTarget
197 CreateTargetWithFileAndArch (const char *filename,
198 const char *archname);
199
200 lldb::SBTarget
201 CreateTarget (const char *filename);
202
203 %feature("docstring",
204 "Return true if target is deleted from the target list of the debugger."
205 ) DeleteTarget;
206 bool
207 DeleteTarget (lldb::SBTarget &target);
208
209 lldb::SBTarget
210 GetTargetAtIndex (uint32_t idx);
211
Jim Inghamf92ddcc2012-05-08 23:06:07 +0000212 uint32_t
213 GetIndexOfTarget (lldb::SBTarget target);
214
Johnny Chen6cf1bc32011-07-18 22:11:53 +0000215 lldb::SBTarget
216 FindTargetWithProcessID (pid_t pid);
217
218 lldb::SBTarget
219 FindTargetWithFileAndArch (const char *filename,
220 const char *arch);
221
222 uint32_t
223 GetNumTargets ();
224
225 lldb::SBTarget
226 GetSelectedTarget ();
227
Jim Ingham83dd2032011-09-13 23:25:31 +0000228 void
229 SetSelectedTarget (lldb::SBTarget &target);
230
Jim Inghamcc637462011-09-13 00:29:56 +0000231 lldb::SBSourceManager
Johnny Chen6cf1bc32011-07-18 22:11:53 +0000232 GetSourceManager ();
233
234 // REMOVE: just for a quick fix, need to expose platforms through
235 // SBPlatform from this class.
236 lldb::SBError
237 SetCurrentPlatform (const char *platform_name);
238
239 bool
240 SetCurrentPlatformSDKRoot (const char *sysroot);
241
242 // FIXME: Once we get the set show stuff in place, the driver won't need
243 // an interface to the Set/Get UseExternalEditor.
244 bool
245 SetUseExternalEditor (bool input);
246
247 bool
248 GetUseExternalEditor ();
249
250 static bool
251 GetDefaultArchitecture (char *arch_name, size_t arch_name_len);
252
253 static bool
254 SetDefaultArchitecture (const char *arch_name);
255
256 lldb::ScriptLanguage
257 GetScriptingLanguage (const char *script_language_name);
258
259 static const char *
260 GetVersionString ();
261
262 static const char *
263 StateAsCString (lldb::StateType state);
264
265 static bool
266 StateIsRunningState (lldb::StateType state);
267
268 static bool
269 StateIsStoppedState (lldb::StateType state);
270
Jim Ingham6c530f22012-02-21 02:23:08 +0000271 bool
272 EnableLog (const char *channel, const char ** types);
273
Johnny Chen6cf1bc32011-07-18 22:11:53 +0000274 void
275 DispatchInput (void *baton, const void *data, size_t data_len);
276
277 void
278 DispatchInputInterrupt ();
279
280 void
281 DispatchInputEndOfFile ();
282
283 void
284 PushInputReader (lldb::SBInputReader &reader);
285
286 void
287 NotifyTopInputReader (lldb::InputReaderAction notification);
288
289 bool
290 InputReaderIsTopReader (const lldb::SBInputReader &reader);
291
292 const char *
293 GetInstanceName ();
294
295 static SBDebugger
296 FindDebuggerWithID (int id);
297
298 static lldb::SBError
299 SetInternalVariable (const char *var_name, const char *value, const char *debugger_instance_name);
300
301 static lldb::SBStringList
302 GetInternalVariableValue (const char *var_name, const char *debugger_instance_name);
303
304 bool
305 GetDescription (lldb::SBStream &description);
306
307 uint32_t
308 GetTerminalWidth () const;
309
310 void
311 SetTerminalWidth (uint32_t term_width);
312
313 lldb::user_id_t
314 GetID ();
315
316 const char *
317 GetPrompt() const;
318
319 void
320 SetPrompt (const char *prompt);
321
322 lldb::ScriptLanguage
323 GetScriptLanguage() const;
324
325 void
326 SetScriptLanguage (lldb::ScriptLanguage script_lang);
327
328 bool
329 GetCloseInputOnEOF () const;
330
331 void
332 SetCloseInputOnEOF (bool b);
Enrico Granata16376ed2012-02-15 02:34:21 +0000333
334 lldb::SBTypeCategory
335 GetCategory (const char* category_name);
336
337 lldb::SBTypeCategory
338 CreateCategory (const char* category_name);
339
340 bool
341 DeleteCategory (const char* category_name);
342
343 uint32_t
344 GetNumCategories ();
345
346 lldb::SBTypeCategory
347 GetCategoryAtIndex (uint32_t);
348
349 lldb::SBTypeCategory
350 GetDefaultCategory();
351
352 lldb::SBTypeFormat
353 GetFormatForType (lldb::SBTypeNameSpecifier);
354
355 lldb::SBTypeSummary
356 GetSummaryForType (lldb::SBTypeNameSpecifier);
357
358 lldb::SBTypeFilter
359 GetFilterForType (lldb::SBTypeNameSpecifier);
360
361 lldb::SBTypeSynthetic
362 GetSyntheticForType (lldb::SBTypeNameSpecifier);
363
Johnny Chen6cf1bc32011-07-18 22:11:53 +0000364}; // class SBDebugger
365
366} // namespace lldb