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