]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - scripts/interface/SBDebugger.i
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / scripts / interface / SBDebugger.i
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::SBPlatform
235     GetSelectedPlatform();
236     
237     void
238     SetSelectedPlatform(lldb::SBPlatform &platform);
239
240     lldb::SBSourceManager
241     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
259     bool
260     SetUseColor (bool use_color);
261
262     bool
263     GetUseColor () const;
264
265     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
286     bool
287     EnableLog (const char *channel, const char ** types);
288
289     void
290     SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton);
291
292     void
293     DispatchInput (const void *data, size_t data_len);
294
295     void
296     DispatchInputInterrupt ();
297
298     void
299     DispatchInputEndOfFile ();
300     
301     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);
342     
343     lldb::SBTypeCategory
344     GetCategory (const char* category_name);
345     
346     SBTypeCategory
347     GetCategory (lldb::LanguageType lang_type);
348     
349     lldb::SBTypeCategory
350     CreateCategory (const char* category_name);
351     
352     bool
353     DeleteCategory (const char* category_name);
354     
355     uint32_t
356     GetNumCategories ();
357     
358     lldb::SBTypeCategory
359     GetCategoryAtIndex (uint32_t);
360     
361     lldb::SBTypeCategory
362     GetDefaultCategory();
363     
364     lldb::SBTypeFormat
365     GetFormatForType (lldb::SBTypeNameSpecifier);
366
367     lldb::SBTypeSummary
368     GetSummaryForType (lldb::SBTypeNameSpecifier);
369
370     lldb::SBTypeFilter
371     GetFilterForType (lldb::SBTypeNameSpecifier);
372
373     lldb::SBTypeSynthetic
374     GetSyntheticForType (lldb::SBTypeNameSpecifier);
375
376     void
377     RunCommandInterpreter (bool auto_handle_events,
378                            bool spawn_thread,
379                            SBCommandInterpreterRunOptions &options,
380                            int  &num_errors,
381                            bool &quit_requested,
382                            bool &stopped_for_crash);
383     
384     lldb::SBError
385     RunREPL (lldb::LanguageType language, const char *repl_options);
386 }; // class SBDebugger
387
388 } // namespace lldb