xref: /freebsd-src/contrib/llvm-project/lldb/bindings/interface/SBDebuggerDocstrings.i (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1*06c3fb27SDimitry Andric %feature("docstring",
2*06c3fb27SDimitry Andric "SBDebugger is the primordial object that creates SBTargets and provides
3*06c3fb27SDimitry Andric access to them.  It also manages the overall debugging experiences.
4*06c3fb27SDimitry Andric 
5*06c3fb27SDimitry Andric For example (from example/disasm.py),::
6*06c3fb27SDimitry Andric 
7*06c3fb27SDimitry Andric     import lldb
8*06c3fb27SDimitry Andric     import os
9*06c3fb27SDimitry Andric     import sys
10*06c3fb27SDimitry Andric 
11*06c3fb27SDimitry Andric     def disassemble_instructions (insts):
12*06c3fb27SDimitry Andric         for i in insts:
13*06c3fb27SDimitry Andric             print i
14*06c3fb27SDimitry Andric 
15*06c3fb27SDimitry Andric     ...
16*06c3fb27SDimitry Andric 
17*06c3fb27SDimitry Andric     # Create a new debugger instance
18*06c3fb27SDimitry Andric     debugger = lldb.SBDebugger.Create()
19*06c3fb27SDimitry Andric 
20*06c3fb27SDimitry Andric     # When we step or continue, don't return from the function until the process
21*06c3fb27SDimitry Andric     # stops. We do this by setting the async mode to false.
22*06c3fb27SDimitry Andric     debugger.SetAsync (False)
23*06c3fb27SDimitry Andric 
24*06c3fb27SDimitry Andric     # Create a target from a file and arch
25*06c3fb27SDimitry Andric     print('Creating a target for \'%s\'' % exe)
26*06c3fb27SDimitry Andric 
27*06c3fb27SDimitry Andric     target = debugger.CreateTargetWithFileAndArch (exe, lldb.LLDB_ARCH_DEFAULT)
28*06c3fb27SDimitry Andric 
29*06c3fb27SDimitry Andric     if target:
30*06c3fb27SDimitry Andric         # If the target is valid set a breakpoint at main
31*06c3fb27SDimitry Andric         main_bp = target.BreakpointCreateByName (fname, target.GetExecutable().GetFilename());
32*06c3fb27SDimitry Andric 
33*06c3fb27SDimitry Andric         print main_bp
34*06c3fb27SDimitry Andric 
35*06c3fb27SDimitry Andric         # Launch the process. Since we specified synchronous mode, we won't return
36*06c3fb27SDimitry Andric         # from this function until we hit the breakpoint at main
37*06c3fb27SDimitry Andric         process = target.LaunchSimple (None, None, os.getcwd())
38*06c3fb27SDimitry Andric 
39*06c3fb27SDimitry Andric         # Make sure the launch went ok
40*06c3fb27SDimitry Andric         if process:
41*06c3fb27SDimitry Andric             # Print some simple process info
42*06c3fb27SDimitry Andric             state = process.GetState ()
43*06c3fb27SDimitry Andric             print process
44*06c3fb27SDimitry Andric             if state == lldb.eStateStopped:
45*06c3fb27SDimitry Andric                 # Get the first thread
46*06c3fb27SDimitry Andric                 thread = process.GetThreadAtIndex (0)
47*06c3fb27SDimitry Andric                 if thread:
48*06c3fb27SDimitry Andric                     # Print some simple thread info
49*06c3fb27SDimitry Andric                     print thread
50*06c3fb27SDimitry Andric                     # Get the first frame
51*06c3fb27SDimitry Andric                     frame = thread.GetFrameAtIndex (0)
52*06c3fb27SDimitry Andric                     if frame:
53*06c3fb27SDimitry Andric                         # Print some simple frame info
54*06c3fb27SDimitry Andric                         print frame
55*06c3fb27SDimitry Andric                         function = frame.GetFunction()
56*06c3fb27SDimitry Andric                         # See if we have debug info (a function)
57*06c3fb27SDimitry Andric                         if function:
58*06c3fb27SDimitry Andric                             # We do have a function, print some info for the function
59*06c3fb27SDimitry Andric                             print function
60*06c3fb27SDimitry Andric                             # Now get all instructions for this function and print them
61*06c3fb27SDimitry Andric                             insts = function.GetInstructions(target)
62*06c3fb27SDimitry Andric                             disassemble_instructions (insts)
63*06c3fb27SDimitry Andric                         else:
64*06c3fb27SDimitry Andric                             # See if we have a symbol in the symbol table for where we stopped
65*06c3fb27SDimitry Andric                             symbol = frame.GetSymbol();
66*06c3fb27SDimitry Andric                             if symbol:
67*06c3fb27SDimitry Andric                                 # We do have a symbol, print some info for the symbol
68*06c3fb27SDimitry Andric                                 print symbol
69*06c3fb27SDimitry Andric                                 # Now get all instructions for this symbol and print them
70*06c3fb27SDimitry Andric                                 insts = symbol.GetInstructions(target)
71*06c3fb27SDimitry Andric                                 disassemble_instructions (insts)
72*06c3fb27SDimitry Andric 
73*06c3fb27SDimitry Andric                         registerList = frame.GetRegisters()
74*06c3fb27SDimitry Andric                         print('Frame registers (size of register set = %d):' % registerList.GetSize())
75*06c3fb27SDimitry Andric                         for value in registerList:
76*06c3fb27SDimitry Andric                             #print value
77*06c3fb27SDimitry Andric                             print('%s (number of children = %d):' % (value.GetName(), value.GetNumChildren()))
78*06c3fb27SDimitry Andric                             for child in value:
79*06c3fb27SDimitry Andric                                 print('Name: ', child.GetName(), ' Value: ', child.GetValue())
80*06c3fb27SDimitry Andric 
81*06c3fb27SDimitry Andric                 print('Hit the breakpoint at main, enter to continue and wait for program to exit or \'Ctrl-D\'/\'quit\' to terminate the program')
82*06c3fb27SDimitry Andric                 next = sys.stdin.readline()
83*06c3fb27SDimitry Andric                 if not next or next.rstrip('\\n') == 'quit':
84*06c3fb27SDimitry Andric                     print('Terminating the inferior process...')
85*06c3fb27SDimitry Andric                     process.Kill()
86*06c3fb27SDimitry Andric                 else:
87*06c3fb27SDimitry Andric                     # Now continue to the program exit
88*06c3fb27SDimitry Andric                     process.Continue()
89*06c3fb27SDimitry Andric                     # When we return from the above function we will hopefully be at the
90*06c3fb27SDimitry Andric                     # program exit. Print out some process info
91*06c3fb27SDimitry Andric                     print process
92*06c3fb27SDimitry Andric             elif state == lldb.eStateExited:
93*06c3fb27SDimitry Andric                 print('Didn\'t hit the breakpoint at main, program has exited...')
94*06c3fb27SDimitry Andric             else:
95*06c3fb27SDimitry Andric                 print('Unexpected process state: %s, killing process...' % debugger.StateAsCString (state))
96*06c3fb27SDimitry Andric                 process.Kill()
97*06c3fb27SDimitry Andric 
98*06c3fb27SDimitry Andric Sometimes you need to create an empty target that will get filled in later.  The most common use for this
99*06c3fb27SDimitry Andric is to attach to a process by name or pid where you don't know the executable up front.  The most convenient way
100*06c3fb27SDimitry Andric to do this is: ::
101*06c3fb27SDimitry Andric 
102*06c3fb27SDimitry Andric     target = debugger.CreateTarget('')
103*06c3fb27SDimitry Andric     error = lldb.SBError()
104*06c3fb27SDimitry Andric     process = target.AttachToProcessWithName(debugger.GetListener(), 'PROCESS_NAME', False, error)
105*06c3fb27SDimitry Andric 
106*06c3fb27SDimitry Andric or the equivalent arguments for :py:class:`SBTarget.AttachToProcessWithID` ."
107*06c3fb27SDimitry Andric ) lldb::SBDebugger;
108*06c3fb27SDimitry Andric 
109*06c3fb27SDimitry Andric %feature("docstring",
110*06c3fb27SDimitry Andric     "The dummy target holds breakpoints and breakpoint names that will prime newly created targets."
111*06c3fb27SDimitry Andric ) lldb::SBDebugger::GetDummyTarget;
112*06c3fb27SDimitry Andric 
113*06c3fb27SDimitry Andric %feature("docstring",
114*06c3fb27SDimitry Andric     "Return true if target is deleted from the target list of the debugger."
115*06c3fb27SDimitry Andric ) lldb::SBDebugger::DeleteTarget;
116*06c3fb27SDimitry Andric 
117*06c3fb27SDimitry Andric %feature("docstring",
118*06c3fb27SDimitry Andric     "Get the number of currently active platforms."
119*06c3fb27SDimitry Andric ) lldb::SBDebugger::GetNumPlatforms;
120*06c3fb27SDimitry Andric 
121*06c3fb27SDimitry Andric %feature("docstring",
122*06c3fb27SDimitry Andric     "Get one of the currently active platforms."
123*06c3fb27SDimitry Andric ) lldb::SBDebugger::GetPlatformAtIndex;
124*06c3fb27SDimitry Andric 
125*06c3fb27SDimitry Andric %feature("docstring",
126*06c3fb27SDimitry Andric     "Get the number of available platforms."
127*06c3fb27SDimitry Andric ) lldb::SBDebugger::GetNumAvailablePlatforms;
128*06c3fb27SDimitry Andric 
129*06c3fb27SDimitry Andric %feature("docstring", "
130*06c3fb27SDimitry Andric     Get the name and description of one of the available platforms.
131*06c3fb27SDimitry Andric 
132*06c3fb27SDimitry Andric     @param idx Zero-based index of the platform for which info should be
133*06c3fb27SDimitry Andric                retrieved, must be less than the value returned by
134*06c3fb27SDimitry Andric                GetNumAvailablePlatforms()."
135*06c3fb27SDimitry Andric ) lldb::SBDebugger::GetAvailablePlatformInfoAtIndex;
136*06c3fb27SDimitry Andric 
137*06c3fb27SDimitry Andric %feature("docstring",
138*06c3fb27SDimitry Andric "Launch a command interpreter session. Commands are read from standard input or
139*06c3fb27SDimitry Andric from the input handle specified for the debugger object. Output/errors are
140*06c3fb27SDimitry Andric similarly redirected to standard output/error or the configured handles.
141*06c3fb27SDimitry Andric 
142*06c3fb27SDimitry Andric @param[in] auto_handle_events If true, automatically handle resulting events.
143*06c3fb27SDimitry Andric @param[in] spawn_thread If true, start a new thread for IO handling.
144*06c3fb27SDimitry Andric @param[in] options Parameter collection of type SBCommandInterpreterRunOptions.
145*06c3fb27SDimitry Andric @param[in] num_errors Initial error counter.
146*06c3fb27SDimitry Andric @param[in] quit_requested Initial quit request flag.
147*06c3fb27SDimitry Andric @param[in] stopped_for_crash Initial crash flag.
148*06c3fb27SDimitry Andric 
149*06c3fb27SDimitry Andric @return
150*06c3fb27SDimitry Andric A tuple with the number of errors encountered by the interpreter, a boolean
151*06c3fb27SDimitry Andric indicating whether quitting the interpreter was requested and another boolean
152*06c3fb27SDimitry Andric set to True in case of a crash.
153*06c3fb27SDimitry Andric 
154*06c3fb27SDimitry Andric Example: ::
155*06c3fb27SDimitry Andric 
156*06c3fb27SDimitry Andric     # Start an interactive lldb session from a script (with a valid debugger object
157*06c3fb27SDimitry Andric     # created beforehand):
158*06c3fb27SDimitry Andric     n_errors, quit_requested, has_crashed = debugger.RunCommandInterpreter(True,
159*06c3fb27SDimitry Andric         False, lldb.SBCommandInterpreterRunOptions(), 0, False, False)"
160*06c3fb27SDimitry Andric ) lldb::SBDebugger::RunCommandInterpreter;
161