54
54
"ESP32" : "esp32"
55
55
}
56
56
57
+ BACKTRACE_REGEX = re .compile (r"(?:\s+(0x40[0-2](?:\d|[a-f]|[A-F]){5}):0x(?:\d|[a-f]|[A-F]){8})\b" )
57
58
EXCEPTION_REGEX = re .compile ("^Exception \\ ((?P<exc>[0-9]*)\\ ):$" )
58
59
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]+) '
59
60
'excvaddr=(?P<excvaddr>0x[0-9a-f]+) depc=(?P<depc>0x[0-9a-f]+)$' )
@@ -85,6 +86,12 @@ def __init__(self):
85
86
86
87
self .stack = []
87
88
89
+ def _parse_backtrace (self , line ):
90
+ if line .startswith ('Backtrace:' ):
91
+ self .stack = [StackLine (offset = 0 , content = (addr ,)) for addr in BACKTRACE_REGEX .findall (line )]
92
+ return None
93
+ return self ._parse_backtrace
94
+
88
95
def _parse_exception (self , line ):
89
96
match = EXCEPTION_REGEX .match (line )
90
97
if match is not None :
@@ -134,10 +141,13 @@ def _parse_stack_line(self, line):
134
141
return self ._parse_stack_line
135
142
return None
136
143
137
- def parse_file (self , file , stack_only = False ):
138
- func = self ._parse_exception
139
- if stack_only :
140
- func = self ._parse_stack_begin
144
+ def parse_file (self , file , platform , stack_only = False ):
145
+ if platform == 'ESP32' :
146
+ func = self ._parse_backtrace
147
+ else :
148
+ func = self ._parse_exception
149
+ if stack_only :
150
+ func = self ._parse_stack_begin
141
151
142
152
for line in file :
143
153
func = func (line .strip ())
@@ -237,8 +247,8 @@ def print_stack(lines, resolver):
237
247
print (out )
238
248
239
249
240
- def print_result (parser , resolver , full = True , stack_only = False ):
241
- if not stack_only :
250
+ def print_result (parser , resolver , platform , full = True , stack_only = False ):
251
+ if platform == 'ESP8266' and not stack_only :
242
252
print ('Exception: {} ({})' .format (parser .exception , EXCEPTIONS [parser .exception ]))
243
253
244
254
print ("" )
@@ -291,6 +301,8 @@ def parse_args():
291
301
292
302
addr2line = os .path .join (os .path .abspath (os .path .expanduser (args .tool )),
293
303
"bin/xtensa-" + PLATFORMS [args .platform ] + "-elf-addr2line" )
304
+ if os .name == 'nt' :
305
+ addr2line += '.exe'
294
306
if not os .path .exists (addr2line ):
295
307
print ("ERROR: addr2line not found (" + addr2line + ")" )
296
308
@@ -301,7 +313,7 @@ def parse_args():
301
313
parser = ExceptionDataParser ()
302
314
resolver = AddressResolver (addr2line , elf_file )
303
315
304
- parser .parse_file (file , args .stack_only )
316
+ parser .parse_file (file , args .platform , args . stack_only )
305
317
resolver .fill (parser )
306
318
307
- print_result (parser , resolver , args .full , args .stack_only )
319
+ print_result (parser , resolver , args .platform , args . full , args .stack_only )
0 commit comments