Skip to content

Commit f02e2c7

Browse files
committed
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
1 parent eda4e08 commit f02e2c7

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Diff for: tools/decoder.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def decode_lines(format_addresses, elf, lines):
105105
STACK_LINE_RE = re.compile(r"^[0-9a-f]{8}:\s\s+")
106106

107107
CUT_HERE_STRING = "CUT HERE FOR EXCEPTION DECODER"
108+
DECODE_IT = "DECODE IT"
108109
EXCEPTION_STRING = "Exception ("
109110
EPC_STRING = "epc1="
110111

@@ -125,6 +126,7 @@ def print_all_addresses(addresses):
125126
def format_address(address):
126127
return "\n".join(format_addresses(elf, [address]))
127128

129+
lastepc = 0
128130
for line in lines:
129131
# ctx could happen multiple times. for the 2nd one, reset list
130132
# ctx: bearssl *or* ctx: cont *or* ctx: sys *or* ctx: whatever
@@ -143,9 +145,13 @@ def format_address(address):
143145
for pair in pairs:
144146
name, addr = pair.split("=")
145147
if name in ["epc1", "excvaddr"]:
146-
output = format_address(addr)
147-
if output:
148-
print(f"{name}={output}")
148+
addr = addr.rstrip(',')
149+
if lastepc != addr:
150+
if addr != '0x00000000':
151+
lastepc = addr
152+
output = format_address(addr)
153+
if output:
154+
print(f"{name}={output}")
149155
# Exception (123):
150156
# Other reasons coming before the guard shown as-is
151157
elif EXCEPTION_STRING in line:
@@ -163,8 +169,10 @@ def format_address(address):
163169
in_stack = True
164170
# ignore
165171
elif "<<<stack<<<" in line:
172+
in_stack = False
173+
stack_addresses = print_all_addresses(stack_addresses)
166174
continue
167-
elif CUT_HERE_STRING in line:
175+
elif CUT_HERE_STRING in line or DECODE_IT in line:
168176
continue
169177
else:
170178
line = line.strip()
@@ -181,6 +189,9 @@ def select_tool(toolchain_path, tool, func):
181189
path = f"xtensa-lx106-elf-{tool}"
182190
if toolchain_path:
183191
path = os.path.join(toolchain_path, path)
192+
if not os.path.isfile(path):
193+
print(f"error: not existing tool (path -- tool): '{path}'", file=sys.stderr)
194+
sys.exit(1)
184195

185196
def formatter(func, path):
186197
def wrapper(elf, addresses):

0 commit comments

Comments
 (0)