/*
* gdb server stub
*
+ * This implements a subset of the remote protocol as described in:
+ *
+ * https://sourceware.org/gdb/onlinedocs/gdb/Remote-Protocol.html
+ *
* Copyright (c) 2003-2005 Fabrice Bellard
*
* This library is free software; you can redistribute it and/or
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGPL-2.0+
*/
#include "qemu/osdep.h"
#include "qemu/sockets.h"
#include "sysemu/hw_accel.h"
#include "sysemu/kvm.h"
+#include "sysemu/runstate.h"
#include "hw/semihosting/semihost.h"
#include "exec/exec-all.h"
put_packet(gdb_ctx->s, "E22");
}
+/*
+ * handle_set/get_reg
+ *
+ * Older gdb are really dumb, and don't use 'G/g' if 'P/p' is available.
+ * This works, but can be very slow. Anything new enough to understand
+ * XML also knows how to use this properly. However to use this we
+ * need to define a local XML file as well as be talking to a
+ * reasonably modern gdb. Responding with an empty packet will cause
+ * the remote gdb to fallback to older methods.
+ */
+
static void handle_set_reg(GdbCmdContext *gdb_ctx, void *user_ctx)
{
int reg_size;
if (!gdb_has_xml) {
- put_packet(gdb_ctx->s, "E00");
+ put_packet(gdb_ctx->s, "");
return;
}
{
int reg_size;
- /*
- * Older gdb are really dumb, and don't use 'g' if 'p' is avaialable.
- * This works, but can be very slow. Anything new enough to
- * understand XML also knows how to use this properly.
- */
if (!gdb_has_xml) {
put_packet(gdb_ctx->s, "");
return;
static void handle_file_io(GdbCmdContext *gdb_ctx, void *user_ctx)
{
- if (gdb_ctx->num_params >= 2 && gdb_ctx->s->current_syscall_cb) {
+ if (gdb_ctx->num_params >= 1 && gdb_ctx->s->current_syscall_cb) {
target_ulong ret, err;
ret = (target_ulong)gdb_ctx->params[0].val_ull;
- err = (target_ulong)gdb_ctx->params[1].val_ull;
+ if (gdb_ctx->num_params >= 2) {
+ err = (target_ulong)gdb_ctx->params[1].val_ull;
+ } else {
+ err = 0;
+ }
gdb_ctx->s->current_syscall_cb(gdb_ctx->s->c_cpu, ret, err);
gdb_ctx->s->current_syscall_cb = NULL;
}
break;
}
- run_cmd_parser(s, line_buf, cmd_parser);
+ if (cmd_parser) {
+ run_cmd_parser(s, line_buf, cmd_parser);
+ }
return RS_IDLE;
}