1133f202bSGustavo Romero #ifndef GDBSTUB_COMMANDS_H 2133f202bSGustavo Romero #define GDBSTUB 3133f202bSGustavo Romero 4133f202bSGustavo Romero typedef void (*GdbCmdHandler)(GArray *params, void *user_ctx); 5133f202bSGustavo Romero 6133f202bSGustavo Romero typedef enum GDBThreadIdKind { 7133f202bSGustavo Romero GDB_ONE_THREAD = 0, 8133f202bSGustavo Romero GDB_ALL_THREADS, /* One process, all threads */ 9133f202bSGustavo Romero GDB_ALL_PROCESSES, 10133f202bSGustavo Romero GDB_READ_THREAD_ERR 11133f202bSGustavo Romero } GDBThreadIdKind; 12133f202bSGustavo Romero 13133f202bSGustavo Romero typedef union GdbCmdVariant { 14133f202bSGustavo Romero const char *data; 15133f202bSGustavo Romero uint8_t opcode; 16133f202bSGustavo Romero unsigned long val_ul; 17133f202bSGustavo Romero unsigned long long val_ull; 18133f202bSGustavo Romero struct { 19133f202bSGustavo Romero GDBThreadIdKind kind; 20133f202bSGustavo Romero uint32_t pid; 21133f202bSGustavo Romero uint32_t tid; 22133f202bSGustavo Romero } thread_id; 23133f202bSGustavo Romero } GdbCmdVariant; 24133f202bSGustavo Romero 25133f202bSGustavo Romero #define gdb_get_cmd_param(p, i) (&g_array_index(p, GdbCmdVariant, i)) 26133f202bSGustavo Romero 27133f202bSGustavo Romero /** 28133f202bSGustavo Romero * typedef GdbCmdParseEntry - gdb command parser 29133f202bSGustavo Romero * 30133f202bSGustavo Romero * This structure keeps the information necessary to match a gdb command, 31133f202bSGustavo Romero * parse it (extract its parameters), and select the correct handler for it. 32133f202bSGustavo Romero * 33133f202bSGustavo Romero * @cmd: The command to be matched 34133f202bSGustavo Romero * @cmd_startswith: If true, @cmd is compared using startswith 35133f202bSGustavo Romero * @schema: Each schema for the command parameter entry consists of 2 chars, 36133f202bSGustavo Romero * the first char represents the parameter type handling the second char 37133f202bSGustavo Romero * represents the delimiter for the next parameter. 38133f202bSGustavo Romero * 39133f202bSGustavo Romero * Currently supported schema types: 40133f202bSGustavo Romero * 'l' -> unsigned long (stored in .val_ul) 41133f202bSGustavo Romero * 'L' -> unsigned long long (stored in .val_ull) 42133f202bSGustavo Romero * 's' -> string (stored in .data) 43133f202bSGustavo Romero * 'o' -> single char (stored in .opcode) 44133f202bSGustavo Romero * 't' -> thread id (stored in .thread_id) 45133f202bSGustavo Romero * '?' -> skip according to delimiter 46133f202bSGustavo Romero * 47133f202bSGustavo Romero * Currently supported delimiters: 48133f202bSGustavo Romero * '?' -> Stop at any delimiter (",;:=\0") 49133f202bSGustavo Romero * '0' -> Stop at "\0" 50133f202bSGustavo Romero * '.' -> Skip 1 char unless reached "\0" 51133f202bSGustavo Romero * Any other value is treated as the delimiter value itself 52133f202bSGustavo Romero * 53133f202bSGustavo Romero * @allow_stop_reply: True iff the gdbstub can respond to this command with a 54133f202bSGustavo Romero * "stop reply" packet. The list of commands that accept such response is 55133f202bSGustavo Romero * defined at the GDB Remote Serial Protocol documentation. See: 56133f202bSGustavo Romero * https://sourceware.org/gdb/onlinedocs/gdb/Stop-Reply-Packets.html#Stop-Reply-Packets. 57133f202bSGustavo Romero */ 58133f202bSGustavo Romero typedef struct GdbCmdParseEntry { 59133f202bSGustavo Romero GdbCmdHandler handler; 60133f202bSGustavo Romero const char *cmd; 61133f202bSGustavo Romero bool cmd_startswith; 62133f202bSGustavo Romero const char *schema; 63133f202bSGustavo Romero bool allow_stop_reply; 64133f202bSGustavo Romero } GdbCmdParseEntry; 65133f202bSGustavo Romero 66133f202bSGustavo Romero /** 67133f202bSGustavo Romero * gdb_put_packet() - put string into gdb server's buffer so it is sent 68133f202bSGustavo Romero * to the client 69133f202bSGustavo Romero */ 70133f202bSGustavo Romero int gdb_put_packet(const char *buf); 71133f202bSGustavo Romero 72*60f4ce8eSGustavo Romero /** 73*60f4ce8eSGustavo Romero * gdb_extend_query_table() - Extend query table. 74*60f4ce8eSGustavo Romero * @table: The table with the additional query packet handlers. 75*60f4ce8eSGustavo Romero * @size: The number of handlers to be added. 76*60f4ce8eSGustavo Romero */ 77*60f4ce8eSGustavo Romero void gdb_extend_query_table(GdbCmdParseEntry *table, int size); 78*60f4ce8eSGustavo Romero 79*60f4ce8eSGustavo Romero /** 80*60f4ce8eSGustavo Romero * gdb_extend_set_table() - Extend set table. 81*60f4ce8eSGustavo Romero * @table: The table with the additional set packet handlers. 82*60f4ce8eSGustavo Romero * @size: The number of handlers to be added. 83*60f4ce8eSGustavo Romero */ 84*60f4ce8eSGustavo Romero void gdb_extend_set_table(GdbCmdParseEntry *table, int size); 85*60f4ce8eSGustavo Romero 86*60f4ce8eSGustavo Romero /** 87*60f4ce8eSGustavo Romero * gdb_extend_qsupported_features() - Extend the qSupported features string. 88*60f4ce8eSGustavo Romero * @qsupported_features: The additional qSupported feature(s) string. The string 89*60f4ce8eSGustavo Romero * should start with a semicolon and, if there are more than one feature, the 90*60f4ce8eSGustavo Romero * features should be separate by a semiocolon. 91*60f4ce8eSGustavo Romero */ 92*60f4ce8eSGustavo Romero void gdb_extend_qsupported_features(char *qsupported_features); 93*60f4ce8eSGustavo Romero 94133f202bSGustavo Romero #endif /* GDBSTUB_COMMANDS_H */ 95