]> git.proxmox.com Git - mirror_qemu.git/blame - include/exec/gdbstub.h
Fix virtio-net-pci* "vectors" compat
[mirror_qemu.git] / include / exec / gdbstub.h
CommitLineData
1fddef4b
FB
1#ifndef GDBSTUB_H
2#define GDBSTUB_H
3
cfc3475a 4#define DEFAULT_GDBSTUB_PORT "1234"
1fddef4b 5
e22a25c9
AL
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
1c14f162 13#ifdef NEED_CPU_H
33c11879
PB
14#include "cpu.h"
15
9e0c5422 16typedef void (*gdb_syscall_complete_cb)(CPUState *cpu,
a2d1ebaf
PB
17 target_ulong ret, target_ulong err);
18
19239b39
PM
19/**
20 * gdb_do_syscall:
21 * @cb: function to call when the system call has completed
22 * @fmt: gdb syscall format string
23 * ...: list of arguments to interpolate into @fmt
24 *
25 * Send a GDB syscall request. This function will return immediately;
26 * the callback function will be called later when the remote system
27 * call has completed.
28 *
29 * @fmt should be in the 'call-id,parameter,parameter...' format documented
30 * for the F request packet in the GDB remote protocol. A limited set of
31 * printf-style format specifiers is supported:
32 * %x - target_ulong argument printed in hex
33 * %lx - 64-bit argument printed in hex
34 * %s - string pointer (target_ulong) and length (int) pair
35 */
7ccfb2eb 36void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...);
19239b39
PM
37/**
38 * gdb_do_syscallv:
39 * @cb: function to call when the system call has completed
40 * @fmt: gdb syscall format string
41 * @va: arguments to interpolate into @fmt
42 *
43 * As gdb_do_syscall, but taking a va_list rather than a variable
44 * argument list.
45 */
46void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va);
a2d1ebaf 47int use_gdb_syscalls(void);
64f6b346 48void gdb_set_stop_cpu(CPUState *cpu);
5ef0317f
AB
49
50/**
51 * gdb_exit: exit gdb session, reporting inferior status
52 * @code: exit code reported
53 *
54 * This closes the session and sends a final packet to GDB reporting
55 * the exit status of the program. It also cleans up any connections
56 * detritus before returning.
57 */
58void gdb_exit(int code);
59
1fddef4b 60#ifdef CONFIG_USER_ONLY
4f710866
PM
61/**
62 * gdb_handlesig: yield control to gdb
63 * @cpu: CPU
64 * @sig: if non-zero, the signal number which caused us to stop
65 *
66 * This function yields control to gdb, when a user-mode-only target
67 * needs to stop execution. If @sig is non-zero, then we will send a
68 * stop packet to tell gdb that we have stopped because of this signal.
69 *
70 * This function will block (handling protocol requests from gdb)
71 * until gdb tells us to continue target execution. When it does
72 * return, the return value is a signal to deliver to the target,
73 * or 0 if no signal should be delivered, ie the signal that caused
74 * us to stop should be ignored.
75 */
db6b81d4 76int gdb_handlesig(CPUState *, int);
9349b4f9 77void gdb_signalled(CPUArchState *, int);
f7ec7f7b 78void gdbserver_fork(CPUState *);
4046d913 79#endif
56aebc89 80/* Get or set a register. Returns the size of the register. */
a010bdbe
AB
81typedef int (*gdb_get_reg_cb)(CPUArchState *env, GByteArray *buf, int reg);
82typedef int (*gdb_set_reg_cb)(CPUArchState *env, uint8_t *buf, int reg);
22169d41 83void gdb_register_coprocessor(CPUState *cpu,
a010bdbe 84 gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg,
56aebc89 85 int num_regs, const char *xml, int g_pos);
1fddef4b 86
a010bdbe
AB
87/*
88 * The GDB remote protocol transfers values in target byte order. As
89 * the gdbstub may be batching up several register values we always
90 * append to the array.
986a2998
AF
91 */
92
a010bdbe 93static inline int gdb_get_reg8(GByteArray *buf, uint8_t val)
986a2998 94{
a010bdbe 95 g_byte_array_append(buf, &val, 1);
986a2998
AF
96 return 1;
97}
98
a010bdbe 99static inline int gdb_get_reg16(GByteArray *buf, uint16_t val)
986a2998 100{
a010bdbe
AB
101 uint16_t to_word = tswap16(val);
102 g_byte_array_append(buf, (uint8_t *) &to_word, 2);
986a2998
AF
103 return 2;
104}
105
a010bdbe 106static inline int gdb_get_reg32(GByteArray *buf, uint32_t val)
986a2998 107{
a010bdbe
AB
108 uint32_t to_long = tswap32(val);
109 g_byte_array_append(buf, (uint8_t *) &to_long, 4);
986a2998
AF
110 return 4;
111}
112
a010bdbe 113static inline int gdb_get_reg64(GByteArray *buf, uint64_t val)
986a2998 114{
a010bdbe
AB
115 uint64_t to_quad = tswap64(val);
116 g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
986a2998
AF
117 return 8;
118}
119
a010bdbe 120static inline int gdb_get_reg128(GByteArray *buf, uint64_t val_hi,
532cc1fb
AB
121 uint64_t val_lo)
122{
a010bdbe 123 uint64_t to_quad;
532cc1fb 124#ifdef TARGET_WORDS_BIGENDIAN
a010bdbe
AB
125 to_quad = tswap64(val_hi);
126 g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
127 to_quad = tswap64(val_lo);
128 g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
532cc1fb 129#else
a010bdbe
AB
130 to_quad = tswap64(val_lo);
131 g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
132 to_quad = tswap64(val_hi);
133 g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
532cc1fb
AB
134#endif
135 return 16;
136}
137
7b8c1527
PMD
138static inline int gdb_get_zeroes(GByteArray *array, size_t len)
139{
140 guint oldlen = array->len;
141 g_byte_array_set_size(array, oldlen + len);
142 memset(array->data + oldlen, 0, len);
143
144 return len;
145}
146
a010bdbe
AB
147/**
148 * gdb_get_reg_ptr: get pointer to start of last element
149 * @len: length of element
150 *
151 * This is a helper function to extract the pointer to the last
152 * element for additional processing. Some front-ends do additional
153 * dynamic swapping of the elements based on CPU state.
154 */
155static inline uint8_t * gdb_get_reg_ptr(GByteArray *buf, int len)
156{
157 return buf->data + buf->len - len;
158}
159
986a2998
AF
160#if TARGET_LONG_BITS == 64
161#define gdb_get_regl(buf, val) gdb_get_reg64(buf, val)
162#define ldtul_p(addr) ldq_p(addr)
163#else
164#define gdb_get_regl(buf, val) gdb_get_reg32(buf, val)
165#define ldtul_p(addr) ldl_p(addr)
166#endif
167
1fddef4b 168#endif
1c14f162 169
fcedd920
AB
170/**
171 * gdbserver_start: start the gdb server
172 * @port_or_device: connection spec for gdb
173 *
174 * For CONFIG_USER this is either a tcp port or a path to a fifo. For
175 * system emulation you can use a full chardev spec for your gdbserver
176 * port.
177 */
178int gdbserver_start(const char *port_or_device);
1c14f162 179
5b50e790
AF
180/**
181 * gdb_has_xml:
182 * This is an ugly hack to cope with both new and old gdb.
183 * If gdb sends qXfer:features:read then assume we're talking to a newish
184 * gdb that understands target descriptions.
185 */
186extern bool gdb_has_xml;
187
4c3b5a48 188/* in gdbstub-xml.c, generated by scripts/feature_to_c.sh */
0b65b9e1
BS
189extern const char *const xml_builtin[][2];
190
1c14f162 191#endif