gdbstub.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * This module, when enabled with the LUA_USE_MODULES_GDBSTUB define causes
  3. * the gdbstub code to be included and enabled to handle all fatal exceptions.
  4. * This allows you to use the lx106 gdb to catch the exception and then poke
  5. * around. You can't continue from an exception (at least not easily).
  6. *
  7. * This should not be included in production builds as any exception will
  8. * put the nodemcu into a state where it is waiting for serial input and it has
  9. * the watchdog disabled. Good for debugging. Bad for unattended operation!
  10. *
  11. * See the docs for more information.
  12. *
  13. * Philip Gladstone, N1DQ
  14. */
  15. #include "module.h"
  16. #include "lauxlib.h"
  17. #include "platform.h"
  18. #include "c_types.h"
  19. #include "user_interface.h"
  20. #include "../esp-gdbstub/gdbstub.h"
  21. // gdbstub.brk() just executes a break instruction. Enters gdb
  22. static int lgdbstub_break(lua_State *L) {
  23. asm("break 0,0" ::);
  24. return 0;
  25. }
  26. // gdbstub.gdboutput(1) switches the output to gdb format so that gdb can display it
  27. static int lgdbstub_gdboutput(lua_State *L) {
  28. gdbstub_redirect_output(lua_toboolean(L, 1));
  29. return 0;
  30. }
  31. static int lgdbstub_open(lua_State *L) {
  32. gdbstub_init();
  33. return 0;
  34. }
  35. // Module function map
  36. static const LUA_REG_TYPE gdbstub_map[] = {
  37. { LSTRKEY( "brk" ), LFUNCVAL( lgdbstub_break ) },
  38. { LSTRKEY( "gdboutput" ), LFUNCVAL( lgdbstub_gdboutput) },
  39. { LNILKEY, LNILVAL }
  40. };
  41. NODEMCU_MODULE(GDBSTUB, "gdbstub", gdbstub_map, lgdbstub_open);