FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fixed running on Windows. Added ESP32 backtrace parsing. by me21 · Pull Request #5 · janLo/EspArduinoExceptionDecoder · GitHub

Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
28 changes: 20 additions & 8 deletions decoder.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"ESP32": "esp32"
}

BACKTRACE_REGEX = re.compile(r"(?:\s+(0x40[0-2](?:\d|[a-f]|[A-F]){5}):0x(?:\d|[a-f]|[A-F]){8})\b")
EXCEPTION_REGEX = re.compile("^Exception \\((?P<exc>[0-9]*)\\):$")
COUNTER_REGEX = re.compile('^epc1=(?P<epc1>0x[0-9a-f]+) epc2=(?P<epc2>0x[0-9a-f]+) epc3=(?P<epc3>0x[0-9a-f]+) '
'excvaddr=(?P<excvaddr>0x[0-9a-f]+) depc=(?P<depc>0x[0-9a-f]+)$')
Expand Down Expand Up @@ -85,6 +86,12 @@ def __init__(self):

self.stack = []

def _parse_backtrace(self, line):
if line.startswith('Backtrace:'):
self.stack = [StackLine(offset=0, content=(addr,)) for addr in BACKTRACE_REGEX.findall(line)]
return None
return self._parse_backtrace

def _parse_exception(self, line):
match = EXCEPTION_REGEX.match(line)
if match is not None:
Expand Down Expand Up @@ -134,10 +141,13 @@ def _parse_stack_line(self, line):
return self._parse_stack_line
return None

def parse_file(self, file, stack_only=False):
func = self._parse_exception
if stack_only:
func = self._parse_stack_begin
def parse_file(self, file, platform, stack_only=False):
if platform == 'ESP32':
func = self._parse_backtrace
else:
func = self._parse_exception
if stack_only:
func = self._parse_stack_begin

for line in file:
func = func(line.strip())
Expand Down Expand Up @@ -237,8 +247,8 @@ def print_stack(lines, resolver):
print(out)


def print_result(parser, resolver, full=True, stack_only=False):
if not stack_only:
def print_result(parser, resolver, platform, full=True, stack_only=False):
if platform == 'ESP8266' and not stack_only:
print('Exception: {} ({})'.format(parser.exception, EXCEPTIONS[parser.exception]))

print("")
Expand Down Expand Up @@ -291,6 +301,8 @@ def parse_args():

addr2line = os.path.join(os.path.abspath(os.path.expanduser(args.tool)),
"bin/xtensa-" + PLATFORMS[args.platform] + "-elf-addr2line")
if os.name == 'nt':
addr2line += '.exe'
if not os.path.exists(addr2line):
print("ERROR: addr2line not found (" + addr2line + ")")

Expand All @@ -301,7 +313,7 @@ def parse_args():
parser = ExceptionDataParser()
resolver = AddressResolver(addr2line, elf_file)

parser.parse_file(file, args.stack_only)
parser.parse_file(file, args.platform, args.stack_only)
resolver.fill(parser)

print_result(parser, resolver, args.full, args.stack_only)
print_result(parser, resolver, args.platform, args.full, args.stack_only)

Back | FazBrowse Home | New Git URL