xref: /openbmc/qemu/include/gdbstub/commands.h (revision e8122a71)
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.
572be4d5dbSGustavo Romero  *
582be4d5dbSGustavo Romero  * @need_cpu_context: Pass current CPU context to command handler via user_ctx.
59133f202bSGustavo Romero  */
60133f202bSGustavo Romero typedef struct GdbCmdParseEntry {
61133f202bSGustavo Romero     GdbCmdHandler handler;
62133f202bSGustavo Romero     const char *cmd;
63133f202bSGustavo Romero     bool cmd_startswith;
64133f202bSGustavo Romero     const char *schema;
65133f202bSGustavo Romero     bool allow_stop_reply;
662be4d5dbSGustavo Romero     bool need_cpu_context;
67133f202bSGustavo Romero } GdbCmdParseEntry;
68133f202bSGustavo Romero 
69133f202bSGustavo Romero /**
70133f202bSGustavo Romero  * gdb_put_packet() - put string into gdb server's buffer so it is sent
71133f202bSGustavo Romero  * to the client
72133f202bSGustavo Romero  */
73133f202bSGustavo Romero int gdb_put_packet(const char *buf);
74133f202bSGustavo Romero 
7560f4ce8eSGustavo Romero /**
7660f4ce8eSGustavo Romero  * gdb_extend_query_table() - Extend query table.
77*e8122a71SAlex Bennée  * @table: GPtrArray of GdbCmdParseEntry entries.
78*e8122a71SAlex Bennée  *
79*e8122a71SAlex Bennée  * The caller should free @table afterwards
8060f4ce8eSGustavo Romero  */
81*e8122a71SAlex Bennée void gdb_extend_query_table(GPtrArray *table);
8260f4ce8eSGustavo Romero 
8360f4ce8eSGustavo Romero /**
8460f4ce8eSGustavo Romero  * gdb_extend_set_table() - Extend set table.
85*e8122a71SAlex Bennée  * @table: GPtrArray of GdbCmdParseEntry entries.
86*e8122a71SAlex Bennée  *
87*e8122a71SAlex Bennée  * The caller should free @table afterwards
8860f4ce8eSGustavo Romero  */
89*e8122a71SAlex Bennée void gdb_extend_set_table(GPtrArray *table);
9060f4ce8eSGustavo Romero 
9160f4ce8eSGustavo Romero /**
9260f4ce8eSGustavo Romero  * gdb_extend_qsupported_features() - Extend the qSupported features string.
9360f4ce8eSGustavo Romero  * @qsupported_features: The additional qSupported feature(s) string. The string
9460f4ce8eSGustavo Romero  * should start with a semicolon and, if there are more than one feature, the
95*e8122a71SAlex Bennée  * features should be separate by a semicolon.
96*e8122a71SAlex Bennée  *
97*e8122a71SAlex Bennée  * The caller should free @qsupported_features afterwards if
98*e8122a71SAlex Bennée  * dynamically allocated.
9960f4ce8eSGustavo Romero  */
10060f4ce8eSGustavo Romero void gdb_extend_qsupported_features(char *qsupported_features);
10160f4ce8eSGustavo Romero 
1023ce0fc57SGustavo Romero /**
1033ce0fc57SGustavo Romero  * Convert a hex string to bytes. Conversion is done per byte, so 2 hex digits
1043ce0fc57SGustavo Romero  * are converted to 1 byte. Invalid hex digits are treated as 0 digits.
1053ce0fc57SGustavo Romero  */
1063ce0fc57SGustavo Romero void gdb_hextomem(GByteArray *mem, const char *buf, int len);
1073ce0fc57SGustavo Romero 
108133f202bSGustavo Romero #endif /* GDBSTUB_COMMANDS_H */
109