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

✨ Print stack trace to brain screen on data abort #651

Open
wants to merge 22 commits into
base: develop-pros-4
Choose a base branch
from
Open
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d744720
Updated unwind.c to print stack addresses to brain screen
ion098 Apr 22, 2024
526eafd
Update unwind.c to fit bigger stacktrace
ion098 Apr 23, 2024
8d5d0d1
Added cast to void*, renamed some stuff
ion098 Apr 24, 2024
b0e0e8e
Fixed code so it should compile, code style changes
ion098 Apr 26, 2024
4830bac
Added curly braces
ion098 Apr 26, 2024
e9f5fbb
increased trace size, added truncation logic
ion098 Apr 26, 2024
cafdb6c
Formatted stacktrace message
ion098 Apr 28, 2024
7b36ef2
Merge branch 'purduesigbots:develop-pros-4' into develop-pros-4
ion098 Apr 30, 2024
f71ab48
Merge branch 'purduesigbots:develop-pros-4' into develop-pros-4
ion098 May 4, 2024
5a1913f
Fixed off by one error in stacktrace printing
ion098 May 5, 2024
e5a1214
Update unwind.c to add null ptr check
ion098 May 6, 2024
0cc7583
Merge branch 'purduesigbots:develop-pros-4' into develop-pros-4
ion098 May 13, 2024
6a334c2
Attempt to fix random uft8 errors during data abort
ion098 Jun 18, 2024
8778086
test: :white_check_mark: Improve segfault test
ion098 Jun 25, 2024
c51387d
Merge branch 'develop-pros-4' of https://github.com/ion098/pros into …
ion098 Jun 25, 2024
90bdc36
Merge branch 'purduesigbots:develop-pros-4' into develop-pros-4
ion098 Jun 26, 2024
11ca8dd
feat: :construction: Add stacktrace to prefetch errors
ion098 Jul 23, 2024
d0b6384
Merge branch 'develop-pros-4' of https://github.com/ion098/pros into …
ion098 Jul 23, 2024
d0c5d01
fix: :bug: Unbreak stacktrace printing again
ion098 Jul 28, 2024
f7f372c
feat: :children_crossing: Print stack trace as hex numbers
ion098 Jul 30, 2024
3bf8300
fix: :adhesive_bandage: Stop motors on data/prefetch abort
ion098 Aug 2, 2024
d83d118
docs: :bulb: Fix comment before report_fatal_error
ion098 Aug 2, 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
31 changes: 29 additions & 2 deletions src/system/unwind.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,18 @@ _Unwind_Ptr __gnu_Unwind_Find_exidx(_Unwind_Ptr pc, int* nrec) {
return (_Unwind_Ptr)&__exidx_start;
}

struct {
ion098 marked this conversation as resolved.
Show resolved Hide resolved
uint32_t[12] pcs;
ion098 marked this conversation as resolved.
Show resolved Hide resolved
size_t size;
} trace;

_Unwind_Reason_Code trace_fn(_Unwind_Context* unwind_ctx, void* d) {
uint32_t pc = _Unwind_GetIP(unwind_ctx);
fprintf(stderr, "\t%p\n", (void*)pc);
if (trace.size < sizeof(trace.pcs) / sizeof(trace.pcs[0]))
trace.pcs[trace.size++] = pc;
else
; // TODO: handle this
ion098 marked this conversation as resolved.
Show resolved Hide resolved
extern void task_clean_up();
if (pc == (uint32_t)task_clean_up) {
return _URC_FAILURE;
Expand Down Expand Up @@ -140,11 +149,14 @@ void report_data_abort(uint32_t _sp) {
fputs("\n\nDATA ABORT EXCEPTION\n\n", stderr);
vexDisplayForegroundColor(ClrWhite);
vexDisplayBackgroundColor(ClrRed);
vexDisplayRectClear(0, 25, 480, 125);
vexDisplayRectClear(0, 25, 480, 200);
vexDisplayString(2, "DATA ABORT EXCEPTION");
vexDisplayString(3, "PC: %x", vrs.core.r[R_PC]);

int brain_line_no = 4;

if (pxCurrentTCB) {
vexDisplayString(4, "CURRENT TASK: %.32s\n", pxCurrentTCB->pcTaskName);
vexDisplayString(brain_line_no++, "CURRENT TASK: %.32s\n", pxCurrentTCB->pcTaskName);
fprintf(stderr, "CURRENT TASK: %.32s\n", pxCurrentTCB->pcTaskName);
}

Expand All @@ -155,6 +167,21 @@ void report_data_abort(uint32_t _sp) {
fprintf(stderr, "\t%p\n", (void*)vrs.core.r[R_PC]);
__gnu_Unwind_Backtrace(trace_fn, NULL, &vrs);
ion098 marked this conversation as resolved.
Show resolved Hide resolved
fputs("END OF TRACE\n", stderr);

for(size_t i = 0; i < trace.size / 4; i++) {
vexDisplayString(brain_line_no++, "%p %p %p %p", (void*)trace.pcs[4*i], (void*)trace.pcs[4*i+1], (void*)trace.pcs[4*i+2], (void*)trace.pcs[4*i+3]);
ion098 marked this conversation as resolved.
Show resolved Hide resolved
}
switch (trace.size % 4) {
case 3:
vexDisplayString(brain_line_no++, "%p %p %p", (void*)trace.pcs[trace.size-2], (void*)trace.pcs[trace.size-1], (void*)trace.pcs[trace.size]);
break;
case 2:
vexDisplayString(brain_line_no++, "%p %p", (void*)trace.pcs[trace.size-1], (void*)trace.pcs[trace.size]);
break;
case 1:
vexDisplayString(brain_line_no++, "%p", (void*)trace.pcs[trace.size]);
break;
}

struct mallinfo info = mallinfo();
fprintf(stderr, "HEAP USED: %d bytes\n", info.uordblks);
Expand Down
Loading