Merge pull request #3169 from lambdageek/fix-regression-70561
[mono-project.git] / data / lldb / monobt.py
blob0e4713816d742ad79cccd869b4911d8687fbec2f
1 import lldb
3 def print_frames(thread, num_frames, current_thread):
4 # TODO: Make output header similar to bt.
5 print '%c thread #%i' % ('*' if current_thread else ' ', thread.idx)
7 if current_thread:
8 selected_frame = thread.GetSelectedFrame()
10 for frame in thread.frames[:+num_frames]:
11 pc = str(frame.addr)
12 fmt = ' %c %s'
13 var = frame
14 if pc[0] == '0':
15 try:
16 framestr = frame.EvaluateExpression('(char*)mono_pmip((void*)%s)' % pc).summary[1:-1]
17 var = 'frame #%i: %s%s' % (frame.idx, pc, framestr)
18 except:
19 pass
21 print fmt % ('*' if current_thread and frame.idx == selected_frame.idx else ' ', var)
23 def monobt(debugger, command, result, dict):
24 opts = {'all_bt': False, 'num_frames': None}
26 if command == 'all':
27 opts['all_bt'] = True
28 elif command.isdigit():
29 opts['num_frames'] = int(command)
30 elif command != '':
31 print 'error: monobt [<number>|all]'
32 return
34 target = debugger.GetSelectedTarget()
35 process = target.process
37 if not process.IsValid():
38 print 'error: invalid process'
39 return
41 if opts['all_bt']:
42 for thread in process.threads:
43 print_frames(thread, len(thread), process.selected_thread == thread)
44 print ''
45 else:
46 thread = process.selected_thread
47 num_frames = len(thread) if opts['num_frames'] is None else opts['num_frames']
48 print_frames(thread, num_frames, True)
50 return None
52 def __lldb_init_module (debugger, dict):
53 # This initializer is being run from LLDB in the embedded command interpreter
54 # Add any commands contained in this module to LLDB
55 debugger.HandleCommand('command script add -f monobt.monobt monobt')
56 print '"monobt" command installed'