blob: 1882021f5e9de70cf722cc0f828d0492c908f0fc [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
122 static void
123 Destroy (lldb::SBDebugger &debugger);
124
Greg Claytonc5486872011-12-15 04:38:41 +0000125 static void
126 MemoryPressureDetected();
127
Johnny Chen6cf1bc32011-07-18 22:11:53 +0000128 SBDebugger();
129
130 SBDebugger(const lldb::SBDebugger &rhs);
131
132 ~SBDebugger();
133
134 bool
135 IsValid() const;
136
137 void
138 Clear ();
139
140 void
141 SetAsync (bool b);
Jim Ingham83dd2032011-09-13 23:25:31 +0000142
143 bool
144 GetAsync ();
Johnny Chen6cf1bc32011-07-18 22:11:53 +0000145
146 void
147 SkipLLDBInitFiles (bool b);
148
149 void
150 SetInputFileHandle (FILE *f, bool transfer_ownership);
151
152 void
153 SetOutputFileHandle (FILE *f, bool transfer_ownership);
154
155 void
156 SetErrorFileHandle (FILE *f, bool transfer_ownership);
157
158 FILE *
159 GetInputFileHandle ();
160
161 FILE *
162 GetOutputFileHandle ();
163
164 FILE *
165 GetErrorFileHandle ();
166
167 lldb::SBCommandInterpreter
168 GetCommandInterpreter ();
169
170 void
171 HandleCommand (const char *command);
172
173 lldb::SBListener
174 GetListener ();
175
176 void
177 HandleProcessEvent (const lldb::SBProcess &process,
178 const lldb::SBEvent &event,
179 FILE *out,
180 FILE *err);
181
182 lldb::SBTarget
Greg Clayton3e8c25f2011-09-24 00:52:29 +0000183 CreateTarget (const char *filename,
184 const char *target_triple,
185 const char *platform_name,
186 bool add_dependent_modules,
187 lldb::SBError& sb_error);
188
189 lldb::SBTarget
Johnny Chen6cf1bc32011-07-18 22:11:53 +0000190 CreateTargetWithFileAndTargetTriple (const char *filename,
191 const char *target_triple);
192
193 lldb::SBTarget
194 CreateTargetWithFileAndArch (const char *filename,
195 const char *archname);
196
197 lldb::SBTarget
198 CreateTarget (const char *filename);
199
200 %feature("docstring",
201 "Return true if target is deleted from the target list of the debugger."
202 ) DeleteTarget;
203 bool
204 DeleteTarget (lldb::SBTarget &target);
205
206 lldb::SBTarget
207 GetTargetAtIndex (uint32_t idx);
208
209 lldb::SBTarget
210 FindTargetWithProcessID (pid_t pid);
211
212 lldb::SBTarget
213 FindTargetWithFileAndArch (const char *filename,
214 const char *arch);
215
216 uint32_t
217 GetNumTargets ();
218
219 lldb::SBTarget
220 GetSelectedTarget ();
221
Jim Ingham83dd2032011-09-13 23:25:31 +0000222 void
223 SetSelectedTarget (lldb::SBTarget &target);
224
Jim Inghamcc637462011-09-13 00:29:56 +0000225 lldb::SBSourceManager
Johnny Chen6cf1bc32011-07-18 22:11:53 +0000226 GetSourceManager ();
227
228 // REMOVE: just for a quick fix, need to expose platforms through
229 // SBPlatform from this class.
230 lldb::SBError
231 SetCurrentPlatform (const char *platform_name);
232
233 bool
234 SetCurrentPlatformSDKRoot (const char *sysroot);
235
236 // FIXME: Once we get the set show stuff in place, the driver won't need
237 // an interface to the Set/Get UseExternalEditor.
238 bool
239 SetUseExternalEditor (bool input);
240
241 bool
242 GetUseExternalEditor ();
243
244 static bool
245 GetDefaultArchitecture (char *arch_name, size_t arch_name_len);
246
247 static bool
248 SetDefaultArchitecture (const char *arch_name);
249
250 lldb::ScriptLanguage
251 GetScriptingLanguage (const char *script_language_name);
252
253 static const char *
254 GetVersionString ();
255
256 static const char *
257 StateAsCString (lldb::StateType state);
258
259 static bool
260 StateIsRunningState (lldb::StateType state);
261
262 static bool
263 StateIsStoppedState (lldb::StateType state);
264
265 void
266 DispatchInput (void *baton, const void *data, size_t data_len);
267
268 void
269 DispatchInputInterrupt ();
270
271 void
272 DispatchInputEndOfFile ();
273
274 void
275 PushInputReader (lldb::SBInputReader &reader);
276
277 void
278 NotifyTopInputReader (lldb::InputReaderAction notification);
279
280 bool
281 InputReaderIsTopReader (const lldb::SBInputReader &reader);
282
283 const char *
284 GetInstanceName ();
285
286 static SBDebugger
287 FindDebuggerWithID (int id);
288
289 static lldb::SBError
290 SetInternalVariable (const char *var_name, const char *value, const char *debugger_instance_name);
291
292 static lldb::SBStringList
293 GetInternalVariableValue (const char *var_name, const char *debugger_instance_name);
294
295 bool
296 GetDescription (lldb::SBStream &description);
297
298 uint32_t
299 GetTerminalWidth () const;
300
301 void
302 SetTerminalWidth (uint32_t term_width);
303
304 lldb::user_id_t
305 GetID ();
306
307 const char *
308 GetPrompt() const;
309
310 void
311 SetPrompt (const char *prompt);
312
313 lldb::ScriptLanguage
314 GetScriptLanguage() const;
315
316 void
317 SetScriptLanguage (lldb::ScriptLanguage script_lang);
318
319 bool
320 GetCloseInputOnEOF () const;
321
322 void
323 SetCloseInputOnEOF (bool b);
324}; // class SBDebugger
325
326} // namespace lldb