Skip to content

Commit 8f2ce1e

Browse files
committed
Update GDBStub library with the source of esp-gdbstub
1 parent 119ddca commit 8f2ce1e

File tree

14 files changed

+2103
-380
lines changed

14 files changed

+2103
-380
lines changed

libraries/GDBStub/License

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
ESPRESSIF MIT License
2+
3+
Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
4+
5+
Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case, it is free of charge, to any person obtaining a copy of this software and associated documentation files (the ��Software��), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED ��AS IS��, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10+
11+
12+
���� MIT ����֤
13+
14+
��Ȩ (c) 2015 <������Ϣ�Ƽ����Ϻ������޹�˾>
15+
16+
������֤��Ȩ������������Ϣ�Ƽ� ESP8266 ��Ʒ��Ӧ�ÿ������ڴ�����£�������֤�����Ȩ�κλ�ø�������������ĵ���ͳ��Ϊ�������������������Ƶؾ�Ӫ�����������������Ƶ�ʹ�á����ơ��޸ġ��ϲ������淢�С�ɢ��������Ȩ������������������������Ȩ��������Ȩ����������ЩȨ����ͬʱ������������������
17+
18+
�����������������и����ж�����������ϵİ�Ȩ��������Ȩ������
19+
20+
�������������������ṩ��û���κ���ȷ�򰵺��ĵ������������������ڹ��������ԡ��ʺ�ijһ�ض���;�ͷ���Ȩ�ı�֤�����ߺͰ�Ȩ���������κ�����¾�����������������ʹ��������Ժ�ͬ��ʽ��������Ȩ��������ʽ������κ����⡢�𺦻��������θ���
21+
22+
23+
24+

libraries/GDBStub/README-lib.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
GDBSTUB
3+
=======
4+
5+
Intro
6+
-----
7+
8+
While the ESP8266 supports the standard Gnu set of C programming utilities, for now the choice of debuggers
9+
has been limited: there is an attempt at [OpenOCD support](https://github.com/projectgus/openocd), but at
10+
the time of writing, it doesn't support hardware watchpoints and breakpoints yet, and it needs a separate
11+
JTAG adapter connecting to the ESP8266s JTAG pins. As an alternative, [Cesanta](https://www.cesanta.com/)
12+
has implemented a barebones[GDB stub](https://blog.cesanta.com/esp8266-gdb) in their Smart.js solution -
13+
unfortunately, this only supports exception catching and needs some work before you can use it outside of
14+
the Smart.js platform. Moreover, it also does not work with FreeRTOS.
15+
16+
For internal use, we at Espressif desired a GDB stub that works with FreeRTOS and is a bit more capable,
17+
so we designed our own implementation of it. This stub works both under FreeRTOS as well as the OS-less
18+
SDK and is able to catch exceptions and do backtraces on them, read and write memory, forward [os_]printf
19+
statements to gdb, single-step instructions and set hardware break- and watchpoints. It connects to the
20+
host machine (which runs gdb) using the standard serial connection that's also used for programming.
21+
22+
In order to be useful the gdbstub has to be used in conjunction with an xtensa-lx106-elf-gdb, for example
23+
as generated by the [esp-open-sdk](https://github.com/pfalcon/esp-open-sdk) project.
24+
25+
Usage
26+
-----
27+
* Grab the gdbstub project and put the files in a directory called 'gdbstub' in your project. You can do this
28+
either by checking out the Git repo, or adding the Git repo as a submodule to your project if it's already
29+
in Git.
30+
* Modify your Makefile. You'll need to include the gdbstub sources: if your Makefile is structured like the
31+
ones in the Espressif examples, you can add `gdbstub` to the `SUBDIRS` define and `gdbstub/libgdbstub.a` to the
32+
`COMPONENTS_eagle.app.v6` define. Also, you probably want to add `-ggdb` to your compiler flags (`TARGET_LDFLAGS`)
33+
and, if you are debugging, change any optimation flags (-Os, -O2 etc) into `-Og`. Finally, make sure your Makefile
34+
also compiles .S files.
35+
* Configure gdbstub by editting `gdbstub-cfg.h`. There are a bunch of options you can tweak: FreeRTOS or bare SDK,
36+
private exception/breakpoint stack, console redirection to GDB, wait till debugger attachment etc. You can also
37+
configure the options by including the proper -Dwhatever gcc flags in your Makefiles.
38+
* In your user_main.c, add an `#include <../gdbstub/gdbstub.h>` and call `gdbstub_init();` somewhere in user_main.
39+
* Compile and flash your board.
40+
* Run gdb, depending on your configuration immediately after resetting the board or after it has run into
41+
an exception. The easiest way to do it is to use the provided script: xtensa-lx106-elf-gdb -x gdbcmds -b 38400
42+
Change the '38400' into the baud rate your code uses. You may need to change the gdbcmds script to fit the
43+
configuration of your hardware and build environment.
44+
45+
Notes
46+
-----
47+
* Using software breakpoints ('br') only works on code that's in RAM. Code in flash can only have a hardware
48+
breakpoint ('hbr').
49+
* Due to hardware limitations, only one hardware breakpount and one hardware watchpoint are available.
50+
* Pressing control-C to interrupt the running program depends on gdbstub hooking the UART interrupt.
51+
If some code re-hooks this afterwards, gdbstub won't be able to receive characters. If gdbstub handles
52+
the interrupt, the user code will not receive any characters.
53+
* Continuing from an exception is not (yet) supported in FreeRTOS mode.
54+
* The WiFi hardware is designed to be serviced by software periodically. It has some buffers so it
55+
will behave OK when some data comes in while the processor is busy, but these buffers are not infinite.
56+
If the WiFi hardware receives lots of data while the debugger has stopped the CPU, it is bound
57+
to crash. This will happen mostly when working with UDP and/or ICMP; TCP-connections in general will
58+
not send much more data when the other side doesn't send any ACKs.
59+
60+
License
61+
-------
62+
This gdbstub is licensed under the Espressif MIT license, as described in the License file.
63+
64+
65+
Thanks
66+
------
67+
* Cesanta, for their initial ESP8266 exception handling only gdbstub,
68+
* jcmvbkbc, for providing an incompatible but interesting gdbstub for other Xtensa CPUs,
69+
* Sysprogs (makers of VisualGDB), for their suggestions and bugreports.

libraries/GDBStub/README.md

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ Change port and baud rate as necessary. This command requires python and pyseria
1111
```
1212
nc localhost 9980
1313
```
14-
- When crash happens, `Trap %d: pc=%p va=%p` line will appear in serial output.
15-
- Close nc and start gdb:
14+
- Once crash happens, close nc and start gdb:
1615
```
1716
xtensa-lx106-elf-gdb /path/to/Sketch.cpp.elf -ex "target remote :9980"
1817
```
18+
Or, using the provided gdbcmds file:
19+
```
20+
xtensa-lx106-elf-gdb /path/to/Sketch.cpp.elf -x gdbcmds
21+
```
1922
- Use gdb to inspect program state at the point of an exception.
2023

2124
## Tips and tricks
@@ -28,22 +31,4 @@ at the top of `__wrap_system_restart_local` in core_esp8266_postmortem.c.
2831

2932
## License
3033

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>.
34+
Espressif MIT License. See License file.

libraries/GDBStub/gdbcmds

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set remote hardware-breakpoint-limit 1
2+
set remote hardware-watchpoint-limit 1
3+
target remote :9980

libraries/GDBStub/library.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=GDBStub
2-
version=0.1
3-
author=Marko Mikulicic (Cesanta)
2+
version=0.2
3+
author=Jeroen Domburg
44
maintainer=Ivan Grokhotkov <ivan@esp8266.com>
5-
sentence=GDB server stub from Cesanta's Smart.js
5+
sentence=GDB server stub by Espressif
66
paragraph=GDB server stub helps debug crashes when JTAG isn't an option.
77
category=Uncategorized
8-
url=https://github.com/cesanta/smart.js
8+
url=https://github.com/espressif/esp-gdbstub
99
architectures=esp8266

0 commit comments

Comments
 (0)