__init__.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import re
  2. from serial.tools import miniterm
  3. from .console_parser import ConsoleParser
  4. from .constants import CMD_STOP, CTRL_T
  5. from .output_helpers import red_print
  6. try:
  7. import queue # noqa
  8. except ImportError:
  9. import Queue as queue # type: ignore # noqa
  10. # regex matches an potential PC value (0x4xxxxxxx)
  11. MATCH_PCADDR = re.compile(r'0x4[0-9a-f]{7}', re.IGNORECASE)
  12. DEFAULT_TOOLCHAIN_PREFIX = 'xtensa-esp32-elf-'
  13. DEFAULT_PRINT_FILTER = ''
  14. # coredump related messages
  15. COREDUMP_UART_START = b'================= CORE DUMP START ================='
  16. COREDUMP_UART_END = b'================= CORE DUMP END ================='
  17. COREDUMP_UART_PROMPT = b'Press Enter to print core dump to UART...'
  18. # coredump states
  19. COREDUMP_IDLE = 0
  20. COREDUMP_READING = 1
  21. COREDUMP_DONE = 2
  22. # coredump decoding options
  23. COREDUMP_DECODE_DISABLE = 'disable'
  24. COREDUMP_DECODE_INFO = 'info'
  25. # panic handler related messages
  26. PANIC_START = r'Core \s*\d+ register dump:'
  27. PANIC_END = b'ELF file SHA256:'
  28. PANIC_STACK_DUMP = b'Stack memory:'
  29. # panic handler decoding states
  30. PANIC_IDLE = 0
  31. PANIC_READING = 1
  32. # panic handler decoding options
  33. PANIC_DECODE_DISABLE = 'disable'
  34. PANIC_DECODE_BACKTRACE = 'backtrace'
  35. def prompt_next_action(reason, console, console_parser, event_queue, cmd_queue):
  36. # type: (str, miniterm.Console, ConsoleParser, queue.Queue, queue.Queue) -> None
  37. console.setup() # set up console to trap input characters
  38. try:
  39. red_print('--- {}'.format(reason))
  40. red_print(console_parser.get_next_action_text())
  41. k = CTRL_T # ignore CTRL-T here, so people can muscle-memory Ctrl-T Ctrl-F, etc.
  42. while k == CTRL_T:
  43. k = console.getkey()
  44. finally:
  45. console.cleanup()
  46. ret = console_parser.parse_next_action_key(k)
  47. if ret is not None:
  48. cmd = ret[1]
  49. if cmd == CMD_STOP:
  50. # the stop command should be handled last
  51. event_queue.put(ret)
  52. else:
  53. cmd_queue.put(ret)