Skip to content

Commit 5a15963

Browse files
committed
Finish data abort realtime stack trace functionality
1 parent 7f2ad9d commit 5a15963

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

pros/serial/terminal/terminal.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class Terminal(object):
173173
stackTraceFile = None
174174

175175
def __init__(self, port_instance: StreamDevice, transformations=(),
176-
output_raw: bool = False, request_banner: bool = True,
176+
output_raw: bool = False, request_banner: bool = True,
177177
auto_stack_trace: bool = True, stack_trace_file: str = None):
178178
self.device = port_instance
179179
self.device.subscribe(b'sout')
@@ -234,37 +234,36 @@ def reader(self):
234234
addr = "0x" + decode_bytes_to_str(data[1])[:7]
235235

236236
convert_trace = (self.beginStackTrace and
237-
addr.isalnum() and
238-
addr[3] != 'x' and
239-
self.convert_stack_traces and
237+
addr.isalnum() and
238+
addr[3] != 'x' and
239+
self.convert_stack_traces and
240240
((os.name != 'nt') or os.environ.get('PROS_TOOLCHAIN')))
241-
241+
242242
if convert_trace:
243243
if os.name == 'nt' and os.environ.get('PROS_TOOLCHAIN'):
244-
addr2line_path = os.path.join(os.environ.get('PROS_TOOLCHAIN'), 'bin', 'arm-none-eabi-addr2line.exe')
244+
addr2line_path = os.path.join(os.environ.get('PROS_TOOLCHAIN'), 'bin', 'arm-none-eabi-addr2line')
245245
else:
246-
addr2line_path = 'addr2line'
246+
addr2line_path = 'arm-none-eabi-addr2line'
247247

248248
def getTrace(s, path):
249249
if not os.path.exists(path):
250250
return ''
251-
temp = subprocess.Popen([addr2line_path, '-faps', '-e', path, s],
252-
stdout=subprocess.PIPE,shell=True).communicate()[0].decode('utf-8')
251+
temp = subprocess.run([addr2line_path, '-faps', '-e', path, s], capture_output=True).stdout.decode('utf-8')
253252
if (temp.find('?') != -1):
254253
return ''
255254
else:
256255
return temp[12: len(temp) - 2]
257256

258257
trace = ' : {}{}{}'.format(
259-
getTrace(addr, "bin/hot.package.elf"),
260-
getTrace(addr, "bin/cold.package.elf"),
261-
getTrace(addr, "bin/monolith.elf"))
258+
getTrace(addr, "./bin/hot.package.elf"),
259+
getTrace(addr, "./bin/cold.package.elf"),
260+
getTrace(addr, "./bin/monolith.elf"))
262261
text = '{}{}{}{}{}{}'.format(colorama.Fore.RED, decode_bytes_to_str(data[1]), colorama.Style.RESET_ALL, colorama.Fore.WHITE, trace, colorama.Style.RESET_ALL)
263-
if(self.stack_trace_file):
262+
if(self.stack_trace_file):
264263
file.write(addr + trace + '\n')
265264
else:
266265
text = '{}{}{}'.format(colorama.Fore.RED, decode_bytes_to_str(data[1]), colorama.Style.RESET_ALL)
267-
266+
268267
if "BEGIN STACK TRACE" in text:
269268
self.beginStackTrace = True
270269
if(self.convert_stack_traces):
@@ -279,7 +278,7 @@ def getTrace(s, path):
279278
if(self.stack_trace_file):
280279
file.close()
281280
file = None
282-
281+
283282
elif data[0] == b'kdbg':
284283
text = '{}\n\nKERNEL DEBUG:\t{}{}\n'.format(colorama.Back.GREEN + colorama.Style.BRIGHT,
285284
decode_bytes_to_str(data[1]),

0 commit comments

Comments
 (0)