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