Skip to content

Commit b698c99

Browse files
committed
decoder.py: allowing to use it live, fix in_stack and avoid ctx repetition
using it live: pyserial-miniterm /dev/ttyUSB0 115200 | decoder.py <args>
1 parent 2bb1b5a commit b698c99

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

Diff for: tools/decoder.py

+19-7
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def addresses_addr2line(addr2line, elf, addresses):
9696

9797

9898
def decode_lines(format_addresses, elf, lines):
99-
STACK_RE = re.compile(r"^[0-9a-f]{8}:\s+([0-9a-f]{8} ?)+ *$")
99+
STACK_RE = re.compile(r"^[0-9a-f]{8}:\s+([0-9a-f]{8} ?)+ *")
100100

101101
LAST_ALLOC_RE = re.compile(
102102
r"last failed alloc call: ([0-9a-fA-F]{8})\(([0-9]+)\).*"
@@ -106,17 +106,23 @@ def decode_lines(format_addresses, elf, lines):
106106
CUT_HERE_STRING = "CUT HERE FOR EXCEPTION DECODER"
107107
EXCEPTION_STRING = "Exception ("
108108
EPC_STRING = "epc1="
109+
DECODE_IT = "DECODE IT"
109110

110111
# either print everything as-is, or cache current string and dump after stack contents end
111112
last_stack = None
112113
stack_addresses = {}
113114

114115
in_stack = False
116+
lastctx = ''
117+
lastepc = 0
115118

116119
def print_all_addresses(addresses):
120+
nonlocal lastctx
117121
for ctx, addrs in addresses.items():
118-
print()
119-
print(ctx)
122+
if ctx != lastctx:
123+
print()
124+
print(ctx)
125+
lastctx = ctx
120126
for formatted in format_addresses(elf, addrs):
121127
print(formatted)
122128
return dict()
@@ -138,15 +144,20 @@ def format_address(address):
138144
stack_addresses.setdefault(last_stack, [])
139145
for addr in addrs:
140146
stack_addresses[last_stack].append(addr)
147+
stack_addresses = print_all_addresses(stack_addresses)
141148
# epc1=0xfffefefe epc2=0xfefefefe epc3=0xefefefef excvaddr=0xfefefefe depc=0xfefefefe
142149
elif EPC_STRING in line:
143150
pairs = line.split()
144151
for pair in pairs:
145152
name, addr = pair.split("=")
153+
addr = addr.rstrip(',')
146154
if name in ["epc1", "excvaddr"]:
147-
output = format_address(addr)
148-
if output:
149-
print(f"{name}={output}")
155+
if lastepc != addr:
156+
if addr != '0x00000000':
157+
lastepc = addr
158+
output = format_address(addr)
159+
if output:
160+
print(f"{name}={output}")
150161
# Exception (123):
151162
# Other reasons coming before the guard shown as-is
152163
elif EXCEPTION_STRING in line:
@@ -164,8 +175,9 @@ def format_address(address):
164175
in_stack = True
165176
# ignore
166177
elif "<<<stack<<<" in line:
178+
in_stack = False
167179
continue
168-
elif CUT_HERE_STRING in line:
180+
elif CUT_HERE_STRING in line or DECODE_IT in line:
169181
continue
170182
else:
171183
line = line.strip()

0 commit comments

Comments
 (0)