xref: /qemu/include/exec/gdbstub.h (revision 0e3aff9ec34059512d597eacfcf4d1b5d4570c50)
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 num_regs;
10 } GDBFeature;
11 
12 typedef struct GDBFeatureBuilder {
13     GDBFeature *feature;
14     GPtrArray *xml;
15     GPtrArray *regs;
16     int base_reg;
17 } GDBFeatureBuilder;
18 
19 
20 /* Get or set a register.  Returns the size of the register.  */
21 typedef int (*gdb_get_reg_cb)(CPUState *cpu, GByteArray *buf, int reg);
22 typedef int (*gdb_set_reg_cb)(CPUState *cpu, uint8_t *buf, int reg);
23 
24 /**
25  * gdb_init_cpu(): Initialize the CPU for gdbstub.
26  * @cpu: The CPU to be initialized.
27  */
28 void gdb_init_cpu(CPUState *cpu);
29 
30 /**
31  * gdb_register_coprocessor() - register a supplemental set of registers
32  * @cpu - the CPU associated with registers
33  * @get_reg - get function (gdb reading)
34  * @set_reg - set function (gdb modifying)
35  * @num_regs - number of registers in set
36  * @xml - xml name of set
37  * @gpos - non-zero to append to "general" register set at @gpos
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, int g_pos);
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  * The error handle should be either &error_fatal (for start-up) or
59  * &error_warn (for QMP/HMP initiated sessions).
60  *
61  * Returns true when server successfully started.
62  */
63 bool gdbserver_start(const char *port_or_device, Error **errp);
64 
65 /**
66  * gdb_feature_builder_init() - Initialize GDBFeatureBuilder.
67  * @builder: The builder to be initialized.
68  * @feature: The feature to be filled.
69  * @name: The name of the feature.
70  * @xmlname: The name of the XML.
71  * @base_reg: The base number of the register ID.
72  */
73 void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feature,
74                               const char *name, const char *xmlname,
75                               int base_reg);
76 
77 /**
78  * gdb_feature_builder_append_tag() - Append a tag.
79  * @builder: The builder.
80  * @format: The format of the tag.
81  * @...: The values to be formatted.
82  */
83 void G_GNUC_PRINTF(2, 3)
84 gdb_feature_builder_append_tag(const GDBFeatureBuilder *builder,
85                                const char *format, ...);
86 
87 /**
88  * gdb_feature_builder_append_reg() - Append a register.
89  * @builder: The builder.
90  * @name: The register's name; it must be unique within a CPU.
91  * @bitsize: The register's size, in bits.
92  * @regnum: The offset of the register's number in the feature.
93  * @type: The type of the register.
94  * @group: The register group to which this register belongs; it can be NULL.
95  */
96 void gdb_feature_builder_append_reg(const GDBFeatureBuilder *builder,
97                                     const char *name,
98                                     int bitsize,
99                                     int regnum,
100                                     const char *type,
101                                     const char *group);
102 
103 /**
104  * gdb_feature_builder_end() - End building GDBFeature.
105  * @builder: The builder.
106  */
107 void gdb_feature_builder_end(const GDBFeatureBuilder *builder);
108 
109 /**
110  * gdb_find_static_feature() - Find a static feature.
111  * @xmlname: The name of the XML.
112  *
113  * Return: The static feature.
114  */
115 const GDBFeature *gdb_find_static_feature(const char *xmlname);
116 
117 /**
118  * gdb_read_register() - Read a register associated with a CPU.
119  * @cpu: The CPU associated with the register.
120  * @buf: The buffer that the read register will be appended to.
121  * @reg: The register's number returned by gdb_find_feature_register().
122  *
123  * Return: The number of read bytes.
124  */
125 int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
126 
127 /**
128  * typedef GDBRegDesc - a register description from gdbstub
129  */
130 typedef struct {
131     int gdb_reg;
132     const char *name;
133     const char *feature_name;
134 } GDBRegDesc;
135 
136 /**
137  * gdb_get_register_list() - Return list of all registers for CPU
138  * @cpu: The CPU being searched
139  *
140  * Returns a GArray of GDBRegDesc, caller frees array but not the
141  * const strings.
142  */
143 GArray *gdb_get_register_list(CPUState *cpu);
144 
145 void gdb_set_stop_cpu(CPUState *cpu);
146 
147 /* in gdbstub-xml.c, generated by scripts/feature_to_c.py */
148 extern const GDBFeature gdb_static_features[];
149 
150 #endif /* GDBSTUB_H */
151