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
36 print 'Creating a target for \'%s\'' % exe
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()
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()
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;
109 class SBDebugger
110 {
111 public:
112 
113     static void
114     Initialize();
115 
116     static void
117     Terminate();
118 
119     static lldb::SBDebugger
120     Create();
121 
122     static lldb::SBDebugger
123     Create(bool source_init_files);
124 
125     static lldb::SBDebugger
126     Create(bool source_init_files, lldb::LogOutputCallback log_callback, void *baton);
127 
128     static void
129     Destroy (lldb::SBDebugger &debugger);
130 
131     static void
132     MemoryPressureDetected();
133 
134     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);
148 
149     bool
150     GetAsync ();
151 
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
189     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
196     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 
215     uint32_t
216     GetIndexOfTarget (lldb::SBTarget target);
217 
218     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 
231     void
232     SetSelectedTarget (lldb::SBTarget &target);
233 
234     lldb::SBSourceManager
235     GetSourceManager ();
236 
237     // REMOVE: just for a quick fix, need to expose platforms through
238     // SBPlatform from this class.
239     lldb::SBError
240     SetCurrentPlatform (const char *platform_name);
241 
242     bool
243     SetCurrentPlatformSDKRoot (const char *sysroot);
244 
245     // FIXME: Once we get the set show stuff in place, the driver won't need
246     // an interface to the Set/Get UseExternalEditor.
247     bool
248     SetUseExternalEditor (bool input);
249 
250     bool
251     GetUseExternalEditor ();
252 
253     static bool
254     GetDefaultArchitecture (char *arch_name, size_t arch_name_len);
255 
256     static bool
257     SetDefaultArchitecture (const char *arch_name);
258 
259     lldb::ScriptLanguage
260     GetScriptingLanguage (const char *script_language_name);
261 
262     static const char *
263     GetVersionString ();
264 
265     static const char *
266     StateAsCString (lldb::StateType state);
267 
268     static bool
269     StateIsRunningState (lldb::StateType state);
270 
271     static bool
272     StateIsStoppedState (lldb::StateType state);
273 
274     bool
275     EnableLog (const char *channel, const char ** types);
276 
277     void
278     SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton);
279 
280     void
281     DispatchInput (const void *data, size_t data_len);
282 
283     void
284     DispatchInputInterrupt ();
285 
286     void
287     DispatchInputEndOfFile ();
288 
289     void
290     PushInputReader (lldb::SBInputReader &reader);
291 
292     void
293     NotifyTopInputReader (lldb::InputReaderAction notification);
294 
295     bool
296     InputReaderIsTopReader (const lldb::SBInputReader &reader);
297 
298     const char *
299     GetInstanceName  ();
300 
301     static SBDebugger
302     FindDebuggerWithID (int id);
303 
304     static lldb::SBError
305     SetInternalVariable (const char *var_name, const char *value, const char *debugger_instance_name);
306 
307     static lldb::SBStringList
308     GetInternalVariableValue (const char *var_name, const char *debugger_instance_name);
309 
310     bool
311     GetDescription (lldb::SBStream &description);
312 
313     uint32_t
314     GetTerminalWidth () const;
315 
316     void
317     SetTerminalWidth (uint32_t term_width);
318 
319     lldb::user_id_t
320     GetID ();
321 
322     const char *
323     GetPrompt() const;
324 
325     void
326     SetPrompt (const char *prompt);
327 
328     lldb::ScriptLanguage
329     GetScriptLanguage() const;
330 
331     void
332     SetScriptLanguage (lldb::ScriptLanguage script_lang);
333 
334     bool
335     GetCloseInputOnEOF () const;
336 
337     void
338     SetCloseInputOnEOF (bool b);
339 
340     lldb::SBTypeCategory
341     GetCategory (const char* category_name);
342 
343     lldb::SBTypeCategory
344     CreateCategory (const char* category_name);
345 
346     bool
347     DeleteCategory (const char* category_name);
348 
349     uint32_t
350     GetNumCategories ();
351 
352     lldb::SBTypeCategory
353     GetCategoryAtIndex (uint32_t);
354 
355     lldb::SBTypeCategory
356     GetDefaultCategory();
357 
358     lldb::SBTypeFormat
359     GetFormatForType (lldb::SBTypeNameSpecifier);
360 
361     lldb::SBTypeSummary
362     GetSummaryForType (lldb::SBTypeNameSpecifier);
363 
364     lldb::SBTypeFilter
365     GetFilterForType (lldb::SBTypeNameSpecifier);
366 
367     lldb::SBTypeSynthetic
368     GetSyntheticForType (lldb::SBTypeNameSpecifier);
369 
370 }; // class SBDebugger
371 
372 } // namespace lldb
373