xref: /qemu/include/gdbstub/commands.h (revision 133f202b)
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 #endif /* GDBSTUB_COMMANDS_H */
73