4 #define DEFAULT_GDBSTUB_PORT "1234"
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
13 /* For gdb file i/o remote protocol open flags. */
14 #define GDB_O_RDONLY 0
15 #define GDB_O_WRONLY 1
17 #define GDB_O_APPEND 8
18 #define GDB_O_CREAT 0x200
19 #define GDB_O_TRUNC 0x400
20 #define GDB_O_EXCL 0x800
22 /* For gdb file i/o remote protocol errno values */
32 #define GDB_ENOTDIR 20
41 #define GDB_ENAMETOOLONG 91
42 #define GDB_EUNKNOWN 9999
44 /* For gdb file i/o remote protocol lseek whence. */
45 #define GDB_SEEK_SET 0
46 #define GDB_SEEK_CUR 1
47 #define GDB_SEEK_END 2
49 /* For gdb file i/o stat/fstat. */
50 typedef uint32_t gdb_mode_t
;
51 typedef uint32_t gdb_time_t
;
54 uint32_t gdb_st_dev
; /* device */
55 uint32_t gdb_st_ino
; /* inode */
56 gdb_mode_t gdb_st_mode
; /* protection */
57 uint32_t gdb_st_nlink
; /* number of hard links */
58 uint32_t gdb_st_uid
; /* user ID of owner */
59 uint32_t gdb_st_gid
; /* group ID of owner */
60 uint32_t gdb_st_rdev
; /* device type (if inode device) */
61 uint64_t gdb_st_size
; /* total size, in bytes */
62 uint64_t gdb_st_blksize
; /* blocksize for filesystem I/O */
63 uint64_t gdb_st_blocks
; /* number of blocks allocated */
64 gdb_time_t gdb_st_atime
; /* time of last access */
65 gdb_time_t gdb_st_mtime
; /* time of last modification */
66 gdb_time_t gdb_st_ctime
; /* time of last change */
70 gdb_time_t tv_sec
; /* second */
71 uint64_t tv_usec
; /* microsecond */
74 typedef void (*gdb_syscall_complete_cb
)(CPUState
*cpu
, uint64_t ret
, int err
);
78 * @cb: function to call when the system call has completed
79 * @fmt: gdb syscall format string
80 * ...: list of arguments to interpolate into @fmt
82 * Send a GDB syscall request. This function will return immediately;
83 * the callback function will be called later when the remote system
86 * @fmt should be in the 'call-id,parameter,parameter...' format documented
87 * for the F request packet in the GDB remote protocol. A limited set of
88 * printf-style format specifiers is supported:
89 * %x - target_ulong argument printed in hex
90 * %lx - 64-bit argument printed in hex
91 * %s - string pointer (target_ulong) and length (int) pair
93 void gdb_do_syscall(gdb_syscall_complete_cb cb
, const char *fmt
, ...);
96 * @cb: function to call when the system call has completed
97 * @fmt: gdb syscall format string
98 * @va: arguments to interpolate into @fmt
100 * As gdb_do_syscall, but taking a va_list rather than a variable
103 void gdb_do_syscallv(gdb_syscall_complete_cb cb
, const char *fmt
, va_list va
);
104 int use_gdb_syscalls(void);
106 /* Get or set a register. Returns the size of the register. */
107 typedef int (*gdb_get_reg_cb
)(CPUArchState
*env
, GByteArray
*buf
, int reg
);
108 typedef int (*gdb_set_reg_cb
)(CPUArchState
*env
, uint8_t *buf
, int reg
);
109 void gdb_register_coprocessor(CPUState
*cpu
,
110 gdb_get_reg_cb get_reg
, gdb_set_reg_cb set_reg
,
111 int num_regs
, const char *xml
, int g_pos
);
117 * The GDB remote protocol transfers values in target byte order. As
118 * the gdbstub may be batching up several register values we always
119 * append to the array.
122 static inline int gdb_get_reg8(GByteArray
*buf
, uint8_t val
)
124 g_byte_array_append(buf
, &val
, 1);
128 static inline int gdb_get_reg16(GByteArray
*buf
, uint16_t val
)
130 uint16_t to_word
= tswap16(val
);
131 g_byte_array_append(buf
, (uint8_t *) &to_word
, 2);
135 static inline int gdb_get_reg32(GByteArray
*buf
, uint32_t val
)
137 uint32_t to_long
= tswap32(val
);
138 g_byte_array_append(buf
, (uint8_t *) &to_long
, 4);
142 static inline int gdb_get_reg64(GByteArray
*buf
, uint64_t val
)
144 uint64_t to_quad
= tswap64(val
);
145 g_byte_array_append(buf
, (uint8_t *) &to_quad
, 8);
149 static inline int gdb_get_reg128(GByteArray
*buf
, uint64_t val_hi
,
153 #if TARGET_BIG_ENDIAN
154 to_quad
= tswap64(val_hi
);
155 g_byte_array_append(buf
, (uint8_t *) &to_quad
, 8);
156 to_quad
= tswap64(val_lo
);
157 g_byte_array_append(buf
, (uint8_t *) &to_quad
, 8);
159 to_quad
= tswap64(val_lo
);
160 g_byte_array_append(buf
, (uint8_t *) &to_quad
, 8);
161 to_quad
= tswap64(val_hi
);
162 g_byte_array_append(buf
, (uint8_t *) &to_quad
, 8);
167 static inline int gdb_get_zeroes(GByteArray
*array
, size_t len
)
169 guint oldlen
= array
->len
;
170 g_byte_array_set_size(array
, oldlen
+ len
);
171 memset(array
->data
+ oldlen
, 0, len
);
177 * gdb_get_reg_ptr: get pointer to start of last element
178 * @len: length of element
180 * This is a helper function to extract the pointer to the last
181 * element for additional processing. Some front-ends do additional
182 * dynamic swapping of the elements based on CPU state.
184 static inline uint8_t * gdb_get_reg_ptr(GByteArray
*buf
, int len
)
186 return buf
->data
+ buf
->len
- len
;
189 #if TARGET_LONG_BITS == 64
190 #define gdb_get_regl(buf, val) gdb_get_reg64(buf, val)
191 #define ldtul_p(addr) ldq_p(addr)
193 #define gdb_get_regl(buf, val) gdb_get_reg32(buf, val)
194 #define ldtul_p(addr) ldl_p(addr)
197 #endif /* NEED_CPU_H */
200 * gdbserver_start: start the gdb server
201 * @port_or_device: connection spec for gdb
203 * For CONFIG_USER this is either a tcp port or a path to a fifo. For
204 * system emulation you can use a full chardev spec for your gdbserver
207 int gdbserver_start(const char *port_or_device
);
210 * gdb_exit: exit gdb session, reporting inferior status
211 * @code: exit code reported
213 * This closes the session and sends a final packet to GDB reporting
214 * the exit status of the program. It also cleans up any connections
215 * detritus before returning.
217 void gdb_exit(int code
);
219 void gdb_set_stop_cpu(CPUState
*cpu
);
223 * This is an ugly hack to cope with both new and old gdb.
224 * If gdb sends qXfer:features:read then assume we're talking to a newish
225 * gdb that understands target descriptions.
227 extern bool gdb_has_xml
;
229 /* in gdbstub-xml.c, generated by scripts/feature_to_c.sh */
230 extern const char *const xml_builtin
[][2];