Skip to content

Commit

Permalink
esp8266: add exception handler to print stack dump
Browse files Browse the repository at this point in the history
  • Loading branch information
tve committed Apr 17, 2016
1 parent 23d8b78 commit 30aae54
Show file tree
Hide file tree
Showing 8 changed files with 687 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Makefile
Expand Up @@ -675,7 +675,7 @@ endif
ifdef DEBUG
#OPTIMIZEFLAGS=-Os -g
ifeq ($(FAMILY),ESP8266)
OPTIMIZEFLAGS=-g -Os
OPTIMIZEFLAGS=-g -Os -std=gnu11 -fgnu89-inline -Wl,--allow-multiple-definition
else
OPTIMIZEFLAGS=-g
endif
Expand Down Expand Up @@ -1597,6 +1597,8 @@ SOURCES += targets/esp8266/uart.c \
targets/esp8266/jshardware.c \
targets/esp8266/i2c_master.c \
targets/esp8266/esp8266_board_utils.c \
targets/esp8266/gdbstub.c \
targets/esp8266/gdbstub-entry.S \
libs/network/esp8266/network_esp8266.c

# The tool used for building the firmware and flashing
Expand Down
61 changes: 61 additions & 0 deletions targets/esp8266/gdbstub-cfg.h
@@ -0,0 +1,61 @@
#ifndef GDBSTUB_CFG_H
#define GDBSTUB_CFG_H

/*
Enable this define if you're using the RTOS SDK. It will use a custom exception handler instead of the HAL
and do some other magic to make everything work and compile under FreeRTOS.
*/
#ifndef GDBSTUB_FREERTOS
#define GDBSTUB_FREERTOS 0
#endif

/*
Enable this to make the exception and debugging handlers switch to a private stack. This will use
up 1K of RAM, but may be useful if you're debugging stack or stack pointer corruption problems. It's
normally disabled because not many situations need it. If for some reason the GDB communication
stops when you run into an error in your code, try enabling this.
*/
#ifndef GDBSTUB_USE_OWN_STACK
#define GDBSTUB_USE_OWN_STACK 0
#endif

/*
If this is defined, gdbstub will break the program when you press Ctrl-C in gdb. it does this by
hooking the UART interrupt. Unfortunately, this means receiving stuff over the serial port won't
work for your program anymore. This will fail if your program sets an UART interrupt handler after
the gdbstub_init call.
*/
#ifndef GDBSTUB_CTRLC_BREAK
#define GDBSTUB_CTRLC_BREAK 0
#endif

/*
Enabling this will redirect console output to GDB. This basically means that printf/os_printf output
will show up in your gdb session, which is useful if you use gdb to do stuff. It also means that if
you use a normal terminal, you can't read the printfs anymore.
*/
#ifndef GDBSTUB_REDIRECT_CONSOLE_OUTPUT
#define GDBSTUB_REDIRECT_CONSOLE_OUTPUT 0
#endif

/*
Enable this if you want the GDB stub to wait for you to attach GDB before running. It does this by
breaking in the init routine; use the gdb 'c' command (continue) to start the program.
*/
#ifndef GDBSTUB_BREAK_ON_INIT
#define GDBSTUB_BREAK_ON_INIT 0
#endif

/*
Function attributes for function types.
Gdbstub functions are placed in flash or IRAM using attributes, as defined here. The gdbinit function
(and related) can always be in flash, because it's called in the normal code flow. The rest of the
gdbstub functions can be in flash too, but only if there's no chance of them being called when the
flash somehow is disabled (eg during SPI operations or flash write/erase operations). If the routines
are called when the flash is disabled (eg due to a Ctrl-C at the wrong time), the ESP8266 will most
likely crash.
*/
#define ATTR_GDBINIT ICACHE_FLASH_ATTR
#define ATTR_GDBFN

#endif

0 comments on commit 30aae54

Please sign in to comment.