22
22
#include <stdint.h>
23
23
#include <stddef.h>
24
24
#include <stdbool.h>
25
+ #include "debug.h"
25
26
#include "ets_sys.h"
26
27
#include "user_interface.h"
27
28
#include "esp8266_peri.h"
30
31
extern void __real_system_restart_local ();
31
32
extern cont_t g_cont ;
32
33
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;
33
39
34
40
void uart_write_char_d (char c );
35
41
static void uart0_write_char_d (char c );
@@ -56,7 +62,13 @@ void __wrap_system_restart_local() {
56
62
57
63
ets_install_putc1 (& uart_write_char_d );
58
64
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 ) {
60
72
ets_printf ("\nException (%d):\nepc1=0x%08x epc2=0x%08x epc3=0x%08x excvaddr=0x%08x depc=0x%08x\n" ,
61
73
rst_info .exccause , rst_info .epc1 , rst_info .epc2 , rst_info .epc3 , rst_info .excvaddr , rst_info .depc );
62
74
}
@@ -158,3 +170,25 @@ static void uart1_write_char_d(char c) {
158
170
}
159
171
USF (1 ) = c ;
160
172
}
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