arm: move trace dump to crash handler
This commit is contained in:
@@ -7,14 +7,19 @@
|
||||
#include "timer.h"
|
||||
#include "uart.h"
|
||||
|
||||
#ifndef SBRK_STATS
|
||||
#define SBRK_STATS 0
|
||||
#endif
|
||||
|
||||
extern unsigned char _heap_begin, _heap_end;
|
||||
|
||||
namespace {
|
||||
[[maybe_unused]]
|
||||
void LogStats(unsigned char* heap) {
|
||||
char number[] = "00000000\r\n";
|
||||
UartWriteBlocking("Program break now at 0x");
|
||||
UartWriteCrash("Program break now at 0x");
|
||||
itoa(reinterpret_cast<int>(heap), number);
|
||||
UartWriteBlocking(number);
|
||||
UartWriteCrash(number);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -22,11 +27,13 @@ extern "C" void* _sbrk(int increment) {
|
||||
static unsigned char* heap = &_heap_begin;
|
||||
unsigned char* prev_heap = heap;
|
||||
if (heap + increment >= &_heap_end) {
|
||||
UartWriteBlocking("Heap overflow!\r\n");
|
||||
UartWriteCrash("Heap overflow!\r\n");
|
||||
return reinterpret_cast<void*>(-1);
|
||||
}
|
||||
heap += increment;
|
||||
#if SBRK_STATS
|
||||
LogStats(heap);
|
||||
#endif
|
||||
return prev_heap;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user