Update gdbstub.
This commit is contained in:
parent
9ac39e6a12
commit
8eaf2c0b7b
|
@ -53,6 +53,7 @@
|
||||||
"ostream": "cpp",
|
"ostream": "cpp",
|
||||||
"stdexcept": "cpp",
|
"stdexcept": "cpp",
|
||||||
"streambuf": "cpp",
|
"streambuf": "cpp",
|
||||||
"typeinfo": "cpp"
|
"typeinfo": "cpp",
|
||||||
|
"internals.h": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* QEMU breakpoint & watchpoint definitions
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012 SUSE LINUX Products GmbH
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
*/
|
||||||
|
#ifndef EXEC_BREAKPOINT_H
|
||||||
|
#define EXEC_BREAKPOINT_H
|
||||||
|
|
||||||
|
#include "qemu/queue.h"
|
||||||
|
#include "exec/vaddr.h"
|
||||||
|
#include "exec/memattrs.h"
|
||||||
|
|
||||||
|
typedef struct CPUBreakpoint {
|
||||||
|
vaddr pc;
|
||||||
|
int flags; /* BP_* */
|
||||||
|
QTAILQ_ENTRY(CPUBreakpoint) entry;
|
||||||
|
} CPUBreakpoint;
|
||||||
|
|
||||||
|
typedef struct CPUWatchpoint {
|
||||||
|
vaddr vaddr;
|
||||||
|
vaddr len;
|
||||||
|
vaddr hitaddr;
|
||||||
|
MemTxAttrs hitattrs;
|
||||||
|
int flags; /* BP_* */
|
||||||
|
QTAILQ_ENTRY(CPUWatchpoint) entry;
|
||||||
|
} CPUWatchpoint;
|
||||||
|
|
||||||
|
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -46,6 +46,13 @@ set(CMAKE_CXX_EXTENSIONS ON)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
find_package(PkgConfig REQUIRED) # 查找 GLib 库
|
||||||
|
pkg_check_modules(GLIB REQUIRED glib-2.0)
|
||||||
|
include_directories(${GLIB_INCLUDE_DIRS}) # 添加头文件路径
|
||||||
|
link_directories(${GLIB_LIBRARY_DIRS}) # 添加链接库
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
file(GLOB UTILS_SRC
|
file(GLOB UTILS_SRC
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/utils/*.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/utils/*.cpp
|
||||||
|
@ -55,4 +62,4 @@ set_source_files_properties(${UTILS_SRC} PROPERTIES LANGUAGE CXX)
|
||||||
add_executable(stub ${UTILS_SRC} stub.cpp)
|
add_executable(stub ${UTILS_SRC} stub.cpp)
|
||||||
target_include_directories(stub PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
target_include_directories(stub PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
target_include_directories(stub PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/utils)
|
target_include_directories(stub PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/utils)
|
||||||
|
target_link_libraries(stub ${GLIB_LIBRARIES})
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* QEMU breakpoint & watchpoint definitions
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012 SUSE LINUX Products GmbH
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
*/
|
||||||
|
#ifndef EXEC_BREAKPOINT_H
|
||||||
|
#define EXEC_BREAKPOINT_H
|
||||||
|
|
||||||
|
// #include "qemu/queue.h"
|
||||||
|
// #include "exec/vaddr.h"
|
||||||
|
// #include "exec/memattrs.h"
|
||||||
|
|
||||||
|
typedef struct CPUBreakpoint {
|
||||||
|
uintptr_t pc;
|
||||||
|
int flags; /* BP_* */
|
||||||
|
struct CPUBreakpoint* entry;
|
||||||
|
} CPUBreakpoint;
|
||||||
|
|
||||||
|
typedef struct CPUWatchpoint {
|
||||||
|
uintptr_t vaddr;
|
||||||
|
uintptr_t len;
|
||||||
|
uintptr_t hitaddr;
|
||||||
|
// MemTxAttrs hitattrs;
|
||||||
|
int flags; /* BP_* */
|
||||||
|
struct CPUWatchpoint* entry;
|
||||||
|
} CPUWatchpoint;
|
||||||
|
|
||||||
|
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -11,6 +11,12 @@
|
||||||
|
|
||||||
#define DEFAULT_GDBSTUB_PORT "1234"
|
#define DEFAULT_GDBSTUB_PORT "1234"
|
||||||
|
|
||||||
|
|
||||||
|
typedef uintptr_t vaddr;
|
||||||
|
typedef int Error;
|
||||||
|
|
||||||
|
#define MMU_ACCESS_COUNT 16
|
||||||
|
|
||||||
/* GDB breakpoint/watchpoint types */
|
/* GDB breakpoint/watchpoint types */
|
||||||
#define GDB_BREAKPOINT_SW 0
|
#define GDB_BREAKPOINT_SW 0
|
||||||
#define GDB_BREAKPOINT_HW 1
|
#define GDB_BREAKPOINT_HW 1
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef GDBSTUB_H
|
#ifndef GDBSTUB_H
|
||||||
#define GDBSTUB_H
|
#define GDBSTUB_H
|
||||||
|
|
||||||
|
#include "cpu.h"
|
||||||
|
|
||||||
typedef struct GDBFeature {
|
typedef struct GDBFeature {
|
||||||
const char *xmlname;
|
const char *xmlname;
|
||||||
const char *xml;
|
const char *xml;
|
||||||
|
@ -16,7 +18,6 @@ typedef struct GDBFeatureBuilder {
|
||||||
int base_reg;
|
int base_reg;
|
||||||
} GDBFeatureBuilder;
|
} GDBFeatureBuilder;
|
||||||
|
|
||||||
|
|
||||||
/* Get or set a register. Returns the size of the register. */
|
/* Get or set a register. Returns the size of the register. */
|
||||||
typedef int (*gdb_get_reg_cb)(CPUState *cpu, GByteArray *buf, int reg);
|
typedef int (*gdb_get_reg_cb)(CPUState *cpu, GByteArray *buf, int reg);
|
||||||
typedef int (*gdb_set_reg_cb)(CPUState *cpu, uint8_t *buf, int reg);
|
typedef int (*gdb_set_reg_cb)(CPUState *cpu, uint8_t *buf, int reg);
|
||||||
|
@ -36,9 +37,8 @@ void gdb_init_cpu(CPUState *cpu);
|
||||||
* @xml - xml name of set
|
* @xml - xml name of set
|
||||||
* @gpos - non-zero to append to "general" register set at @gpos
|
* @gpos - non-zero to append to "general" register set at @gpos
|
||||||
*/
|
*/
|
||||||
void gdb_register_coprocessor(CPUState *cpu,
|
void gdb_register_coprocessor(CPUState *cpu, gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg, const GDBFeature *feature,
|
||||||
gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg,
|
int g_pos);
|
||||||
const GDBFeature *feature, int g_pos);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gdb_unregister_coprocessor_all() - unregisters supplemental set of registers
|
* gdb_unregister_coprocessor_all() - unregisters supplemental set of registers
|
||||||
|
@ -70,8 +70,7 @@ bool gdbserver_start(const char *port_or_device, Error **errp);
|
||||||
* @xmlname: The name of the XML.
|
* @xmlname: The name of the XML.
|
||||||
* @base_reg: The base number of the register ID.
|
* @base_reg: The base number of the register ID.
|
||||||
*/
|
*/
|
||||||
void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feature,
|
void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feature, const char *name, const char *xmlname,
|
||||||
const char *name, const char *xmlname,
|
|
||||||
int base_reg);
|
int base_reg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,9 +79,7 @@ void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feature,
|
||||||
* @format: The format of the tag.
|
* @format: The format of the tag.
|
||||||
* @...: The values to be formatted.
|
* @...: The values to be formatted.
|
||||||
*/
|
*/
|
||||||
void G_GNUC_PRINTF(2, 3)
|
void G_GNUC_PRINTF(2, 3) gdb_feature_builder_append_tag(const GDBFeatureBuilder *builder, const char *format, ...);
|
||||||
gdb_feature_builder_append_tag(const GDBFeatureBuilder *builder,
|
|
||||||
const char *format, ...);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gdb_feature_builder_append_reg() - Append a register.
|
* gdb_feature_builder_append_reg() - Append a register.
|
||||||
|
@ -93,12 +90,8 @@ gdb_feature_builder_append_tag(const GDBFeatureBuilder *builder,
|
||||||
* @type: The type of the register.
|
* @type: The type of the register.
|
||||||
* @group: The register group to which this register belongs; it can be NULL.
|
* @group: The register group to which this register belongs; it can be NULL.
|
||||||
*/
|
*/
|
||||||
void gdb_feature_builder_append_reg(const GDBFeatureBuilder *builder,
|
void gdb_feature_builder_append_reg(const GDBFeatureBuilder *builder, const char *name, int bitsize, int regnum,
|
||||||
const char *name,
|
const char *type, const char *group);
|
||||||
int bitsize,
|
|
||||||
int regnum,
|
|
||||||
const char *type,
|
|
||||||
const char *group);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gdb_feature_builder_end() - End building GDBFeature.
|
* gdb_feature_builder_end() - End building GDBFeature.
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
|
||||||
// #include "gdbstub.h"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "conn.h"
|
#include "conn.h"
|
||||||
|
#include "gdbstub.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
conn_t conn;
|
conn_t conn;
|
||||||
|
|
194
gdbstub/system.c
194
gdbstub/system.c
|
@ -10,29 +10,29 @@
|
||||||
* SPDX-License-Identifier: LGPL-2.0-or-later
|
* SPDX-License-Identifier: LGPL-2.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "accel/accel-cpu-ops.h"
|
||||||
#include "qapi/error.h"
|
#include "accel/accel-ops.h"
|
||||||
#include "qemu/error-report.h"
|
#include "chardev/char-fe.h"
|
||||||
#include "qemu/cutils.h"
|
#include "chardev/char.h"
|
||||||
#include "exec/gdbstub.h"
|
#include "exec/gdbstub.h"
|
||||||
#include "gdbstub/syscalls.h"
|
|
||||||
#include "gdbstub/commands.h"
|
|
||||||
#include "exec/hwaddr.h"
|
#include "exec/hwaddr.h"
|
||||||
#include "exec/tb-flush.h"
|
#include "exec/tb-flush.h"
|
||||||
#include "accel/accel-ops.h"
|
#include "gdbstub/commands.h"
|
||||||
#include "accel/accel-cpu-ops.h"
|
#include "gdbstub/syscalls.h"
|
||||||
#include "system/cpus.h"
|
#include "hw/boards.h"
|
||||||
#include "system/runstate.h"
|
|
||||||
#include "system/replay.h"
|
|
||||||
#include "system/tcg.h"
|
|
||||||
#include "hw/core/cpu.h"
|
#include "hw/core/cpu.h"
|
||||||
#include "hw/cpu/cluster.h"
|
#include "hw/cpu/cluster.h"
|
||||||
#include "hw/boards.h"
|
|
||||||
#include "chardev/char.h"
|
|
||||||
#include "chardev/char-fe.h"
|
|
||||||
#include "monitor/monitor.h"
|
|
||||||
#include "trace.h"
|
|
||||||
#include "internals.h"
|
#include "internals.h"
|
||||||
|
#include "monitor/monitor.h"
|
||||||
|
#include "qapi/error.h"
|
||||||
|
#include "qemu/cutils.h"
|
||||||
|
#include "qemu/error-report.h"
|
||||||
|
#include "qemu/osdep.h"
|
||||||
|
#include "system/cpus.h"
|
||||||
|
#include "system/replay.h"
|
||||||
|
#include "system/runstate.h"
|
||||||
|
#include "system/tcg.h"
|
||||||
|
#include "trace.h"
|
||||||
|
|
||||||
/* System emulation specific state */
|
/* System emulation specific state */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -42,8 +42,7 @@ typedef struct {
|
||||||
|
|
||||||
GDBSystemState gdbserver_system_state;
|
GDBSystemState gdbserver_system_state;
|
||||||
|
|
||||||
static void reset_gdbserver_state(void)
|
static void reset_gdbserver_state(void) {
|
||||||
{
|
|
||||||
g_free(gdbserver_state.processes);
|
g_free(gdbserver_state.processes);
|
||||||
gdbserver_state.processes = NULL;
|
gdbserver_state.processes = NULL;
|
||||||
gdbserver_state.process_num = 0;
|
gdbserver_state.process_num = 0;
|
||||||
|
@ -56,18 +55,12 @@ static void reset_gdbserver_state(void)
|
||||||
* In system mode GDB numbers CPUs from 1 as 0 is reserved as an "any
|
* In system mode GDB numbers CPUs from 1 as 0 is reserved as an "any
|
||||||
* cpu" index.
|
* cpu" index.
|
||||||
*/
|
*/
|
||||||
int gdb_get_cpu_index(CPUState *cpu)
|
int gdb_get_cpu_index(CPUState *cpu) { return cpu->cpu_index + 1; }
|
||||||
{
|
|
||||||
return cpu->cpu_index + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We check the status of the last message in the chardev receive code
|
* We check the status of the last message in the chardev receive code
|
||||||
*/
|
*/
|
||||||
bool gdb_got_immediate_ack(void)
|
bool gdb_got_immediate_ack(void) { return true; }
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GDB Connection management. For system emulation we do all of this
|
* GDB Connection management. For system emulation we do all of this
|
||||||
|
@ -75,8 +68,7 @@ bool gdb_got_immediate_ack(void)
|
||||||
* network and unix sockets.
|
* network and unix sockets.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void gdb_put_buffer(const uint8_t *buf, int len)
|
void gdb_put_buffer(const uint8_t *buf, int len) {
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* XXX this blocks entire thread. Rewrite to use
|
* XXX this blocks entire thread. Rewrite to use
|
||||||
* qemu_chr_fe_write and background I/O callbacks
|
* qemu_chr_fe_write and background I/O callbacks
|
||||||
|
@ -84,8 +76,7 @@ void gdb_put_buffer(const uint8_t *buf, int len)
|
||||||
qemu_chr_fe_write_all(&gdbserver_system_state.chr, buf, len);
|
qemu_chr_fe_write_all(&gdbserver_system_state.chr, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gdb_chr_event(void *opaque, QEMUChrEvent event)
|
static void gdb_chr_event(void *opaque, QEMUChrEvent event) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
GDBState *s = (GDBState *)opaque;
|
GDBState *s = (GDBState *)opaque;
|
||||||
|
|
||||||
|
@ -115,14 +106,12 @@ static void gdb_chr_event(void *opaque, QEMUChrEvent event)
|
||||||
* state, which can cause packets to be dropped and state transition
|
* state, which can cause packets to be dropped and state transition
|
||||||
* 'T' packets to be sent while the syscall is still being processed.
|
* 'T' packets to be sent while the syscall is still being processed.
|
||||||
*/
|
*/
|
||||||
void gdb_syscall_handling(const char *syscall_packet)
|
void gdb_syscall_handling(const char *syscall_packet) {
|
||||||
{
|
|
||||||
vm_stop(RUN_STATE_DEBUG);
|
vm_stop(RUN_STATE_DEBUG);
|
||||||
qemu_cpu_kick(gdbserver_state.c_cpu);
|
qemu_cpu_kick(gdbserver_state.c_cpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gdb_vm_state_change(void *opaque, bool running, RunState state)
|
static void gdb_vm_state_change(void *opaque, bool running, RunState state) {
|
||||||
{
|
|
||||||
CPUState *cpu = gdbserver_state.c_cpu;
|
CPUState *cpu = gdbserver_state.c_cpu;
|
||||||
g_autoptr(GString) buf = g_string_new(NULL);
|
g_autoptr(GString) buf = g_string_new(NULL);
|
||||||
g_autoptr(GString) tid = g_string_new(NULL);
|
g_autoptr(GString) tid = g_string_new(NULL);
|
||||||
|
@ -163,11 +152,8 @@ static void gdb_vm_state_change(void *opaque, bool running, RunState state)
|
||||||
type = "";
|
type = "";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
trace_gdbstub_hit_watchpoint(type,
|
trace_gdbstub_hit_watchpoint(type, gdb_get_cpu_index(cpu), cpu->watchpoint_hit->vaddr);
|
||||||
gdb_get_cpu_index(cpu),
|
g_string_printf(buf, "T%02xthread:%s;%swatch:%" VADDR_PRIx ";", GDB_SIGNAL_TRAP, tid->str, type,
|
||||||
cpu->watchpoint_hit->vaddr);
|
|
||||||
g_string_printf(buf, "T%02xthread:%s;%swatch:%" VADDR_PRIx ";",
|
|
||||||
GDB_SIGNAL_TRAP, tid->str, type,
|
|
||||||
cpu->watchpoint_hit->vaddr);
|
cpu->watchpoint_hit->vaddr);
|
||||||
cpu->watchpoint_hit = NULL;
|
cpu->watchpoint_hit = NULL;
|
||||||
goto send_packet;
|
goto send_packet;
|
||||||
|
@ -221,31 +207,18 @@ send_packet:
|
||||||
cpu_single_step(cpu, 0);
|
cpu_single_step(cpu, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _WIN32
|
static int gdb_monitor_write(Chardev *chr, const uint8_t *buf, int len) {
|
||||||
static void gdb_sigterm_handler(int signal)
|
|
||||||
{
|
|
||||||
if (runstate_is_running()) {
|
|
||||||
vm_stop(RUN_STATE_PAUSED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int gdb_monitor_write(Chardev *chr, const uint8_t *buf, int len)
|
|
||||||
{
|
|
||||||
g_autoptr(GString) hex_buf = g_string_new("O");
|
g_autoptr(GString) hex_buf = g_string_new("O");
|
||||||
gdb_memtohex(hex_buf, buf, len);
|
gdb_memtohex(hex_buf, buf, len);
|
||||||
gdb_put_packet(hex_buf->str);
|
gdb_put_packet(hex_buf->str);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gdb_monitor_open(Chardev *chr, ChardevBackend *backend,
|
static void gdb_monitor_open(Chardev *chr, ChardevBackend *backend, bool *be_opened, Error **errp) {
|
||||||
bool *be_opened, Error **errp)
|
|
||||||
{
|
|
||||||
*be_opened = false;
|
*be_opened = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void char_gdb_class_init(ObjectClass *oc, const void *data)
|
static void char_gdb_class_init(ObjectClass *oc, const void *data) {
|
||||||
{
|
|
||||||
ChardevClass *cc = CHARDEV_CLASS(oc);
|
ChardevClass *cc = CHARDEV_CLASS(oc);
|
||||||
|
|
||||||
cc->internal = true;
|
cc->internal = true;
|
||||||
|
@ -261,8 +234,7 @@ static const TypeInfo char_gdb_type_info = {
|
||||||
.class_init = char_gdb_class_init,
|
.class_init = char_gdb_class_init,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int gdb_chr_can_receive(void *opaque)
|
static int gdb_chr_can_receive(void *opaque) {
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* We can handle an arbitrarily large amount of data.
|
* We can handle an arbitrarily large amount of data.
|
||||||
* Pick the maximum packet size, which is as good as anything.
|
* Pick the maximum packet size, which is as good as anything.
|
||||||
|
@ -270,8 +242,7 @@ static int gdb_chr_can_receive(void *opaque)
|
||||||
return MAX_PACKET_LENGTH;
|
return MAX_PACKET_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gdb_chr_receive(void *opaque, const uint8_t *buf, int size)
|
static void gdb_chr_receive(void *opaque, const uint8_t *buf, int size) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
|
@ -279,8 +250,7 @@ static void gdb_chr_receive(void *opaque, const uint8_t *buf, int size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int find_cpu_clusters(Object *child, void *opaque)
|
static int find_cpu_clusters(Object *child, void *opaque) {
|
||||||
{
|
|
||||||
if (object_dynamic_cast(child, TYPE_CPU_CLUSTER)) {
|
if (object_dynamic_cast(child, TYPE_CPU_CLUSTER)) {
|
||||||
GDBState *s = (GDBState *)opaque;
|
GDBState *s = (GDBState *)opaque;
|
||||||
CPUClusterState *cluster = CPU_CLUSTER(child);
|
CPUClusterState *cluster = CPU_CLUSTER(child);
|
||||||
|
@ -306,8 +276,7 @@ static int find_cpu_clusters(Object *child, void *opaque)
|
||||||
return object_child_foreach(child, find_cpu_clusters, opaque);
|
return object_child_foreach(child, find_cpu_clusters, opaque);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pid_order(const void *a, const void *b)
|
static int pid_order(const void *a, const void *b) {
|
||||||
{
|
|
||||||
GDBProcess *pa = (GDBProcess *)a;
|
GDBProcess *pa = (GDBProcess *)a;
|
||||||
GDBProcess *pb = (GDBProcess *)b;
|
GDBProcess *pb = (GDBProcess *)b;
|
||||||
|
|
||||||
|
@ -320,35 +289,32 @@ static int pid_order(const void *a, const void *b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void create_processes(GDBState *s)
|
static void create_processes(GDBState *s) {
|
||||||
{
|
|
||||||
object_child_foreach(object_get_root(), find_cpu_clusters, s);
|
object_child_foreach(object_get_root(), find_cpu_clusters, s);
|
||||||
|
|
||||||
if (gdbserver_state.processes) {
|
if (gdbserver_state.processes) {
|
||||||
/* Sort by PID */
|
/* Sort by PID */
|
||||||
qsort(gdbserver_state.processes,
|
qsort(gdbserver_state.processes, gdbserver_state.process_num, sizeof(gdbserver_state.processes[0]), pid_order);
|
||||||
gdbserver_state.process_num,
|
|
||||||
sizeof(gdbserver_state.processes[0]),
|
|
||||||
pid_order);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gdb_create_default_process(s);
|
gdb_create_default_process(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gdbserver_start(const char *device, Error **errp)
|
bool gdbserver_start(const char *device, Error **errp) {
|
||||||
{
|
|
||||||
Chardev *chr = NULL;
|
Chardev *chr = NULL;
|
||||||
Chardev *mon_chr;
|
Chardev *mon_chr;
|
||||||
g_autoptr(GString) cs = g_string_new(device);
|
g_autoptr(GString) cs = g_string_new(device);
|
||||||
|
|
||||||
if (!first_cpu) {
|
if (!first_cpu) {
|
||||||
error_setg(errp, "gdbstub: meaningless to attach gdb to a "
|
error_setg(errp,
|
||||||
|
"gdbstub: meaningless to attach gdb to a "
|
||||||
"machine without any CPU.");
|
"machine without any CPU.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gdb_supports_guest_debug()) {
|
if (!gdb_supports_guest_debug()) {
|
||||||
error_setg(errp, "gdbstub: current accelerator doesn't "
|
error_setg(errp,
|
||||||
|
"gdbstub: current accelerator doesn't "
|
||||||
"support guest debugging");
|
"support guest debugging");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -391,8 +357,7 @@ bool gdbserver_start(const char *device, Error **errp)
|
||||||
qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL);
|
qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL);
|
||||||
|
|
||||||
/* Initialize a monitor terminal for gdb */
|
/* Initialize a monitor terminal for gdb */
|
||||||
mon_chr = qemu_chardev_new(NULL, TYPE_CHARDEV_GDB,
|
mon_chr = qemu_chardev_new(NULL, TYPE_CHARDEV_GDB, NULL, NULL, &error_abort);
|
||||||
NULL, NULL, &error_abort);
|
|
||||||
monitor_init_hmp(mon_chr, false, &error_abort);
|
monitor_init_hmp(mon_chr, false, &error_abort);
|
||||||
} else {
|
} else {
|
||||||
qemu_chr_fe_deinit(&gdbserver_system_state.chr, true);
|
qemu_chr_fe_deinit(&gdbserver_system_state.chr, true);
|
||||||
|
@ -404,10 +369,8 @@ bool gdbserver_start(const char *device, Error **errp)
|
||||||
|
|
||||||
if (chr) {
|
if (chr) {
|
||||||
qemu_chr_fe_init(&gdbserver_system_state.chr, chr, &error_abort);
|
qemu_chr_fe_init(&gdbserver_system_state.chr, chr, &error_abort);
|
||||||
qemu_chr_fe_set_handlers(&gdbserver_system_state.chr,
|
qemu_chr_fe_set_handlers(&gdbserver_system_state.chr, gdb_chr_can_receive, gdb_chr_receive, gdb_chr_event, NULL,
|
||||||
gdb_chr_can_receive,
|
&gdbserver_state, NULL, true);
|
||||||
gdb_chr_receive, gdb_chr_event,
|
|
||||||
NULL, &gdbserver_state, NULL, true);
|
|
||||||
}
|
}
|
||||||
gdbserver_state.state = chr ? RS_IDLE : RS_INACTIVE;
|
gdbserver_state.state = chr ? RS_IDLE : RS_INACTIVE;
|
||||||
gdbserver_system_state.mon_chr = mon_chr;
|
gdbserver_system_state.mon_chr = mon_chr;
|
||||||
|
@ -416,16 +379,12 @@ bool gdbserver_start(const char *device, Error **errp)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void register_types(void)
|
static void register_types(void) { type_register_static(&char_gdb_type_info); }
|
||||||
{
|
|
||||||
type_register_static(&char_gdb_type_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
type_init(register_types);
|
type_init(register_types);
|
||||||
|
|
||||||
/* Tell the remote gdb that the process has exited. */
|
/* Tell the remote gdb that the process has exited. */
|
||||||
void gdb_exit(int code)
|
void gdb_exit(int code) {
|
||||||
{
|
|
||||||
char buf[4];
|
char buf[4];
|
||||||
|
|
||||||
if (!gdbserver_state.init) {
|
if (!gdbserver_state.init) {
|
||||||
|
@ -443,20 +402,14 @@ void gdb_exit(int code)
|
||||||
qemu_chr_fe_deinit(&gdbserver_system_state.chr, true);
|
qemu_chr_fe_deinit(&gdbserver_system_state.chr, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gdb_qemu_exit(int code)
|
void gdb_qemu_exit(int code) { qemu_system_shutdown_request_with_code(SHUTDOWN_CAUSE_GUEST_SHUTDOWN, code); }
|
||||||
{
|
|
||||||
qemu_system_shutdown_request_with_code(SHUTDOWN_CAUSE_GUEST_SHUTDOWN,
|
|
||||||
code);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Memory access
|
* Memory access
|
||||||
*/
|
*/
|
||||||
static int phy_memory_mode;
|
static int phy_memory_mode;
|
||||||
|
|
||||||
int gdb_target_memory_rw_debug(CPUState *cpu, hwaddr addr,
|
int gdb_target_memory_rw_debug(CPUState *cpu, hwaddr addr, uint8_t *buf, int len, bool is_write) {
|
||||||
uint8_t *buf, int len, bool is_write)
|
|
||||||
{
|
|
||||||
if (phy_memory_mode) {
|
if (phy_memory_mode) {
|
||||||
if (is_write) {
|
if (is_write) {
|
||||||
cpu_physical_memory_write(addr, buf, len);
|
cpu_physical_memory_write(addr, buf, len);
|
||||||
|
@ -477,30 +430,23 @@ int gdb_target_memory_rw_debug(CPUState *cpu, hwaddr addr,
|
||||||
* cpu helpers
|
* cpu helpers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned int gdb_get_max_cpus(void)
|
unsigned int gdb_get_max_cpus(void) {
|
||||||
{
|
|
||||||
MachineState *ms = MACHINE(qdev_get_machine());
|
MachineState *ms = MACHINE(qdev_get_machine());
|
||||||
return ms->smp.max_cpus;
|
return ms->smp.max_cpus;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gdb_can_reverse(void)
|
bool gdb_can_reverse(void) { return replay_mode == REPLAY_MODE_PLAY; }
|
||||||
{
|
|
||||||
return replay_mode == REPLAY_MODE_PLAY;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Softmmu specific command helpers
|
* Softmmu specific command helpers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void gdb_handle_query_qemu_phy_mem_mode(GArray *params,
|
void gdb_handle_query_qemu_phy_mem_mode(GArray *params, void *ctx) {
|
||||||
void *ctx)
|
|
||||||
{
|
|
||||||
g_string_printf(gdbserver_state.str_buf, "%d", phy_memory_mode);
|
g_string_printf(gdbserver_state.str_buf, "%d", phy_memory_mode);
|
||||||
gdb_put_strbuf();
|
gdb_put_strbuf();
|
||||||
}
|
}
|
||||||
|
|
||||||
void gdb_handle_set_qemu_phy_mem_mode(GArray *params, void *ctx)
|
void gdb_handle_set_qemu_phy_mem_mode(GArray *params, void *ctx) {
|
||||||
{
|
|
||||||
if (!params->len) {
|
if (!params->len) {
|
||||||
gdb_put_packet("E22");
|
gdb_put_packet("E22");
|
||||||
return;
|
return;
|
||||||
|
@ -514,8 +460,7 @@ void gdb_handle_set_qemu_phy_mem_mode(GArray *params, void *ctx)
|
||||||
gdb_put_packet("OK");
|
gdb_put_packet("OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
void gdb_handle_query_rcmd(GArray *params, void *ctx)
|
void gdb_handle_query_rcmd(GArray *params, void *ctx) {
|
||||||
{
|
|
||||||
const guint8 zero = 0;
|
const guint8 zero = 0;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
@ -534,9 +479,7 @@ void gdb_handle_query_rcmd(GArray *params, void *ctx)
|
||||||
len = len / 2;
|
len = len / 2;
|
||||||
gdb_hextomem(gdbserver_state.mem_buf, gdb_get_cmd_param(params, 0)->data, len);
|
gdb_hextomem(gdbserver_state.mem_buf, gdb_get_cmd_param(params, 0)->data, len);
|
||||||
g_byte_array_append(gdbserver_state.mem_buf, &zero, 1);
|
g_byte_array_append(gdbserver_state.mem_buf, &zero, 1);
|
||||||
qemu_chr_be_write(gdbserver_system_state.mon_chr,
|
qemu_chr_be_write(gdbserver_system_state.mon_chr, gdbserver_state.mem_buf->data, gdbserver_state.mem_buf->len);
|
||||||
gdbserver_state.mem_buf->data,
|
|
||||||
gdbserver_state.mem_buf->len);
|
|
||||||
gdb_put_packet("OK");
|
gdb_put_packet("OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,13 +487,9 @@ void gdb_handle_query_rcmd(GArray *params, void *ctx)
|
||||||
* Execution state helpers
|
* Execution state helpers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void gdb_handle_query_attached(GArray *params, void *ctx)
|
void gdb_handle_query_attached(GArray *params, void *ctx) { gdb_put_packet("1"); }
|
||||||
{
|
|
||||||
gdb_put_packet("1");
|
|
||||||
}
|
|
||||||
|
|
||||||
void gdb_continue(void)
|
void gdb_continue(void) {
|
||||||
{
|
|
||||||
if (!runstate_needs_reset()) {
|
if (!runstate_needs_reset()) {
|
||||||
trace_gdbstub_op_continue();
|
trace_gdbstub_op_continue();
|
||||||
vm_start();
|
vm_start();
|
||||||
|
@ -560,8 +499,7 @@ void gdb_continue(void)
|
||||||
/*
|
/*
|
||||||
* Resume execution, per CPU actions.
|
* Resume execution, per CPU actions.
|
||||||
*/
|
*/
|
||||||
int gdb_continue_partial(char *newstates)
|
int gdb_continue_partial(char *newstates) {
|
||||||
{
|
|
||||||
CPUState *cpu;
|
CPUState *cpu;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
int flag = 0;
|
int flag = 0;
|
||||||
|
@ -612,13 +550,9 @@ int gdb_continue_partial(char *newstates)
|
||||||
* signals are not yet supported.
|
* signals are not yet supported.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum {
|
enum { TARGET_SIGINT = 2, TARGET_SIGTRAP = 5 };
|
||||||
TARGET_SIGINT = 2,
|
|
||||||
TARGET_SIGTRAP = 5
|
|
||||||
};
|
|
||||||
|
|
||||||
int gdb_signal_to_target(int sig)
|
int gdb_signal_to_target(int sig) {
|
||||||
{
|
|
||||||
switch (sig) {
|
switch (sig) {
|
||||||
case 2:
|
case 2:
|
||||||
return TARGET_SIGINT;
|
return TARGET_SIGINT;
|
||||||
|
@ -633,8 +567,7 @@ int gdb_signal_to_target(int sig)
|
||||||
* Break/Watch point helpers
|
* Break/Watch point helpers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool gdb_supports_guest_debug(void)
|
bool gdb_supports_guest_debug(void) {
|
||||||
{
|
|
||||||
const AccelOpsClass *ops = cpus_get_accel();
|
const AccelOpsClass *ops = cpus_get_accel();
|
||||||
if (ops->supports_guest_debug) {
|
if (ops->supports_guest_debug) {
|
||||||
return ops->supports_guest_debug();
|
return ops->supports_guest_debug();
|
||||||
|
@ -642,8 +575,7 @@ bool gdb_supports_guest_debug(void)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gdb_breakpoint_insert(CPUState *cs, int type, vaddr addr, vaddr len)
|
int gdb_breakpoint_insert(CPUState *cs, int type, vaddr addr, vaddr len) {
|
||||||
{
|
|
||||||
const AccelOpsClass *ops = cpus_get_accel();
|
const AccelOpsClass *ops = cpus_get_accel();
|
||||||
if (ops->insert_breakpoint) {
|
if (ops->insert_breakpoint) {
|
||||||
return ops->insert_breakpoint(cs, type, addr, len);
|
return ops->insert_breakpoint(cs, type, addr, len);
|
||||||
|
@ -651,8 +583,7 @@ int gdb_breakpoint_insert(CPUState *cs, int type, vaddr addr, vaddr len)
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gdb_breakpoint_remove(CPUState *cs, int type, vaddr addr, vaddr len)
|
int gdb_breakpoint_remove(CPUState *cs, int type, vaddr addr, vaddr len) {
|
||||||
{
|
|
||||||
const AccelOpsClass *ops = cpus_get_accel();
|
const AccelOpsClass *ops = cpus_get_accel();
|
||||||
if (ops->remove_breakpoint) {
|
if (ops->remove_breakpoint) {
|
||||||
return ops->remove_breakpoint(cs, type, addr, len);
|
return ops->remove_breakpoint(cs, type, addr, len);
|
||||||
|
@ -660,8 +591,7 @@ int gdb_breakpoint_remove(CPUState *cs, int type, vaddr addr, vaddr len)
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gdb_breakpoint_remove_all(CPUState *cs)
|
void gdb_breakpoint_remove_all(CPUState *cs) {
|
||||||
{
|
|
||||||
const AccelOpsClass *ops = cpus_get_accel();
|
const AccelOpsClass *ops = cpus_get_accel();
|
||||||
if (ops->remove_all_breakpoints) {
|
if (ops->remove_all_breakpoints) {
|
||||||
ops->remove_all_breakpoints(cs);
|
ops->remove_all_breakpoints(cs);
|
||||||
|
|
Loading…
Reference in New Issue