gdbstub.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 continue from a break, but attempting to continue from an
  6. * exception usually fails.
  7. *
  8. * This should not be included in production builds as any exception will
  9. * put the nodemcu into a state where it is waiting for serial input and it has
  10. * the watchdog disabled. Good for debugging. Bad for unattended operation!
  11. *
  12. * See the docs for more information.
  13. *
  14. * Philip Gladstone, N1DQ
  15. */
  16. #include "module.h"
  17. #include "lauxlib.h"
  18. #include "platform.h"
  19. #include "c_types.h"
  20. #include "user_interface.h"
  21. #include "../esp-gdbstub/gdbstub.h"
  22. // gdbstub.brk() just executes a break instruction. Enters gdb
  23. static int lgdbstub_break(lua_State *L) {
  24. asm("break 0,0" ::);
  25. return 0;
  26. }
  27. // gdbstub.gdboutput(1) switches the output to gdb format so that gdb can display it
  28. static int lgdbstub_gdboutput(lua_State *L) {
  29. gdbstub_redirect_output(lua_toboolean(L, 1));
  30. return 0;
  31. }
  32. static int lgdbstub_open(lua_State *L) {
  33. gdbstub_init();
  34. return 0;
  35. }
  36. // Module function map
  37. static const LUA_REG_TYPE gdbstub_map[] = {
  38. { LSTRKEY( "brk" ), LFUNCVAL( lgdbstub_break ) },
  39. { LSTRKEY( "gdboutput" ), LFUNCVAL( lgdbstub_gdboutput) },
  40. { LSTRKEY( "open" ), LFUNCVAL( lgdbstub_open) },
  41. { LNILKEY, LNILVAL }
  42. };
  43. NODEMCU_MODULE(GDBSTUB, "gdbstub", gdbstub_map, NULL);