Skip to content

Commit

Permalink
decoder.py: allowing to use it live, fix in_stack and avoid ctx repet…
Browse files Browse the repository at this point in the history
…ition

using it live:
    pyserial-miniterm /dev/ttyUSB0 115200 | decoder.py <args>
  • Loading branch information
d-a-v committed Mar 24, 2024
1 parent 2bb1b5a commit b698c99
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions tools/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def addresses_addr2line(addr2line, elf, addresses):


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

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

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

in_stack = False
lastctx = ''
lastepc = 0

def print_all_addresses(addresses):
nonlocal lastctx
for ctx, addrs in addresses.items():
print()
print(ctx)
if ctx != lastctx:
print()
print(ctx)
lastctx = ctx
for formatted in format_addresses(elf, addrs):
print(formatted)
return dict()
Expand All @@ -138,15 +144,20 @@ def format_address(address):
stack_addresses.setdefault(last_stack, [])
for addr in addrs:
stack_addresses[last_stack].append(addr)
stack_addresses = print_all_addresses(stack_addresses)
# epc1=0xfffefefe epc2=0xfefefefe epc3=0xefefefef excvaddr=0xfefefefe depc=0xfefefefe
elif EPC_STRING in line:
pairs = line.split()
for pair in pairs:
name, addr = pair.split("=")
addr = addr.rstrip(',')
if name in ["epc1", "excvaddr"]:
output = format_address(addr)
if output:
print(f"{name}={output}")
if lastepc != addr:
if addr != '0x00000000':
lastepc = addr
output = format_address(addr)
if output:
print(f"{name}={output}")
# Exception (123):
# Other reasons coming before the guard shown as-is
elif EXCEPTION_STRING in line:
Expand All @@ -164,8 +175,9 @@ def format_address(address):
in_stack = True
# ignore
elif "<<<stack<<<" in line:
in_stack = False
continue
elif CUT_HERE_STRING in line:
elif CUT_HERE_STRING in line or DECODE_IT in line:
continue
else:
line = line.strip()
Expand Down

0 comments on commit b698c99

Please sign in to comment.