mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Improve debug output on critical errors
This commit is contained in:
parent
590eefa210
commit
8bf1e98f24
@ -17,14 +17,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <debug.h>
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "ets_sys.h"
|
#include "ets_sys.h"
|
||||||
#include "os_type.h"
|
#include "os_type.h"
|
||||||
#include "osapi.h"
|
#include "osapi.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "user_interface.h"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *operator new(size_t size) {
|
void *operator new(size_t size) {
|
||||||
size = ((size + 3) & ~((size_t)0x3));
|
size = ((size + 3) & ~((size_t)0x3));
|
||||||
return os_malloc(size);
|
return os_malloc(size);
|
||||||
@ -47,27 +49,26 @@ extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
|
|||||||
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
|
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
|
||||||
|
|
||||||
void __cxa_pure_virtual(void) {
|
void __cxa_pure_virtual(void) {
|
||||||
abort();
|
panic();
|
||||||
}
|
}
|
||||||
|
|
||||||
void __cxa_deleted_virtual(void) {
|
void __cxa_deleted_virtual(void) {
|
||||||
abort();
|
panic();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
void __throw_bad_function_call() {
|
void __throw_bad_function_call() {
|
||||||
abort();
|
panic();
|
||||||
}
|
}
|
||||||
|
|
||||||
void __throw_length_error(char const*) {
|
void __throw_length_error(char const*) {
|
||||||
abort();
|
panic();
|
||||||
}
|
}
|
||||||
|
|
||||||
void __throw_bad_alloc() {
|
void __throw_bad_alloc() {
|
||||||
abort();
|
panic();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: rebuild windows toolchain to make this unnecessary:
|
// TODO: rebuild windows toolchain to make this unnecessary:
|
||||||
void* __dso_handle;
|
void* __dso_handle;
|
||||||
|
|
||||||
|
@ -66,13 +66,6 @@ static os_event_t g_loop_queue[LOOP_QUEUE_SIZE];
|
|||||||
|
|
||||||
static uint32_t g_micros_at_task_start;
|
static uint32_t g_micros_at_task_start;
|
||||||
|
|
||||||
|
|
||||||
extern "C" void abort() {
|
|
||||||
do {
|
|
||||||
*((int*)0) = 0;
|
|
||||||
} while(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void esp_yield() {
|
extern "C" void esp_yield() {
|
||||||
if (cont_can_yield(&g_cont)) {
|
if (cont_can_yield(&g_cont)) {
|
||||||
cont_yield(&g_cont);
|
cont_yield(&g_cont);
|
||||||
@ -89,7 +82,7 @@ extern "C" void __yield() {
|
|||||||
esp_yield();
|
esp_yield();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
abort();
|
panic();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,9 +110,8 @@ static void loop_wrapper() {
|
|||||||
static void loop_task(os_event_t *events) {
|
static void loop_task(os_event_t *events) {
|
||||||
g_micros_at_task_start = system_get_time();
|
g_micros_at_task_start = system_get_time();
|
||||||
cont_run(&g_cont, &loop_wrapper);
|
cont_run(&g_cont, &loop_wrapper);
|
||||||
if(cont_check(&g_cont) != 0) {
|
if (cont_check(&g_cont) != 0) {
|
||||||
ets_printf("\r\nsketch stack overflow detected\r\n");
|
panic();
|
||||||
abort();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include "debug.h"
|
||||||
#include "ets_sys.h"
|
#include "ets_sys.h"
|
||||||
#include "user_interface.h"
|
#include "user_interface.h"
|
||||||
#include "esp8266_peri.h"
|
#include "esp8266_peri.h"
|
||||||
@ -30,6 +31,11 @@
|
|||||||
extern void __real_system_restart_local();
|
extern void __real_system_restart_local();
|
||||||
extern cont_t g_cont;
|
extern cont_t g_cont;
|
||||||
|
|
||||||
|
static const char* s_panic_file = 0;
|
||||||
|
static int s_panic_line = 0;
|
||||||
|
static const char* s_panic_func = 0;
|
||||||
|
|
||||||
|
static bool s_abort_called = false;
|
||||||
|
|
||||||
void uart_write_char_d(char c);
|
void uart_write_char_d(char c);
|
||||||
static void uart0_write_char_d(char c);
|
static void uart0_write_char_d(char c);
|
||||||
@ -56,7 +62,13 @@ void __wrap_system_restart_local() {
|
|||||||
|
|
||||||
ets_install_putc1(&uart_write_char_d);
|
ets_install_putc1(&uart_write_char_d);
|
||||||
|
|
||||||
if (rst_info.reason == REASON_EXCEPTION_RST) {
|
if (s_panic_line) {
|
||||||
|
ets_printf("\nPanic %s:%d %s\n", s_panic_file, s_panic_line, s_panic_func);
|
||||||
|
}
|
||||||
|
else if (s_abort_called) {
|
||||||
|
ets_printf("Abort called\n");
|
||||||
|
}
|
||||||
|
else if (rst_info.reason == REASON_EXCEPTION_RST) {
|
||||||
ets_printf("\nException (%d):\nepc1=0x%08x epc2=0x%08x epc3=0x%08x excvaddr=0x%08x depc=0x%08x\n",
|
ets_printf("\nException (%d):\nepc1=0x%08x epc2=0x%08x epc3=0x%08x excvaddr=0x%08x depc=0x%08x\n",
|
||||||
rst_info.exccause, rst_info.epc1, rst_info.epc2, rst_info.epc3, rst_info.excvaddr, rst_info.depc);
|
rst_info.exccause, rst_info.epc1, rst_info.epc2, rst_info.epc3, rst_info.excvaddr, rst_info.depc);
|
||||||
}
|
}
|
||||||
@ -158,3 +170,25 @@ static void uart1_write_char_d(char c) {
|
|||||||
}
|
}
|
||||||
USF(1) = c;
|
USF(1) = c;
|
||||||
}
|
}
|
||||||
|
void abort() __attribute__((noreturn));
|
||||||
|
|
||||||
|
void abort(){
|
||||||
|
// cause exception
|
||||||
|
s_abort_called = true;
|
||||||
|
do {
|
||||||
|
*((int*)0) = 0;
|
||||||
|
} while(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __assert_func(const char *file, int line, const char *func, const char *what) {
|
||||||
|
s_panic_file = file;
|
||||||
|
s_panic_line = line;
|
||||||
|
s_panic_func = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
void __panic_func(const char* file, int line, const char* func) {
|
||||||
|
s_panic_file = file;
|
||||||
|
s_panic_line = line;
|
||||||
|
s_panic_func = func;
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
#define ARD_DEBUG_H
|
#define ARD_DEBUG_H
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
//#define DEBUGV(...) ets_printf(__VA_ARGS__)
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define DEBUGV(...) ets_printf(__VA_ARGS__)
|
||||||
|
|
||||||
#ifndef DEBUGV
|
#ifndef DEBUGV
|
||||||
#define DEBUGV(...)
|
#define DEBUGV(...)
|
||||||
@ -14,4 +16,16 @@ void hexdump(uint8_t *mem, uint32_t len, uint8_t cols = 16);
|
|||||||
void hexdump(uint8_t *mem, uint32_t len, uint8_t cols);
|
void hexdump(uint8_t *mem, uint32_t len, uint8_t cols);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void __panic_func(const char* file, int line, const char* func) __attribute__((noreturn));
|
||||||
|
#define panic() __panic_func(__FILE__, __LINE__, __func__)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif//ARD_DEBUG_H
|
#endif//ARD_DEBUG_H
|
||||||
|
@ -384,8 +384,7 @@ extern "C" void* ax_port_malloc(size_t size, const char* file, int line) {
|
|||||||
|
|
||||||
if (result == nullptr) {
|
if (result == nullptr) {
|
||||||
DEBUG_TLS_MEM_PRINT("%s:%d malloc %d failed, left %d\r\n", file, line, size, ESP.getFreeHeap());
|
DEBUG_TLS_MEM_PRINT("%s:%d malloc %d failed, left %d\r\n", file, line, size, ESP.getFreeHeap());
|
||||||
|
panic();
|
||||||
while(true){}
|
|
||||||
}
|
}
|
||||||
if (size >= 1024)
|
if (size >= 1024)
|
||||||
DEBUG_TLS_MEM_PRINT("%s:%d malloc %d, left %d\r\n", file, line, size, ESP.getFreeHeap());
|
DEBUG_TLS_MEM_PRINT("%s:%d malloc %d, left %d\r\n", file, line, size, ESP.getFreeHeap());
|
||||||
@ -402,7 +401,7 @@ extern "C" void* ax_port_realloc(void* ptr, size_t size, const char* file, int l
|
|||||||
void* result = realloc(ptr, size);
|
void* result = realloc(ptr, size);
|
||||||
if (result == nullptr) {
|
if (result == nullptr) {
|
||||||
DEBUG_TLS_MEM_PRINT("%s:%d realloc %d failed, left %d\r\n", file, line, size, ESP.getFreeHeap());
|
DEBUG_TLS_MEM_PRINT("%s:%d realloc %d failed, left %d\r\n", file, line, size, ESP.getFreeHeap());
|
||||||
while(true){}
|
panic();
|
||||||
}
|
}
|
||||||
if (size >= 1024)
|
if (size >= 1024)
|
||||||
DEBUG_TLS_MEM_PRINT("%s:%d realloc %d, left %d\r\n", file, line, size, ESP.getFreeHeap());
|
DEBUG_TLS_MEM_PRINT("%s:%d realloc %d, left %d\r\n", file, line, size, ESP.getFreeHeap());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user