arm: move trace dump to crash handler

This commit is contained in:
Paul Mathieu 2022-06-19 09:48:28 +02:00
parent ec024adfff
commit 02fbb1c671
3 changed files with 14 additions and 7 deletions

View File

@ -3,6 +3,7 @@
#include "gpio.h" #include "gpio.h"
#include "itoa.h" #include "itoa.h"
#include "sleep.h" #include "sleep.h"
#include "trace.h"
#include "uart.h" #include "uart.h"
extern "C" uint32_t _initial_stack_pointer, _text_begin, _text_end; extern "C" uint32_t _initial_stack_pointer, _text_begin, _text_end;
@ -80,6 +81,8 @@ void CrashHandler(Armv6mRegs* regs) {
UartWriteCrash("- Stack trace:\r\n"); UartWriteCrash("- Stack trace:\r\n");
StackTrace(reinterpret_cast<uint32_t*>(regs->sp)); StackTrace(reinterpret_cast<uint32_t*>(regs->sp));
tracing::dump();
while (1) { while (1) {
gpio0->data = 0x55; gpio0->data = 0x55;
sleep(100); sleep(100);

View File

@ -18,10 +18,7 @@ void Uart0Isr() {
HandleUartIsr(); HandleUartIsr();
} }
void Timer0Isr() { void Timer0Isr() { __builtin_trap(); }
tracing::dump();
__builtin_trap();
}
void SetupUart() { void SetupUart() {
InitUarts(); InitUarts();

View File

@ -7,14 +7,19 @@
#include "timer.h" #include "timer.h"
#include "uart.h" #include "uart.h"
#ifndef SBRK_STATS
#define SBRK_STATS 0
#endif
extern unsigned char _heap_begin, _heap_end; extern unsigned char _heap_begin, _heap_end;
namespace { namespace {
[[maybe_unused]]
void LogStats(unsigned char* heap) { void LogStats(unsigned char* heap) {
char number[] = "00000000\r\n"; char number[] = "00000000\r\n";
UartWriteBlocking("Program break now at 0x"); UartWriteCrash("Program break now at 0x");
itoa(reinterpret_cast<int>(heap), number); itoa(reinterpret_cast<int>(heap), number);
UartWriteBlocking(number); UartWriteCrash(number);
} }
} // namespace } // namespace
@ -22,11 +27,13 @@ extern "C" void* _sbrk(int increment) {
static unsigned char* heap = &_heap_begin; static unsigned char* heap = &_heap_begin;
unsigned char* prev_heap = heap; unsigned char* prev_heap = heap;
if (heap + increment >= &_heap_end) { if (heap + increment >= &_heap_end) {
UartWriteBlocking("Heap overflow!\r\n"); UartWriteCrash("Heap overflow!\r\n");
return reinterpret_cast<void*>(-1); return reinterpret_cast<void*>(-1);
} }
heap += increment; heap += increment;
#if SBRK_STATS
LogStats(heap); LogStats(heap);
#endif
return prev_heap; return prev_heap;
} }