-
Notifications
You must be signed in to change notification settings - Fork 37
✨ Add interactive stack trace #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 13 commits
1bb0480
2285d9d
8581cae
c5d5eb1
466503e
221ae03
2304312
3e8c63c
059b077
33124e1
efc6095
3125d4a
1b9167c
02e98c0
9e5fcb7
283712e
f4ae10c
7f2ad9d
30f83ab
5a15963
afcd1e7
de60210
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -30,6 +30,7 @@ def terminal_cli(): | |||||
| help='Specify 2 ports for the "share" backend. The default option deterministically selects ports ' | ||||||
| 'based on the serial port name') | ||||||
| @click.option('--banner/--no-banner', 'request_banner', default=True) | ||||||
| @click.option('--auto_stack_trace', default=True) | ||||||
| @click.option('--output', nargs = 1, type=str, is_eager = True, help='Redirect terminal output to a file', default=None) | ||||||
|
|
||||||
| def terminal(port: str, backend: str, **kwargs): | ||||||
|
|
@@ -83,7 +84,7 @@ def terminal(port: str, backend: str, **kwargs): | |||||
| device = devices.RawStreamDevice(ser) | ||||||
| else: | ||||||
| device = devices.vex.V5UserDevice(ser) | ||||||
| term = Terminal(device, request_banner=kwargs.pop('request_banner', True)) | ||||||
| term = Terminal(device, request_banner=kwargs.pop('request_banner', True), auto_stack_trace=kwargs.pop('auto_stack_trace', True)) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| class TerminalOutput(object): | ||||||
| def __init__(self, file): | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,10 +1,12 @@ | ||||||
| import codecs | ||||||
| import os | ||||||
| import signal | ||||||
| import subprocess | ||||||
| import sys | ||||||
| import threading | ||||||
|
|
||||||
| import colorama | ||||||
| from sqlalchemy import null | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| from pros.common.utils import logger | ||||||
| from pros.serial import decode_bytes_to_str | ||||||
|
|
@@ -165,12 +167,13 @@ def cleanup(self): | |||||
| 'Sorry no implementation for your platform ({})' | ||||||
| ' available.'.format(sys.platform)) | ||||||
|
|
||||||
|
|
||||||
| class Terminal(object): | ||||||
| """This class is loosely based off of the pyserial miniterm""" | ||||||
| beginStackTrace = False | ||||||
| stackTraceFile = null | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Did we ever decide if we needed to do this @ryan-doan ? |
||||||
| def __init__(self, port_instance: StreamDevice, transformations=(), | ||||||
| output_raw: bool = False, request_banner: bool = True): | ||||||
| output_raw: bool = False, request_banner: bool = True, auto_stack_trace: bool = True): | ||||||
| self.device = port_instance | ||||||
| self.device.subscribe(b'sout') | ||||||
| self.device.subscribe(b'serr') | ||||||
|
|
@@ -224,7 +227,35 @@ def reader(self): | |||||
| if data[0] == b'sout': | ||||||
| text = decode_bytes_to_str(data[1]) | ||||||
| elif data[0] == b'serr': | ||||||
| text = '{}{}{}'.format(colorama.Fore.RED, decode_bytes_to_str(data[1]), colorama.Style.RESET_ALL) | ||||||
| #print(len(text)) | ||||||
| addr = "0x" + decode_bytes_to_str(data[1])[:7] | ||||||
| if self.beginStackTrace and addr.isalnum() and addr[3] != 'x': | ||||||
| def getTrace(s, path): | ||||||
| if not os.path.exists(path): | ||||||
| return ' : ??' | ||||||
| temp = subprocess.Popen(['addr2line', '-faps', '-e', path, s], | ||||||
| stdout=subprocess.PIPE).communicate()[0].decode('utf-8') | ||||||
| if (temp.find('?') != -1): | ||||||
| return ' : ??' | ||||||
| else: | ||||||
| return ' : ' + temp[12: len(temp) - 2] | ||||||
| trace = getTrace(addr, "bin/hot.package.elf") | ||||||
| trace += getTrace(addr, "bin/cold.package.elf") | ||||||
| trace += getTrace(addr, "bin/monolith.elf") | ||||||
| text = '{}{}{}'.format(colorama.Fore.RED, decode_bytes_to_str(data[1]) + trace, colorama.Style.RESET_ALL) | ||||||
| file.write(addr + trace + '\n') | ||||||
| else: | ||||||
| text = '{}{}{}'.format(colorama.Fore.RED, decode_bytes_to_str(data[1]), colorama.Style.RESET_ALL) | ||||||
|
|
||||||
| if "BEGIN STACK TRACE" in text: | ||||||
| file = open("stack_trace.txt", "w") | ||||||
| self.beginStackTrace = True | ||||||
|
|
||||||
| if "END OF TRACE" in text: | ||||||
| file.close() | ||||||
| file = null | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| self.beginStackTrace = False | ||||||
|
|
||||||
| elif data[0] == b'kdbg': | ||||||
| text = '{}\n\nKERNEL DEBUG:\t{}{}\n'.format(colorama.Back.GREEN + colorama.Style.BRIGHT, | ||||||
| decode_bytes_to_str(data[1]), | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.