Skip to content

Commit a0d6b01

Browse files
committed
Add gdb stub library
1 parent b135070 commit a0d6b01

File tree

6 files changed

+427
-4
lines changed

6 files changed

+427
-4
lines changed

hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_main.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,12 @@ static void do_global_ctors(void) {
129129
(*p)();
130130
}
131131

132+
extern "C" void __gdb_init() {}
133+
extern "C" void gdb_init(void) __attribute__ ((weak, alias("__gdb_init")));
134+
132135
void init_done() {
133136
system_set_os_print(1);
137+
gdb_init();
134138
do_global_ctors();
135139
esp_schedule();
136140
}

hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_postmortem.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extern void __real_system_restart_local();
3131
extern cont_t g_cont;
3232

3333

34-
static void uart_write_char_d(char c);
34+
void uart_write_char_d(char c);
3535
static void uart0_write_char_d(char c);
3636
static void uart1_write_char_d(char c);
3737
static void print_stack(uint32_t start, uint32_t end);
@@ -133,16 +133,16 @@ void uart_write_char_d(char c) {
133133
uart1_write_char_d(c);
134134
}
135135

136-
void uart0_write_char_d(char c) {
137-
while (((USS(0) >> USTXC) & 0xff) >= 0x7e) { }
136+
static void uart0_write_char_d(char c) {
137+
while (((USS(0) >> USTXC) & 0xff)) { }
138138

139139
if (c == '\n') {
140140
USF(0) = '\r';
141141
}
142142
USF(0) = c;
143143
}
144144

145-
void uart1_write_char_d(char c) {
145+
static void uart1_write_char_d(char c) {
146146
while (((USS(1) >> USTXC) & 0xff) >= 0x7e) { }
147147

148148
if (c == '\n') {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## Using GDB stub
2+
3+
- Add `#include <GDBStub.h>` to the sketch
4+
- Upload the sketch
5+
- Redirect serial port to TCP port:
6+
```
7+
tcp_serial_redirect.py -p /dev/tty.SLAB_USBtoUART -b 115200 --spy -P 9980 --rts=0 --dtr=0
8+
```
9+
Change port and baud rate as necessary. This command requires python and pyserial.
10+
- Observe serial output:
11+
```
12+
nc localhost 9980
13+
```
14+
- When crash happens, `Trap %d: pc=%p va=%p` line will appear in serial output.
15+
- Close nc and start gdb:
16+
```
17+
xtensa-lx106-elf-gdb /path/to/Sketch.cpp.elf -ex "target remote :9980"
18+
```
19+
- Use gdb to inspect program state at the point of an exception.
20+
21+
## Tips and tricks
22+
23+
- To halt the target when software WDT fires, add
24+
```
25+
((int*)0) = 0;
26+
```
27+
at the top of `__wrap_system_restart_local` in core_esp8266_postmortem.c.
28+
29+
## License
30+
31+
GDB Server stub by Marko Mikulicic was taken from Cesanta's smart.js
32+
33+
https://github.com/cesanta/smart.js
34+
35+
Copyright (c) 2013-2014 Cesanta Software Limited
36+
All rights reserved
37+
38+
This software is dual-licensed: you can redistribute it and/or modify
39+
it under the terms of the GNU General Public License version 2 as
40+
published by the Free Software Foundation. For the terms of this
41+
license, see <http://www.gnu.org/licenses>.
42+
43+
You are free to use this software under the terms of the GNU General
44+
Public License, but WITHOUT ANY WARRANTY; without even the implied
45+
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
46+
See the GNU General Public License for more details.
47+
48+
Alternatively, you can license this software under a commercial
49+
license, as set out in <https://www.cesanta.com/license>.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=GDBStub
2+
version=0.1
3+
author=Marko Mikulicic (Cesanta)
4+
maintainer=Ivan Grokhotkov <[email protected]>
5+
sentence=GDB server stub from Cesanta's Smart.js
6+
paragraph=GDB server stub helps debug crashes when JTAG isn't an option.
7+
category=Uncategorized
8+
url=https://github.com/cesanta/smart.js
9+
architectures=esp8266

0 commit comments

Comments
 (0)