1,655 changes: 142 additions & 1,513 deletions gdbstub/gdbstub.c

Large diffs are not rendered by default.

212 changes: 209 additions & 3 deletions gdbstub/internals.h
Expand Up @@ -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 */
34 changes: 31 additions & 3 deletions gdbstub/meson.build
Expand Up @@ -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'))
603 changes: 602 additions & 1 deletion gdbstub/softmmu.c

Large diffs are not rendered by default.

205 changes: 205 additions & 0 deletions gdbstub/syscalls.c
@@ -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();
}
4 changes: 3 additions & 1 deletion gdbstub/trace-events
Expand Up @@ -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"
Expand All @@ -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 ""
283 changes: 283 additions & 0 deletions gdbstub/user-target.c
@@ -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
423 changes: 422 additions & 1 deletion gdbstub/user.c

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions hw/ppc/spapr_hcall.c
Expand Up @@ -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"
Expand Down
19 changes: 1 addition & 18 deletions include/exec/cpu-defs.h
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion include/exec/exec-all.h
Expand Up @@ -677,7 +677,6 @@ void tb_invalidate_phys_addr(target_ulong addr);
#else
void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs);
#endif
void tb_flush(CPUState *cpu);
void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr);
void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end);
void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr);
Expand Down
208 changes: 0 additions & 208 deletions include/exec/gdbstub.h
Expand Up @@ -10,212 +10,14 @@
#define GDB_WATCHPOINT_READ 3
#define GDB_WATCHPOINT_ACCESS 4

/* For gdb file i/o remote protocol open flags. */
#define GDB_O_RDONLY 0
#define GDB_O_WRONLY 1
#define GDB_O_RDWR 2
#define GDB_O_APPEND 8
#define GDB_O_CREAT 0x200
#define GDB_O_TRUNC 0x400
#define GDB_O_EXCL 0x800

/* For gdb file i/o remote protocol errno values */
#define GDB_EPERM 1
#define GDB_ENOENT 2
#define GDB_EINTR 4
#define GDB_EBADF 9
#define GDB_EACCES 13
#define GDB_EFAULT 14
#define GDB_EBUSY 16
#define GDB_EEXIST 17
#define GDB_ENODEV 19
#define GDB_ENOTDIR 20
#define GDB_EISDIR 21
#define GDB_EINVAL 22
#define GDB_ENFILE 23
#define GDB_EMFILE 24
#define GDB_EFBIG 27
#define GDB_ENOSPC 28
#define GDB_ESPIPE 29
#define GDB_EROFS 30
#define GDB_ENAMETOOLONG 91
#define GDB_EUNKNOWN 9999

/* For gdb file i/o remote protocol lseek whence. */
#define GDB_SEEK_SET 0
#define GDB_SEEK_CUR 1
#define GDB_SEEK_END 2

/* For gdb file i/o stat/fstat. */
typedef uint32_t gdb_mode_t;
typedef uint32_t gdb_time_t;

struct gdb_stat {
uint32_t gdb_st_dev; /* device */
uint32_t gdb_st_ino; /* inode */
gdb_mode_t gdb_st_mode; /* protection */
uint32_t gdb_st_nlink; /* number of hard links */
uint32_t gdb_st_uid; /* user ID of owner */
uint32_t gdb_st_gid; /* group ID of owner */
uint32_t gdb_st_rdev; /* device type (if inode device) */
uint64_t gdb_st_size; /* total size, in bytes */
uint64_t gdb_st_blksize; /* blocksize for filesystem I/O */
uint64_t gdb_st_blocks; /* number of blocks allocated */
gdb_time_t gdb_st_atime; /* time of last access */
gdb_time_t gdb_st_mtime; /* time of last modification */
gdb_time_t gdb_st_ctime; /* time of last change */
} QEMU_PACKED;

struct gdb_timeval {
gdb_time_t tv_sec; /* second */
uint64_t tv_usec; /* microsecond */
} QEMU_PACKED;

#ifdef NEED_CPU_H
#include "cpu.h"

typedef void (*gdb_syscall_complete_cb)(CPUState *cpu, uint64_t ret, int err);

/**
* gdb_do_syscall:
* @cb: function to call when the system call has completed
* @fmt: gdb syscall format string
* ...: list of arguments to interpolate into @fmt
*
* Send a GDB syscall request. This function will return immediately;
* the callback function will be called later when the remote system
* call has completed.
*
* @fmt should be in the 'call-id,parameter,parameter...' format documented
* for the F request packet in the GDB remote protocol. A limited set of
* printf-style format specifiers is supported:
* %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, ...);
/**
* gdb_do_syscallv:
* @cb: function to call when the system call has completed
* @fmt: gdb syscall format string
* @va: arguments to interpolate into @fmt
*
* As gdb_do_syscall, but taking a va_list rather than a variable
* argument list.
*/
void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va);
int use_gdb_syscalls(void);

#ifdef CONFIG_USER_ONLY
/**
* gdb_handlesig: yield control to gdb
* @cpu: CPU
* @sig: if non-zero, the signal number which caused us to stop
*
* This function yields control to gdb, when a user-mode-only target
* needs to stop execution. If @sig is non-zero, then we will send a
* stop packet to tell gdb that we have stopped because of this signal.
*
* This function will block (handling protocol requests from gdb)
* until gdb tells us to continue target execution. When it does
* return, the return value is a signal to deliver to the target,
* or 0 if no signal should be delivered, ie the signal that caused
* us to stop should be ignored.
*/
int gdb_handlesig(CPUState *, int);
void gdb_signalled(CPUArchState *, int);
void gdbserver_fork(CPUState *);
#endif
/* Get or set a register. Returns the size of the register. */
typedef int (*gdb_get_reg_cb)(CPUArchState *env, GByteArray *buf, int reg);
typedef int (*gdb_set_reg_cb)(CPUArchState *env, uint8_t *buf, int reg);
void gdb_register_coprocessor(CPUState *cpu,
gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg,
int num_regs, const char *xml, int g_pos);

/*
* The GDB remote protocol transfers values in target byte order. As
* the gdbstub may be batching up several register values we always
* append to the array.
*/

static inline int gdb_get_reg8(GByteArray *buf, uint8_t val)
{
g_byte_array_append(buf, &val, 1);
return 1;
}

static inline int gdb_get_reg16(GByteArray *buf, uint16_t val)
{
uint16_t to_word = tswap16(val);
g_byte_array_append(buf, (uint8_t *) &to_word, 2);
return 2;
}

static inline int gdb_get_reg32(GByteArray *buf, uint32_t val)
{
uint32_t to_long = tswap32(val);
g_byte_array_append(buf, (uint8_t *) &to_long, 4);
return 4;
}

static inline int gdb_get_reg64(GByteArray *buf, uint64_t val)
{
uint64_t to_quad = tswap64(val);
g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
return 8;
}

static inline int gdb_get_reg128(GByteArray *buf, uint64_t val_hi,
uint64_t val_lo)
{
uint64_t to_quad;
#if TARGET_BIG_ENDIAN
to_quad = tswap64(val_hi);
g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
to_quad = tswap64(val_lo);
g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
#else
to_quad = tswap64(val_lo);
g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
to_quad = tswap64(val_hi);
g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
#endif
return 16;
}

static inline int gdb_get_zeroes(GByteArray *array, size_t len)
{
guint oldlen = array->len;
g_byte_array_set_size(array, oldlen + len);
memset(array->data + oldlen, 0, len);

return len;
}

/**
* gdb_get_reg_ptr: get pointer to start of last element
* @len: length of element
*
* This is a helper function to extract the pointer to the last
* element for additional processing. Some front-ends do additional
* dynamic swapping of the elements based on CPU state.
*/
static inline uint8_t * gdb_get_reg_ptr(GByteArray *buf, int len)
{
return buf->data + buf->len - len;
}

#if TARGET_LONG_BITS == 64
#define gdb_get_regl(buf, val) gdb_get_reg64(buf, val)
#define ldtul_p(addr) ldq_p(addr)
#else
#define gdb_get_regl(buf, val) gdb_get_reg32(buf, val)
#define ldtul_p(addr) ldl_p(addr)
#endif

#endif /* NEED_CPU_H */

/**
* gdbserver_start: start the gdb server
* @port_or_device: connection spec for gdb
Expand All @@ -226,16 +28,6 @@ static inline uint8_t * gdb_get_reg_ptr(GByteArray *buf, int len)
*/
int gdbserver_start(const char *port_or_device);

/**
* gdb_exit: exit gdb session, reporting inferior status
* @code: exit code reported
*
* This closes the session and sends a final packet to GDB reporting
* the exit status of the program. It also cleans up any connections
* detritus before returning.
*/
void gdb_exit(int code);

void gdb_set_stop_cpu(CPUState *cpu);

/**
Expand Down
42 changes: 42 additions & 0 deletions include/exec/target_long.h
@@ -0,0 +1,42 @@
/*
* Target Long Definitions
*
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2023 Linaro Ltd
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#ifndef _TARGET_LONG_H_
#define _TARGET_LONG_H_

/*
* Usually this should only be included via cpu-defs.h however for
* certain cases where we want to build only two versions of a binary
* object we can include directly. However the build-system must
* ensure TARGET_LONG_BITS is defined directly.
*/
#ifndef TARGET_LONG_BITS
#error TARGET_LONG_BITS not defined
#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

#endif /* _TARGET_LONG_H_ */
26 changes: 26 additions & 0 deletions include/exec/tb-flush.h
@@ -0,0 +1,26 @@
/*
* tb-flush prototype for use by the rest of the system.
*
* Copyright (c) 2022 Linaro Ltd
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef _TB_FLUSH_H_
#define _TB_FLUSH_H_

/**
* tb_flush() - flush all translation blocks
* @cs: CPUState (must be valid, but treated as anonymous pointer)
*
* Used to flush all the translation blocks in the system. Sometimes
* it is simpler to flush everything than work out which individual
* translations are now invalid and ensure they are not called
* anymore.
*
* tb_flush() takes care of running the flush in an exclusive context
* if it is not already running in one. This means no guest code will
* run until this complete.
*/
void tb_flush(CPUState *cs);

#endif /* _TB_FLUSH_H_ */
103 changes: 103 additions & 0 deletions include/gdbstub/helpers.h
@@ -0,0 +1,103 @@
/*
* gdbstub helpers
*
* These are all used by the various frontends and have to be host
* aware to ensure things are store in target order.
*
* Copyright (c) 2022 Linaro Ltd
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#ifndef _GDBSTUB_HELPERS_H_
#define _GDBSTUB_HELPERS_H_

#ifdef NEED_CPU_H
#include "cpu.h"

/*
* The GDB remote protocol transfers values in target byte order. As
* the gdbstub may be batching up several register values we always
* append to the array.
*/

static inline int gdb_get_reg8(GByteArray *buf, uint8_t val)
{
g_byte_array_append(buf, &val, 1);
return 1;
}

static inline int gdb_get_reg16(GByteArray *buf, uint16_t val)
{
uint16_t to_word = tswap16(val);
g_byte_array_append(buf, (uint8_t *) &to_word, 2);
return 2;
}

static inline int gdb_get_reg32(GByteArray *buf, uint32_t val)
{
uint32_t to_long = tswap32(val);
g_byte_array_append(buf, (uint8_t *) &to_long, 4);
return 4;
}

static inline int gdb_get_reg64(GByteArray *buf, uint64_t val)
{
uint64_t to_quad = tswap64(val);
g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
return 8;
}

static inline int gdb_get_reg128(GByteArray *buf, uint64_t val_hi,
uint64_t val_lo)
{
uint64_t to_quad;
#if TARGET_BIG_ENDIAN
to_quad = tswap64(val_hi);
g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
to_quad = tswap64(val_lo);
g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
#else
to_quad = tswap64(val_lo);
g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
to_quad = tswap64(val_hi);
g_byte_array_append(buf, (uint8_t *) &to_quad, 8);
#endif
return 16;
}

static inline int gdb_get_zeroes(GByteArray *array, size_t len)
{
guint oldlen = array->len;
g_byte_array_set_size(array, oldlen + len);
memset(array->data + oldlen, 0, len);

return len;
}

/**
* gdb_get_reg_ptr: get pointer to start of last element
* @len: length of element
*
* This is a helper function to extract the pointer to the last
* element for additional processing. Some front-ends do additional
* dynamic swapping of the elements based on CPU state.
*/
static inline uint8_t *gdb_get_reg_ptr(GByteArray *buf, int len)
{
return buf->data + buf->len - len;
}

#if TARGET_LONG_BITS == 64
#define gdb_get_regl(buf, val) gdb_get_reg64(buf, val)
#define ldtul_p(addr) ldq_p(addr)
#else
#define gdb_get_regl(buf, val) gdb_get_reg32(buf, val)
#define ldtul_p(addr) ldl_p(addr)
#endif

#else
#error "gdbstub helpers should only be included by target specific code"
#endif

#endif /* _GDBSTUB_HELPERS_H_ */
113 changes: 113 additions & 0 deletions include/gdbstub/syscalls.h
@@ -0,0 +1,113 @@
/*
* GDB Syscall support
*
* Copyright (c) 2023 Linaro Ltd
*
* SPDX-License-Identifier: LGPL-2.0+
*/

#ifndef _SYSCALLS_H_
#define _SYSCALLS_H_

/* For gdb file i/o remote protocol open flags. */
#define GDB_O_RDONLY 0
#define GDB_O_WRONLY 1
#define GDB_O_RDWR 2
#define GDB_O_APPEND 8
#define GDB_O_CREAT 0x200
#define GDB_O_TRUNC 0x400
#define GDB_O_EXCL 0x800

/* For gdb file i/o remote protocol errno values */
#define GDB_EPERM 1
#define GDB_ENOENT 2
#define GDB_EINTR 4
#define GDB_EBADF 9
#define GDB_EACCES 13
#define GDB_EFAULT 14
#define GDB_EBUSY 16
#define GDB_EEXIST 17
#define GDB_ENODEV 19
#define GDB_ENOTDIR 20
#define GDB_EISDIR 21
#define GDB_EINVAL 22
#define GDB_ENFILE 23
#define GDB_EMFILE 24
#define GDB_EFBIG 27
#define GDB_ENOSPC 28
#define GDB_ESPIPE 29
#define GDB_EROFS 30
#define GDB_ENAMETOOLONG 91
#define GDB_EUNKNOWN 9999

/* For gdb file i/o remote protocol lseek whence. */
#define GDB_SEEK_SET 0
#define GDB_SEEK_CUR 1
#define GDB_SEEK_END 2

/* For gdb file i/o stat/fstat. */
typedef uint32_t gdb_mode_t;
typedef uint32_t gdb_time_t;

struct gdb_stat {
uint32_t gdb_st_dev; /* device */
uint32_t gdb_st_ino; /* inode */
gdb_mode_t gdb_st_mode; /* protection */
uint32_t gdb_st_nlink; /* number of hard links */
uint32_t gdb_st_uid; /* user ID of owner */
uint32_t gdb_st_gid; /* group ID of owner */
uint32_t gdb_st_rdev; /* device type (if inode device) */
uint64_t gdb_st_size; /* total size, in bytes */
uint64_t gdb_st_blksize; /* blocksize for filesystem I/O */
uint64_t gdb_st_blocks; /* number of blocks allocated */
gdb_time_t gdb_st_atime; /* time of last access */
gdb_time_t gdb_st_mtime; /* time of last modification */
gdb_time_t gdb_st_ctime; /* time of last change */
} QEMU_PACKED;

struct gdb_timeval {
gdb_time_t tv_sec; /* second */
uint64_t tv_usec; /* microsecond */
} QEMU_PACKED;

typedef void (*gdb_syscall_complete_cb)(CPUState *cpu, uint64_t ret, int err);

/**
* gdb_do_syscall:
* @cb: function to call when the system call has completed
* @fmt: gdb syscall format string
* ...: list of arguments to interpolate into @fmt
*
* Send a GDB syscall request. This function will return immediately;
* the callback function will be called later when the remote system
* call has completed.
*
* @fmt should be in the 'call-id,parameter,parameter...' format documented
* for the F request packet in the GDB remote protocol. A limited set of
* printf-style format specifiers is supported:
* %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, ...);

/**
* use_gdb_syscalls() - report if GDB should be used for syscalls
*
* This is mostly driven by the semihosting mode the user configures
* but assuming GDB is allowed by that we report true if GDB is
* connected to the stub.
*/
int use_gdb_syscalls(void);

/**
* gdb_exit: exit gdb session, reporting inferior status
* @code: exit code reported
*
* This closes the session and sends a final packet to GDB reporting
* the exit status of the program. It also cleans up any connections
* detritus before returning.
*/
void gdb_exit(int code);

#endif /* _SYSCALLS_H_ */
43 changes: 43 additions & 0 deletions include/gdbstub/user.h
@@ -0,0 +1,43 @@
/*
* gdbstub user-mode only APIs
*
* Copyright (c) 2022 Linaro Ltd
*
* SPDX-License-Identifier: LGPL-2.0+
*/

#ifndef GDBSTUB_USER_H
#define GDBSTUB_USER_H

/**
* gdb_handlesig() - yield control to gdb
* @cpu: CPU
* @sig: if non-zero, the signal number which caused us to stop
*
* This function yields control to gdb, when a user-mode-only target
* needs to stop execution. If @sig is non-zero, then we will send a
* stop packet to tell gdb that we have stopped because of this signal.
*
* This function will block (handling protocol requests from gdb)
* until gdb tells us to continue target execution. When it does
* return, the return value is a signal to deliver to the target,
* or 0 if no signal should be delivered, ie the signal that caused
* us to stop should be ignored.
*/
int gdb_handlesig(CPUState *, int);

/**
* gdb_signalled() - inform remote gdb of sig exit
* @as: current CPUArchState
* @sig: signal number
*/
void gdb_signalled(CPUArchState *as, int sig);

/**
* gdbserver_fork() - disable gdb stub for child processes.
* @cs: CPU
*/
void gdbserver_fork(CPUState *cs);


#endif /* GDBSTUB_USER_H */
1 change: 1 addition & 0 deletions include/sysemu/accel-ops.h
Expand Up @@ -48,6 +48,7 @@ struct AccelOpsClass {

/* gdbstub hooks */
bool (*supports_guest_debug)(void);
int (*update_guest_debug)(CPUState *cpu);
int (*insert_breakpoint)(CPUState *cpu, int type, vaddr addr, vaddr len);
int (*remove_breakpoint)(CPUState *cpu, int type, vaddr addr, vaddr len);
void (*remove_all_breakpoints)(CPUState *cpu);
Expand Down
2 changes: 1 addition & 1 deletion linux-user/exit.c
Expand Up @@ -18,7 +18,7 @@
*/
#include "qemu/osdep.h"
#include "accel/tcg/perf.h"
#include "exec/gdbstub.h"
#include "gdbstub/syscalls.h"
#include "qemu.h"
#include "user-internals.h"
#ifdef CONFIG_GPROF
Expand Down
1 change: 1 addition & 0 deletions linux-user/main.c
Expand Up @@ -40,6 +40,7 @@
#include "qemu/plugin.h"
#include "exec/exec-all.h"
#include "exec/gdbstub.h"
#include "gdbstub/user.h"
#include "tcg/tcg.h"
#include "qemu/timer.h"
#include "qemu/envlist.h"
Expand Down
2 changes: 1 addition & 1 deletion linux-user/signal.c
Expand Up @@ -18,7 +18,7 @@
*/
#include "qemu/osdep.h"
#include "qemu/bitops.h"
#include "exec/gdbstub.h"
#include "gdbstub/user.h"
#include "hw/core/tcg-cpu-ops.h"

#include <sys/ucontext.h>
Expand Down
1 change: 1 addition & 0 deletions linux-user/user-internals.h
Expand Up @@ -20,6 +20,7 @@

#include "exec/user/thunk.h"
#include "exec/exec-all.h"
#include "exec/tb-flush.h"
#include "qemu/log.h"

extern char *exec_path;
Expand Down
Binary file modified pc-bios/openbios-ppc
Binary file not shown.
Binary file modified pc-bios/openbios-sparc32
Binary file not shown.
Binary file modified pc-bios/openbios-sparc64
Binary file not shown.
1 change: 1 addition & 0 deletions plugins/core.c
Expand Up @@ -24,6 +24,7 @@
#include "exec/cpu-common.h"

#include "exec/exec-all.h"
#include "exec/tb-flush.h"
#include "exec/helper-proto.h"
#include "tcg/tcg.h"
#include "tcg/tcg-op.h"
Expand Down
2 changes: 1 addition & 1 deletion plugins/loader.c
Expand Up @@ -29,7 +29,7 @@
#include "qemu/plugin.h"
#include "qemu/memalign.h"
#include "hw/core/cpu.h"
#include "exec/exec-all.h"
#include "exec/tb-flush.h"
#ifndef CONFIG_USER_ONLY
#include "hw/boards.h"
#endif
Expand Down
2 changes: 1 addition & 1 deletion roms/openbios
Submodule openbios updated from 0e0afa to af97fd
88 changes: 88 additions & 0 deletions scripts/probe-gdb-support.py
@@ -0,0 +1,88 @@
#!/usr/bin/env python3
# coding: utf-8
#
# Probe gdb for supported architectures.
#
# This is required to support testing of the gdbstub as its hard to
# handle errors gracefully during the test. Instead this script when
# passed a GDB binary will probe its architecture support and return a
# string of supported arches, stripped of guff.
#
# Copyright 2023 Linaro Ltd
#
# Author: Alex Bennée <alex.bennee@linaro.org>
#
# This work is licensed under the terms of the GNU GPL, version 2 or later.
# See the COPYING file in the top-level directory.
#
# SPDX-License-Identifier: GPL-2.0-or-later

import argparse
import re
from subprocess import check_output, STDOUT

# mappings from gdb arch to QEMU target
mappings = {
"alpha" : "alpha",
"aarch64" : ["aarch64", "aarch64_be"],
"armv7": "arm",
"armv8-a" : ["aarch64", "aarch64_be"],
"avr" : "avr",
"cris" : "cris",
# no hexagon in upstream gdb
"hppa1.0" : "hppa",
"i386" : "i386",
"i386:x86-64" : "x86_64",
"Loongarch64" : "loongarch64",
"m68k" : "m68k",
"MicroBlaze" : "microblaze",
"mips:isa64" : ["mips64", "mips64el"],
"nios2" : "nios2",
"or1k" : "or1k",
"powerpc:common" : "ppc",
"powerpc:common64" : ["ppc64", "ppc64le"],
"riscv:rv32" : "riscv32",
"riscv:rv64" : "riscv64",
"s390:64-bit" : "s390x",
"sh4" : ["sh4", "sh4eb"],
"sparc": "sparc",
"sparc:v8plus": "sparc32plus",
"sparc:v9a" : "sparc64",
# no tricore in upstream gdb
"xtensa" : ["xtensa", "xtensaeb"]
}

def do_probe(gdb):
gdb_out = check_output([gdb,
"-ex", "set architecture",
"-ex", "quit"], stderr=STDOUT)

m = re.search(r"Valid arguments are (.*)",
gdb_out.decode("utf-8"))

valid_arches = set()

if m.group(1):
for arch in m.group(1).split(", "):
if arch in mappings:
mapping = mappings[arch]
if isinstance(mapping, str):
valid_arches.add(mapping)
else:
for entry in mapping:
valid_arches.add(entry)

return valid_arches

def main() -> None:
parser = argparse.ArgumentParser(description='Probe GDB Architectures')
parser.add_argument('gdb', help='Path to GDB binary.')

args = parser.parse_args()

supported = do_probe(args.gdb)

print(" ".join(supported))

if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions semihosting/arm-compat-semi.c
Expand Up @@ -34,6 +34,7 @@
#include "qemu/osdep.h"
#include "qemu/timer.h"
#include "exec/gdbstub.h"
#include "gdbstub/syscalls.h"
#include "semihosting/semihost.h"
#include "semihosting/console.h"
#include "semihosting/common-semi.h"
Expand Down
2 changes: 1 addition & 1 deletion semihosting/guestfd.c
Expand Up @@ -9,7 +9,7 @@
*/

#include "qemu/osdep.h"
#include "exec/gdbstub.h"
#include "gdbstub/syscalls.h"
#include "semihosting/semihost.h"
#include "semihosting/guestfd.h"
#ifdef CONFIG_USER_ONLY
Expand Down
37 changes: 22 additions & 15 deletions semihosting/syscalls.c
Expand Up @@ -7,7 +7,8 @@
*/

#include "qemu/osdep.h"
#include "exec/gdbstub.h"
#include "cpu.h"
#include "gdbstub/syscalls.h"
#include "semihosting/guestfd.h"
#include "semihosting/syscalls.h"
#include "semihosting/console.h"
Expand Down Expand Up @@ -138,46 +139,48 @@ static void gdb_open(CPUState *cs, gdb_syscall_complete_cb complete,

gdb_open_complete = complete;
gdb_do_syscall(gdb_open_cb, "open,%s,%x,%x",
fname, len, (target_ulong)gdb_flags, (target_ulong)mode);
(uint64_t)fname, (uint32_t)len,
(uint32_t)gdb_flags, (uint32_t)mode);
}

static void gdb_close(CPUState *cs, gdb_syscall_complete_cb complete,
GuestFD *gf)
{
gdb_do_syscall(complete, "close,%x", (target_ulong)gf->hostfd);
gdb_do_syscall(complete, "close,%x", (uint32_t)gf->hostfd);
}

static void gdb_read(CPUState *cs, gdb_syscall_complete_cb complete,
GuestFD *gf, target_ulong buf, target_ulong len)
{
gdb_do_syscall(complete, "read,%x,%x,%x",
(target_ulong)gf->hostfd, buf, len);
gdb_do_syscall(complete, "read,%x,%lx,%lx",
(uint32_t)gf->hostfd, (uint64_t)buf, (uint64_t)len);
}

static void gdb_write(CPUState *cs, gdb_syscall_complete_cb complete,
GuestFD *gf, target_ulong buf, target_ulong len)
{
gdb_do_syscall(complete, "write,%x,%x,%x",
(target_ulong)gf->hostfd, buf, len);
gdb_do_syscall(complete, "write,%x,%lx,%lx",
(uint32_t)gf->hostfd, (uint64_t)buf, (uint64_t)len);
}

static void gdb_lseek(CPUState *cs, gdb_syscall_complete_cb complete,
GuestFD *gf, int64_t off, int gdb_whence)
{
gdb_do_syscall(complete, "lseek,%x,%lx,%x",
(target_ulong)gf->hostfd, off, (target_ulong)gdb_whence);
(uint32_t)gf->hostfd, off, (uint32_t)gdb_whence);
}

static void gdb_isatty(CPUState *cs, gdb_syscall_complete_cb complete,
GuestFD *gf)
{
gdb_do_syscall(complete, "isatty,%x", (target_ulong)gf->hostfd);
gdb_do_syscall(complete, "isatty,%x", (uint32_t)gf->hostfd);
}

static void gdb_fstat(CPUState *cs, gdb_syscall_complete_cb complete,
GuestFD *gf, target_ulong addr)
{
gdb_do_syscall(complete, "fstat,%x,%x", (target_ulong)gf->hostfd, addr);
gdb_do_syscall(complete, "fstat,%x,%lx",
(uint32_t)gf->hostfd, (uint64_t)addr);
}

static void gdb_stat(CPUState *cs, gdb_syscall_complete_cb complete,
Expand All @@ -190,7 +193,8 @@ static void gdb_stat(CPUState *cs, gdb_syscall_complete_cb complete,
return;
}

gdb_do_syscall(complete, "stat,%s,%x", fname, len, addr);
gdb_do_syscall(complete, "stat,%s,%lx",
(uint64_t)fname, (uint32_t)len, (uint64_t)addr);
}

static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete,
Expand All @@ -202,7 +206,7 @@ static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete,
return;
}

gdb_do_syscall(complete, "unlink,%s", fname, len);
gdb_do_syscall(complete, "unlink,%s", (uint64_t)fname, (uint32_t)len);
}

static void gdb_rename(CPUState *cs, gdb_syscall_complete_cb complete,
Expand All @@ -222,7 +226,9 @@ static void gdb_rename(CPUState *cs, gdb_syscall_complete_cb complete,
return;
}

gdb_do_syscall(complete, "rename,%s,%s", oname, olen, nname, nlen);
gdb_do_syscall(complete, "rename,%s,%s",
(uint64_t)oname, (uint32_t)olen,
(uint64_t)nname, (uint32_t)nlen);
}

static void gdb_system(CPUState *cs, gdb_syscall_complete_cb complete,
Expand All @@ -234,13 +240,14 @@ static void gdb_system(CPUState *cs, gdb_syscall_complete_cb complete,
return;
}

gdb_do_syscall(complete, "system,%s", cmd, len);
gdb_do_syscall(complete, "system,%s", (uint64_t)cmd, (uint32_t)len);
}

static void gdb_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete,
target_ulong tv_addr, target_ulong tz_addr)
{
gdb_do_syscall(complete, "gettimeofday,%x,%x", tv_addr, tz_addr);
gdb_do_syscall(complete, "gettimeofday,%lx,%lx",
(uint64_t)tv_addr, (uint64_t)tz_addr);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion softmmu/runstate.c
Expand Up @@ -30,7 +30,7 @@
#include "crypto/cipher.h"
#include "crypto/init.h"
#include "exec/cpu-common.h"
#include "exec/gdbstub.h"
#include "gdbstub/syscalls.h"
#include "hw/boards.h"
#include "migration/misc.h"
#include "migration/postcopy-ram.h"
Expand Down
1 change: 1 addition & 0 deletions stubs/meson.build
Expand Up @@ -61,4 +61,5 @@ if have_system
else
stub_ss.add(files('qdev.c'))
endif
stub_ss.add(files('semihost-all.c'))
stub_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_false: files('vfio-user-obj.c'))
17 changes: 17 additions & 0 deletions stubs/semihost-all.c
@@ -0,0 +1,17 @@
/*
* Semihosting Stubs for all targets
*
* Copyright (c) 2023 Linaro Ltd
*
* Stubs for all targets that don't actually do semihosting.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "qemu/osdep.h"
#include "semihosting/semihost.h"

SemihostingTarget semihosting_get_target(void)
{
return SEMIHOSTING_TARGET_AUTO;
}
5 changes: 0 additions & 5 deletions stubs/semihost.c
Expand Up @@ -28,11 +28,6 @@ bool semihosting_enabled(bool is_user)
return false;
}

SemihostingTarget semihosting_get_target(void)
{
return SEMIHOSTING_TARGET_AUTO;
}

/*
* All the rest are empty subs. We could g_assert_not_reached() but
* that adds extra weight to the final binary. Waste not want not.
Expand Down
2 changes: 1 addition & 1 deletion target/alpha/gdbstub.c
Expand Up @@ -19,7 +19,7 @@
*/
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"

int alpha_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
{
Expand Down
1 change: 1 addition & 0 deletions target/alpha/sys_helper.c
Expand Up @@ -20,6 +20,7 @@
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/exec-all.h"
#include "exec/tb-flush.h"
#include "exec/helper-proto.h"
#include "sysemu/runstate.h"
#include "sysemu/sysemu.h"
Expand Down
1 change: 1 addition & 0 deletions target/arm/gdbstub.c
Expand Up @@ -20,6 +20,7 @@
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "internals.h"
#include "cpregs.h"

Expand Down
2 changes: 1 addition & 1 deletion target/arm/gdbstub64.c
Expand Up @@ -20,7 +20,7 @@
#include "qemu/log.h"
#include "cpu.h"
#include "internals.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"

int aarch64_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
{
Expand Down
2 changes: 1 addition & 1 deletion target/arm/tcg/helper-a64.c
Expand Up @@ -20,7 +20,7 @@
#include "qemu/osdep.h"
#include "qemu/units.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "exec/helper-proto.h"
#include "qemu/host-utils.h"
#include "qemu/log.h"
Expand Down
1 change: 1 addition & 0 deletions target/arm/tcg/m_helper.c
Expand Up @@ -9,6 +9,7 @@
#include "qemu/osdep.h"
#include "cpu.h"
#include "internals.h"
#include "gdbstub/helpers.h"
#include "exec/helper-proto.h"
#include "qemu/main-loop.h"
#include "qemu/bitops.h"
Expand Down
2 changes: 1 addition & 1 deletion target/avr/gdbstub.c
Expand Up @@ -19,7 +19,7 @@
*/

#include "qemu/osdep.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"

int avr_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
{
Expand Down
2 changes: 1 addition & 1 deletion target/cris/gdbstub.c
Expand Up @@ -19,7 +19,7 @@
*/
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"

int crisv10_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
{
Expand Down
2 changes: 1 addition & 1 deletion target/hexagon/gdbstub.c
Expand Up @@ -16,7 +16,7 @@
*/

#include "qemu/osdep.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "cpu.h"
#include "internal.h"

Expand Down
2 changes: 1 addition & 1 deletion target/hppa/gdbstub.c
Expand Up @@ -19,7 +19,7 @@

#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"

int hppa_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
{
Expand Down
2 changes: 1 addition & 1 deletion target/i386/gdbstub.c
Expand Up @@ -19,7 +19,7 @@
*/
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "include/gdbstub/helpers.h"

#ifdef TARGET_X86_64
static const int gpr_map[16] = {
Expand Down
2 changes: 1 addition & 1 deletion target/i386/whpx/whpx-all.c
Expand Up @@ -12,7 +12,7 @@
#include "cpu.h"
#include "exec/address-spaces.h"
#include "exec/ioport.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "qemu/accel.h"
#include "sysemu/whpx.h"
#include "sysemu/cpus.h"
Expand Down
1 change: 1 addition & 0 deletions target/loongarch/gdbstub.c
Expand Up @@ -10,6 +10,7 @@
#include "cpu.h"
#include "internals.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"

uint64_t read_fcc(CPULoongArchState *env)
{
Expand Down
2 changes: 1 addition & 1 deletion target/m68k/gdbstub.c
Expand Up @@ -19,7 +19,7 @@
*/
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"

int m68k_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
{
Expand Down
1 change: 1 addition & 0 deletions target/m68k/helper.c
Expand Up @@ -23,6 +23,7 @@
#include "exec/exec-all.h"
#include "exec/gdbstub.h"
#include "exec/helper-proto.h"
#include "gdbstub/helpers.h"
#include "fpu/softfloat.h"
#include "qemu/qemu-print.h"

Expand Down
3 changes: 2 additions & 1 deletion target/m68k/m68k-semi.c
Expand Up @@ -20,7 +20,8 @@
#include "qemu/osdep.h"

#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/syscalls.h"
#include "gdbstub/helpers.h"
#include "semihosting/syscalls.h"
#include "semihosting/softmmu-uaccess.h"
#include "hw/boards.h"
Expand Down
2 changes: 1 addition & 1 deletion target/microblaze/gdbstub.c
Expand Up @@ -19,7 +19,7 @@
*/
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"

/*
* GDB expects SREGs in the following order:
Expand Down
2 changes: 1 addition & 1 deletion target/mips/gdbstub.c
Expand Up @@ -20,7 +20,7 @@
#include "qemu/osdep.h"
#include "cpu.h"
#include "internal.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "fpu_helper.h"

int mips_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
Expand Down
3 changes: 2 additions & 1 deletion target/mips/tcg/sysemu/mips-semi.c
Expand Up @@ -20,7 +20,8 @@
#include "qemu/osdep.h"
#include "cpu.h"
#include "qemu/log.h"
#include "exec/gdbstub.h"
#include "gdbstub/syscalls.h"
#include "gdbstub/helpers.h"
#include "semihosting/softmmu-uaccess.h"
#include "semihosting/semihost.h"
#include "semihosting/console.h"
Expand Down
2 changes: 1 addition & 1 deletion target/nios2/cpu.c
Expand Up @@ -23,7 +23,7 @@
#include "qapi/error.h"
#include "cpu.h"
#include "exec/log.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "hw/qdev-properties.h"

static void nios2_cpu_set_pc(CPUState *cs, vaddr value)
Expand Down
3 changes: 2 additions & 1 deletion target/nios2/nios2-semi.c
Expand Up @@ -23,7 +23,8 @@

#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/syscalls.h"
#include "gdbstub/helpers.h"
#include "semihosting/syscalls.h"
#include "semihosting/softmmu-uaccess.h"
#include "qemu/log.h"
Expand Down
2 changes: 1 addition & 1 deletion target/openrisc/gdbstub.c
Expand Up @@ -19,7 +19,7 @@
*/
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"

int openrisc_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
{
Expand Down
2 changes: 1 addition & 1 deletion target/openrisc/interrupt.c
Expand Up @@ -21,7 +21,7 @@
#include "qemu/log.h"
#include "cpu.h"
#include "exec/exec-all.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "qemu/host-utils.h"
#ifndef CONFIG_USER_ONLY
#include "hw/loader.h"
Expand Down
2 changes: 1 addition & 1 deletion target/openrisc/mmu.c
Expand Up @@ -22,7 +22,7 @@
#include "qemu/log.h"
#include "cpu.h"
#include "exec/exec-all.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "qemu/host-utils.h"
#include "hw/loader.h"

Expand Down
2 changes: 1 addition & 1 deletion target/ppc/cpu_init.c
Expand Up @@ -20,7 +20,7 @@

#include "qemu/osdep.h"
#include "disas/dis-asm.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "kvm_ppc.h"
#include "sysemu/cpus.h"
#include "sysemu/hw_accel.h"
Expand Down
1 change: 1 addition & 0 deletions target/ppc/gdbstub.c
Expand Up @@ -20,6 +20,7 @@
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "internal.h"

static int ppc_gdb_register_len_apple(int n)
Expand Down
1 change: 1 addition & 0 deletions target/riscv/csr.c
Expand Up @@ -25,6 +25,7 @@
#include "time_helper.h"
#include "qemu/main-loop.h"
#include "exec/exec-all.h"
#include "exec/tb-flush.h"
#include "sysemu/cpu-timers.h"
#include "qemu/guest-random.h"
#include "qapi/error.h"
Expand Down
1 change: 1 addition & 0 deletions target/riscv/gdbstub.c
Expand Up @@ -18,6 +18,7 @@

#include "qemu/osdep.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "cpu.h"

struct TypeSize {
Expand Down
2 changes: 1 addition & 1 deletion target/rx/gdbstub.c
Expand Up @@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"

int rx_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
{
Expand Down
1 change: 1 addition & 0 deletions target/s390x/gdbstub.c
Expand Up @@ -23,6 +23,7 @@
#include "s390x-internal.h"
#include "exec/exec-all.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "qemu/bitops.h"
#include "sysemu/hw_accel.h"
#include "sysemu/tcg.h"
Expand Down
2 changes: 1 addition & 1 deletion target/s390x/helper.c
Expand Up @@ -21,7 +21,7 @@
#include "qemu/osdep.h"
#include "cpu.h"
#include "s390x-internal.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "qemu/timer.h"
#include "hw/s390x/ioinst.h"
#include "hw/s390x/pv.h"
Expand Down
2 changes: 1 addition & 1 deletion target/sh4/gdbstub.c
Expand Up @@ -19,7 +19,7 @@
*/
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"

/* Hint: Use "set architecture sh4" in GDB to see fpu registers */
/* FIXME: We should use XML for this. */
Expand Down
2 changes: 1 addition & 1 deletion target/sparc/gdbstub.c
Expand Up @@ -19,7 +19,7 @@
*/
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"

#ifdef TARGET_ABI32
#define gdb_get_rega(buf, val) gdb_get_reg32(buf, val)
Expand Down
2 changes: 1 addition & 1 deletion target/tricore/gdbstub.c
Expand Up @@ -18,7 +18,7 @@
*/

#include "qemu/osdep.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"


#define LCX_REGNUM 32
Expand Down
2 changes: 1 addition & 1 deletion target/xtensa/core-dc232b.c
Expand Up @@ -27,7 +27,7 @@

#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "qemu/host-utils.h"
#include "qemu/timer.h"

Expand Down
2 changes: 1 addition & 1 deletion target/xtensa/core-dc233c.c
Expand Up @@ -27,7 +27,7 @@

#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "qemu/host-utils.h"

#include "core-dc233c/core-isa.h"
Expand Down
2 changes: 1 addition & 1 deletion target/xtensa/core-de212.c
Expand Up @@ -27,7 +27,7 @@

#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "qemu/host-utils.h"

#include "core-de212/core-isa.h"
Expand Down
2 changes: 1 addition & 1 deletion target/xtensa/core-de233_fpu.c
Expand Up @@ -27,7 +27,7 @@

#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "qemu/host-utils.h"

#include "core-de233_fpu/core-isa.h"
Expand Down
2 changes: 1 addition & 1 deletion target/xtensa/core-dsp3400.c
Expand Up @@ -27,7 +27,7 @@

#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "qemu/host-utils.h"

#include "core-dsp3400/core-isa.h"
Expand Down
2 changes: 1 addition & 1 deletion target/xtensa/core-fsf.c
Expand Up @@ -27,7 +27,7 @@

#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "qemu/host-utils.h"

#include "core-fsf/core-isa.h"
Expand Down
2 changes: 1 addition & 1 deletion target/xtensa/core-lx106.c
Expand Up @@ -27,7 +27,7 @@

#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "qemu/host-utils.h"

#include "core-lx106/core-isa.h"
Expand Down
2 changes: 1 addition & 1 deletion target/xtensa/core-sample_controller.c
Expand Up @@ -27,7 +27,7 @@

#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "qemu/host-utils.h"

#include "core-sample_controller/core-isa.h"
Expand Down
2 changes: 1 addition & 1 deletion target/xtensa/core-test_kc705_be.c
Expand Up @@ -27,7 +27,7 @@

#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "qemu/host-utils.h"

#include "core-test_kc705_be/core-isa.h"
Expand Down
2 changes: 1 addition & 1 deletion target/xtensa/core-test_mmuhifi_c3.c
Expand Up @@ -27,7 +27,7 @@

#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "qemu/host-utils.h"

#include "core-test_mmuhifi_c3/core-isa.h"
Expand Down
2 changes: 1 addition & 1 deletion target/xtensa/gdbstub.c
Expand Up @@ -19,7 +19,7 @@
*/
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "qemu/log.h"

enum {
Expand Down
2 changes: 1 addition & 1 deletion target/xtensa/helper.c
Expand Up @@ -29,7 +29,7 @@
#include "qemu/log.h"
#include "cpu.h"
#include "exec/exec-all.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "exec/helper-proto.h"
#include "qemu/error-report.h"
#include "qemu/qemu-print.h"
Expand Down
2 changes: 1 addition & 1 deletion target/xtensa/import_core.sh
Expand Up @@ -41,7 +41,7 @@ tar -xf "$OVERLAY" -O binutils/xtensa-modules.c | \
cat <<EOF > "${TARGET}.c"
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/gdbstub.h"
#include "gdbstub/helpers.h"
#include "qemu/host-utils.h"

#include "core-$NAME/core-isa.h"
Expand Down
2 changes: 1 addition & 1 deletion tests/tcg/aarch64/Makefile.target
Expand Up @@ -81,7 +81,7 @@ sha512-vector: sha512.c

TESTS += sha512-vector

ifneq ($(HAVE_GDB_BIN),)
ifeq ($(HOST_GDB_SUPPORTS_ARCH),y)
GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py

run-gdbstub-sysregs: sysregs
Expand Down
5 changes: 5 additions & 0 deletions tests/tcg/multiarch/Makefile.target
Expand Up @@ -64,6 +64,7 @@ run-test-mmap-%: test-mmap
$(call run-test, test-mmap-$*, $(QEMU) -p $* $<, $< ($* byte pages))

ifneq ($(HAVE_GDB_BIN),)
ifeq ($(HOST_GDB_SUPPORTS_ARCH),y)
GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py

run-gdbstub-sha1: sha1
Expand All @@ -87,6 +88,10 @@ run-gdbstub-thread-breakpoint: testthread
--bin $< --test $(MULTIARCH_SRC)/gdbstub/test-thread-breakpoint.py, \
hitting a breakpoint on non-main thread)

else
run-gdbstub-%:
$(call skip-test, "gdbstub test $*", "no guest arch support")
endif
else
run-gdbstub-%:
$(call skip-test, "gdbstub test $*", "need working gdb")
Expand Down
6 changes: 5 additions & 1 deletion tests/tcg/multiarch/system/Makefile.softmmu-target
Expand Up @@ -15,6 +15,7 @@ MULTIARCH_TEST_SRCS=$(wildcard $(MULTIARCH_SYSTEM_SRC)/*.c)
MULTIARCH_TESTS = $(patsubst $(MULTIARCH_SYSTEM_SRC)/%.c, %, $(MULTIARCH_TEST_SRCS))

ifneq ($(HAVE_GDB_BIN),)
ifeq ($(HOST_GDB_SUPPORTS_ARCH),y)
GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py

run-gdbstub-memory: memory
Expand All @@ -26,7 +27,10 @@ run-gdbstub-memory: memory
"-monitor none -display none -chardev file$(COMMA)path=$<.out$(COMMA)id=output $(QEMU_OPTS)" \
--bin $< --test $(MULTIARCH_SRC)/gdbstub/memory.py, \
softmmu gdbstub support)

else
run-gdbstub-%:
$(call skip-test, "gdbstub test $*", "no guest arch support")
endif
else
run-gdbstub-%:
$(call skip-test, "gdbstub test $*", "need working gdb")
Expand Down
2 changes: 1 addition & 1 deletion tests/tcg/s390x/Makefile.target
Expand Up @@ -51,7 +51,7 @@ $(Z15_TESTS): CFLAGS+=-march=z15 -O2
TESTS+=$(Z15_TESTS)
endif

ifneq ($(HAVE_GDB_BIN),)
ifeq ($(HOST_GDB_SUPPORTS_ARCH),y)
GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py

run-gdbstub-signals-s390x: signals-s390x
Expand Down