From f02e2c7375e4725e9fe1815bafff2a59433e21ce Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Tue, 26 Mar 2024 15:40:21 +0100 Subject: [PATCH 1/6] decoder.py: allowing to use it live - avoid ctx repetition - hide "DECODE IT" - immediately print stack at closing marker - check for executable decoder at startup live command line example: pyserial-miniterm /dev/ttyUSB0 115200 | \ path/to/esp8266/Arduino/tools/decoder.py \ --tool addr2line \ --toolchain-path path/to/esp8266/Arduino/tools/xtensa-lx106-elf/bin path/to/build.elf --- tools/decoder.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tools/decoder.py b/tools/decoder.py index 0055693648..e496725955 100755 --- a/tools/decoder.py +++ b/tools/decoder.py @@ -105,6 +105,7 @@ def decode_lines(format_addresses, elf, lines): STACK_LINE_RE = re.compile(r"^[0-9a-f]{8}:\s\s+") CUT_HERE_STRING = "CUT HERE FOR EXCEPTION DECODER" + DECODE_IT = "DECODE IT" EXCEPTION_STRING = "Exception (" EPC_STRING = "epc1=" @@ -125,6 +126,7 @@ def print_all_addresses(addresses): def format_address(address): return "\n".join(format_addresses(elf, [address])) + lastepc = 0 for line in lines: # ctx could happen multiple times. for the 2nd one, reset list # ctx: bearssl *or* ctx: cont *or* ctx: sys *or* ctx: whatever @@ -143,9 +145,13 @@ def format_address(address): for pair in pairs: name, addr = pair.split("=") if name in ["epc1", "excvaddr"]: - output = format_address(addr) - if output: - print(f"{name}={output}") + addr = addr.rstrip(',') + 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: @@ -163,8 +169,10 @@ def format_address(address): in_stack = True # ignore elif "<< Date: Wed, 27 Mar 2024 23:43:27 +0100 Subject: [PATCH 2/6] clean dup check --- tools/decoder.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/decoder.py b/tools/decoder.py index e496725955..ed2edf241c 100755 --- a/tools/decoder.py +++ b/tools/decoder.py @@ -126,7 +126,7 @@ def print_all_addresses(addresses): def format_address(address): return "\n".join(format_addresses(elf, [address])) - lastepc = 0 + lastaddr = {} for line in lines: # ctx could happen multiple times. for the 2nd one, reset list # ctx: bearssl *or* ctx: cont *or* ctx: sys *or* ctx: whatever @@ -146,9 +146,9 @@ def format_address(address): name, addr = pair.split("=") if name in ["epc1", "excvaddr"]: addr = addr.rstrip(',') - if lastepc != addr: + if not name in lastaddr or lastaddr[name] != addr: if addr != '0x00000000': - lastepc = addr + lastaddr[name] = addr output = format_address(addr) if output: print(f"{name}={output}") From 2d0ba9757d587dccc622593e128492040d4fc14e Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Thu, 28 Mar 2024 13:08:58 +0100 Subject: [PATCH 3/6] review: use shutil.which() --- tools/decoder.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/decoder.py b/tools/decoder.py index ed2edf241c..e245015e09 100755 --- a/tools/decoder.py +++ b/tools/decoder.py @@ -10,6 +10,7 @@ import sys import re import subprocess +import shutil # https://github.com/me-no-dev/EspExceptionDecoder/blob/349d17e4c9896306e2c00b4932be3ba510cad208/src/EspExceptionDecoder.java#L59-L90 EXCEPTION_CODES = ( @@ -189,9 +190,8 @@ def select_tool(toolchain_path, tool, func): path = f"xtensa-lx106-elf-{tool}" if toolchain_path: path = os.path.join(toolchain_path, path) - if not os.path.isfile(path): - print(f"error: not existing tool (path -- tool): '{path}'", file=sys.stderr) - sys.exit(1) + if not shutil.which(path): + raise FileNotFoundError(path) def formatter(func, path): def wrapper(elf, addresses): From 7c5366bb8f5f6e9420c4981197da6b10f4270173 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Thu, 28 Mar 2024 13:21:52 +0100 Subject: [PATCH 4/6] per review: hide duplicate system log, remove previous dup management --- tools/decoder.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tools/decoder.py b/tools/decoder.py index e245015e09..98962bdc51 100755 --- a/tools/decoder.py +++ b/tools/decoder.py @@ -105,6 +105,8 @@ def decode_lines(format_addresses, elf, lines): STACK_LINE_RE = re.compile(r"^[0-9a-f]{8}:\s\s+") + IGNORE_DUP = re.compile(r"^(epc1=0x........,|Fatal exception )") + CUT_HERE_STRING = "CUT HERE FOR EXCEPTION DECODER" DECODE_IT = "DECODE IT" EXCEPTION_STRING = "Exception (" @@ -127,7 +129,6 @@ def print_all_addresses(addresses): def format_address(address): return "\n".join(format_addresses(elf, [address])) - lastaddr = {} for line in lines: # ctx could happen multiple times. for the 2nd one, reset list # ctx: bearssl *or* ctx: cont *or* ctx: sys *or* ctx: whatever @@ -135,6 +136,8 @@ def format_address(address): stack_addresses = print_all_addresses(stack_addresses) last_stack = line.strip() # 3fffffb0: feefeffe feefeffe 3ffe85d8 401004ed + elif IGNORE_DUP.match(line): + continue elif in_stack and STACK_LINE_RE.match(line): _, addrs = line.split(":") addrs = ANY_ADDR_RE.findall(addrs) @@ -146,13 +149,9 @@ def format_address(address): for pair in pairs: name, addr = pair.split("=") if name in ["epc1", "excvaddr"]: - addr = addr.rstrip(',') - if not name in lastaddr or lastaddr[name] != addr: - if addr != '0x00000000': - lastaddr[name] = addr - output = format_address(addr) - if output: - print(f"{name}={output}") + 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: From 44341e88090e69c992ba8d481436b3e732ff941a Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Thu, 28 Mar 2024 13:28:44 +0100 Subject: [PATCH 5/6] fix variable name --- tools/decoder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/decoder.py b/tools/decoder.py index 98962bdc51..203b0e5b00 100755 --- a/tools/decoder.py +++ b/tools/decoder.py @@ -105,7 +105,7 @@ def decode_lines(format_addresses, elf, lines): STACK_LINE_RE = re.compile(r"^[0-9a-f]{8}:\s\s+") - IGNORE_DUP = re.compile(r"^(epc1=0x........,|Fatal exception )") + IGNORE_FIRMWARE_RE = re.compile(r"^(epc1=0x........, |Fatal exception )") CUT_HERE_STRING = "CUT HERE FOR EXCEPTION DECODER" DECODE_IT = "DECODE IT" @@ -136,7 +136,7 @@ def format_address(address): stack_addresses = print_all_addresses(stack_addresses) last_stack = line.strip() # 3fffffb0: feefeffe feefeffe 3ffe85d8 401004ed - elif IGNORE_DUP.match(line): + elif IGNORE_FIRMWARE_RE.match(line): continue elif in_stack and STACK_LINE_RE.match(line): _, addrs = line.split(":") From d1557c9b9fe77545f1f0351692f17c5690657590 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Sun, 31 Mar 2024 18:33:13 +0300 Subject: [PATCH 6/6] Update tools/decoder.py --- tools/decoder.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/decoder.py b/tools/decoder.py index 203b0e5b00..b1f1706767 100755 --- a/tools/decoder.py +++ b/tools/decoder.py @@ -189,8 +189,9 @@ def select_tool(toolchain_path, tool, func): path = f"xtensa-lx106-elf-{tool}" if toolchain_path: path = os.path.join(toolchain_path, path) - if not shutil.which(path): - raise FileNotFoundError(path) + + if not shutil.which(path): + raise FileNotFoundError(path) def formatter(func, path): def wrapper(elf, addresses):