4 * Copyright (c) 2022 Linaro Ltd
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #ifndef GDBSTUB_INTERNALS_H
10 #define GDBSTUB_INTERNALS_H
12 #include "exec/cpu-common.h"
14 #define MAX_PACKET_LENGTH 4096
17 * Shared structures and definitions
20 typedef struct GDBProcess {
24 char target_xml[1024];
37 typedef struct GDBState {
38 bool init; /* have we been initialised? */
39 CPUState *c_cpu; /* current CPU for step/continue ops */
40 CPUState *g_cpu; /* current CPU for other ops */
41 CPUState *query_cpu; /* for q{f|s}ThreadInfo */
42 enum RSState state; /* parsing state */
43 char line_buf[MAX_PACKET_LENGTH];
45 int line_sum; /* running checksum */
46 int line_csum; /* checksum at the end of the packet */
47 GByteArray *last_packet;
50 GDBProcess *processes;
52 char syscall_buf[256];
53 gdb_syscall_complete_cb current_syscall_cb;
57 int supported_sstep_flags;
62 * Inline utility function, convert from int to hex and back
65 static inline int fromhex(int v)
67 if (v >= '0' && v <= '9') {
69 } else if (v >= 'A' && v <= 'F') {
71 } else if (v >= 'a' && v <= 'f') {
78 static inline int tohex(int v)
88 * Connection helpers for both softmmu and user backends
91 void gdb_put_strbuf(void);
92 int gdb_put_packet(const char *buf);
93 int gdb_put_packet_binary(const char *buf, int len, bool dump);
94 void gdb_hextomem(GByteArray *mem, const char *buf, int len);
95 void gdb_memtohex(GString *buf, const uint8_t *mem, int len);
96 void gdb_memtox(GString *buf, const char *mem, int len);
97 void gdb_read_byte(uint8_t ch);
100 CPUState *gdb_first_attached_cpu(void);
101 void gdb_append_thread_id(CPUState *cpu, GString *buf);
102 int gdb_get_cpu_index(CPUState *cpu);
104 void gdb_init_gdbserver_state(void);
105 void gdb_create_default_process(GDBState *s);
108 * Helpers with separate softmmu and user implementations
110 void gdb_put_buffer(const uint8_t *buf, int len);
113 * Break/Watch point support - there is an implementation for softmmu
116 bool gdb_supports_guest_debug(void);
117 int gdb_breakpoint_insert(CPUState *cs, int type, vaddr addr, vaddr len);
118 int gdb_breakpoint_remove(CPUState *cs, int type, vaddr addr, vaddr len);
119 void gdb_breakpoint_remove_all(CPUState *cs);
121 #endif /* GDBSTUB_INTERNALS_H */