commands.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef GDBSTUB_COMMANDS_H
  2. #define GDBSTUB
  3. typedef void (*GdbCmdHandler)(GArray *params, void *user_ctx);
  4. typedef enum GDBThreadIdKind {
  5. GDB_ONE_THREAD = 0,
  6. GDB_ALL_THREADS, /* One process, all threads */
  7. GDB_ALL_PROCESSES,
  8. GDB_READ_THREAD_ERR
  9. } GDBThreadIdKind;
  10. typedef union GdbCmdVariant {
  11. const char *data;
  12. uint8_t opcode;
  13. unsigned long val_ul;
  14. unsigned long long val_ull;
  15. struct {
  16. GDBThreadIdKind kind;
  17. uint32_t pid;
  18. uint32_t tid;
  19. } thread_id;
  20. } GdbCmdVariant;
  21. #define gdb_get_cmd_param(p, i) (&g_array_index(p, GdbCmdVariant, i))
  22. /**
  23. * typedef GdbCmdParseEntry - gdb command parser
  24. *
  25. * This structure keeps the information necessary to match a gdb command,
  26. * parse it (extract its parameters), and select the correct handler for it.
  27. *
  28. * @cmd: The command to be matched
  29. * @cmd_startswith: If true, @cmd is compared using startswith
  30. * @schema: Each schema for the command parameter entry consists of 2 chars,
  31. * the first char represents the parameter type handling the second char
  32. * represents the delimiter for the next parameter.
  33. *
  34. * Currently supported schema types:
  35. * 'l' -> unsigned long (stored in .val_ul)
  36. * 'L' -> unsigned long long (stored in .val_ull)
  37. * 's' -> string (stored in .data)
  38. * 'o' -> single char (stored in .opcode)
  39. * 't' -> thread id (stored in .thread_id)
  40. * '?' -> skip according to delimiter
  41. *
  42. * Currently supported delimiters:
  43. * '?' -> Stop at any delimiter (",;:=\0")
  44. * '0' -> Stop at "\0"
  45. * '.' -> Skip 1 char unless reached "\0"
  46. * Any other value is treated as the delimiter value itself
  47. *
  48. * @allow_stop_reply: True iff the gdbstub can respond to this command with a
  49. * "stop reply" packet. The list of commands that accept such response is
  50. * defined at the GDB Remote Serial Protocol documentation. See:
  51. * https://sourceware.org/gdb/onlinedocs/gdb/Stop-Reply-Packets.html#Stop-Reply-Packets.
  52. *
  53. * @need_cpu_context: Pass current CPU context to command handler via user_ctx.
  54. */
  55. typedef struct GdbCmdParseEntry {
  56. GdbCmdHandler handler;
  57. const char *cmd;
  58. bool cmd_startswith;
  59. const char *schema;
  60. bool allow_stop_reply;
  61. bool need_cpu_context;
  62. } GdbCmdParseEntry;
  63. /**
  64. * gdb_put_packet() - put string into gdb server's buffer so it is sent
  65. * to the client
  66. */
  67. int gdb_put_packet(const char *buf);
  68. /**
  69. * gdb_extend_query_table() - Extend query table.
  70. * @table: GPtrArray of GdbCmdParseEntry entries.
  71. *
  72. * The caller should free @table afterwards
  73. */
  74. void gdb_extend_query_table(GPtrArray *table);
  75. /**
  76. * gdb_extend_set_table() - Extend set table.
  77. * @table: GPtrArray of GdbCmdParseEntry entries.
  78. *
  79. * The caller should free @table afterwards
  80. */
  81. void gdb_extend_set_table(GPtrArray *table);
  82. /**
  83. * gdb_extend_qsupported_features() - Extend the qSupported features string.
  84. * @qsupported_features: The additional qSupported feature(s) string. The string
  85. * should start with a semicolon and, if there are more than one feature, the
  86. * features should be separate by a semicolon.
  87. *
  88. * The caller should free @qsupported_features afterwards if
  89. * dynamically allocated.
  90. */
  91. void gdb_extend_qsupported_features(char *qsupported_features);
  92. /**
  93. * Convert a hex string to bytes. Conversion is done per byte, so 2 hex digits
  94. * are converted to 1 byte. Invalid hex digits are treated as 0 digits.
  95. */
  96. void gdb_hextomem(GByteArray *mem, const char *buf, int len);
  97. #endif /* GDBSTUB_COMMANDS_H */