From 6b942d9a458b0489e860f4cfe4ac8d10124c27f9 Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Wed, 15 Jun 2022 22:54:00 -1000 Subject: [PATCH] Better fix for esp32_exception_decoder missing space (#831) Recent versions of ESP-IDF have a bug in which the Backtrace: line is malformed. Old/Good: Backtrace: 0xN:0xM 0xN:0xM 0xN:0xM ... New/Bad: Backtrace:0xN:0xM0xN:0xM 0xN:0xM ... I issued https://github.com/espressif/esp-idf/pull/9138 against ESP-IDF to fix the underlying problem, but it is unclear when or if that PR will be accepted, especially since the monitor program in ESP-IDF is immune to the problem. By using a decoding technique similar to the one in ESP-IDF's monitor, either backtrace format can be accepted. Supersedes #687 , which does not quite work, in that it misses one of the entries. --- monitor/filter_exception_decoder.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/monitor/filter_exception_decoder.py b/monitor/filter_exception_decoder.py index 11e45ba..5702fbf 100644 --- a/monitor/filter_exception_decoder.py +++ b/monitor/filter_exception_decoder.py @@ -32,11 +32,11 @@ IS_WINDOWS = sys.platform.startswith("win") class Esp32ExceptionDecoder(DeviceMonitorFilterBase): NAME = "esp32_exception_decoder" + BACKTRACE_PATTERN = re.compile(r"^Backtrace:(((\s?0x[0-9a-fA-F]{8}:0x[0-9a-fA-F]{8}))+)") + BACKTRACE_ADDRESS_PATTERN = re.compile(r'0x[0-9a-f]{8}:0x[0-9a-f]{8}') + def __call__(self): self.buffer = "" - self.backtrace_re = re.compile( - r"^Backtrace: ?((0x[0-9a-fA-F]+:0x[0-9a-fA-F]+ ?)+)\s*" - ) self.firmware_path = None self.addr2line_path = None @@ -100,7 +100,7 @@ See https://docs.platformio.org/page/projectconf/build_configurations.html self.buffer = "" last = idx + 1 - m = self.backtrace_re.match(line) + m = self.BACKTRACE_PATTERN.match(line) if m is None: continue @@ -111,11 +111,11 @@ See https://docs.platformio.org/page/projectconf/build_configurations.html return text def get_backtrace(self, match): - trace = "" + trace = "\n" enc = "mbcs" if IS_WINDOWS else "utf-8" args = [self.addr2line_path, u"-fipC", u"-e", self.firmware_path] try: - for i, addr in enumerate(match.group(1).split()): + for i, addr in enumerate(self.BACKTRACE_ADDRESS_PATTERN.findall(match.group(1))): output = ( subprocess.check_output(args + [addr]) .decode(enc)