xref: /openbmc/qemu/include/exec/gdbstub.h (revision 0cc14182)
1 #ifndef GDBSTUB_H
2 #define GDBSTUB_H
3 
4 #define DEFAULT_GDBSTUB_PORT "1234"
5 
6 /* GDB breakpoint/watchpoint types */
7 #define GDB_BREAKPOINT_SW        0
8 #define GDB_BREAKPOINT_HW        1
9 #define GDB_WATCHPOINT_WRITE     2
10 #define GDB_WATCHPOINT_READ      3
11 #define GDB_WATCHPOINT_ACCESS    4
12 
13 typedef struct GDBFeature {
14     const char *xmlname;
15     const char *xml;
16     const char *name;
17     const char * const *regs;
18     int num_regs;
19 } GDBFeature;
20 
21 typedef struct GDBFeatureBuilder {
22     GDBFeature *feature;
23     GPtrArray *xml;
24     GPtrArray *regs;
25     int base_reg;
26 } GDBFeatureBuilder;
27 
28 
29 /* Get or set a register.  Returns the size of the register.  */
30 typedef int (*gdb_get_reg_cb)(CPUState *cpu, GByteArray *buf, int reg);
31 typedef int (*gdb_set_reg_cb)(CPUState *cpu, uint8_t *buf, int reg);
32 
33 /**
34  * gdb_init_cpu(): Initialize the CPU for gdbstub.
35  * @cpu: The CPU to be initialized.
36  */
37 void gdb_init_cpu(CPUState *cpu);
38 
39 /**
40  * gdb_register_coprocessor() - register a supplemental set of registers
41  * @cpu - the CPU associated with registers
42  * @get_reg - get function (gdb reading)
43  * @set_reg - set function (gdb modifying)
44  * @num_regs - number of registers in set
45  * @xml - xml name of set
46  * @gpos - non-zero to append to "general" register set at @gpos
47  */
48 void gdb_register_coprocessor(CPUState *cpu,
49                               gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg,
50                               const GDBFeature *feature, int g_pos);
51 
52 /**
53  * gdbserver_start: start the gdb server
54  * @port_or_device: connection spec for gdb
55  *
56  * For CONFIG_USER this is either a tcp port or a path to a fifo. For
57  * system emulation you can use a full chardev spec for your gdbserver
58  * port.
59  */
60 int gdbserver_start(const char *port_or_device);
61 
62 /**
63  * gdb_feature_builder_init() - Initialize GDBFeatureBuilder.
64  * @builder: The builder to be initialized.
65  * @feature: The feature to be filled.
66  * @name: The name of the feature.
67  * @xmlname: The name of the XML.
68  * @base_reg: The base number of the register ID.
69  */
70 void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feature,
71                               const char *name, const char *xmlname,
72                               int base_reg);
73 
74 /**
75  * gdb_feature_builder_append_tag() - Append a tag.
76  * @builder: The builder.
77  * @format: The format of the tag.
78  * @...: The values to be formatted.
79  */
80 void G_GNUC_PRINTF(2, 3)
81 gdb_feature_builder_append_tag(const GDBFeatureBuilder *builder,
82                                const char *format, ...);
83 
84 /**
85  * gdb_feature_builder_append_reg() - Append a register.
86  * @builder: The builder.
87  * @name: The register's name; it must be unique within a CPU.
88  * @bitsize: The register's size, in bits.
89  * @regnum: The offset of the register's number in the feature.
90  * @type: The type of the register.
91  * @group: The register group to which this register belongs; it can be NULL.
92  */
93 void gdb_feature_builder_append_reg(const GDBFeatureBuilder *builder,
94                                     const char *name,
95                                     int bitsize,
96                                     int regnum,
97                                     const char *type,
98                                     const char *group);
99 
100 /**
101  * gdb_feature_builder_end() - End building GDBFeature.
102  * @builder: The builder.
103  */
104 void gdb_feature_builder_end(const GDBFeatureBuilder *builder);
105 
106 /**
107  * gdb_find_static_feature() - Find a static feature.
108  * @xmlname: The name of the XML.
109  *
110  * Return: The static feature.
111  */
112 const GDBFeature *gdb_find_static_feature(const char *xmlname);
113 
114 /**
115  * gdb_read_register() - Read a register associated with a CPU.
116  * @cpu: The CPU associated with the register.
117  * @buf: The buffer that the read register will be appended to.
118  * @reg: The register's number returned by gdb_find_feature_register().
119  *
120  * Return: The number of read bytes.
121  */
122 int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
123 
124 /**
125  * typedef GDBRegDesc - a register description from gdbstub
126  */
127 typedef struct {
128     int gdb_reg;
129     const char *name;
130     const char *feature_name;
131 } GDBRegDesc;
132 
133 /**
134  * gdb_get_register_list() - Return list of all registers for CPU
135  * @cpu: The CPU being searched
136  *
137  * Returns a GArray of GDBRegDesc, caller frees array but not the
138  * const strings.
139  */
140 GArray *gdb_get_register_list(CPUState *cpu);
141 
142 void gdb_set_stop_cpu(CPUState *cpu);
143 
144 /* in gdbstub-xml.c, generated by scripts/feature_to_c.py */
145 extern const GDBFeature gdb_static_features[];
146 
147 #endif
148