Skip to content
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

✨ Add interactive stack trace #233

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1bb0480
Formatted stack trace and save to file
ryan-doan Sep 27, 2022
2285d9d
code formatting changes
ryan-doan Sep 30, 2022
8581cae
Delete stack_trace.py
ryan-doan Sep 30, 2022
c5d5eb1
Update pros/serial/terminal/terminal.py
ryan-doan Oct 4, 2022
466503e
Update pros/cli/terminal.py
ryan-doan Oct 4, 2022
221ae03
update correct path, prevent addr2line from running if elf file doesn…
ryan-doan Oct 4, 2022
2304312
Merge branch 'add-interactive-stack-trace' of https://github.com/purd…
ryan-doan Oct 4, 2022
3e8c63c
remove project folder
ryan-doan Oct 4, 2022
059b077
added css styling to upload button
ryan-doan Oct 5, 2022
33124e1
Revert "added css styling to upload button"
ryan-doan Oct 5, 2022
efc6095
remove stack_trace.txt
ryan-doan Oct 18, 2022
3125d4a
fix errors with path
ryan-doan Oct 18, 2022
1b9167c
rewrote code to make it functional
ryan-doan Oct 19, 2022
02e98c0
Remove sqlalchemy, add options, string formatting, add colored output.
BennyBot Oct 19, 2022
9e5fcb7
Merge branch 'develop' into add-interactive-stack-trace
ryan-doan Oct 25, 2022
283712e
add shell argument to subprocess open
Andrewtho5942 Feb 24, 2023
f4ae10c
Merging in develop
Ghurfa Mar 1, 2024
7f2ad9d
Changed the addr2line path to use the toolchain
Ghurfa Mar 1, 2024
30f83ab
Merge branch 'develop' into add-interactive-stack-trace
Rocky14683 Jun 11, 2024
5a15963
Finish data abort realtime stack trace functionality
Rocky14683 Jun 11, 2024
afcd1e7
Merge remote-tracking branch 'origin/add-interactive-stack-trace' int…
Rocky14683 Jun 11, 2024
de60210
Work on formatting and color
Rocky14683 Jul 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pros/cli/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@click.option('--auto_stack_trace', default=True)
@click.option('--raw_stack_trace', is_flag=True, default=False)

@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):
Expand Down Expand Up @@ -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), request_banner=kwargs.pop('auto_stack_trace', True))
ryan-doan marked this conversation as resolved.
Show resolved Hide resolved

class TerminalOutput(object):
def __init__(self, file):
Expand Down
10 changes: 10 additions & 0 deletions pros/serial/terminal/stack_trace.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
0x7800184 : 5apple5faultEv at main.cpp:27 : ?? : ??
0x381a484 : ?? : ouch_bits_update_released at llemu.c:49 : vmap at lv_draw_vbasic.c:431
0x382ae60 : ?? : btn_signal at lv_btn.c:616 : ??
0x381bbe4 : ?? : ev_proc_release at lv_indev.c:722 : _init at lv_theme_alien.c:165
0x381c240 : ?? : ev_button_proc at lv_indev.c:571 : endar_init at lv_theme_alien.c:438
0x3828718 : ?? : task_exec at lv_task.c:332 : ??
0x38288d8 : ?? : task_handler at lv_task.c:135 : ??
0x381a098 : ?? : p_daemon at display.c:25 (discriminator 1) : vletter at lv_draw_vbasic.c:312
0x384b8cc : ?? : k_fn_wrapper at cpp_support.cpp:26 : ??
0x3845d5c : ?? : k_clean_up at port.c:219 : ??
28 changes: 25 additions & 3 deletions pros/serial/terminal/terminal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import codecs
import os
import signal
import subprocess
import sys
import threading

Expand Down Expand Up @@ -165,12 +166,11 @@ 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"""

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
file = None

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')
Expand Down Expand Up @@ -208,7 +208,7 @@ def _start_tx(self):
def _stop_tx(self):
self.console.cancel()
self._transmitter_alive = False
self.transmitter_thread.join()
self.transmitter_thread.join()
ryan-doan marked this conversation as resolved.
Show resolved Hide resolved

def reader(self):
if self.request_banner:
Expand All @@ -225,10 +225,32 @@ def reader(self):
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)

elif data[0] == b'kdbg':
text = '{}\n\nKERNEL DEBUG:\t{}{}\n'.format(colorama.Back.GREEN + colorama.Style.BRIGHT,
decode_bytes_to_str(data[1]),
colorama.Style.RESET_ALL)
if (self.auto_stack_trace):
start = text.find("BEGIN STACK TRACE") + 18
end = text.find("END OF TRACE")
addrArray = text[start: end].split()
out = ''
for i, s in enumerate(addrArray):
def getTrace(s, path):
temp = subprocess.Popen(['addr2line', '-faps', '-e', path, s],
stdout=subprocess.PIPE).communicate()[0].decode('utf-8')
if (temp.find('?') != -1):
return ' : ??'
else:
return ' : ' + temp[15: len(temp)-2]
out += " " + s + getTrace(s, "..\..\..\\test-project2\\bin\hot.package.elf")
ryan-doan marked this conversation as resolved.
Show resolved Hide resolved
out += getTrace(s, "..\..\..\\test-project2\\bin\cold.package.elf")
out += getTrace(s, "..\..\..\\test-project2\\bin\monolith.elf") + '\n'
text = text[:start] + out + text[end:]
print(text)
file = open("stack_trace.txt", "w")
file.write(out)
file.close()
elif data[0] != b'':
text = '{}{}'.format(decode_bytes_to_str(data[0]), decode_bytes_to_str(data[1]))
else:
Expand Down
16 changes: 16 additions & 0 deletions test-project2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Compiled Object files
ryan-doan marked this conversation as resolved.
Show resolved Hide resolved
*.o
*.obj

# Executables
*.bin
*.elf

# PROS
bin/
.vscode/
compile_commands.json
temp.log
temp.errors
*.ini
.d/
45 changes: 45 additions & 0 deletions test-project2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
################################################################################
######################### User configurable parameters #########################
# filename extensions
CEXTS:=c
ASMEXTS:=s S
CXXEXTS:=cpp c++ cc

# probably shouldn't modify these, but you may need them below
ROOT=.
FWDIR:=$(ROOT)/firmware
BINDIR=$(ROOT)/bin
SRCDIR=$(ROOT)/src
INCDIR=$(ROOT)/include

WARNFLAGS+=
EXTRA_CFLAGS=
EXTRA_CXXFLAGS=

# Set to 1 to enable hot/cold linking
USE_PACKAGE:=1

# Add libraries you do not wish to include in the cold image here
# EXCLUDE_COLD_LIBRARIES:= $(FWDIR)/your_library.a
EXCLUDE_COLD_LIBRARIES:=

# Set this to 1 to add additional rules to compile your project as a PROS library template
IS_LIBRARY:=0
# TODO: CHANGE THIS!
LIBNAME:=libbest
VERSION:=1.0.0
# EXCLUDE_SRC_FROM_LIB= $(SRCDIR)/unpublishedfile.c
# this line excludes opcontrol.c and similar files
EXCLUDE_SRC_FROM_LIB+=$(foreach file, $(SRCDIR)/main,$(foreach cext,$(CEXTS),$(file).$(cext)) $(foreach cxxext,$(CXXEXTS),$(file).$(cxxext)))

# files that get distributed to every user (beyond your source archive) - add
# whatever files you want here. This line is configured to add all header files
# that are in the the include directory get exported
TEMPLATE_FILES=$(INCDIR)/**/*.h $(INCDIR)/**/*.hpp

.DEFAULT_GOAL=quick

################################################################################
################################################################################
########## Nothing below this line should be edited by typical users ###########
-include ./common.mk
Loading