master
h 161 lines 4.9 KB
Raw
1 #ifndef GDBSTUB_H
2 #define GDBSTUB_H
3
4 typedef struct GDBFeature {
5 const char *xmlname;
6 const char *xml;
7 const char *name;
8 const char * const *regs;
9 int base_reg;
10 int num_regs;
11 } GDBFeature;
12
13 typedef struct GDBFeatureBuilder {
14 GDBFeature *feature;
15 GPtrArray *xml;
16 GPtrArray *regs;
17 int base_reg;
18 } GDBFeatureBuilder;
19
20
21 /* Get or set a register. Returns the size of the register. */
22 typedef int (*gdb_get_reg_cb)(CPUState *cpu, GByteArray *buf, int reg);
23 typedef int (*gdb_set_reg_cb)(CPUState *cpu, uint8_t *buf, int reg);
24
25 /**
26 * gdb_init_cpu(): Initialize the CPU for gdbstub.
27 * @cpu: The CPU to be initialized.
28 */
29 void gdb_init_cpu(CPUState *cpu);
30
31 /**
32 * gdb_register_coprocessor() - register a supplemental set of registers
33 * @cpu - the CPU associated with registers
34 * @get_reg - get function (gdb reading)
35 * @set_reg - set function (gdb modifying)
36 * @num_regs - number of registers in set
37 * @xml - xml name of set
38 */
39 void gdb_register_coprocessor(CPUState *cpu,
40 gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg,
41 const GDBFeature *feature);
42
43 /**
44 * gdb_unregister_coprocessor_all() - unregisters supplemental set of registers
45 * @cpu - the CPU associated with registers
46 */
47 void gdb_unregister_coprocessor_all(CPUState *cpu);
48
49 /**
50 * gdbserver_start: start the gdb server
51 * @port_or_device: connection spec for gdb
52 * @errp: error handle
53 *
54 * For CONFIG_USER this is either a tcp port or a path to a fifo. For
55 * system emulation you can use a full chardev spec for your gdbserver
56 * port.
57 *
58 * Returns true when server successfully started.
59 */
60 bool gdbserver_start(const char *port_or_device, Error **errp);
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 * gdb_write_register() - Write a register associated with a CPU.
126 * @cpu: The CPU associated with the register.
127 * @buf: The buffer that the register contents will be set to.
128 * @reg: The register's number returned by gdb_find_feature_register().
129 *
130 * The size of @buf must be at least the size of the register being
131 * written.
132 *
133 * Return: The number of written bytes, or 0 if an error occurred (for
134 * example, an unknown register was provided).
135 */
136 int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg);
137
138 /**
139 * typedef GDBRegDesc - a register description from gdbstub
140 */
141 typedef struct {
142 int gdb_reg;
143 const char *name;
144 const char *feature_name;
145 } GDBRegDesc;
146
147 /**
148 * gdb_get_register_list() - Return list of all registers for CPU
149 * @cpu: The CPU being searched
150 *
151 * Returns a GArray of GDBRegDesc, caller frees array but not the
152 * const strings.
153 */
154 GArray *gdb_get_register_list(CPUState *cpu);
155
156 void gdb_set_stop_cpu(CPUState *cpu);
157
158 /* in gdbstub-xml.c, generated by scripts/feature_to_c.py */
159 extern const GDBFeature gdb_static_features[];
160
161 #endif /* GDBSTUB_H */