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 */
77 typedef void (*gdb_syscall_complete_cb
)(CPUState
*cpu
, uint64_t ret
, int err
);
81 * @cb: function to call when the system call has completed
82 * @fmt: gdb syscall format string
83 * ...: list of arguments to interpolate into @fmt
85 * Send a GDB syscall request. This function will return immediately;
86 * the callback function will be called later when the remote system
89 * @fmt should be in the 'call-id,parameter,parameter...' format documented
90 * for the F request packet in the GDB remote protocol. A limited set of
91 * printf-style format specifiers is supported:
92 * %x - target_ulong argument printed in hex
93 * %lx - 64-bit argument printed in hex
94 * %s - string pointer (target_ulong) and length (int) pair
96 void gdb_do_syscall(gdb_syscall_complete_cb cb
, const char *fmt
, ...);
99 * @cb: function to call when the system call has completed
100 * @fmt: gdb syscall format string
101 * @va: arguments to interpolate into @fmt
103 * As gdb_do_syscall, but taking a va_list rather than a variable
106 void gdb_do_syscallv(gdb_syscall_complete_cb cb
, const char *fmt
, va_list va
);
107 int use_gdb_syscalls(void);
109 #ifdef CONFIG_USER_ONLY
111 * gdb_handlesig: yield control to gdb
113 * @sig: if non-zero, the signal number which caused us to stop
115 * This function yields control to gdb, when a user-mode-only target
116 * needs to stop execution. If @sig is non-zero, then we will send a
117 * stop packet to tell gdb that we have stopped because of this signal.
119 * This function will block (handling protocol requests from gdb)
120 * until gdb tells us to continue target execution. When it does
121 * return, the return value is a signal to deliver to the target,
122 * or 0 if no signal should be delivered, ie the signal that caused
123 * us to stop should be ignored.
125 int gdb_handlesig(CPUState
*, int);
126 void gdb_signalled(CPUArchState
*, int);
127 void gdbserver_fork(CPUState
*);
129 /* Get or set a register. Returns the size of the register. */
130 typedef int (*gdb_get_reg_cb
)(CPUArchState
*env
, GByteArray
*buf
, int reg
);
131 typedef int (*gdb_set_reg_cb
)(CPUArchState
*env
, uint8_t *buf
, int reg
);
132 void gdb_register_coprocessor(CPUState
*cpu
,
133 gdb_get_reg_cb get_reg
, gdb_set_reg_cb set_reg
,
134 int num_regs
, const char *xml
, int g_pos
);
137 * The GDB remote protocol transfers values in target byte order. As
138 * the gdbstub may be batching up several register values we always
139 * append to the array.
142 static inline int gdb_get_reg8(GByteArray
*buf
, uint8_t val
)
144 g_byte_array_append(buf
, &val
, 1);
148 static inline int gdb_get_reg16(GByteArray
*buf
, uint16_t val
)
150 uint16_t to_word
= tswap16(val
);
151 g_byte_array_append(buf
, (uint8_t *) &to_word
, 2);
155 static inline int gdb_get_reg32(GByteArray
*buf
, uint32_t val
)
157 uint32_t to_long
= tswap32(val
);
158 g_byte_array_append(buf
, (uint8_t *) &to_long
, 4);
162 static inline int gdb_get_reg64(GByteArray
*buf
, uint64_t val
)
164 uint64_t to_quad
= tswap64(val
);
165 g_byte_array_append(buf
, (uint8_t *) &to_quad
, 8);
169 static inline int gdb_get_reg128(GByteArray
*buf
, uint64_t val_hi
,
173 #if TARGET_BIG_ENDIAN
174 to_quad
= tswap64(val_hi
);
175 g_byte_array_append(buf
, (uint8_t *) &to_quad
, 8);
176 to_quad
= tswap64(val_lo
);
177 g_byte_array_append(buf
, (uint8_t *) &to_quad
, 8);
179 to_quad
= tswap64(val_lo
);
180 g_byte_array_append(buf
, (uint8_t *) &to_quad
, 8);
181 to_quad
= tswap64(val_hi
);
182 g_byte_array_append(buf
, (uint8_t *) &to_quad
, 8);
187 static inline int gdb_get_zeroes(GByteArray
*array
, size_t len
)
189 guint oldlen
= array
->len
;
190 g_byte_array_set_size(array
, oldlen
+ len
);
191 memset(array
->data
+ oldlen
, 0, len
);
197 * gdb_get_reg_ptr: get pointer to start of last element
198 * @len: length of element
200 * This is a helper function to extract the pointer to the last
201 * element for additional processing. Some front-ends do additional
202 * dynamic swapping of the elements based on CPU state.
204 static inline uint8_t * gdb_get_reg_ptr(GByteArray
*buf
, int len
)
206 return buf
->data
+ buf
->len
- len
;
209 #if TARGET_LONG_BITS == 64
210 #define gdb_get_regl(buf, val) gdb_get_reg64(buf, val)
211 #define ldtul_p(addr) ldq_p(addr)
213 #define gdb_get_regl(buf, val) gdb_get_reg32(buf, val)
214 #define ldtul_p(addr) ldl_p(addr)
217 #endif /* NEED_CPU_H */
220 * gdbserver_start: start the gdb server
221 * @port_or_device: connection spec for gdb
223 * For CONFIG_USER this is either a tcp port or a path to a fifo. For
224 * system emulation you can use a full chardev spec for your gdbserver
227 int gdbserver_start(const char *port_or_device
);
230 * gdb_exit: exit gdb session, reporting inferior status
231 * @code: exit code reported
233 * This closes the session and sends a final packet to GDB reporting
234 * the exit status of the program. It also cleans up any connections
235 * detritus before returning.
237 void gdb_exit(int code
);
239 void gdb_set_stop_cpu(CPUState
*cpu
);
243 * This is an ugly hack to cope with both new and old gdb.
244 * If gdb sends qXfer:features:read then assume we're talking to a newish
245 * gdb that understands target descriptions.
247 extern bool gdb_has_xml
;
249 /* in gdbstub-xml.c, generated by scripts/feature_to_c.sh */
250 extern const char *const xml_builtin
[][2];