[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / data / lldb / monobt.py
blob8da89c2fb4c560ac6ac7a018bee770b3e1eafbde
1 import lldb
2 import traceback
4 def print_frames(thread, num_frames, current_thread):
5 # TODO: Make output header similar to bt.
6 print('%c thread #%i' % ('*' if current_thread else ' ', thread.idx))
8 if current_thread:
9 selected_frame = thread.GetSelectedFrame()
11 for frame in thread.frames[:+num_frames]:
12 pc = str(frame.addr)
13 var = frame
14 function_name = frame.GetFunctionName()
15 if function_name == "interp_exec_method_full":
16 try:
17 s = 'frame->imethod->method'
18 methoddesc = frame.EvaluateExpression('(char*) mono_method_full_name (' + s + ', 1)').summary[1:-1]
20 ipoffset = frame.EvaluateExpression('ip').GetValueAsUnsigned()
21 insn = ''
22 if ipoffset != 0:
23 ipoffset -= frame.EvaluateExpression('frame->imethod->code').GetValueAsUnsigned()
24 insn = "\"" + frame.EvaluateExpression('mono_interp_opname (*ip)').summary[1:-1] + "\""
25 var = '%s @ %d %s || %s' % (methoddesc, ipoffset, insn, frame)
26 except Exception as e:
27 traceback.print_exc()
28 elif function_name == "mono_interp_transform_method":
29 try:
30 s = 'runtime_method->method'
31 klassname = frame.EvaluateExpression('(char*) ' + s + '->klass->name').summary[1:-1]
32 methodname = frame.EvaluateExpression('(char*) ' + s + '->name').summary[1:-1]
33 var = 'transforming %s::%s || %s' % (klassname, methodname, frame)
34 except Exception as e:
35 print("DBG: transformfail:" + str(e))
36 elif pc[0] == '0':
37 try:
38 framestr = frame.EvaluateExpression('(char*)mono_pmip((void*)%s)' % pc).summary[1:-1]
39 var = 'frame #%i: %s%s' % (frame.idx, pc, framestr)
40 except:
41 pass
43 print(' %c %s' % ('*' if current_thread and frame.idx == selected_frame.idx else ' ', var))
45 def monobt(debugger, command, result, dict):
46 opts = {'all_bt': False, 'num_frames': None}
48 if command == 'all':
49 opts['all_bt'] = True
50 elif command.isdigit():
51 opts['num_frames'] = int(command)
52 elif command != '':
53 print('error: monobt [<number>|all]')
54 return
56 target = debugger.GetSelectedTarget()
57 process = target.process
59 if not process.IsValid():
60 print('error: invalid process')
61 return
63 if opts['all_bt']:
64 for thread in process.threads:
65 print_frames(thread, len(thread), process.selected_thread == thread)
66 print('')
67 else:
68 thread = process.selected_thread
69 num_frames = len(thread) if opts['num_frames'] is None else opts['num_frames']
70 print_frames(thread, num_frames, True)
72 return None
74 def __lldb_init_module (debugger, dict):
75 # This initializer is being run from LLDB in the embedded command interpreter
76 # Add any commands contained in this module to LLDB
77 debugger.HandleCommand('command script add -f monobt.monobt monobt')
78 debugger.HandleCommand('command alias mbt monobt')
79 print('"monobt" command installed')