28
28
#include "esp8266_peri.h"
29
29
#include "cont.h"
30
30
#include "pgmspace.h"
31
+ #include "gdb_hooks.h"
31
32
32
33
extern void __real_system_restart_local ();
33
- extern void gdb_do_break ();
34
34
35
35
extern cont_t g_cont ;
36
36
37
37
// These will be pointers to PROGMEM const strings
38
38
static const char * s_panic_file = 0 ;
39
39
static int s_panic_line = 0 ;
40
40
static const char * s_panic_func = 0 ;
41
-
42
41
static bool s_abort_called = false;
43
42
44
- void uart_write_char_d (char c );
43
+ void abort () __attribute__((noreturn ));
44
+ static void uart_write_char_d (char c );
45
45
static void uart0_write_char_d (char c );
46
46
static void uart1_write_char_d (char c );
47
47
static void print_stack (uint32_t start , uint32_t end );
48
- //static void print_pcs(uint32_t start, uint32_t end);
49
-
50
- bool __attribute((weak )) crash_for_gdb = 0 ;
48
+ static void raise_exception () __attribute__((noreturn ));
51
49
52
50
extern void __custom_crash_callback ( struct rst_info * rst_info , uint32_t stack , uint32_t stack_end ) {
53
51
(void ) rst_info ;
@@ -66,9 +64,17 @@ static void ets_puts_P(const char *romString) {
66
64
}
67
65
68
66
void __wrap_system_restart_local () {
69
- if (crash_for_gdb ) * ((int * )0 ) = 0 ;
70
67
register uint32_t sp asm("a1" );
71
68
69
+ if (gdb_present ()) {
70
+ /* When GDBStub is present, exceptions are handled by GDBStub,
71
+ but Soft WDT will still call this function.
72
+ Trigger an exception to break into GDB.
73
+ TODO: check why gdb_do_break() or asm("break.n 0") do not
74
+ break into GDB here. */
75
+ raise_exception ();
76
+ }
77
+
72
78
struct rst_info rst_info = {0 };
73
79
system_rtc_mem_read (0 , & rst_info , sizeof (rst_info ));
74
80
if (rst_info .reason != REASON_SOFT_WDT_RST &&
@@ -129,7 +135,6 @@ void __wrap_system_restart_local() {
129
135
130
136
ets_printf ("sp: %08x end: %08x offset: %04x\n" , sp , stack_end , offset );
131
137
132
- // print_pcs(sp + offset, stack_end);
133
138
print_stack (sp + offset , stack_end );
134
139
135
140
custom_crash_callback ( & rst_info , sp + offset , stack_end );
@@ -153,24 +158,7 @@ static void print_stack(uint32_t start, uint32_t end) {
153
158
ets_puts_P (PSTR ("<<<stack<<<\n" ));
154
159
}
155
160
156
- /*
157
- static void print_pcs(uint32_t start, uint32_t end) {
158
- uint32_t n = 0;
159
- ets_printf("\n>>>pc>>>\n");
160
- for (uint32_t pos = start; pos < end; pos += 16, ++n) {
161
- uint32_t* sf = (uint32_t*) pos;
162
-
163
- uint32_t pc_ret = sf[3];
164
- uint32_t sp_ret = sf[2];
165
- if (pc_ret < 0x40000000 || pc_ret > 0x40f00000 || sp_ret != pos + 16)
166
- continue;
167
- ets_printf("%08x\n", pc_ret);
168
- }
169
- ets_printf("<<<pc<<<\n");
170
- }
171
- */
172
-
173
- void uart_write_char_d (char c ) {
161
+ static void uart_write_char_d (char c ) {
174
162
uart0_write_char_d (c );
175
163
uart1_write_char_d (c );
176
164
}
@@ -192,29 +180,30 @@ static void uart1_write_char_d(char c) {
192
180
}
193
181
USF (1 ) = c ;
194
182
}
195
- void abort () __attribute__((noreturn ));
196
183
197
- void abort (){
198
- // cause exception
184
+ static void raise_exception () {
185
+ __asm__ __volatile__ ("syscall" );
186
+ while (1 ); // never reached, needed to satisfy "noreturn" attribute
187
+ }
188
+
189
+ void abort () {
199
190
s_abort_called = true;
200
- do {
201
- * ((int * )0 ) = 0 ;
202
- } while (true);
191
+ raise_exception ();
203
192
}
204
193
205
194
void __assert_func (const char * file , int line , const char * func , const char * what ) {
206
195
(void ) what ;
207
196
s_panic_file = file ;
208
197
s_panic_line = line ;
209
198
s_panic_func = func ;
210
- gdb_do_break ();
199
+ gdb_do_break (); /* if GDB is not present, this is a no-op */
211
200
}
212
201
213
202
void __panic_func (const char * file , int line , const char * func ) {
214
203
s_panic_file = file ;
215
204
s_panic_line = line ;
216
205
s_panic_func = func ;
217
- gdb_do_break ();
218
- abort ();
206
+ gdb_do_break (); /* if GDB is not present, this is a no-op */
207
+ raise_exception ();
219
208
}
220
209
0 commit comments