2222#include <stdint.h>
2323#include <stddef.h>
2424#include <stdbool.h>
25+ #include "debug.h"
2526#include "ets_sys.h"
2627#include "user_interface.h"
2728#include "esp8266_peri.h"
3031extern void __real_system_restart_local ();
3132extern cont_t g_cont ;
3233
34+ static const char * s_panic_file = 0 ;
35+ static int s_panic_line = 0 ;
36+ static const char * s_panic_func = 0 ;
37+
38+ static bool s_abort_called = false;
3339
3440void uart_write_char_d (char c );
3541static void uart0_write_char_d (char c );
@@ -56,7 +62,13 @@ void __wrap_system_restart_local() {
5662
5763 ets_install_putc1 (& uart_write_char_d );
5864
59- if (rst_info .reason == REASON_EXCEPTION_RST ) {
65+ if (s_panic_line ) {
66+ ets_printf ("\nPanic %s:%d %s\n" , s_panic_file , s_panic_line , s_panic_func );
67+ }
68+ else if (s_abort_called ) {
69+ ets_printf ("Abort called\n" );
70+ }
71+ else if (rst_info .reason == REASON_EXCEPTION_RST ) {
6072 ets_printf ("\nException (%d):\nepc1=0x%08x epc2=0x%08x epc3=0x%08x excvaddr=0x%08x depc=0x%08x\n" ,
6173 rst_info .exccause , rst_info .epc1 , rst_info .epc2 , rst_info .epc3 , rst_info .excvaddr , rst_info .depc );
6274 }
@@ -158,3 +170,25 @@ static void uart1_write_char_d(char c) {
158170 }
159171 USF (1 ) = c ;
160172}
173+ void abort () __attribute__((noreturn ));
174+
175+ void abort (){
176+ // cause exception
177+ s_abort_called = true;
178+ do {
179+ * ((int * )0 ) = 0 ;
180+ } while (true);
181+ }
182+
183+ void __assert_func (const char * file , int line , const char * func , const char * what ) {
184+ s_panic_file = file ;
185+ s_panic_line = line ;
186+ s_panic_func = func ;
187+ }
188+
189+ void __panic_func (const char * file , int line , const char * func ) {
190+ s_panic_file = file ;
191+ s_panic_line = line ;
192+ s_panic_func = func ;
193+ abort ();
194+ }
0 commit comments