mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
Merge tag 'pull-gdbstub-070323-3' of https://gitlab.com/stsquad/qemu into staging
gdbstub refactor: - split user and softmmu code - use cleaner headers for tb_flush, target_ulong - probe for gdb multiarch support at configure - make syscall handling target independent - add update guest debug of accel ops # -----BEGIN PGP SIGNATURE----- # # iQEzBAABCgAdFiEEZoWumedRZ7yvyN81+9DbCVqeKkQFAmQHomMACgkQ+9DbCVqe # KkTtFAf/aEyKY0iUNxtB4/oV1L2VnLaZi+iKoZT4RQgrhOhzr5WV6/3/V05cw1RJ # SIwcl8wB4gowYILs44eM/Qzcixiugl++2rvM4YVXiQyWKzkH6sY4X2iFuPGTwHLp # y+E7RM77QNS7M9xYaVkdsQawnbsgjG67wZKbb88aaekFEn61UuDg1V2Nqa2ICy7Y # /8yGIB2ixDfXOF0z4g8NOG44BXTDBtJbcEzf5GMz6D4HGnPZUbENy1nT0OcBk3zK # PqKPNkPFZ360pqA9MtougjZ3xTBb7Afe9nRRMquV2RoFmkkY2otSjdPBFQu5GBlm # NyTXEzjIQ6tCZlbS0eqdPVrUHHUx9g== # =Al36 # -----END PGP SIGNATURE----- # gpg: Signature made Tue 07 Mar 2023 20:45:23 GMT # gpg: using RSA key 6685AE99E75167BCAFC8DF35FBD0DB095A9E2A44 # gpg: Good signature from "Alex Bennée (Master Work Key) <alex.bennee@linaro.org>" [full] # Primary key fingerprint: 6685 AE99 E751 67BC AFC8 DF35 FBD0 DB09 5A9E 2A44 * tag 'pull-gdbstub-070323-3' of https://gitlab.com/stsquad/qemu: (30 commits) gdbstub: move update guest debug to accel ops gdbstub: Build syscall.c once stubs: split semihosting_get_target from system only stubs gdbstub: Adjust gdb_do_syscall to only use uint32_t and uint64_t gdbstub: Remove gdb_do_syscallv gdbstub: split out softmmu/user specifics for syscall handling include: split target_long definition from cpu-defs testing: probe gdb for supported architectures ahead of time gdbstub: only compile gdbstub twice for whole build gdbstub: move syscall handling to new file gdbstub: move register helpers into standalone include gdbstub: don't use target_ulong while handling registers gdbstub: fix address type of gdb_set_cpu_pc gdbstub: specialise stub_can_reverse gdbstub: introduce gdb_get_max_cpus gdbstub: specialise target_memory_rw_debug gdbstub: specialise handle_query_attached gdbstub: abstract target specific details from gdb_put_packet_binary gdbstub: rationalise signal mapping in softmmu gdbstub: move chunks of user code into own files ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
@@ -136,6 +136,8 @@ F: docs/devel/decodetree.rst
|
||||
F: docs/devel/tcg*
|
||||
F: include/exec/cpu*.h
|
||||
F: include/exec/exec-all.h
|
||||
F: include/exec/tb-flush.h
|
||||
F: include/exec/target_long.h
|
||||
F: include/exec/helper*.h
|
||||
F: include/sysemu/cpus.h
|
||||
F: include/sysemu/tcg.h
|
||||
@@ -2751,9 +2753,11 @@ S: Maintained
|
||||
F: docs/system/gdb.rst
|
||||
F: gdbstub/*
|
||||
F: include/exec/gdbstub.h
|
||||
F: include/gdbstub/*
|
||||
F: gdb-xml/
|
||||
F: tests/tcg/multiarch/gdbstub/
|
||||
F: scripts/feature_to_c.sh
|
||||
F: scripts/probe-gdb-support.py
|
||||
|
||||
Memory API
|
||||
M: Paolo Bonzini <pbonzini@redhat.com>
|
||||
|
||||
@@ -86,6 +86,13 @@ static bool kvm_cpus_are_resettable(void)
|
||||
return !kvm_enabled() || kvm_cpu_check_are_resettable();
|
||||
}
|
||||
|
||||
#ifdef KVM_CAP_SET_GUEST_DEBUG
|
||||
static int kvm_update_guest_debug_ops(CPUState *cpu)
|
||||
{
|
||||
return kvm_update_guest_debug(cpu, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void kvm_accel_ops_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
|
||||
@@ -99,6 +106,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, void *data)
|
||||
ops->synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm;
|
||||
|
||||
#ifdef KVM_CAP_SET_GUEST_DEBUG
|
||||
ops->update_guest_debug = kvm_update_guest_debug_ops;
|
||||
ops->supports_guest_debug = kvm_supports_guest_debug;
|
||||
ops->insert_breakpoint = kvm_insert_breakpoint;
|
||||
ops->remove_breakpoint = kvm_remove_breakpoint;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "exec/tb-flush.h"
|
||||
#include "exec/exec-all.h"
|
||||
|
||||
void tb_flush(CPUState *cpu)
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "exec/cputlb.h"
|
||||
#include "exec/log.h"
|
||||
#include "exec/exec-all.h"
|
||||
#include "exec/tb-flush.h"
|
||||
#include "exec/translate-all.h"
|
||||
#include "sysemu/tcg.h"
|
||||
#include "tcg/tcg.h"
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include "exec/cputlb.h"
|
||||
#include "exec/translate-all.h"
|
||||
#include "exec/translator.h"
|
||||
#include "exec/tb-flush.h"
|
||||
#include "qemu/bitmap.h"
|
||||
#include "qemu/qemu-print.h"
|
||||
#include "qemu/main-loop.h"
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
#include <sys/sysctl.h>
|
||||
#include <utime.h>
|
||||
|
||||
#include "include/gdbstub/syscalls.h"
|
||||
|
||||
#include "qemu.h"
|
||||
#include "signal-common.h"
|
||||
#include "user/syscall-trace.h"
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include "trace/control.h"
|
||||
#include "crypto/init.h"
|
||||
#include "qemu/guest-random.h"
|
||||
#include "gdbstub/user.h"
|
||||
|
||||
#include "host-os.h"
|
||||
#include "target_arch_cpu.h"
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/log.h"
|
||||
#include "qemu.h"
|
||||
#include "gdbstub/user.h"
|
||||
#include "signal-common.h"
|
||||
#include "trace.h"
|
||||
#include "hw/core/tcg-cpu-ops.h"
|
||||
|
||||
@@ -230,6 +230,7 @@ stack_protector=""
|
||||
safe_stack=""
|
||||
use_containers="yes"
|
||||
gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
|
||||
gdb_arches=""
|
||||
|
||||
if test -e "$source_path/.git"
|
||||
then
|
||||
@@ -2396,6 +2397,7 @@ if test -n "$gdb_bin"; then
|
||||
gdb_version=$($gdb_bin --version | head -n 1)
|
||||
if version_ge ${gdb_version##* } 9.1; then
|
||||
echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak
|
||||
gdb_arches=$("$source_path/scripts/probe-gdb-support.py" $gdb_bin)
|
||||
else
|
||||
gdb_bin=""
|
||||
fi
|
||||
@@ -2520,6 +2522,12 @@ for target in $target_list; do
|
||||
write_target_makefile "build-tcg-tests-$target" >> "$config_target_mak"
|
||||
echo "BUILD_STATIC=$build_static" >> "$config_target_mak"
|
||||
echo "QEMU=$PWD/$qemu" >> "$config_target_mak"
|
||||
|
||||
# will GDB work with these binaries?
|
||||
if test "${gdb_arches#*$arch}" != "$gdb_arches"; then
|
||||
echo "HOST_GDB_SUPPORTS_ARCH=y" >> "$config_target_mak"
|
||||
fi
|
||||
|
||||
echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> Makefile.prereqs
|
||||
tcg_tests_targets="$tcg_tests_targets $target"
|
||||
fi
|
||||
|
||||
@@ -31,11 +31,12 @@
|
||||
#include "hw/core/sysemu-cpu-ops.h"
|
||||
#include "exec/address-spaces.h"
|
||||
#endif
|
||||
#include "sysemu/cpus.h"
|
||||
#include "sysemu/tcg.h"
|
||||
#include "sysemu/kvm.h"
|
||||
#include "exec/replay-core.h"
|
||||
#include "exec/cpu-common.h"
|
||||
#include "exec/exec-all.h"
|
||||
#include "exec/tb-flush.h"
|
||||
#include "exec/translate-all.h"
|
||||
#include "exec/log.h"
|
||||
#include "hw/core/accel-cpu.h"
|
||||
@@ -325,9 +326,14 @@ void cpu_single_step(CPUState *cpu, int enabled)
|
||||
{
|
||||
if (cpu->singlestep_enabled != enabled) {
|
||||
cpu->singlestep_enabled = enabled;
|
||||
if (kvm_enabled()) {
|
||||
kvm_update_guest_debug(cpu, 0);
|
||||
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
const AccelOpsClass *ops = cpus_get_accel();
|
||||
if (ops->update_guest_debug) {
|
||||
ops->update_guest_debug(cpu);
|
||||
}
|
||||
#endif
|
||||
|
||||
trace_breakpoint_singlestep(cpu->cpu_index, enabled);
|
||||
}
|
||||
}
|
||||
|
||||
+142
-1513
File diff suppressed because it is too large
Load Diff
+209
-3
@@ -6,14 +6,220 @@
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef _INTERNALS_H_
|
||||
#define _INTERNALS_H_
|
||||
#ifndef GDBSTUB_INTERNALS_H
|
||||
#define GDBSTUB_INTERNALS_H
|
||||
|
||||
#include "exec/cpu-common.h"
|
||||
|
||||
#define MAX_PACKET_LENGTH 4096
|
||||
|
||||
/*
|
||||
* Shared structures and definitions
|
||||
*/
|
||||
|
||||
enum {
|
||||
GDB_SIGNAL_0 = 0,
|
||||
GDB_SIGNAL_INT = 2,
|
||||
GDB_SIGNAL_QUIT = 3,
|
||||
GDB_SIGNAL_TRAP = 5,
|
||||
GDB_SIGNAL_ABRT = 6,
|
||||
GDB_SIGNAL_ALRM = 14,
|
||||
GDB_SIGNAL_IO = 23,
|
||||
GDB_SIGNAL_XCPU = 24,
|
||||
GDB_SIGNAL_UNKNOWN = 143
|
||||
};
|
||||
|
||||
typedef struct GDBProcess {
|
||||
uint32_t pid;
|
||||
bool attached;
|
||||
|
||||
char target_xml[1024];
|
||||
} GDBProcess;
|
||||
|
||||
enum RSState {
|
||||
RS_INACTIVE,
|
||||
RS_IDLE,
|
||||
RS_GETLINE,
|
||||
RS_GETLINE_ESC,
|
||||
RS_GETLINE_RLE,
|
||||
RS_CHKSUM1,
|
||||
RS_CHKSUM2,
|
||||
};
|
||||
|
||||
typedef struct GDBState {
|
||||
bool init; /* have we been initialised? */
|
||||
CPUState *c_cpu; /* current CPU for step/continue ops */
|
||||
CPUState *g_cpu; /* current CPU for other ops */
|
||||
CPUState *query_cpu; /* for q{f|s}ThreadInfo */
|
||||
enum RSState state; /* parsing state */
|
||||
char line_buf[MAX_PACKET_LENGTH];
|
||||
int line_buf_index;
|
||||
int line_sum; /* running checksum */
|
||||
int line_csum; /* checksum at the end of the packet */
|
||||
GByteArray *last_packet;
|
||||
int signal;
|
||||
bool multiprocess;
|
||||
GDBProcess *processes;
|
||||
int process_num;
|
||||
GString *str_buf;
|
||||
GByteArray *mem_buf;
|
||||
int sstep_flags;
|
||||
int supported_sstep_flags;
|
||||
} GDBState;
|
||||
|
||||
/* lives in main gdbstub.c */
|
||||
extern GDBState gdbserver_state;
|
||||
|
||||
/*
|
||||
* Inline utility function, convert from int to hex and back
|
||||
*/
|
||||
|
||||
static inline int fromhex(int v)
|
||||
{
|
||||
if (v >= '0' && v <= '9') {
|
||||
return v - '0';
|
||||
} else if (v >= 'A' && v <= 'F') {
|
||||
return v - 'A' + 10;
|
||||
} else if (v >= 'a' && v <= 'f') {
|
||||
return v - 'a' + 10;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static inline int tohex(int v)
|
||||
{
|
||||
if (v < 10) {
|
||||
return v + '0';
|
||||
} else {
|
||||
return v - 10 + 'a';
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Connection helpers for both softmmu and user backends
|
||||
*/
|
||||
|
||||
void gdb_put_strbuf(void);
|
||||
int gdb_put_packet(const char *buf);
|
||||
int gdb_put_packet_binary(const char *buf, int len, bool dump);
|
||||
void gdb_hextomem(GByteArray *mem, const char *buf, int len);
|
||||
void gdb_memtohex(GString *buf, const uint8_t *mem, int len);
|
||||
void gdb_memtox(GString *buf, const char *mem, int len);
|
||||
void gdb_read_byte(uint8_t ch);
|
||||
|
||||
/*
|
||||
* Packet acknowledgement - we handle this slightly differently
|
||||
* between user and softmmu mode, mainly to deal with the differences
|
||||
* between the flexible chardev and the direct fd approaches.
|
||||
*
|
||||
* We currently don't support a negotiated QStartNoAckMode
|
||||
*/
|
||||
|
||||
/**
|
||||
* gdb_got_immediate_ack() - check ok to continue
|
||||
*
|
||||
* Returns true to continue, false to re-transmit for user only, the
|
||||
* softmmu stub always returns true.
|
||||
*/
|
||||
bool gdb_got_immediate_ack(void);
|
||||
/* utility helpers */
|
||||
CPUState *gdb_first_attached_cpu(void);
|
||||
void gdb_append_thread_id(CPUState *cpu, GString *buf);
|
||||
int gdb_get_cpu_index(CPUState *cpu);
|
||||
unsigned int gdb_get_max_cpus(void); /* both */
|
||||
bool gdb_can_reverse(void); /* softmmu, stub for user */
|
||||
|
||||
void gdb_create_default_process(GDBState *s);
|
||||
|
||||
/* signal mapping, common for softmmu, specialised for user-mode */
|
||||
int gdb_signal_to_target(int sig);
|
||||
int gdb_target_signal_to_gdb(int sig);
|
||||
|
||||
int gdb_get_char(void); /* user only */
|
||||
|
||||
/**
|
||||
* gdb_continue() - handle continue in mode specific way.
|
||||
*/
|
||||
void gdb_continue(void);
|
||||
|
||||
/**
|
||||
* gdb_continue_partial() - handle partial continue in mode specific way.
|
||||
*/
|
||||
int gdb_continue_partial(char *newstates);
|
||||
|
||||
/*
|
||||
* Helpers with separate softmmu and user implementations
|
||||
*/
|
||||
void gdb_put_buffer(const uint8_t *buf, int len);
|
||||
|
||||
/*
|
||||
* Command handlers - either specialised or softmmu or user only
|
||||
*/
|
||||
void gdb_init_gdbserver_state(void);
|
||||
|
||||
typedef enum GDBThreadIdKind {
|
||||
GDB_ONE_THREAD = 0,
|
||||
GDB_ALL_THREADS, /* One process, all threads */
|
||||
GDB_ALL_PROCESSES,
|
||||
GDB_READ_THREAD_ERR
|
||||
} GDBThreadIdKind;
|
||||
|
||||
typedef union GdbCmdVariant {
|
||||
const char *data;
|
||||
uint8_t opcode;
|
||||
unsigned long val_ul;
|
||||
unsigned long long val_ull;
|
||||
struct {
|
||||
GDBThreadIdKind kind;
|
||||
uint32_t pid;
|
||||
uint32_t tid;
|
||||
} thread_id;
|
||||
} GdbCmdVariant;
|
||||
|
||||
#define get_param(p, i) (&g_array_index(p, GdbCmdVariant, i))
|
||||
|
||||
void gdb_handle_query_rcmd(GArray *params, void *user_ctx); /* softmmu */
|
||||
void gdb_handle_query_offsets(GArray *params, void *user_ctx); /* user */
|
||||
void gdb_handle_query_xfer_auxv(GArray *params, void *user_ctx); /*user */
|
||||
|
||||
void gdb_handle_query_attached(GArray *params, void *user_ctx); /* both */
|
||||
|
||||
/* softmmu only */
|
||||
void gdb_handle_query_qemu_phy_mem_mode(GArray *params, void *user_ctx);
|
||||
void gdb_handle_set_qemu_phy_mem_mode(GArray *params, void *user_ctx);
|
||||
|
||||
/* sycall handling */
|
||||
void gdb_handle_file_io(GArray *params, void *user_ctx);
|
||||
bool gdb_handled_syscall(void);
|
||||
void gdb_disable_syscalls(void);
|
||||
void gdb_syscall_reset(void);
|
||||
|
||||
/* user/softmmu specific syscall handling */
|
||||
void gdb_syscall_handling(const char *syscall_packet);
|
||||
|
||||
/*
|
||||
* Break/Watch point support - there is an implementation for softmmu
|
||||
* and user mode.
|
||||
*/
|
||||
bool gdb_supports_guest_debug(void);
|
||||
int gdb_breakpoint_insert(CPUState *cs, int type, vaddr addr, vaddr len);
|
||||
int gdb_breakpoint_remove(CPUState *cs, int type, vaddr addr, vaddr len);
|
||||
void gdb_breakpoint_remove_all(CPUState *cs);
|
||||
|
||||
#endif /* _INTERNALS_H_ */
|
||||
/**
|
||||
* gdb_target_memory_rw_debug() - handle debug access to memory
|
||||
* @cs: CPUState
|
||||
* @addr: nominal address, could be an entire physical address
|
||||
* @buf: data
|
||||
* @len: length of access
|
||||
* @is_write: is it a write operation
|
||||
*
|
||||
* This function is specialised depending on the mode we are running
|
||||
* in. For softmmu guests we can switch the interpretation of the
|
||||
* address to a physical address.
|
||||
*/
|
||||
int gdb_target_memory_rw_debug(CPUState *cs, hwaddr addr,
|
||||
uint8_t *buf, int len, bool is_write);
|
||||
|
||||
#endif /* GDBSTUB_INTERNALS_H */
|
||||
|
||||
+31
-3
@@ -4,6 +4,34 @@
|
||||
# types such as hwaddr.
|
||||
#
|
||||
|
||||
specific_ss.add(files('gdbstub.c'))
|
||||
softmmu_ss.add(files('softmmu.c'))
|
||||
user_ss.add(files('user.c'))
|
||||
# We need to build the core gdb code via a library to be able to tweak
|
||||
# cflags so:
|
||||
|
||||
gdb_user_ss = ss.source_set()
|
||||
gdb_softmmu_ss = ss.source_set()
|
||||
|
||||
# We build two versions of gdbstub, one for each mode
|
||||
gdb_user_ss.add(files('gdbstub.c', 'user.c'))
|
||||
gdb_softmmu_ss.add(files('gdbstub.c', 'softmmu.c'))
|
||||
|
||||
gdb_user_ss = gdb_user_ss.apply(config_host, strict: false)
|
||||
gdb_softmmu_ss = gdb_softmmu_ss.apply(config_host, strict: false)
|
||||
|
||||
libgdb_user = static_library('gdb_user',
|
||||
gdb_user_ss.sources() + genh,
|
||||
name_suffix: 'fa',
|
||||
c_args: '-DCONFIG_USER_ONLY')
|
||||
|
||||
libgdb_softmmu = static_library('gdb_softmmu',
|
||||
gdb_softmmu_ss.sources() + genh,
|
||||
name_suffix: 'fa')
|
||||
|
||||
gdb_user = declare_dependency(link_whole: libgdb_user)
|
||||
user_ss.add(gdb_user)
|
||||
gdb_softmmu = declare_dependency(link_whole: libgdb_softmmu)
|
||||
softmmu_ss.add(gdb_softmmu)
|
||||
|
||||
common_ss.add(files('syscalls.c'))
|
||||
|
||||
# The user-target is specialised by the guest
|
||||
specific_ss.add(when: 'CONFIG_USER_ONLY', if_true: files('user-target.c'))
|
||||
|
||||
+602
-1
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* GDB Syscall Handling
|
||||
*
|
||||
* GDB can execute syscalls on the guests behalf, currently used by
|
||||
* the various semihosting extensions.
|
||||
*
|
||||
* Copyright (c) 2003-2005 Fabrice Bellard
|
||||
* Copyright (c) 2023 Linaro Ltd
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.0+
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "semihosting/semihost.h"
|
||||
#include "sysemu/runstate.h"
|
||||
#include "gdbstub/user.h"
|
||||
#include "gdbstub/syscalls.h"
|
||||
#include "trace.h"
|
||||
#include "internals.h"
|
||||
|
||||
/* Syscall specific state */
|
||||
typedef struct {
|
||||
char syscall_buf[256];
|
||||
gdb_syscall_complete_cb current_syscall_cb;
|
||||
} GDBSyscallState;
|
||||
|
||||
static GDBSyscallState gdbserver_syscall_state;
|
||||
|
||||
/*
|
||||
* Return true if there is a GDB currently connected to the stub
|
||||
* and attached to a CPU
|
||||
*/
|
||||
static bool gdb_attached(void)
|
||||
{
|
||||
return gdbserver_state.init && gdbserver_state.c_cpu;
|
||||
}
|
||||
|
||||
static enum {
|
||||
GDB_SYS_UNKNOWN,
|
||||
GDB_SYS_ENABLED,
|
||||
GDB_SYS_DISABLED,
|
||||
} gdb_syscall_mode;
|
||||
|
||||
/* Decide if either remote gdb syscalls or native file IO should be used. */
|
||||
int use_gdb_syscalls(void)
|
||||
{
|
||||
SemihostingTarget target = semihosting_get_target();
|
||||
if (target == SEMIHOSTING_TARGET_NATIVE) {
|
||||
/* -semihosting-config target=native */
|
||||
return false;
|
||||
} else if (target == SEMIHOSTING_TARGET_GDB) {
|
||||
/* -semihosting-config target=gdb */
|
||||
return true;
|
||||
}
|
||||
|
||||
/* -semihosting-config target=auto */
|
||||
/* On the first call check if gdb is connected and remember. */
|
||||
if (gdb_syscall_mode == GDB_SYS_UNKNOWN) {
|
||||
gdb_syscall_mode = gdb_attached() ? GDB_SYS_ENABLED : GDB_SYS_DISABLED;
|
||||
}
|
||||
return gdb_syscall_mode == GDB_SYS_ENABLED;
|
||||
}
|
||||
|
||||
/* called when the stub detaches */
|
||||
void gdb_disable_syscalls(void)
|
||||
{
|
||||
gdb_syscall_mode = GDB_SYS_DISABLED;
|
||||
}
|
||||
|
||||
void gdb_syscall_reset(void)
|
||||
{
|
||||
gdbserver_syscall_state.current_syscall_cb = NULL;
|
||||
}
|
||||
|
||||
bool gdb_handled_syscall(void)
|
||||
{
|
||||
if (gdbserver_syscall_state.current_syscall_cb) {
|
||||
gdb_put_packet(gdbserver_syscall_state.syscall_buf);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a gdb syscall request.
|
||||
* This accepts limited printf-style format specifiers, specifically:
|
||||
* %x - target_ulong argument printed in hex.
|
||||
* %lx - 64-bit argument printed in hex.
|
||||
* %s - string pointer (target_ulong) and length (int) pair.
|
||||
*/
|
||||
void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...)
|
||||
{
|
||||
char *p, *p_end;
|
||||
va_list va;
|
||||
|
||||
if (!gdb_attached()) {
|
||||
return;
|
||||
}
|
||||
|
||||
gdbserver_syscall_state.current_syscall_cb = cb;
|
||||
va_start(va, fmt);
|
||||
|
||||
p = gdbserver_syscall_state.syscall_buf;
|
||||
p_end = p + sizeof(gdbserver_syscall_state.syscall_buf);
|
||||
*(p++) = 'F';
|
||||
while (*fmt) {
|
||||
if (*fmt == '%') {
|
||||
uint64_t i64;
|
||||
uint32_t i32;
|
||||
|
||||
fmt++;
|
||||
switch (*fmt++) {
|
||||
case 'x':
|
||||
i32 = va_arg(va, uint32_t);
|
||||
p += snprintf(p, p_end - p, "%" PRIx32, i32);
|
||||
break;
|
||||
case 'l':
|
||||
if (*(fmt++) != 'x') {
|
||||
goto bad_format;
|
||||
}
|
||||
i64 = va_arg(va, uint64_t);
|
||||
p += snprintf(p, p_end - p, "%" PRIx64, i64);
|
||||
break;
|
||||
case 's':
|
||||
i64 = va_arg(va, uint64_t);
|
||||
i32 = va_arg(va, uint32_t);
|
||||
p += snprintf(p, p_end - p, "%" PRIx64 "/%x" PRIx32, i64, i32);
|
||||
break;
|
||||
default:
|
||||
bad_format:
|
||||
error_report("gdbstub: Bad syscall format string '%s'",
|
||||
fmt - 1);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
*(p++) = *(fmt++);
|
||||
}
|
||||
}
|
||||
*p = 0;
|
||||
|
||||
va_end(va);
|
||||
gdb_syscall_handling(gdbserver_syscall_state.syscall_buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* GDB Command Handlers
|
||||
*/
|
||||
|
||||
void gdb_handle_file_io(GArray *params, void *user_ctx)
|
||||
{
|
||||
if (params->len >= 1 && gdbserver_syscall_state.current_syscall_cb) {
|
||||
uint64_t ret;
|
||||
int err;
|
||||
|
||||
ret = get_param(params, 0)->val_ull;
|
||||
if (params->len >= 2) {
|
||||
err = get_param(params, 1)->val_ull;
|
||||
} else {
|
||||
err = 0;
|
||||
}
|
||||
|
||||
/* Convert GDB error numbers back to host error numbers. */
|
||||
#define E(X) case GDB_E##X: err = E##X; break
|
||||
switch (err) {
|
||||
case 0:
|
||||
break;
|
||||
E(PERM);
|
||||
E(NOENT);
|
||||
E(INTR);
|
||||
E(BADF);
|
||||
E(ACCES);
|
||||
E(FAULT);
|
||||
E(BUSY);
|
||||
E(EXIST);
|
||||
E(NODEV);
|
||||
E(NOTDIR);
|
||||
E(ISDIR);
|
||||
E(INVAL);
|
||||
E(NFILE);
|
||||
E(MFILE);
|
||||
E(FBIG);
|
||||
E(NOSPC);
|
||||
E(SPIPE);
|
||||
E(ROFS);
|
||||
E(NAMETOOLONG);
|
||||
default:
|
||||
err = EINVAL;
|
||||
break;
|
||||
}
|
||||
#undef E
|
||||
|
||||
gdbserver_syscall_state.current_syscall_cb(gdbserver_state.c_cpu,
|
||||
ret, err);
|
||||
gdbserver_syscall_state.current_syscall_cb = NULL;
|
||||
}
|
||||
|
||||
if (params->len >= 3 && get_param(params, 2)->opcode == (uint8_t)'C') {
|
||||
gdb_put_packet("T02");
|
||||
return;
|
||||
}
|
||||
|
||||
gdb_continue();
|
||||
}
|
||||
@@ -7,7 +7,6 @@ gdbstub_op_continue(void) "Continuing all CPUs"
|
||||
gdbstub_op_continue_cpu(int cpu_index) "Continuing CPU %d"
|
||||
gdbstub_op_stepping(int cpu_index) "Stepping CPU %d"
|
||||
gdbstub_op_extra_info(const char *info) "Thread extra info: %s"
|
||||
gdbstub_hit_watchpoint(const char *type, int cpu_gdb_index, uint64_t vaddr) "Watchpoint hit, type=\"%s\" cpu=%d, vaddr=0x%" PRIx64 ""
|
||||
gdbstub_hit_internal_error(void) "RUN_STATE_INTERNAL_ERROR"
|
||||
gdbstub_hit_break(void) "RUN_STATE_DEBUG"
|
||||
gdbstub_hit_paused(void) "RUN_STATE_PAUSED"
|
||||
@@ -27,3 +26,6 @@ gdbstub_err_invalid_repeat(uint8_t ch) "got invalid RLE count: 0x%02x"
|
||||
gdbstub_err_invalid_rle(void) "got invalid RLE sequence"
|
||||
gdbstub_err_checksum_invalid(uint8_t ch) "got invalid command checksum digit: 0x%02x"
|
||||
gdbstub_err_checksum_incorrect(uint8_t expected, uint8_t got) "got command packet with incorrect checksum, expected=0x%02x, received=0x%02x"
|
||||
|
||||
# softmmu.c
|
||||
gdbstub_hit_watchpoint(const char *type, int cpu_gdb_index, uint64_t vaddr) "Watchpoint hit, type=\"%s\" cpu=%d, vaddr=0x%" PRIx64 ""
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
/*
|
||||
* Target specific user-mode handling
|
||||
*
|
||||
* Copyright (c) 2003-2005 Fabrice Bellard
|
||||
* Copyright (c) 2022 Linaro Ltd
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.0+
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "exec/gdbstub.h"
|
||||
#include "qemu.h"
|
||||
#include "internals.h"
|
||||
|
||||
/*
|
||||
* Map target signal numbers to GDB protocol signal numbers and vice
|
||||
* versa. For user emulation's currently supported systems, we can
|
||||
* assume most signals are defined.
|
||||
*/
|
||||
|
||||
static int gdb_signal_table[] = {
|
||||
0,
|
||||
TARGET_SIGHUP,
|
||||
TARGET_SIGINT,
|
||||
TARGET_SIGQUIT,
|
||||
TARGET_SIGILL,
|
||||
TARGET_SIGTRAP,
|
||||
TARGET_SIGABRT,
|
||||
-1, /* SIGEMT */
|
||||
TARGET_SIGFPE,
|
||||
TARGET_SIGKILL,
|
||||
TARGET_SIGBUS,
|
||||
TARGET_SIGSEGV,
|
||||
TARGET_SIGSYS,
|
||||
TARGET_SIGPIPE,
|
||||
TARGET_SIGALRM,
|
||||
TARGET_SIGTERM,
|
||||
TARGET_SIGURG,
|
||||
TARGET_SIGSTOP,
|
||||
TARGET_SIGTSTP,
|
||||
TARGET_SIGCONT,
|
||||
TARGET_SIGCHLD,
|
||||
TARGET_SIGTTIN,
|
||||
TARGET_SIGTTOU,
|
||||
TARGET_SIGIO,
|
||||
TARGET_SIGXCPU,
|
||||
TARGET_SIGXFSZ,
|
||||
TARGET_SIGVTALRM,
|
||||
TARGET_SIGPROF,
|
||||
TARGET_SIGWINCH,
|
||||
-1, /* SIGLOST */
|
||||
TARGET_SIGUSR1,
|
||||
TARGET_SIGUSR2,
|
||||
#ifdef TARGET_SIGPWR
|
||||
TARGET_SIGPWR,
|
||||
#else
|
||||
-1,
|
||||
#endif
|
||||
-1, /* SIGPOLL */
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
#ifdef __SIGRTMIN
|
||||
__SIGRTMIN + 1,
|
||||
__SIGRTMIN + 2,
|
||||
__SIGRTMIN + 3,
|
||||
__SIGRTMIN + 4,
|
||||
__SIGRTMIN + 5,
|
||||
__SIGRTMIN + 6,
|
||||
__SIGRTMIN + 7,
|
||||
__SIGRTMIN + 8,
|
||||
__SIGRTMIN + 9,
|
||||
__SIGRTMIN + 10,
|
||||
__SIGRTMIN + 11,
|
||||
__SIGRTMIN + 12,
|
||||
__SIGRTMIN + 13,
|
||||
__SIGRTMIN + 14,
|
||||
__SIGRTMIN + 15,
|
||||
__SIGRTMIN + 16,
|
||||
__SIGRTMIN + 17,
|
||||
__SIGRTMIN + 18,
|
||||
__SIGRTMIN + 19,
|
||||
__SIGRTMIN + 20,
|
||||
__SIGRTMIN + 21,
|
||||
__SIGRTMIN + 22,
|
||||
__SIGRTMIN + 23,
|
||||
__SIGRTMIN + 24,
|
||||
__SIGRTMIN + 25,
|
||||
__SIGRTMIN + 26,
|
||||
__SIGRTMIN + 27,
|
||||
__SIGRTMIN + 28,
|
||||
__SIGRTMIN + 29,
|
||||
__SIGRTMIN + 30,
|
||||
__SIGRTMIN + 31,
|
||||
-1, /* SIGCANCEL */
|
||||
__SIGRTMIN,
|
||||
__SIGRTMIN + 32,
|
||||
__SIGRTMIN + 33,
|
||||
__SIGRTMIN + 34,
|
||||
__SIGRTMIN + 35,
|
||||
__SIGRTMIN + 36,
|
||||
__SIGRTMIN + 37,
|
||||
__SIGRTMIN + 38,
|
||||
__SIGRTMIN + 39,
|
||||
__SIGRTMIN + 40,
|
||||
__SIGRTMIN + 41,
|
||||
__SIGRTMIN + 42,
|
||||
__SIGRTMIN + 43,
|
||||
__SIGRTMIN + 44,
|
||||
__SIGRTMIN + 45,
|
||||
__SIGRTMIN + 46,
|
||||
__SIGRTMIN + 47,
|
||||
__SIGRTMIN + 48,
|
||||
__SIGRTMIN + 49,
|
||||
__SIGRTMIN + 50,
|
||||
__SIGRTMIN + 51,
|
||||
__SIGRTMIN + 52,
|
||||
__SIGRTMIN + 53,
|
||||
__SIGRTMIN + 54,
|
||||
__SIGRTMIN + 55,
|
||||
__SIGRTMIN + 56,
|
||||
__SIGRTMIN + 57,
|
||||
__SIGRTMIN + 58,
|
||||
__SIGRTMIN + 59,
|
||||
__SIGRTMIN + 60,
|
||||
__SIGRTMIN + 61,
|
||||
__SIGRTMIN + 62,
|
||||
__SIGRTMIN + 63,
|
||||
__SIGRTMIN + 64,
|
||||
__SIGRTMIN + 65,
|
||||
__SIGRTMIN + 66,
|
||||
__SIGRTMIN + 67,
|
||||
__SIGRTMIN + 68,
|
||||
__SIGRTMIN + 69,
|
||||
__SIGRTMIN + 70,
|
||||
__SIGRTMIN + 71,
|
||||
__SIGRTMIN + 72,
|
||||
__SIGRTMIN + 73,
|
||||
__SIGRTMIN + 74,
|
||||
__SIGRTMIN + 75,
|
||||
__SIGRTMIN + 76,
|
||||
__SIGRTMIN + 77,
|
||||
__SIGRTMIN + 78,
|
||||
__SIGRTMIN + 79,
|
||||
__SIGRTMIN + 80,
|
||||
__SIGRTMIN + 81,
|
||||
__SIGRTMIN + 82,
|
||||
__SIGRTMIN + 83,
|
||||
__SIGRTMIN + 84,
|
||||
__SIGRTMIN + 85,
|
||||
__SIGRTMIN + 86,
|
||||
__SIGRTMIN + 87,
|
||||
__SIGRTMIN + 88,
|
||||
__SIGRTMIN + 89,
|
||||
__SIGRTMIN + 90,
|
||||
__SIGRTMIN + 91,
|
||||
__SIGRTMIN + 92,
|
||||
__SIGRTMIN + 93,
|
||||
__SIGRTMIN + 94,
|
||||
__SIGRTMIN + 95,
|
||||
-1, /* SIGINFO */
|
||||
-1, /* UNKNOWN */
|
||||
-1, /* DEFAULT */
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1
|
||||
#endif
|
||||
};
|
||||
|
||||
int gdb_signal_to_target(int sig)
|
||||
{
|
||||
if (sig < ARRAY_SIZE(gdb_signal_table)) {
|
||||
return gdb_signal_table[sig];
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int gdb_target_signal_to_gdb(int sig)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < ARRAY_SIZE(gdb_signal_table); i++) {
|
||||
if (gdb_signal_table[i] == sig) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return GDB_SIGNAL_UNKNOWN;
|
||||
}
|
||||
|
||||
int gdb_get_cpu_index(CPUState *cpu)
|
||||
{
|
||||
TaskState *ts = (TaskState *) cpu->opaque;
|
||||
return ts ? ts->ts_tid : -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* User-mode specific command helpers
|
||||
*/
|
||||
|
||||
void gdb_handle_query_offsets(GArray *params, void *user_ctx)
|
||||
{
|
||||
TaskState *ts;
|
||||
|
||||
ts = gdbserver_state.c_cpu->opaque;
|
||||
g_string_printf(gdbserver_state.str_buf,
|
||||
"Text=" TARGET_ABI_FMT_lx
|
||||
";Data=" TARGET_ABI_FMT_lx
|
||||
";Bss=" TARGET_ABI_FMT_lx,
|
||||
ts->info->code_offset,
|
||||
ts->info->data_offset,
|
||||
ts->info->data_offset);
|
||||
gdb_put_strbuf();
|
||||
}
|
||||
|
||||
#if defined(CONFIG_LINUX)
|
||||
/* Partial user only duplicate of helper in gdbstub.c */
|
||||
static inline int target_memory_rw_debug(CPUState *cpu, target_ulong addr,
|
||||
uint8_t *buf, int len, bool is_write)
|
||||
{
|
||||
CPUClass *cc;
|
||||
cc = CPU_GET_CLASS(cpu);
|
||||
if (cc->memory_rw_debug) {
|
||||
return cc->memory_rw_debug(cpu, addr, buf, len, is_write);
|
||||
}
|
||||
return cpu_memory_rw_debug(cpu, addr, buf, len, is_write);
|
||||
}
|
||||
|
||||
void gdb_handle_query_xfer_auxv(GArray *params, void *user_ctx)
|
||||
{
|
||||
TaskState *ts;
|
||||
unsigned long offset, len, saved_auxv, auxv_len;
|
||||
|
||||
if (params->len < 2) {
|
||||
gdb_put_packet("E22");
|
||||
return;
|
||||
}
|
||||
|
||||
offset = get_param(params, 0)->val_ul;
|
||||
len = get_param(params, 1)->val_ul;
|
||||
ts = gdbserver_state.c_cpu->opaque;
|
||||
saved_auxv = ts->info->saved_auxv;
|
||||
auxv_len = ts->info->auxv_len;
|
||||
|
||||
if (offset >= auxv_len) {
|
||||
gdb_put_packet("E00");
|
||||
return;
|
||||
}
|
||||
|
||||
if (len > (MAX_PACKET_LENGTH - 5) / 2) {
|
||||
len = (MAX_PACKET_LENGTH - 5) / 2;
|
||||
}
|
||||
|
||||
if (len < auxv_len - offset) {
|
||||
g_string_assign(gdbserver_state.str_buf, "m");
|
||||
} else {
|
||||
g_string_assign(gdbserver_state.str_buf, "l");
|
||||
len = auxv_len - offset;
|
||||
}
|
||||
|
||||
g_byte_array_set_size(gdbserver_state.mem_buf, len);
|
||||
if (target_memory_rw_debug(gdbserver_state.g_cpu, saved_auxv + offset,
|
||||
gdbserver_state.mem_buf->data, len, false)) {
|
||||
gdb_put_packet("E14");
|
||||
return;
|
||||
}
|
||||
|
||||
gdb_memtox(gdbserver_state.str_buf,
|
||||
(const char *)gdbserver_state.mem_buf->data, len);
|
||||
gdb_put_packet_binary(gdbserver_state.str_buf->str,
|
||||
gdbserver_state.str_buf->len, true);
|
||||
}
|
||||
#endif
|
||||
+422
-1
@@ -3,16 +3,423 @@
|
||||
*
|
||||
* We know for user-mode we are using TCG so we can call stuff directly.
|
||||
*
|
||||
* Copyright (c) 2003-2005 Fabrice Bellard
|
||||
* Copyright (c) 2022 Linaro Ltd
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
* SPDX-License-Identifier: LGPL-2.0+
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/sockets.h"
|
||||
#include "exec/hwaddr.h"
|
||||
#include "exec/tb-flush.h"
|
||||
#include "exec/gdbstub.h"
|
||||
#include "gdbstub/syscalls.h"
|
||||
#include "gdbstub/user.h"
|
||||
#include "hw/core/cpu.h"
|
||||
#include "trace.h"
|
||||
#include "internals.h"
|
||||
|
||||
/* User-mode specific state */
|
||||
typedef struct {
|
||||
int fd;
|
||||
char *socket_path;
|
||||
int running_state;
|
||||
} GDBUserState;
|
||||
|
||||
static GDBUserState gdbserver_user_state;
|
||||
|
||||
int gdb_get_char(void)
|
||||
{
|
||||
uint8_t ch;
|
||||
int ret;
|
||||
|
||||
for (;;) {
|
||||
ret = recv(gdbserver_user_state.fd, &ch, 1, 0);
|
||||
if (ret < 0) {
|
||||
if (errno == ECONNRESET) {
|
||||
gdbserver_user_state.fd = -1;
|
||||
}
|
||||
if (errno != EINTR) {
|
||||
return -1;
|
||||
}
|
||||
} else if (ret == 0) {
|
||||
close(gdbserver_user_state.fd);
|
||||
gdbserver_user_state.fd = -1;
|
||||
return -1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
||||
bool gdb_got_immediate_ack(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = gdb_get_char();
|
||||
if (i < 0) {
|
||||
/* no response, continue anyway */
|
||||
return true;
|
||||
}
|
||||
|
||||
if (i == '+') {
|
||||
/* received correctly, continue */
|
||||
return true;
|
||||
}
|
||||
|
||||
/* anything else, including '-' then try again */
|
||||
return false;
|
||||
}
|
||||
|
||||
void gdb_put_buffer(const uint8_t *buf, int len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
while (len > 0) {
|
||||
ret = send(gdbserver_user_state.fd, buf, len, 0);
|
||||
if (ret < 0) {
|
||||
if (errno != EINTR) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
buf += ret;
|
||||
len -= ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Tell the remote gdb that the process has exited. */
|
||||
void gdb_exit(int code)
|
||||
{
|
||||
char buf[4];
|
||||
|
||||
if (!gdbserver_state.init) {
|
||||
return;
|
||||
}
|
||||
if (gdbserver_user_state.socket_path) {
|
||||
unlink(gdbserver_user_state.socket_path);
|
||||
}
|
||||
if (gdbserver_user_state.fd < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
trace_gdbstub_op_exiting((uint8_t)code);
|
||||
|
||||
snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code);
|
||||
gdb_put_packet(buf);
|
||||
}
|
||||
|
||||
int gdb_handlesig(CPUState *cpu, int sig)
|
||||
{
|
||||
char buf[256];
|
||||
int n;
|
||||
|
||||
if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
|
||||
return sig;
|
||||
}
|
||||
|
||||
/* disable single step if it was enabled */
|
||||
cpu_single_step(cpu, 0);
|
||||
tb_flush(cpu);
|
||||
|
||||
if (sig != 0) {
|
||||
gdb_set_stop_cpu(cpu);
|
||||
g_string_printf(gdbserver_state.str_buf,
|
||||
"T%02xthread:", gdb_target_signal_to_gdb(sig));
|
||||
gdb_append_thread_id(cpu, gdbserver_state.str_buf);
|
||||
g_string_append_c(gdbserver_state.str_buf, ';');
|
||||
gdb_put_strbuf();
|
||||
}
|
||||
/*
|
||||
* gdb_put_packet() might have detected that the peer terminated the
|
||||
* connection.
|
||||
*/
|
||||
if (gdbserver_user_state.fd < 0) {
|
||||
return sig;
|
||||
}
|
||||
|
||||
sig = 0;
|
||||
gdbserver_state.state = RS_IDLE;
|
||||
gdbserver_user_state.running_state = 0;
|
||||
while (gdbserver_user_state.running_state == 0) {
|
||||
n = read(gdbserver_user_state.fd, buf, 256);
|
||||
if (n > 0) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
gdb_read_byte(buf[i]);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* XXX: Connection closed. Should probably wait for another
|
||||
* connection before continuing.
|
||||
*/
|
||||
if (n == 0) {
|
||||
close(gdbserver_user_state.fd);
|
||||
}
|
||||
gdbserver_user_state.fd = -1;
|
||||
return sig;
|
||||
}
|
||||
}
|
||||
sig = gdbserver_state.signal;
|
||||
gdbserver_state.signal = 0;
|
||||
return sig;
|
||||
}
|
||||
|
||||
/* Tell the remote gdb that the process has exited due to SIG. */
|
||||
void gdb_signalled(CPUArchState *env, int sig)
|
||||
{
|
||||
char buf[4];
|
||||
|
||||
if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
snprintf(buf, sizeof(buf), "X%02x", gdb_target_signal_to_gdb(sig));
|
||||
gdb_put_packet(buf);
|
||||
}
|
||||
|
||||
static void gdb_accept_init(int fd)
|
||||
{
|
||||
gdb_init_gdbserver_state();
|
||||
gdb_create_default_process(&gdbserver_state);
|
||||
gdbserver_state.processes[0].attached = true;
|
||||
gdbserver_state.c_cpu = gdb_first_attached_cpu();
|
||||
gdbserver_state.g_cpu = gdbserver_state.c_cpu;
|
||||
gdbserver_user_state.fd = fd;
|
||||
gdb_has_xml = false;
|
||||
}
|
||||
|
||||
static bool gdb_accept_socket(int gdb_fd)
|
||||
{
|
||||
int fd;
|
||||
|
||||
for (;;) {
|
||||
fd = accept(gdb_fd, NULL, NULL);
|
||||
if (fd < 0 && errno != EINTR) {
|
||||
perror("accept socket");
|
||||
return false;
|
||||
} else if (fd >= 0) {
|
||||
qemu_set_cloexec(fd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gdb_accept_init(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
static int gdbserver_open_socket(const char *path)
|
||||
{
|
||||
struct sockaddr_un sockaddr = {};
|
||||
int fd, ret;
|
||||
|
||||
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
perror("create socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
sockaddr.sun_family = AF_UNIX;
|
||||
pstrcpy(sockaddr.sun_path, sizeof(sockaddr.sun_path) - 1, path);
|
||||
ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
|
||||
if (ret < 0) {
|
||||
perror("bind socket");
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
ret = listen(fd, 1);
|
||||
if (ret < 0) {
|
||||
perror("listen socket");
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
static bool gdb_accept_tcp(int gdb_fd)
|
||||
{
|
||||
struct sockaddr_in sockaddr = {};
|
||||
socklen_t len;
|
||||
int fd;
|
||||
|
||||
for (;;) {
|
||||
len = sizeof(sockaddr);
|
||||
fd = accept(gdb_fd, (struct sockaddr *)&sockaddr, &len);
|
||||
if (fd < 0 && errno != EINTR) {
|
||||
perror("accept");
|
||||
return false;
|
||||
} else if (fd >= 0) {
|
||||
qemu_set_cloexec(fd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* set short latency */
|
||||
if (socket_set_nodelay(fd)) {
|
||||
perror("setsockopt");
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
gdb_accept_init(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
static int gdbserver_open_port(int port)
|
||||
{
|
||||
struct sockaddr_in sockaddr;
|
||||
int fd, ret;
|
||||
|
||||
fd = socket(PF_INET, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
perror("socket");
|
||||
return -1;
|
||||
}
|
||||
qemu_set_cloexec(fd);
|
||||
|
||||
socket_set_fast_reuse(fd);
|
||||
|
||||
sockaddr.sin_family = AF_INET;
|
||||
sockaddr.sin_port = htons(port);
|
||||
sockaddr.sin_addr.s_addr = 0;
|
||||
ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
|
||||
if (ret < 0) {
|
||||
perror("bind");
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
ret = listen(fd, 1);
|
||||
if (ret < 0) {
|
||||
perror("listen");
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
int gdbserver_start(const char *port_or_path)
|
||||
{
|
||||
int port = g_ascii_strtoull(port_or_path, NULL, 10);
|
||||
int gdb_fd;
|
||||
|
||||
if (port > 0) {
|
||||
gdb_fd = gdbserver_open_port(port);
|
||||
} else {
|
||||
gdb_fd = gdbserver_open_socket(port_or_path);
|
||||
}
|
||||
|
||||
if (gdb_fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (port > 0 && gdb_accept_tcp(gdb_fd)) {
|
||||
return 0;
|
||||
} else if (gdb_accept_socket(gdb_fd)) {
|
||||
gdbserver_user_state.socket_path = g_strdup(port_or_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* gone wrong */
|
||||
close(gdb_fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Disable gdb stub for child processes. */
|
||||
void gdbserver_fork(CPUState *cpu)
|
||||
{
|
||||
if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
|
||||
return;
|
||||
}
|
||||
close(gdbserver_user_state.fd);
|
||||
gdbserver_user_state.fd = -1;
|
||||
cpu_breakpoint_remove_all(cpu, BP_GDB);
|
||||
/* no cpu_watchpoint_remove_all for user-mode */
|
||||
}
|
||||
|
||||
/*
|
||||
* Execution state helpers
|
||||
*/
|
||||
|
||||
void gdb_handle_query_attached(GArray *params, void *user_ctx)
|
||||
{
|
||||
gdb_put_packet("0");
|
||||
}
|
||||
|
||||
void gdb_continue(void)
|
||||
{
|
||||
gdbserver_user_state.running_state = 1;
|
||||
trace_gdbstub_op_continue();
|
||||
}
|
||||
|
||||
/*
|
||||
* Resume execution, for user-mode emulation it's equivalent to
|
||||
* gdb_continue.
|
||||
*/
|
||||
int gdb_continue_partial(char *newstates)
|
||||
{
|
||||
CPUState *cpu;
|
||||
int res = 0;
|
||||
/*
|
||||
* This is not exactly accurate, but it's an improvement compared to the
|
||||
* previous situation, where only one CPU would be single-stepped.
|
||||
*/
|
||||
CPU_FOREACH(cpu) {
|
||||
if (newstates[cpu->cpu_index] == 's') {
|
||||
trace_gdbstub_op_stepping(cpu->cpu_index);
|
||||
cpu_single_step(cpu, gdbserver_state.sstep_flags);
|
||||
}
|
||||
}
|
||||
gdbserver_user_state.running_state = 1;
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* Memory access helpers
|
||||
*/
|
||||
int gdb_target_memory_rw_debug(CPUState *cpu, hwaddr addr,
|
||||
uint8_t *buf, int len, bool is_write)
|
||||
{
|
||||
CPUClass *cc;
|
||||
|
||||
cc = CPU_GET_CLASS(cpu);
|
||||
if (cc->memory_rw_debug) {
|
||||
return cc->memory_rw_debug(cpu, addr, buf, len, is_write);
|
||||
}
|
||||
return cpu_memory_rw_debug(cpu, addr, buf, len, is_write);
|
||||
}
|
||||
|
||||
/*
|
||||
* cpu helpers
|
||||
*/
|
||||
|
||||
unsigned int gdb_get_max_cpus(void)
|
||||
{
|
||||
CPUState *cpu;
|
||||
unsigned int max_cpus = 1;
|
||||
|
||||
CPU_FOREACH(cpu) {
|
||||
max_cpus = max_cpus <= cpu->cpu_index ? cpu->cpu_index + 1 : max_cpus;
|
||||
}
|
||||
|
||||
return max_cpus;
|
||||
}
|
||||
|
||||
/* replay not supported for user-mode */
|
||||
bool gdb_can_reverse(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Break/Watch point helpers
|
||||
*/
|
||||
|
||||
bool gdb_supports_guest_debug(void)
|
||||
{
|
||||
/* user-mode == TCG == supported */
|
||||
@@ -65,3 +472,17 @@ void gdb_breakpoint_remove_all(CPUState *cs)
|
||||
{
|
||||
cpu_breakpoint_remove_all(cs, BP_GDB);
|
||||
}
|
||||
|
||||
/*
|
||||
* For user-mode syscall support we send the system call immediately
|
||||
* and then return control to gdb for it to process the syscall request.
|
||||
* Since the protocol requires that gdb hands control back to us
|
||||
* using a "here are the results" F packet, we don't need to check
|
||||
* gdb_handlesig's return value (which is the signal to deliver if
|
||||
* execution was resumed via a continue packet).
|
||||
*/
|
||||
void gdb_syscall_handling(const char *syscall_packet)
|
||||
{
|
||||
gdb_put_packet(syscall_packet);
|
||||
gdb_handlesig(gdbserver_state.c_cpu, 0);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "qemu/module.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "exec/exec-all.h"
|
||||
#include "exec/tb-flush.h"
|
||||
#include "helper_regs.h"
|
||||
#include "hw/ppc/ppc.h"
|
||||
#include "hw/ppc/spapr.h"
|
||||
|
||||
+1
-18
@@ -55,24 +55,7 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
|
||||
|
||||
/* target_ulong is the type of a virtual address */
|
||||
#if TARGET_LONG_SIZE == 4
|
||||
typedef int32_t target_long;
|
||||
typedef uint32_t target_ulong;
|
||||
#define TARGET_FMT_lx "%08x"
|
||||
#define TARGET_FMT_ld "%d"
|
||||
#define TARGET_FMT_lu "%u"
|
||||
#elif TARGET_LONG_SIZE == 8
|
||||
typedef int64_t target_long;
|
||||
typedef uint64_t target_ulong;
|
||||
#define TARGET_FMT_lx "%016" PRIx64
|
||||
#define TARGET_FMT_ld "%" PRId64
|
||||
#define TARGET_FMT_lu "%" PRIu64
|
||||
#else
|
||||
#error TARGET_LONG_SIZE undefined
|
||||
#endif
|
||||
#include "exec/target_long.h"
|
||||
|
||||
#if !defined(CONFIG_USER_ONLY) && defined(CONFIG_TCG)
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user