]> git.proxmox.com Git - mirror_qemu.git/blame - gdbstub/internals.h
target/hppa: Add BTLB support to hppa TLB functions
[mirror_qemu.git] / gdbstub / internals.h
CommitLineData
ae7467b1
AB
1/*
2 * gdbstub internals
3 *
4 * Copyright (c) 2022 Linaro Ltd
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
97748558
AB
9#ifndef GDBSTUB_INTERNALS_H
10#define GDBSTUB_INTERNALS_H
ae7467b1 11
55b5b8e9
PMD
12#include "exec/cpu-common.h"
13
9f56787c
AB
14#define MAX_PACKET_LENGTH 4096
15
16/*
17 * Shared structures and definitions
18 */
19
b6fa2ec2
AB
20enum {
21 GDB_SIGNAL_0 = 0,
22 GDB_SIGNAL_INT = 2,
23 GDB_SIGNAL_QUIT = 3,
24 GDB_SIGNAL_TRAP = 5,
25 GDB_SIGNAL_ABRT = 6,
26 GDB_SIGNAL_ALRM = 14,
27 GDB_SIGNAL_IO = 23,
28 GDB_SIGNAL_XCPU = 24,
29 GDB_SIGNAL_UNKNOWN = 143
30};
31
9f56787c
AB
32typedef struct GDBProcess {
33 uint32_t pid;
34 bool attached;
35
d0e5fa84 36 /* If gdb sends qXfer:features:read:target.xml this will be populated */
56e534bd 37 char *target_xml;
9f56787c
AB
38} GDBProcess;
39
40enum RSState {
41 RS_INACTIVE,
42 RS_IDLE,
43 RS_GETLINE,
44 RS_GETLINE_ESC,
45 RS_GETLINE_RLE,
46 RS_CHKSUM1,
47 RS_CHKSUM2,
48};
49
50typedef struct GDBState {
51 bool init; /* have we been initialised? */
52 CPUState *c_cpu; /* current CPU for step/continue ops */
53 CPUState *g_cpu; /* current CPU for other ops */
54 CPUState *query_cpu; /* for q{f|s}ThreadInfo */
55 enum RSState state; /* parsing state */
56 char line_buf[MAX_PACKET_LENGTH];
57 int line_buf_index;
58 int line_sum; /* running checksum */
59 int line_csum; /* checksum at the end of the packet */
60 GByteArray *last_packet;
61 int signal;
62 bool multiprocess;
63 GDBProcess *processes;
64 int process_num;
9f56787c
AB
65 GString *str_buf;
66 GByteArray *mem_buf;
67 int sstep_flags;
68 int supported_sstep_flags;
75837005
MTB
69 /*
70 * Whether we are allowed to send a stop reply packet at this moment.
71 * Must be set off after sending the stop reply itself.
72 */
73 bool allow_stop_reply;
9f56787c
AB
74} GDBState;
75
b6fa2ec2
AB
76/* lives in main gdbstub.c */
77extern GDBState gdbserver_state;
1678ea04
AB
78
79/*
80 * Inline utility function, convert from int to hex and back
81 */
82
83static inline int fromhex(int v)
84{
85 if (v >= '0' && v <= '9') {
86 return v - '0';
87 } else if (v >= 'A' && v <= 'F') {
88 return v - 'A' + 10;
89 } else if (v >= 'a' && v <= 'f') {
90 return v - 'a' + 10;
91 } else {
92 return 0;
93 }
94}
95
96static inline int tohex(int v)
97{
98 if (v < 10) {
99 return v + '0';
100 } else {
101 return v - 10 + 'a';
102 }
103}
104
36e067b2
AB
105/*
106 * Connection helpers for both softmmu and user backends
107 */
108
109void gdb_put_strbuf(void);
110int gdb_put_packet(const char *buf);
111int gdb_put_packet_binary(const char *buf, int len, bool dump);
112void gdb_hextomem(GByteArray *mem, const char *buf, int len);
113void gdb_memtohex(GString *buf, const uint8_t *mem, int len);
114void gdb_memtox(GString *buf, const char *mem, int len);
115void gdb_read_byte(uint8_t ch);
116
a7e0f9bd
AB
117/*
118 * Packet acknowledgement - we handle this slightly differently
119 * between user and softmmu mode, mainly to deal with the differences
120 * between the flexible chardev and the direct fd approaches.
121 *
122 * We currently don't support a negotiated QStartNoAckMode
123 */
124
125/**
126 * gdb_got_immediate_ack() - check ok to continue
127 *
128 * Returns true to continue, false to re-transmit for user only, the
129 * softmmu stub always returns true.
130 */
131bool gdb_got_immediate_ack(void);
36e067b2 132/* utility helpers */
a3fcc111
IL
133GDBProcess *gdb_get_process(uint32_t pid);
134CPUState *gdb_get_first_cpu_in_process(GDBProcess *process);
36e067b2
AB
135CPUState *gdb_first_attached_cpu(void);
136void gdb_append_thread_id(CPUState *cpu, GString *buf);
137int gdb_get_cpu_index(CPUState *cpu);
7ea0c33d 138unsigned int gdb_get_max_cpus(void); /* both */
505601d5 139bool gdb_can_reverse(void); /* softmmu, stub for user */
36e067b2 140
36e067b2
AB
141void gdb_create_default_process(GDBState *s);
142
d96bf49b
AB
143/* signal mapping, common for softmmu, specialised for user-mode */
144int gdb_signal_to_target(int sig);
145int gdb_target_signal_to_gdb(int sig);
146
147int gdb_get_char(void); /* user only */
148
149/**
150 * gdb_continue() - handle continue in mode specific way.
151 */
152void gdb_continue(void);
153
154/**
155 * gdb_continue_partial() - handle partial continue in mode specific way.
156 */
157int gdb_continue_partial(char *newstates);
158
36e067b2
AB
159/*
160 * Helpers with separate softmmu and user implementations
161 */
162void gdb_put_buffer(const uint8_t *buf, int len);
163
b6fa2ec2 164/*
8a2025b3 165 * Command handlers - either specialised or softmmu or user only
b6fa2ec2
AB
166 */
167void gdb_init_gdbserver_state(void);
168
169typedef enum GDBThreadIdKind {
170 GDB_ONE_THREAD = 0,
171 GDB_ALL_THREADS, /* One process, all threads */
172 GDB_ALL_PROCESSES,
173 GDB_READ_THREAD_ERR
174} GDBThreadIdKind;
175
176typedef union GdbCmdVariant {
177 const char *data;
178 uint8_t opcode;
179 unsigned long val_ul;
180 unsigned long long val_ull;
181 struct {
182 GDBThreadIdKind kind;
183 uint32_t pid;
184 uint32_t tid;
185 } thread_id;
186} GdbCmdVariant;
187
188#define get_param(p, i) (&g_array_index(p, GdbCmdVariant, i))
189
190void gdb_handle_query_rcmd(GArray *params, void *user_ctx); /* softmmu */
d96bf49b
AB
191void gdb_handle_query_offsets(GArray *params, void *user_ctx); /* user */
192void gdb_handle_query_xfer_auxv(GArray *params, void *user_ctx); /*user */
e282010b
IL
193void gdb_handle_v_file_open(GArray *params, void *user_ctx); /* user */
194void gdb_handle_v_file_close(GArray *params, void *user_ctx); /* user */
195void gdb_handle_v_file_pread(GArray *params, void *user_ctx); /* user */
196void gdb_handle_v_file_readlink(GArray *params, void *user_ctx); /* user */
197void gdb_handle_query_xfer_exec_file(GArray *params, void *user_ctx); /* user */
b6fa2ec2 198
8a2025b3
AB
199void gdb_handle_query_attached(GArray *params, void *user_ctx); /* both */
200
589a5867
AB
201/* softmmu only */
202void gdb_handle_query_qemu_phy_mem_mode(GArray *params, void *user_ctx);
203void gdb_handle_set_qemu_phy_mem_mode(GArray *params, void *user_ctx);
204
c566080c
AB
205/* sycall handling */
206void gdb_handle_file_io(GArray *params, void *user_ctx);
207bool gdb_handled_syscall(void);
208void gdb_disable_syscalls(void);
209void gdb_syscall_reset(void);
210
131f387d
AB
211/* user/softmmu specific syscall handling */
212void gdb_syscall_handling(const char *syscall_packet);
213
9f56787c
AB
214/*
215 * Break/Watch point support - there is an implementation for softmmu
216 * and user mode.
217 */
a48e7d9e 218bool gdb_supports_guest_debug(void);
55b5b8e9
PMD
219int gdb_breakpoint_insert(CPUState *cs, int type, vaddr addr, vaddr len);
220int gdb_breakpoint_remove(CPUState *cs, int type, vaddr addr, vaddr len);
ae7467b1
AB
221void gdb_breakpoint_remove_all(CPUState *cs);
222
589a5867
AB
223/**
224 * gdb_target_memory_rw_debug() - handle debug access to memory
225 * @cs: CPUState
226 * @addr: nominal address, could be an entire physical address
227 * @buf: data
228 * @len: length of access
229 * @is_write: is it a write operation
230 *
231 * This function is specialised depending on the mode we are running
232 * in. For softmmu guests we can switch the interpretation of the
233 * address to a physical address.
234 */
235int gdb_target_memory_rw_debug(CPUState *cs, hwaddr addr,
236 uint8_t *buf, int len, bool is_write);
237
97748558 238#endif /* GDBSTUB_INTERNALS_H */