2016-09-21 03:38:12 +02:00
|
|
|
/*
|
|
|
|
* This module, when enabled with the LUA_USE_MODULES_GDBSTUB define causes
|
|
|
|
* the gdbstub code to be included and enabled to handle all fatal exceptions.
|
|
|
|
* This allows you to use the lx106 gdb to catch the exception and then poke
|
2019-02-17 19:26:29 +01:00
|
|
|
* around. You can continue from a break, but attempting to continue from an
|
|
|
|
* exception usually fails.
|
2016-09-21 03:38:12 +02:00
|
|
|
*
|
|
|
|
* This should not be included in production builds as any exception will
|
|
|
|
* put the nodemcu into a state where it is waiting for serial input and it has
|
|
|
|
* the watchdog disabled. Good for debugging. Bad for unattended operation!
|
|
|
|
*
|
|
|
|
* See the docs for more information.
|
|
|
|
*
|
|
|
|
* Philip Gladstone, N1DQ
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "lauxlib.h"
|
|
|
|
#include "platform.h"
|
2019-07-23 06:22:38 +02:00
|
|
|
#include <stdint.h>
|
2016-09-21 03:38:12 +02:00
|
|
|
#include "user_interface.h"
|
|
|
|
#include "../esp-gdbstub/gdbstub.h"
|
|
|
|
|
2020-04-27 02:13:38 +02:00
|
|
|
static int init_done = 0;
|
|
|
|
static int lgdbstub_open(lua_State *L);
|
|
|
|
|
|
|
|
// gdbstub.brk() init gdb if nec and execute a break instructiont to entry gdb
|
2016-09-21 03:38:12 +02:00
|
|
|
static int lgdbstub_break(lua_State *L) {
|
2020-04-27 02:13:38 +02:00
|
|
|
lgdbstub_open(L);
|
|
|
|
asm("break 0,0" ::);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// as for break but also redirect output to the debugger.
|
|
|
|
static int lgdbstub_pbreak(lua_State *L) {
|
|
|
|
lgdbstub_open(L);
|
|
|
|
gdbstub_redirect_output(1);
|
2016-09-21 03:38:12 +02:00
|
|
|
asm("break 0,0" ::);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// gdbstub.gdboutput(1) switches the output to gdb format so that gdb can display it
|
|
|
|
static int lgdbstub_gdboutput(lua_State *L) {
|
|
|
|
gdbstub_redirect_output(lua_toboolean(L, 1));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lgdbstub_open(lua_State *L) {
|
2020-04-27 02:13:38 +02:00
|
|
|
if (init_done)
|
|
|
|
return 0;
|
2016-09-21 03:38:12 +02:00
|
|
|
gdbstub_init();
|
2020-04-27 02:13:38 +02:00
|
|
|
init_done = 1;
|
2016-09-21 03:38:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module function map
|
2020-04-27 02:13:38 +02:00
|
|
|
LROT_BEGIN(gdbstub, NULL, 0)
|
2019-05-08 13:08:20 +02:00
|
|
|
LROT_FUNCENTRY( brk, lgdbstub_break )
|
2020-04-27 02:13:38 +02:00
|
|
|
LROT_FUNCENTRY( pbrk, lgdbstub_pbreak )
|
2019-05-08 13:08:20 +02:00
|
|
|
LROT_FUNCENTRY( gdboutput, lgdbstub_gdboutput )
|
|
|
|
LROT_FUNCENTRY( open, lgdbstub_open )
|
2020-04-27 02:13:38 +02:00
|
|
|
LROT_END(gdbstub, NULL, 0)
|
2016-09-21 03:38:12 +02:00
|
|
|
|
2019-05-08 13:08:20 +02:00
|
|
|
|
|
|
|
NODEMCU_MODULE(GDBSTUB, "gdbstub", gdbstub, NULL);
|