12 def OutputAddress(cmd_args
=None):
13 """ Returns out address and symbol corresponding to it without newline
14 Parameters: <address whose symbol is needed>
17 print "No arguments passed"
18 print OutputAddress
.__doc
__
20 a
= unsigned(cmd_args
[0])
21 cmd_str
= "image lookup -a {:#x}".format(a
)
22 cmd_out
= lldb_run_command(cmd_str
)
23 if len(cmd_out
) != 0 and cmd_out
!= "ERROR:":
24 cmd_out1
= cmd_out
.split('\n')
25 if len(cmd_out1
) != 0:
26 cmd_out2
= cmd_out1
[1].split('`')
28 cmd_out3
= cmd_out2
[1].split(' at')
29 if len(cmd_out3
) != 0:
30 symbol_str
= "{:#x} <{:s}>".format(unsigned(a
), cmd_out3
[0])
35 def SymbolicateWithInstruction(cmd_args
=None):
36 """ Prints out address and symbol similar to x/i
37 Usage: xi <address whose symbol is needed>
40 print "No arguments passed"
41 print SymbolicateWithInstruction
.__doc
__
43 a
= ArgumentStringToInt(cmd_args
[0])
44 print OutputAddress([a
])
49 @lldb_command('newbt')
50 def NewBt(cmd_args
=None):
51 """ Prints all the instructions by walking the given stack pointer
54 print "No arguments passed"
57 a
= ArgumentStringToInt(cmd_args
[0])
59 if kern
.arch
== "x86_64" or kern
.arch
== "arm64":
63 link_register
= dereference(kern
.GetValueFromAddress(a
+ offset
, 'uintptr_t *'))
64 cmd_str
= "di -s {:#x} -c 1".format(link_register
)
65 cmd_out
= lldb_run_command(cmd_str
)
67 cmd_out1
= cmd_out
.split('\n')
68 if len(cmd_out1
) != 0:
69 print OutputAddress([unsigned(link_register
)]) + ": " + cmd_out1
[0].split(':')[1]
70 a
= dereference(kern
.GetValueFromAddress(unsigned(a
), 'uintptr_t *'))
75 @lldb_command('parseLR')
76 def parseLR(cmd_args
=None):
77 """ Decode the LR value from panic log into source code location
83 if kern
.arch
== "x86_64":
84 paniclog_data
+= returnfunc("\n(lldb) paniclog\n", "paniclog -v")
86 paniclog_data
+= returnfunc("\n(lldb) paniclog\n", "paniclog")
89 srch_string
= "lr:\s+0x[a-fA-F0-9]+\s"
90 lr_pc_srch
= re
.findall(srch_string
, paniclog_data
)
92 print paniclog_data
, lr_pc_srch
93 for match
in lr_pc_srch
:
94 sp
=match
.strip("lr: ")
96 print "(lldb) list *{:s}".format(sp
)
97 print lldb_run_command("list *{:s}".format(sp
))
100 print "Currently unsupported on x86_64 architecture"
103 # Macro: parseLRfromfile
104 @lldb_command('parseLRfromfile')
105 def parseLRfromfile(cmd_args
=None):
106 """ Decode the LR value from file into source code location
108 f
= open('/tmp/lrparsefile', 'r')
110 srch_string
= "lr:\s+0x[a-fA-F0-9]+\s"
111 lr_pc_srch
= re
.findall(srch_string
, parse_data
)
113 print paniclog_data
, lr_pc_srch
114 for match
in lr_pc_srch
:
115 sp
=match
.strip("lr: ")
117 print "(lldb) list *{:s}".format(sp
)
118 print lldb_run_command("list *{:s}".format(sp
))
120 #EndMacro: parseLRfromfile