From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576843753; cv=none; d=zohomail.com; s=zohoarc; b=MK8bNGKarAReoiIE7iSdmLzc32SKd+6vR01Q6sTHo/IS46OuPwdRPthnBEfUY4oyK+Ec2HM80YTL0Yh/F5VCiUpSpM0/HQlGpe/wDZ+UH+b1NnxXFmzXS4PaA7rgik4h/Lh6IVnmFcRod200Snvj6uB8tv1oRe4nNbZYJEEhd44= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576843753; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OtFgNihQmjwXIczGB6RrVvTGCHXdssZoK9FktuuxCfA=; b=PyJlFsJD9MpgxCQVaMNymIz1cS2o/b0baYAQG5ZqloJ59MsVB894/h6CfWfWGASXisRDGnSqAZVxRIe+QLwvXBmsbrO04p4MCGcBlaeR/9S0UgDx+XMoCmyMJwNwbu1OHGfNToUcqplDzVjz12mE5vEPVSHLs4Uov1CiqcRBTyM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157684375303676.86250187761755; Fri, 20 Dec 2019 04:09:13 -0800 (PST) Received: from localhost ([::1]:54010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH5j-00018N-6b for importer@patchew.org; Fri, 20 Dec 2019 07:09:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51739) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1S-0004Ye-3F for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1P-0007HQ-RR for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:45 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:40895) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1P-0007AL-DM for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:43 -0500 Received: by mail-wm1-x341.google.com with SMTP id t14so8960418wmi.5 for ; Fri, 20 Dec 2019 04:04:43 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id x10sm9420713wrv.60.2019.12.20.04.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:39 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id E6BEA1FF8C; Fri, 20 Dec 2019 12:04:38 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OtFgNihQmjwXIczGB6RrVvTGCHXdssZoK9FktuuxCfA=; b=LbCMyns60IYsl2fr34xczYIcdxEpgga2aL+YUPYbIJan0EKbOwPWT9hzJlUbcl+d9f AwZ6eJvNmbG63CJYFUYGIRVbOUTUwNF9SgzjEsg9QwFPzPAmzx/+D/B3TXdIZnDqkxBW Axd6pRuAnxWmJTl0gGBE9cMggpiQWSzBuamL+aWrkkJvDNRRU/Fxg39aDj/OER0nybnA 9GLDP99RipYiAhzg3WlDnfckxlzqrt+Fb39iGTm3z1haFYr7ecP4Krmj+TZEixzBFVQE k3sEWBmuYcDYK3U4f9Yq+1gRRZ/PBl/6mOPlYHcqh+e1Z7FbwCRQELvFVuPMv52N3YTe Fqzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OtFgNihQmjwXIczGB6RrVvTGCHXdssZoK9FktuuxCfA=; b=BvGxsma8af2VvHBVcUobJ0p9Ii8FAYPCbaJUwPWRKnoI8mLwlDUP4t0sFcvFGHH6et simYIknbDw08vaG/EAubfwJbrAhb3uCBTQ4s3SCqdudMDQTbLaPTMC12JTzfG0K/p7ce Ub+Ua4pWniEH7NRzJiCBmQeN2IyEixiL9nSV8A8freXg/4K4RnNTLNNgRvuq+PNqeuK1 O7nVPHIDmIB9kyBNUcu4czgDewEJYeqcOTa9dTWKEEOZ2YBMxI43z/XFM3GXq9B0YTro EqP+YbK7IFKiPDvk/ewnNDoYjIAiOhyP3kSWkf2rkFa2AnerEEvqKwYryr07mRZInNFn /jaQ== X-Gm-Message-State: APjAAAVPMgbl8gMb45JzLY2zhSuKdc2ya/wtd2npPVBTySPOxu5lAjnY ZH0FDCurqqM2cWbSDTlKrWPMvQ== X-Google-Smtp-Source: APXvYqzq2CnJjb8LIV16gGOrJLMRrXM/oY3m01E3DCVOVnsP/Z5yd/67DwGBYJv+kn8oJMKwXgTUtA== X-Received: by 2002:a1c:3dc3:: with SMTP id k186mr15459707wma.95.1576843481218; Fri, 20 Dec 2019 04:04:41 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 01/21] gdbstub: make GDBState static and have common init function Date: Fri, 20 Dec 2019 12:04:18 +0000 Message-Id: <20191220120438.16114-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, luis.machado@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , alan.hayward@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Instead of allocating make this entirely static. We shall reduce the size of the structure in later commits and dynamically allocate parts of it. We introduce an init and reset helper function to keep all the manipulation in one place. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson Reviewed-by: Damien Hedde --- v2 - made entirely static, dropped dh/rth r-b tags due to changes --- gdbstub.c | 168 ++++++++++++++++++++++++++---------------------------- 1 file changed, 81 insertions(+), 87 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 4cf8af365e2..36b1d7a9408 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -342,6 +342,7 @@ enum RSState { 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 */ @@ -372,7 +373,23 @@ typedef struct GDBState { */ static int sstep_flags =3D SSTEP_ENABLE|SSTEP_NOIRQ|SSTEP_NOTIMER; =20 -static GDBState *gdbserver_state; +static GDBState gdbserver_state; + +static void init_gdbserver_state(void) +{ + g_assert(!gdbserver_state.init); + memset(&gdbserver_state, 0, sizeof(GDBState)); + gdbserver_state.init =3D true; +} + +#ifndef CONFIG_USER_ONLY +static void reset_gdbserver_state(void) +{ + g_free(gdbserver_state.processes); + gdbserver_state.processes =3D NULL; + gdbserver_state.process_num =3D 0; +} +#endif =20 bool gdb_has_xml; =20 @@ -425,8 +442,8 @@ int use_gdb_syscalls(void) /* -semihosting-config target=3Dauto */ /* On the first call check if gdb is connected and remember. */ if (gdb_syscall_mode =3D=3D GDB_SYS_UNKNOWN) { - gdb_syscall_mode =3D (gdbserver_state ? GDB_SYS_ENABLED - : GDB_SYS_DISABLED); + gdb_syscall_mode =3D gdbserver_state.init ? + GDB_SYS_ENABLED : GDB_SYS_DISABLED; } return gdb_syscall_mode =3D=3D GDB_SYS_ENABLED; } @@ -984,7 +1001,7 @@ static int gdb_breakpoint_insert(int type, target_ulon= g addr, target_ulong len) int err =3D 0; =20 if (kvm_enabled()) { - return kvm_insert_breakpoint(gdbserver_state->c_cpu, addr, len, ty= pe); + return kvm_insert_breakpoint(gdbserver_state.c_cpu, addr, len, typ= e); } =20 switch (type) { @@ -1021,7 +1038,7 @@ static int gdb_breakpoint_remove(int type, target_ulo= ng addr, target_ulong len) int err =3D 0; =20 if (kvm_enabled()) { - return kvm_remove_breakpoint(gdbserver_state->c_cpu, addr, len, ty= pe); + return kvm_remove_breakpoint(gdbserver_state.c_cpu, addr, len, typ= e); } =20 switch (type) { @@ -1074,7 +1091,7 @@ static void gdb_breakpoint_remove_all(void) CPUState *cpu; =20 if (kvm_enabled()) { - kvm_remove_all_breakpoints(gdbserver_state->c_cpu); + kvm_remove_all_breakpoints(gdbserver_state.c_cpu); return; } =20 @@ -2601,7 +2618,7 @@ static int gdb_handle_packet(GDBState *s, const char = *line_buf) =20 void gdb_set_stop_cpu(CPUState *cpu) { - GDBProcess *p =3D gdb_get_cpu_process(gdbserver_state, cpu); + GDBProcess *p =3D gdb_get_cpu_process(&gdbserver_state, cpu); =20 if (!p->attached) { /* @@ -2611,14 +2628,14 @@ void gdb_set_stop_cpu(CPUState *cpu) return; } =20 - gdbserver_state->c_cpu =3D cpu; - gdbserver_state->g_cpu =3D cpu; + gdbserver_state.c_cpu =3D cpu; + gdbserver_state.g_cpu =3D cpu; } =20 #ifndef CONFIG_USER_ONLY static void gdb_vm_state_change(void *opaque, int running, RunState state) { - GDBState *s =3D gdbserver_state; + GDBState *s =3D &gdbserver_state; CPUState *cpu =3D s->c_cpu; char buf[256]; char thread_id[16]; @@ -2722,17 +2739,16 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, co= nst char *fmt, va_list va) char *p_end; target_ulong addr; uint64_t i64; - GDBState *s; =20 - s =3D gdbserver_state; - if (!s) + if (!gdbserver_state.init) return; - s->current_syscall_cb =3D cb; + + gdbserver_state.current_syscall_cb =3D cb; #ifndef CONFIG_USER_ONLY vm_stop(RUN_STATE_DEBUG); #endif - p =3D s->syscall_buf; - p_end =3D &s->syscall_buf[sizeof(s->syscall_buf)]; + p =3D &gdbserver_state.syscall_buf[0]; + p_end =3D &gdbserver_state.syscall_buf[sizeof(gdbserver_state.syscall_= buf)]; *(p++) =3D 'F'; while (*fmt) { if (*fmt =3D=3D '%') { @@ -2765,14 +2781,14 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, co= nst char *fmt, va_list va) } *p =3D 0; #ifdef CONFIG_USER_ONLY - put_packet(s, s->syscall_buf); + put_packet(&gdbserver_state, gdbserver_state.syscall_buf); /* Return control to gdb for it to process the syscall request. * Since the protocol requires that gdb hands control back to us * using a "here are the results" F packet, we don't need to check * gdb_handlesig's return value (which is the signal to deliver if * execution was resumed via a continue packet). */ - gdb_handlesig(s->c_cpu, 0); + gdb_handlesig(gdbserver_state.c_cpu, 0); #else /* In this case wait to send the syscall packet until notification that the CPU has stopped. This must be done because if the packet is se= nt @@ -2780,7 +2796,7 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, cons= t char *fmt, va_list va) is still in the running state, which can cause packets to be dropped and state transition 'T' packets to be sent while the syscall is st= ill being processed. */ - qemu_cpu_kick(s->c_cpu); + qemu_cpu_kick(gdbserver_state.c_cpu); #endif } =20 @@ -2941,15 +2957,13 @@ static void gdb_read_byte(GDBState *s, uint8_t ch) /* Tell the remote gdb that the process has exited. */ void gdb_exit(CPUArchState *env, int code) { - GDBState *s; char buf[4]; =20 - s =3D gdbserver_state; - if (!s) { + if (!gdbserver_state.init) { return; } #ifdef CONFIG_USER_ONLY - if (gdbserver_fd < 0 || s->fd < 0) { + if (gdbserver_fd < 0 || gdbserver_state.fd < 0) { return; } #endif @@ -2957,10 +2971,10 @@ void gdb_exit(CPUArchState *env, int code) trace_gdbstub_op_exiting((uint8_t)code); =20 snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code); - put_packet(s, buf); + put_packet(&gdbserver_state, buf); =20 #ifndef CONFIG_USER_ONLY - qemu_chr_fe_deinit(&s->chr, true); + qemu_chr_fe_deinit(&gdbserver_state.chr, true); #endif } =20 @@ -2993,12 +3007,10 @@ static void create_default_process(GDBState *s) int gdb_handlesig(CPUState *cpu, int sig) { - GDBState *s; char buf[256]; int n; =20 - s =3D gdbserver_state; - if (gdbserver_fd < 0 || s->fd < 0) { + if (gdbserver_fd < 0 || gdbserver_state.fd < 0) { return sig; } =20 @@ -3008,58 +3020,55 @@ gdb_handlesig(CPUState *cpu, int sig) =20 if (sig !=3D 0) { snprintf(buf, sizeof(buf), "S%02x", target_signal_to_gdb(sig)); - put_packet(s, buf); + put_packet(&gdbserver_state, buf); } /* put_packet() might have detected that the peer terminated the connection. */ - if (s->fd < 0) { + if (gdbserver_state.fd < 0) { return sig; } =20 sig =3D 0; - s->state =3D RS_IDLE; - s->running_state =3D 0; - while (s->running_state =3D=3D 0) { - n =3D read(s->fd, buf, 256); + gdbserver_state.state =3D RS_IDLE; + gdbserver_state.running_state =3D 0; + while (gdbserver_state.running_state =3D=3D 0) { + n =3D read(gdbserver_state.fd, buf, 256); if (n > 0) { int i; =20 for (i =3D 0; i < n; i++) { - gdb_read_byte(s, buf[i]); + gdb_read_byte(&gdbserver_state, buf[i]); } } else { /* XXX: Connection closed. Should probably wait for another connection before continuing. */ if (n =3D=3D 0) { - close(s->fd); + close(gdbserver_state.fd); } - s->fd =3D -1; + gdbserver_state.fd =3D -1; return sig; } } - sig =3D s->signal; - s->signal =3D 0; + sig =3D gdbserver_state.signal; + gdbserver_state.signal =3D 0; return sig; } =20 /* Tell the remote gdb that the process has exited due to SIG. */ void gdb_signalled(CPUArchState *env, int sig) { - GDBState *s; char buf[4]; =20 - s =3D gdbserver_state; - if (gdbserver_fd < 0 || s->fd < 0) { + if (gdbserver_fd < 0 || gdbserver_state.fd < 0) { return; } =20 snprintf(buf, sizeof(buf), "X%02x", target_signal_to_gdb(sig)); - put_packet(s, buf); + put_packet(&gdbserver_state, buf); } =20 static bool gdb_accept(void) { - GDBState *s; struct sockaddr_in sockaddr; socklen_t len; int fd; @@ -3083,15 +3092,13 @@ static bool gdb_accept(void) return false; } =20 - s =3D g_malloc0(sizeof(GDBState)); - create_default_process(s); - s->processes[0].attached =3D true; - s->c_cpu =3D gdb_first_attached_cpu(s); - s->g_cpu =3D s->c_cpu; - s->fd =3D fd; + init_gdbserver_state(); + create_default_process(&gdbserver_state); + gdbserver_state.processes[0].attached =3D true; + gdbserver_state.c_cpu =3D gdb_first_attached_cpu(&gdbserver_state); + gdbserver_state.g_cpu =3D gdbserver_state.c_cpu; + gdbserver_state.fd =3D fd; gdb_has_xml =3D false; - - gdbserver_state =3D s; return true; } =20 @@ -3144,13 +3151,11 @@ int gdbserver_start(int port) /* Disable gdb stub for child processes. */ void gdbserver_fork(CPUState *cpu) { - GDBState *s =3D gdbserver_state; - - if (gdbserver_fd < 0 || s->fd < 0) { + if (gdbserver_fd < 0 || gdbserver_state.fd < 0) { return; } - close(s->fd); - s->fd =3D -1; + close(gdbserver_state.fd); + gdbserver_state.fd =3D -1; cpu_breakpoint_remove_all(cpu, BP_GDB); cpu_watchpoint_remove_all(cpu, BP_GDB); } @@ -3167,7 +3172,7 @@ static void gdb_chr_receive(void *opaque, const uint8= _t *buf, int size) int i; =20 for (i =3D 0; i < size; i++) { - gdb_read_byte(gdbserver_state, buf[i]); + gdb_read_byte(&gdbserver_state, buf[i]); } } =20 @@ -3210,13 +3215,13 @@ static int gdb_monitor_write(Chardev *chr, const ui= nt8_t *buf, int len) const char *p =3D (const char *)buf; int max_sz; =20 - max_sz =3D (sizeof(gdbserver_state->last_packet) - 2) / 2; + max_sz =3D (sizeof(gdbserver_state.last_packet) - 2) / 2; for (;;) { if (len <=3D max_sz) { - gdb_monitor_output(gdbserver_state, p, len); + gdb_monitor_output(&gdbserver_state, p, len); break; } - gdb_monitor_output(gdbserver_state, p, max_sz); + gdb_monitor_output(&gdbserver_state, p, max_sz); p +=3D max_sz; len -=3D max_sz; } @@ -3308,18 +3313,10 @@ static void create_processes(GDBState *s) create_default_process(s); } =20 -static void cleanup_processes(GDBState *s) -{ - g_free(s->processes); - s->process_num =3D 0; - s->processes =3D NULL; -} - int gdbserver_start(const char *device) { trace_gdbstub_op_start(device); =20 - GDBState *s; char gdbstub_device_name[128]; Chardev *chr =3D NULL; Chardev *mon_chr; @@ -3357,10 +3354,8 @@ int gdbserver_start(const char *device) return -1; } =20 - s =3D gdbserver_state; - if (!s) { - s =3D g_malloc0(sizeof(GDBState)); - gdbserver_state =3D s; + if (!gdbserver_state.init) { + init_gdbserver_state(); =20 qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL); =20 @@ -3369,31 +3364,30 @@ int gdbserver_start(const char *device) NULL, NULL, &error_abort); monitor_init_hmp(mon_chr, false); } else { - qemu_chr_fe_deinit(&s->chr, true); - mon_chr =3D s->mon_chr; - cleanup_processes(s); - memset(s, 0, sizeof(GDBState)); - s->mon_chr =3D mon_chr; + qemu_chr_fe_deinit(&gdbserver_state.chr, true); + mon_chr =3D gdbserver_state.mon_chr; + reset_gdbserver_state(); } =20 - create_processes(s); + create_processes(&gdbserver_state); =20 if (chr) { - qemu_chr_fe_init(&s->chr, chr, &error_abort); - qemu_chr_fe_set_handlers(&s->chr, gdb_chr_can_receive, gdb_chr_rec= eive, - gdb_chr_event, NULL, s, NULL, true); + qemu_chr_fe_init(&gdbserver_state.chr, chr, &error_abort); + qemu_chr_fe_set_handlers(&gdbserver_state.chr, gdb_chr_can_receive, + gdb_chr_receive, gdb_chr_event, + NULL, &gdbserver_state, NULL, true); } - s->state =3D chr ? RS_IDLE : RS_INACTIVE; - s->mon_chr =3D mon_chr; - s->current_syscall_cb =3D NULL; + gdbserver_state.state =3D chr ? RS_IDLE : RS_INACTIVE; + gdbserver_state.mon_chr =3D mon_chr; + gdbserver_state.current_syscall_cb =3D NULL; =20 return 0; } =20 void gdbserver_cleanup(void) { - if (gdbserver_state) { - put_packet(gdbserver_state, "W00"); + if (gdbserver_state.init) { + put_packet(&gdbserver_state, "W00"); } } =20 --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576843998; cv=none; d=zohomail.com; s=zohoarc; b=Zb808VwJSh88DbheckITcRr1woKBTxlCrAIju99J64DVZ117siufSyujmpcUQIYn+441YHaow7rzTQLI6kYA7G+OfIKWQQjTgM9yVgrH6+yZrWzkSOjqwp/Vocaxr1L1D+vSsBZFdJNDHr5IAty2TidDK7RYO+bxfOyfTYc2xNU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576843998; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dQOlXAoJ3FKmzm2CRRD+Ds4XAjn4cv/b/o6pTKLN+vI=; b=DkCGoJLXOGOFt9dmnXHz/jiziGHd5Ezcwe3YeztIi2GIoky+q0dT1UbL3apGbk/zPrJGGSqSRnMQT3iwhfsgfTM0chaR2xLIen4ucXMDU5umOGoNmbhKt6QQuw5COh7YxK5eWce4oGav3rlOmJXGrQ+KnI7znJnv3umPzHN7y3M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576843998852352.91618621896566; Fri, 20 Dec 2019 04:13:18 -0800 (PST) Received: from localhost ([::1]:54104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH9h-0006Yl-0W for importer@patchew.org; Fri, 20 Dec 2019 07:13:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52562) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1X-0004gt-Vb for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1S-0007Rc-Fd for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:51 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:40703) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1R-0007NV-W1 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:46 -0500 Received: by mail-wr1-x443.google.com with SMTP id c14so9162041wrn.7 for ; Fri, 20 Dec 2019 04:04:45 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id a14sm10011883wrx.81.2019.12.20.04.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:39 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 0EFC41FF8F; Fri, 20 Dec 2019 12:04:39 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dQOlXAoJ3FKmzm2CRRD+Ds4XAjn4cv/b/o6pTKLN+vI=; b=AhiWv/y8M5rAIJik9jWX2Lllb/CNWYmNQfClwDtmC8PqIzNqOM1dOHuYWIbZ4OZAu0 yi8xkq1EB+Gj64INiuYJ6cJOqfjTZyT9mARy3Qn0XtqRUBcrjv+reB+WDwjW/tHxnj73 pqywfbIQd9eqcw3AShEU6v05AEoktinVbu10CHrdFAdgl6jCUSP2BSd6cR+wNxb3vyTf gBqjJUQODPYZta2VIn1lBEsYgYQGeI0n6Wxe+oEwK/Mjlh1ASJjkh3vI5gw57GVMVyQq I85cG103BczYpoZ3kF/8APG8vo7aDCQjAjc4pzkEpLrOMl+6FhFg3PW/XmSqC04rtFLO 1AfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dQOlXAoJ3FKmzm2CRRD+Ds4XAjn4cv/b/o6pTKLN+vI=; b=ZZc7iQ7t/4e1vbqo2WzkD4PolKTSMPETb2fW/uMsee42u1285WoKHVDsN/kCescKV8 SqO5f99r+e+Wwt2zXI7wv7bza7nWhlrlbzUuWjRtaHij3tZ4qHIne+nGnpx/GFjXzUYn bBv+gZDGiKnsPWfBxHBSbQ629wf5pZszLqGttRy2oCrk4UaDTSYqf0EMDEEJUf9WkmYx D12SPByJ3EcfmhifpBHuIdwx84PMQIgCX6XMsghLU3PWQK+nxYACY+XlWxcqTvd5IU3U SbV9LNCQ/zKRndJeEDEEh6ijAN2b1rfWVkmaekWnbvs1SDWCZFXX2thpE2fU9hXAnJSv d5IQ== X-Gm-Message-State: APjAAAUHfasmU4Yo860zF7Jyv+duI0YIJiiPZMcVhfvFcYBszyKcofDS BB690Q95TZqwsP8YdX3+0FInUfjvoQ4= X-Google-Smtp-Source: APXvYqwMRvThUJ1nIBfQJ92s9W2sQNfQwQvuDwwvy/lehTo7oOQk2XsLymcEoGG4hJsjIElhxNab+w== X-Received: by 2002:adf:dfc2:: with SMTP id q2mr14366564wrn.251.1576843483694; Fri, 20 Dec 2019 04:04:43 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 02/21] gdbstub: stop passing GDBState * around and use global Date: Fri, 20 Dec 2019 12:04:19 +0000 Message-Id: <20191220120438.16114-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Received-From: 2a00:1450:4864:20::443 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, luis.machado@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , alan.hayward@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We only have one GDBState which should be allocated at the time we process any commands. This will make further clean-up a bit easier. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- v3 - remove final *s paramters from function calls v4 - a few fixups for coding style --- gdbstub.c | 561 +++++++++++++++++++++++++++--------------------------- 1 file changed, 278 insertions(+), 283 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 36b1d7a9408..85ef7d37e08 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -397,21 +397,21 @@ bool gdb_has_xml; /* XXX: This is not thread safe. Do we care? */ static int gdbserver_fd =3D -1; =20 -static int get_char(GDBState *s) +static int get_char(void) { uint8_t ch; int ret; =20 for(;;) { - ret =3D qemu_recv(s->fd, &ch, 1, 0); + ret =3D qemu_recv(gdbserver_state.fd, &ch, 1, 0); if (ret < 0) { if (errno =3D=3D ECONNRESET) - s->fd =3D -1; + gdbserver_state.fd =3D -1; if (errno !=3D EINTR) return -1; } else if (ret =3D=3D 0) { - close(s->fd); - s->fd =3D -1; + close(gdbserver_state.fd); + gdbserver_state.fd =3D -1; return -1; } else { break; @@ -449,11 +449,11 @@ int use_gdb_syscalls(void) } =20 /* Resume execution. */ -static inline void gdb_continue(GDBState *s) +static inline void gdb_continue(void) { =20 #ifdef CONFIG_USER_ONLY - s->running_state =3D 1; + gdbserver_state.running_state =3D 1; trace_gdbstub_op_continue(); #else if (!runstate_needs_reset()) { @@ -467,7 +467,7 @@ static inline void gdb_continue(GDBState *s) * Resume execution, per CPU actions. For user-mode emulation it's * equivalent to gdb_continue. */ -static int gdb_continue_partial(GDBState *s, char *newstates) +static int gdb_continue_partial(char *newstates) { CPUState *cpu; int res =3D 0; @@ -482,7 +482,7 @@ static int gdb_continue_partial(GDBState *s, char *news= tates) cpu_single_step(cpu, sstep_flags); } } - s->running_state =3D 1; + gdbserver_state.running_state =3D 1; #else int flag =3D 0; =20 @@ -520,13 +520,13 @@ static int gdb_continue_partial(GDBState *s, char *ne= wstates) return res; } =20 -static void put_buffer(GDBState *s, const uint8_t *buf, int len) +static void put_buffer(const uint8_t *buf, int len) { #ifdef CONFIG_USER_ONLY int ret; =20 while (len > 0) { - ret =3D send(s->fd, buf, len, 0); + ret =3D send(gdbserver_state.fd, buf, len, 0); if (ret < 0) { if (errno !=3D EINTR) return; @@ -538,7 +538,7 @@ static void put_buffer(GDBState *s, const uint8_t *buf,= int len) #else /* XXX this blocks entire thread. Rewrite to use * qemu_chr_fe_write and background I/O callbacks */ - qemu_chr_fe_write_all(&s->chr, buf, len); + qemu_chr_fe_write_all(&gdbserver_state.chr, buf, len); #endif } =20 @@ -620,17 +620,18 @@ static void hexdump(const char *buf, int len, } =20 /* return -1 if error, 0 if OK */ -static int put_packet_binary(GDBState *s, const char *buf, int len, bool d= ump) +static int put_packet_binary(const char *buf, int len, bool dump) { int csum, i; uint8_t *p; + uint8_t *ps =3D &gdbserver_state.last_packet[0]; =20 if (dump && trace_event_get_state_backends(TRACE_GDBSTUB_IO_BINARYREPL= Y)) { hexdump(buf, len, trace_gdbstub_io_binaryreply); } =20 for(;;) { - p =3D s->last_packet; + p =3D ps; *(p++) =3D '$'; memcpy(p, buf, len); p +=3D len; @@ -642,11 +643,11 @@ static int put_packet_binary(GDBState *s, const char = *buf, int len, bool dump) *(p++) =3D tohex((csum >> 4) & 0xf); *(p++) =3D tohex((csum) & 0xf); =20 - s->last_packet_len =3D p - s->last_packet; - put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len); + gdbserver_state.last_packet_len =3D p - ps; + put_buffer(ps, gdbserver_state.last_packet_len); =20 #ifdef CONFIG_USER_ONLY - i =3D get_char(s); + i =3D get_char(); if (i < 0) return -1; if (i =3D=3D '+') @@ -659,11 +660,11 @@ static int put_packet_binary(GDBState *s, const char = *buf, int len, bool dump) } =20 /* return -1 if error, 0 if OK */ -static int put_packet(GDBState *s, const char *buf) +static int put_packet(const char *buf) { trace_gdbstub_io_reply(buf); =20 - return put_packet_binary(s, buf, strlen(buf), false); + return put_packet_binary(buf, strlen(buf), false); } =20 /* Encode data using the encoding for 'x' packets. */ @@ -687,37 +688,38 @@ static int memtox(char *buf, const char *mem, int len) return p - buf; } =20 -static uint32_t gdb_get_cpu_pid(const GDBState *s, CPUState *cpu) +static uint32_t gdb_get_cpu_pid(CPUState *cpu) { /* TODO: In user mode, we should use the task state PID */ if (cpu->cluster_index =3D=3D UNASSIGNED_CLUSTER_INDEX) { /* Return the default process' PID */ - return s->processes[s->process_num - 1].pid; + int index =3D gdbserver_state.process_num - 1; + return gdbserver_state.processes[index].pid; } return cpu->cluster_index + 1; } =20 -static GDBProcess *gdb_get_process(const GDBState *s, uint32_t pid) +static GDBProcess *gdb_get_process(uint32_t pid) { int i; =20 if (!pid) { /* 0 means any process, we take the first one */ - return &s->processes[0]; + return &gdbserver_state.processes[0]; } =20 - for (i =3D 0; i < s->process_num; i++) { - if (s->processes[i].pid =3D=3D pid) { - return &s->processes[i]; + for (i =3D 0; i < gdbserver_state.process_num; i++) { + if (gdbserver_state.processes[i].pid =3D=3D pid) { + return &gdbserver_state.processes[i]; } } =20 return NULL; } =20 -static GDBProcess *gdb_get_cpu_process(const GDBState *s, CPUState *cpu) +static GDBProcess *gdb_get_cpu_process(CPUState *cpu) { - return gdb_get_process(s, gdb_get_cpu_pid(s, cpu)); + return gdb_get_process(gdb_get_cpu_pid(cpu)); } =20 static CPUState *find_cpu(uint32_t thread_id) @@ -733,13 +735,12 @@ static CPUState *find_cpu(uint32_t thread_id) return NULL; } =20 -static CPUState *get_first_cpu_in_process(const GDBState *s, - GDBProcess *process) +static CPUState *get_first_cpu_in_process(GDBProcess *process) { CPUState *cpu; =20 CPU_FOREACH(cpu) { - if (gdb_get_cpu_pid(s, cpu) =3D=3D process->pid) { + if (gdb_get_cpu_pid(cpu) =3D=3D process->pid) { return cpu; } } @@ -747,13 +748,13 @@ static CPUState *get_first_cpu_in_process(const GDBSt= ate *s, return NULL; } =20 -static CPUState *gdb_next_cpu_in_process(const GDBState *s, CPUState *cpu) +static CPUState *gdb_next_cpu_in_process(CPUState *cpu) { - uint32_t pid =3D gdb_get_cpu_pid(s, cpu); + uint32_t pid =3D gdb_get_cpu_pid(cpu); cpu =3D CPU_NEXT(cpu); =20 while (cpu) { - if (gdb_get_cpu_pid(s, cpu) =3D=3D pid) { + if (gdb_get_cpu_pid(cpu) =3D=3D pid) { break; } =20 @@ -764,12 +765,12 @@ static CPUState *gdb_next_cpu_in_process(const GDBSta= te *s, CPUState *cpu) } =20 /* Return the cpu following @cpu, while ignoring unattached processes. */ -static CPUState *gdb_next_attached_cpu(const GDBState *s, CPUState *cpu) +static CPUState *gdb_next_attached_cpu(CPUState *cpu) { cpu =3D CPU_NEXT(cpu); =20 while (cpu) { - if (gdb_get_cpu_process(s, cpu)->attached) { + if (gdb_get_cpu_process(cpu)->attached) { break; } =20 @@ -780,29 +781,29 @@ static CPUState *gdb_next_attached_cpu(const GDBState= *s, CPUState *cpu) } =20 /* Return the first attached cpu */ -static CPUState *gdb_first_attached_cpu(const GDBState *s) +static CPUState *gdb_first_attached_cpu(void) { CPUState *cpu =3D first_cpu; - GDBProcess *process =3D gdb_get_cpu_process(s, cpu); + GDBProcess *process =3D gdb_get_cpu_process(cpu); =20 if (!process->attached) { - return gdb_next_attached_cpu(s, cpu); + return gdb_next_attached_cpu(cpu); } =20 return cpu; } =20 -static CPUState *gdb_get_cpu(const GDBState *s, uint32_t pid, uint32_t tid) +static CPUState *gdb_get_cpu(uint32_t pid, uint32_t tid) { GDBProcess *process; CPUState *cpu; =20 if (!pid && !tid) { /* 0 means any process/thread, we take the first attached one */ - return gdb_first_attached_cpu(s); + return gdb_first_attached_cpu(); } else if (pid && !tid) { /* any thread in a specific process */ - process =3D gdb_get_process(s, pid); + process =3D gdb_get_process(pid); =20 if (process =3D=3D NULL) { return NULL; @@ -812,7 +813,7 @@ static CPUState *gdb_get_cpu(const GDBState *s, uint32_= t pid, uint32_t tid) return NULL; } =20 - return get_first_cpu_in_process(s, process); + return get_first_cpu_in_process(process); } else { /* a specific thread */ cpu =3D find_cpu(tid); @@ -821,7 +822,7 @@ static CPUState *gdb_get_cpu(const GDBState *s, uint32_= t pid, uint32_t tid) return NULL; } =20 - process =3D gdb_get_cpu_process(s, cpu); + process =3D gdb_get_cpu_process(cpu); =20 if (pid && process->pid !=3D pid) { return NULL; @@ -835,13 +836,13 @@ static CPUState *gdb_get_cpu(const GDBState *s, uint3= 2_t pid, uint32_t tid) } } =20 -static const char *get_feature_xml(const GDBState *s, const char *p, - const char **newp, GDBProcess *process) +static const char *get_feature_xml(const char *p, const char **newp, + GDBProcess *process) { size_t len; int i; const char *name; - CPUState *cpu =3D get_first_cpu_in_process(s, process); + CPUState *cpu =3D get_first_cpu_in_process(process); CPUClass *cc =3D CPU_GET_CLASS(cpu); =20 len =3D 0; @@ -1076,13 +1077,13 @@ static inline void gdb_cpu_breakpoint_remove_all(CP= UState *cpu) #endif } =20 -static void gdb_process_breakpoint_remove_all(const GDBState *s, GDBProces= s *p) +static void gdb_process_breakpoint_remove_all(GDBProcess *p) { - CPUState *cpu =3D get_first_cpu_in_process(s, p); + CPUState *cpu =3D get_first_cpu_in_process(p); =20 while (cpu) { gdb_cpu_breakpoint_remove_all(cpu); - cpu =3D gdb_next_cpu_in_process(s, cpu); + cpu =3D gdb_next_cpu_in_process(cpu); } } =20 @@ -1100,20 +1101,19 @@ static void gdb_breakpoint_remove_all(void) } } =20 -static void gdb_set_cpu_pc(GDBState *s, target_ulong pc) +static void gdb_set_cpu_pc(target_ulong pc) { - CPUState *cpu =3D s->c_cpu; + CPUState *cpu =3D gdbserver_state.c_cpu; =20 cpu_synchronize_state(cpu); cpu_set_pc(cpu, pc); } =20 -static char *gdb_fmt_thread_id(const GDBState *s, CPUState *cpu, - char *buf, size_t buf_size) +static char *gdb_fmt_thread_id(CPUState *cpu, char *buf, size_t buf_size) { - if (s->multiprocess) { + if (gdbserver_state.multiprocess) { snprintf(buf, buf_size, "p%02x.%02x", - gdb_get_cpu_pid(s, cpu), cpu_gdb_index(cpu)); + gdb_get_cpu_pid(cpu), cpu_gdb_index(cpu)); } else { snprintf(buf, buf_size, "%02x", cpu_gdb_index(cpu)); } @@ -1180,7 +1180,7 @@ static GDBThreadIdKind read_thread_id(const char *buf= , const char **end_buf, * returns -ENOTSUP if a command is unsupported, -EINVAL or -ERANGE if the= re is * a format error, 0 on success. */ -static int gdb_handle_vcont(GDBState *s, const char *p) +static int gdb_handle_vcont(const char *p) { int res, signal =3D 0; char cur_action; @@ -1255,36 +1255,36 @@ static int gdb_handle_vcont(GDBState *s, const char= *p) goto out; =20 case GDB_ALL_PROCESSES: - cpu =3D gdb_first_attached_cpu(s); + cpu =3D gdb_first_attached_cpu(); while (cpu) { if (newstates[cpu->cpu_index] =3D=3D 1) { newstates[cpu->cpu_index] =3D cur_action; } =20 - cpu =3D gdb_next_attached_cpu(s, cpu); + cpu =3D gdb_next_attached_cpu(cpu); } break; =20 case GDB_ALL_THREADS: - process =3D gdb_get_process(s, pid); + process =3D gdb_get_process(pid); =20 if (!process->attached) { res =3D -EINVAL; goto out; } =20 - cpu =3D get_first_cpu_in_process(s, process); + cpu =3D get_first_cpu_in_process(process); while (cpu) { if (newstates[cpu->cpu_index] =3D=3D 1) { newstates[cpu->cpu_index] =3D cur_action; } =20 - cpu =3D gdb_next_cpu_in_process(s, cpu); + cpu =3D gdb_next_cpu_in_process(cpu); } break; =20 case GDB_ONE_THREAD: - cpu =3D gdb_get_cpu(s, pid, tid); + cpu =3D gdb_get_cpu(pid, tid); =20 /* invalid CPU/thread specified */ if (!cpu) { @@ -1299,8 +1299,8 @@ static int gdb_handle_vcont(GDBState *s, const char *= p) break; } } - s->signal =3D signal; - gdb_continue_partial(s, newstates); + gdbserver_state.signal =3D signal; + gdb_continue_partial(newstates); =20 out: g_free(newstates); @@ -1409,7 +1409,6 @@ static int cmd_parse_params(const char *data, const c= har *schema, } =20 typedef struct GdbCmdContext { - GDBState *s; GdbCmdVariant *params; int num_params; uint8_t mem_buf[MAX_PACKET_LENGTH]; @@ -1453,7 +1452,7 @@ static inline int startswith(const char *string, cons= t char *pattern) return !strncmp(string, pattern, strlen(pattern)); } =20 -static int process_string_cmd(GDBState *s, void *user_ctx, const char *dat= a, +static int process_string_cmd(void *user_ctx, const char *data, const GdbCmdParseEntry *cmds, int num_cmds) { int i, schema_len, max_num_params =3D 0; @@ -1490,7 +1489,6 @@ static int process_string_cmd(GDBState *s, void *user= _ctx, const char *data, return -1; } =20 - gdb_ctx.s =3D s; cmd->handler(&gdb_ctx, user_ctx); return 0; } @@ -1498,8 +1496,7 @@ static int process_string_cmd(GDBState *s, void *user= _ctx, const char *data, return -1; } =20 -static void run_cmd_parser(GDBState *s, const char *data, - const GdbCmdParseEntry *cmd) +static void run_cmd_parser(const char *data, const GdbCmdParseEntry *cmd) { if (!data) { return; @@ -1507,44 +1504,43 @@ static void run_cmd_parser(GDBState *s, const char = *data, =20 /* In case there was an error during the command parsing we must * send a NULL packet to indicate the command is not supported */ - if (process_string_cmd(s, NULL, data, cmd, 1)) { - put_packet(s, ""); + if (process_string_cmd(NULL, data, cmd, 1)) { + put_packet(""); } } =20 static void handle_detach(GdbCmdContext *gdb_ctx, void *user_ctx) { GDBProcess *process; - GDBState *s =3D gdb_ctx->s; uint32_t pid =3D 1; =20 - if (s->multiprocess) { + if (gdbserver_state.multiprocess) { if (!gdb_ctx->num_params) { - put_packet(s, "E22"); + put_packet("E22"); return; } =20 pid =3D gdb_ctx->params[0].val_ul; } =20 - process =3D gdb_get_process(s, pid); - gdb_process_breakpoint_remove_all(s, process); + process =3D gdb_get_process(pid); + gdb_process_breakpoint_remove_all(process); process->attached =3D false; =20 - if (pid =3D=3D gdb_get_cpu_pid(s, s->c_cpu)) { - s->c_cpu =3D gdb_first_attached_cpu(s); + if (pid =3D=3D gdb_get_cpu_pid(gdbserver_state.c_cpu)) { + gdbserver_state.c_cpu =3D gdb_first_attached_cpu(); } =20 - if (pid =3D=3D gdb_get_cpu_pid(s, s->g_cpu)) { - s->g_cpu =3D gdb_first_attached_cpu(s); + if (pid =3D=3D gdb_get_cpu_pid(gdbserver_state.g_cpu)) { + gdbserver_state.g_cpu =3D gdb_first_attached_cpu(); } =20 - if (!s->c_cpu) { + if (!gdbserver_state.c_cpu) { /* No more process attached */ gdb_syscall_mode =3D GDB_SYS_DISABLED; - gdb_continue(s); + gdb_continue(); } - put_packet(s, "OK"); + put_packet("OK"); } =20 static void handle_thread_alive(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1552,33 +1548,33 @@ static void handle_thread_alive(GdbCmdContext *gdb_= ctx, void *user_ctx) CPUState *cpu; =20 if (!gdb_ctx->num_params) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 if (gdb_ctx->params[0].thread_id.kind =3D=3D GDB_READ_THREAD_ERR) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 - cpu =3D gdb_get_cpu(gdb_ctx->s, gdb_ctx->params[0].thread_id.pid, + cpu =3D gdb_get_cpu(gdb_ctx->params[0].thread_id.pid, gdb_ctx->params[0].thread_id.tid); if (!cpu) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } =20 static void handle_continue(GdbCmdContext *gdb_ctx, void *user_ctx) { if (gdb_ctx->num_params) { - gdb_set_cpu_pc(gdb_ctx->s, gdb_ctx->params[0].val_ull); + gdb_set_cpu_pc(gdb_ctx->params[0].val_ull); } =20 - gdb_ctx->s->signal =3D 0; - gdb_continue(gdb_ctx->s); + gdbserver_state.signal =3D 0; + gdb_continue(); } =20 static void handle_cont_with_sig(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1593,11 +1589,11 @@ static void handle_cont_with_sig(GdbCmdContext *gdb= _ctx, void *user_ctx) signal =3D gdb_ctx->params[0].val_ul; } =20 - gdb_ctx->s->signal =3D gdb_signal_to_target(signal); - if (gdb_ctx->s->signal =3D=3D -1) { - gdb_ctx->s->signal =3D 0; + gdbserver_state.signal =3D gdb_signal_to_target(signal); + if (gdbserver_state.signal =3D=3D -1) { + gdbserver_state.signal =3D 0; } - gdb_continue(gdb_ctx->s); + gdb_continue(); } =20 static void handle_set_thread(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1605,24 +1601,24 @@ static void handle_set_thread(GdbCmdContext *gdb_ct= x, void *user_ctx) CPUState *cpu; =20 if (gdb_ctx->num_params !=3D 2) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 if (gdb_ctx->params[1].thread_id.kind =3D=3D GDB_READ_THREAD_ERR) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 if (gdb_ctx->params[1].thread_id.kind !=3D GDB_ONE_THREAD) { - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); return; } =20 - cpu =3D gdb_get_cpu(gdb_ctx->s, gdb_ctx->params[1].thread_id.pid, + cpu =3D gdb_get_cpu(gdb_ctx->params[1].thread_id.pid, gdb_ctx->params[1].thread_id.tid); if (!cpu) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 @@ -1632,15 +1628,15 @@ static void handle_set_thread(GdbCmdContext *gdb_ct= x, void *user_ctx) */ switch (gdb_ctx->params[0].opcode) { case 'c': - gdb_ctx->s->c_cpu =3D cpu; - put_packet(gdb_ctx->s, "OK"); + gdbserver_state.c_cpu =3D cpu; + put_packet("OK"); break; case 'g': - gdb_ctx->s->g_cpu =3D cpu; - put_packet(gdb_ctx->s, "OK"); + gdbserver_state.g_cpu =3D cpu; + put_packet("OK"); break; default: - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); break; } } @@ -1650,7 +1646,7 @@ static void handle_insert_bp(GdbCmdContext *gdb_ctx, = void *user_ctx) int res; =20 if (gdb_ctx->num_params !=3D 3) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 @@ -1658,14 +1654,14 @@ static void handle_insert_bp(GdbCmdContext *gdb_ctx= , void *user_ctx) gdb_ctx->params[1].val_ull, gdb_ctx->params[2].val_ull); if (res >=3D 0) { - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); return; } else if (res =3D=3D -ENOSYS) { - put_packet(gdb_ctx->s, ""); + put_packet(""); return; } =20 - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); } =20 static void handle_remove_bp(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1673,7 +1669,7 @@ static void handle_remove_bp(GdbCmdContext *gdb_ctx, = void *user_ctx) int res; =20 if (gdb_ctx->num_params !=3D 3) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 @@ -1681,14 +1677,14 @@ static void handle_remove_bp(GdbCmdContext *gdb_ctx= , void *user_ctx) gdb_ctx->params[1].val_ull, gdb_ctx->params[2].val_ull); if (res >=3D 0) { - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); return; } else if (res =3D=3D -ENOSYS) { - put_packet(gdb_ctx->s, ""); + put_packet(""); return; } =20 - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); } =20 /* @@ -1707,20 +1703,20 @@ static void handle_set_reg(GdbCmdContext *gdb_ctx, = void *user_ctx) int reg_size; =20 if (!gdb_has_xml) { - put_packet(gdb_ctx->s, ""); + put_packet(""); return; } =20 if (gdb_ctx->num_params !=3D 2) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 reg_size =3D strlen(gdb_ctx->params[1].data) / 2; hextomem(gdb_ctx->mem_buf, gdb_ctx->params[1].data, reg_size); - gdb_write_register(gdb_ctx->s->g_cpu, gdb_ctx->mem_buf, + gdb_write_register(gdbserver_state.g_cpu, gdb_ctx->mem_buf, gdb_ctx->params[0].val_ull); - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } =20 static void handle_get_reg(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1728,73 +1724,73 @@ static void handle_get_reg(GdbCmdContext *gdb_ctx, = void *user_ctx) int reg_size; =20 if (!gdb_has_xml) { - put_packet(gdb_ctx->s, ""); + put_packet(""); return; } =20 if (!gdb_ctx->num_params) { - put_packet(gdb_ctx->s, "E14"); + put_packet("E14"); return; } =20 - reg_size =3D gdb_read_register(gdb_ctx->s->g_cpu, gdb_ctx->mem_buf, + reg_size =3D gdb_read_register(gdbserver_state.g_cpu, gdb_ctx->mem_buf, gdb_ctx->params[0].val_ull); if (!reg_size) { - put_packet(gdb_ctx->s, "E14"); + put_packet("E14"); return; } =20 memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, reg_size); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_write_mem(GdbCmdContext *gdb_ctx, void *user_ctx) { if (gdb_ctx->num_params !=3D 3) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 /* hextomem() reads 2*len bytes */ if (gdb_ctx->params[1].val_ull > strlen(gdb_ctx->params[2].data) / 2) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 hextomem(gdb_ctx->mem_buf, gdb_ctx->params[2].data, gdb_ctx->params[1].val_ull); - if (target_memory_rw_debug(gdb_ctx->s->g_cpu, gdb_ctx->params[0].val_u= ll, + if (target_memory_rw_debug(gdbserver_state.g_cpu, gdb_ctx->params[0].v= al_ull, gdb_ctx->mem_buf, gdb_ctx->params[1].val_ull, true)) { - put_packet(gdb_ctx->s, "E14"); + put_packet("E14"); return; } =20 - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } =20 static void handle_read_mem(GdbCmdContext *gdb_ctx, void *user_ctx) { if (gdb_ctx->num_params !=3D 2) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 /* memtohex() doubles the required space */ if (gdb_ctx->params[1].val_ull > MAX_PACKET_LENGTH / 2) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 - if (target_memory_rw_debug(gdb_ctx->s->g_cpu, gdb_ctx->params[0].val_u= ll, + if (target_memory_rw_debug(gdbserver_state.g_cpu, gdb_ctx->params[0].v= al_ull, gdb_ctx->mem_buf, gdb_ctx->params[1].val_ull, false)) { - put_packet(gdb_ctx->s, "E14"); + put_packet("E14"); return; } =20 memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, gdb_ctx->params[1].val_ul= l); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_write_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1807,37 +1803,37 @@ static void handle_write_all_regs(GdbCmdContext *gd= b_ctx, void *user_ctx) return; } =20 - cpu_synchronize_state(gdb_ctx->s->g_cpu); + cpu_synchronize_state(gdbserver_state.g_cpu); registers =3D gdb_ctx->mem_buf; len =3D strlen(gdb_ctx->params[0].data) / 2; hextomem(registers, gdb_ctx->params[0].data, len); - for (addr =3D 0; addr < gdb_ctx->s->g_cpu->gdb_num_g_regs && len > 0; + for (addr =3D 0; addr < gdbserver_state.g_cpu->gdb_num_g_regs && len >= 0; addr++) { - reg_size =3D gdb_write_register(gdb_ctx->s->g_cpu, registers, addr= ); + reg_size =3D gdb_write_register(gdbserver_state.g_cpu, registers, = addr); len -=3D reg_size; registers +=3D reg_size; } - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } =20 static void handle_read_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) { target_ulong addr, len; =20 - cpu_synchronize_state(gdb_ctx->s->g_cpu); + cpu_synchronize_state(gdbserver_state.g_cpu); len =3D 0; - for (addr =3D 0; addr < gdb_ctx->s->g_cpu->gdb_num_g_regs; addr++) { - len +=3D gdb_read_register(gdb_ctx->s->g_cpu, gdb_ctx->mem_buf + l= en, + for (addr =3D 0; addr < gdbserver_state.g_cpu->gdb_num_g_regs; addr++)= { + len +=3D gdb_read_register(gdbserver_state.g_cpu, gdb_ctx->mem_buf= + len, addr); } =20 memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, len); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_file_io(GdbCmdContext *gdb_ctx, void *user_ctx) { - if (gdb_ctx->num_params >=3D 1 && gdb_ctx->s->current_syscall_cb) { + if (gdb_ctx->num_params >=3D 1 && gdbserver_state.current_syscall_cb) { target_ulong ret, err; =20 ret =3D (target_ulong)gdb_ctx->params[0].val_ull; @@ -1846,31 +1842,31 @@ static void handle_file_io(GdbCmdContext *gdb_ctx, = void *user_ctx) } else { err =3D 0; } - gdb_ctx->s->current_syscall_cb(gdb_ctx->s->c_cpu, ret, err); - gdb_ctx->s->current_syscall_cb =3D NULL; + gdbserver_state.current_syscall_cb(gdbserver_state.c_cpu, ret, err= ); + gdbserver_state.current_syscall_cb =3D NULL; } =20 if (gdb_ctx->num_params >=3D 3 && gdb_ctx->params[2].opcode =3D=3D (ui= nt8_t)'C') { - put_packet(gdb_ctx->s, "T02"); + put_packet("T02"); return; } =20 - gdb_continue(gdb_ctx->s); + gdb_continue(); } =20 static void handle_step(GdbCmdContext *gdb_ctx, void *user_ctx) { if (gdb_ctx->num_params) { - gdb_set_cpu_pc(gdb_ctx->s, (target_ulong)gdb_ctx->params[0].val_ul= l); + gdb_set_cpu_pc((target_ulong)gdb_ctx->params[0].val_ull); } =20 - cpu_single_step(gdb_ctx->s->c_cpu, sstep_flags); - gdb_continue(gdb_ctx->s); + cpu_single_step(gdbserver_state.c_cpu, sstep_flags); + gdb_continue(); } =20 static void handle_v_cont_query(GdbCmdContext *gdb_ctx, void *user_ctx) { - put_packet(gdb_ctx->s, "vCont;c;C;s;S"); + put_packet("vCont;c;C;s;S"); } =20 static void handle_v_cont(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1881,11 +1877,11 @@ static void handle_v_cont(GdbCmdContext *gdb_ctx, v= oid *user_ctx) return; } =20 - res =3D gdb_handle_vcont(gdb_ctx->s, gdb_ctx->params[0].data); + res =3D gdb_handle_vcont(gdb_ctx->params[0].data); if ((res =3D=3D -EINVAL) || (res =3D=3D -ERANGE)) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); } else if (res) { - put_packet(gdb_ctx->s, ""); + put_packet(""); } } =20 @@ -1900,31 +1896,31 @@ static void handle_v_attach(GdbCmdContext *gdb_ctx,= void *user_ctx) goto cleanup; } =20 - process =3D gdb_get_process(gdb_ctx->s, gdb_ctx->params[0].val_ul); + process =3D gdb_get_process(gdb_ctx->params[0].val_ul); if (!process) { goto cleanup; } =20 - cpu =3D get_first_cpu_in_process(gdb_ctx->s, process); + cpu =3D get_first_cpu_in_process(process); if (!cpu) { goto cleanup; } =20 process->attached =3D true; - gdb_ctx->s->g_cpu =3D cpu; - gdb_ctx->s->c_cpu =3D cpu; + gdbserver_state.g_cpu =3D cpu; + gdbserver_state.c_cpu =3D cpu; =20 - gdb_fmt_thread_id(gdb_ctx->s, cpu, thread_id, sizeof(thread_id)); + gdb_fmt_thread_id(cpu, thread_id, sizeof(thread_id)); snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "T%02xthread:%s;", GDB_SIGNAL_TRAP, thread_id); cleanup: - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_v_kill(GdbCmdContext *gdb_ctx, void *user_ctx) { /* Kill the target */ - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); error_report("QEMU: Terminated via GDBstub"); exit(0); } @@ -1961,10 +1957,10 @@ static void handle_v_commands(GdbCmdContext *gdb_ct= x, void *user_ctx) return; } =20 - if (process_string_cmd(gdb_ctx->s, NULL, gdb_ctx->params[0].data, + if (process_string_cmd(NULL, gdb_ctx->params[0].data, gdb_v_commands_table, ARRAY_SIZE(gdb_v_commands_table))) { - put_packet(gdb_ctx->s, ""); + put_packet(""); } } =20 @@ -1973,7 +1969,7 @@ static void handle_query_qemu_sstepbits(GdbCmdContext= *gdb_ctx, void *user_ctx) snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "ENABLE=3D%x,NOIRQ=3D%x,NOTIMER=3D%x", SSTEP_ENABLE, SSTEP_NOIRQ, SSTEP_NOTIMER); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_set_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1983,13 +1979,13 @@ static void handle_set_qemu_sstep(GdbCmdContext *gd= b_ctx, void *user_ctx) } =20 sstep_flags =3D gdb_ctx->params[0].val_ul; - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } =20 static void handle_query_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) { snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "0x%x", sstep_fla= gs); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_query_curr_tid(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -2003,33 +1999,32 @@ static void handle_query_curr_tid(GdbCmdContext *gd= b_ctx, void *user_ctx) * the first thread of the current process (gdb returns the * first thread). */ - process =3D gdb_get_cpu_process(gdb_ctx->s, gdb_ctx->s->g_cpu); - cpu =3D get_first_cpu_in_process(gdb_ctx->s, process); - gdb_fmt_thread_id(gdb_ctx->s, cpu, thread_id, sizeof(thread_id)); + process =3D gdb_get_cpu_process(gdbserver_state.g_cpu); + cpu =3D get_first_cpu_in_process(process); + gdb_fmt_thread_id(cpu, thread_id, sizeof(thread_id)); snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "QC%s", thread_id= ); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_query_threads(GdbCmdContext *gdb_ctx, void *user_ctx) { char thread_id[16]; =20 - if (!gdb_ctx->s->query_cpu) { - put_packet(gdb_ctx->s, "l"); + if (!gdbserver_state.query_cpu) { + put_packet("l"); return; } =20 - gdb_fmt_thread_id(gdb_ctx->s, gdb_ctx->s->query_cpu, thread_id, + gdb_fmt_thread_id(gdbserver_state.query_cpu, thread_id, sizeof(thread_id)); snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "m%s", thread_id); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); - gdb_ctx->s->query_cpu =3D - gdb_next_attached_cpu(gdb_ctx->s, gdb_ctx->s->query_cpu); + put_packet(gdb_ctx->str_buf); + gdbserver_state.query_cpu =3D gdb_next_attached_cpu(gdbserver_state.qu= ery_cpu); } =20 static void handle_query_first_threads(GdbCmdContext *gdb_ctx, void *user_= ctx) { - gdb_ctx->s->query_cpu =3D gdb_first_attached_cpu(gdb_ctx->s); + gdbserver_state.query_cpu =3D gdb_first_attached_cpu(); handle_query_threads(gdb_ctx, user_ctx); } =20 @@ -2040,11 +2035,11 @@ static void handle_query_thread_extra(GdbCmdContext= *gdb_ctx, void *user_ctx) =20 if (!gdb_ctx->num_params || gdb_ctx->params[0].thread_id.kind =3D=3D GDB_READ_THREAD_ERR) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 - cpu =3D gdb_get_cpu(gdb_ctx->s, gdb_ctx->params[0].thread_id.pid, + cpu =3D gdb_get_cpu(gdb_ctx->params[0].thread_id.pid, gdb_ctx->params[0].thread_id.tid); if (!cpu) { return; @@ -2052,7 +2047,7 @@ static void handle_query_thread_extra(GdbCmdContext *= gdb_ctx, void *user_ctx) =20 cpu_synchronize_state(cpu); =20 - if (gdb_ctx->s->multiprocess && (gdb_ctx->s->process_num > 1)) { + if (gdbserver_state.multiprocess && (gdbserver_state.process_num > 1))= { /* Print the CPU model and name in multiprocess mode */ ObjectClass *oc =3D object_get_class(OBJECT(cpu)); const char *cpu_model =3D object_class_get_name(oc); @@ -2069,7 +2064,7 @@ static void handle_query_thread_extra(GdbCmdContext *= gdb_ctx, void *user_ctx) } trace_gdbstub_op_extra_info((char *)gdb_ctx->mem_buf); memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, len); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 #ifdef CONFIG_USER_ONLY @@ -2077,14 +2072,14 @@ static void handle_query_offsets(GdbCmdContext *gdb= _ctx, void *user_ctx) { TaskState *ts; =20 - ts =3D gdb_ctx->s->c_cpu->opaque; + ts =3D gdbserver_state.c_cpu->opaque; snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "Text=3D" TARGET_ABI_FMT_lx ";Data=3D" TARGET_ABI_FMT_lx ";Bss=3D" TARGET_ABI_FMT_lx, ts->info->code_offset, ts->info->data_offset, ts->info->data_offset); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } #else static void handle_query_rcmd(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -2092,21 +2087,21 @@ static void handle_query_rcmd(GdbCmdContext *gdb_ct= x, void *user_ctx) int len; =20 if (!gdb_ctx->num_params) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 len =3D strlen(gdb_ctx->params[0].data); if (len % 2) { - put_packet(gdb_ctx->s, "E01"); + put_packet("E01"); return; } =20 len =3D len / 2; hextomem(gdb_ctx->mem_buf, gdb_ctx->params[0].data, len); gdb_ctx->mem_buf[len++] =3D 0; - qemu_chr_be_write(gdb_ctx->s->mon_chr, gdb_ctx->mem_buf, len); - put_packet(gdb_ctx->s, "OK"); + qemu_chr_be_write(gdbserver_state.mon_chr, gdb_ctx->mem_buf, len); + put_packet("OK"); =20 } #endif @@ -2125,11 +2120,11 @@ static void handle_query_supported(GdbCmdContext *g= db_ctx, void *user_ctx) =20 if (gdb_ctx->num_params && strstr(gdb_ctx->params[0].data, "multiprocess+")) { - gdb_ctx->s->multiprocess =3D true; + gdbserver_state.multiprocess =3D true; } =20 pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), ";multiprocess+"); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_= ctx) @@ -2141,22 +2136,22 @@ static void handle_query_xfer_features(GdbCmdContex= t *gdb_ctx, void *user_ctx) const char *p; =20 if (gdb_ctx->num_params < 3) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 - process =3D gdb_get_cpu_process(gdb_ctx->s, gdb_ctx->s->g_cpu); - cc =3D CPU_GET_CLASS(gdb_ctx->s->g_cpu); + process =3D gdb_get_cpu_process(gdbserver_state.g_cpu); + cc =3D CPU_GET_CLASS(gdbserver_state.g_cpu); if (!cc->gdb_core_xml_file) { - put_packet(gdb_ctx->s, ""); + put_packet(""); return; } =20 gdb_has_xml =3D true; p =3D gdb_ctx->params[0].data; - xml =3D get_feature_xml(gdb_ctx->s, p, &p, process); + xml =3D get_feature_xml(p, &p, process); if (!xml) { - put_packet(gdb_ctx->s, "E00"); + put_packet("E00"); return; } =20 @@ -2164,7 +2159,7 @@ static void handle_query_xfer_features(GdbCmdContext = *gdb_ctx, void *user_ctx) len =3D gdb_ctx->params[2].val_ul; total_len =3D strlen(xml); if (addr > total_len) { - put_packet(gdb_ctx->s, "E00"); + put_packet("E00"); return; } =20 @@ -2180,12 +2175,12 @@ static void handle_query_xfer_features(GdbCmdContex= t *gdb_ctx, void *user_ctx) len =3D memtox(gdb_ctx->str_buf + 1, xml + addr, total_len - addr); } =20 - put_packet_binary(gdb_ctx->s, gdb_ctx->str_buf, len + 1, true); + put_packet_binary(gdb_ctx->str_buf, len + 1, true); } =20 static void handle_query_attached(GdbCmdContext *gdb_ctx, void *user_ctx) { - put_packet(gdb_ctx->s, GDB_ATTACHED); + put_packet(GDB_ATTACHED); } =20 static void handle_query_qemu_supported(GdbCmdContext *gdb_ctx, void *user= _ctx) @@ -2194,7 +2189,7 @@ static void handle_query_qemu_supported(GdbCmdContext= *gdb_ctx, void *user_ctx) #ifndef CONFIG_USER_ONLY pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), ";PhyMemMode"); #endif - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 #ifndef CONFIG_USER_ONLY @@ -2202,13 +2197,13 @@ static void handle_query_qemu_phy_mem_mode(GdbCmdCo= ntext *gdb_ctx, void *user_ctx) { snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "%d", phy_memory_= mode); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } =20 static void handle_set_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *use= r_ctx) { if (!gdb_ctx->num_params) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } =20 @@ -2217,7 +2212,7 @@ static void handle_set_qemu_phy_mem_mode(GdbCmdContex= t *gdb_ctx, void *user_ctx) } else { phy_memory_mode =3D 1; } - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } #endif =20 @@ -2333,16 +2328,16 @@ static void handle_gen_query(GdbCmdContext *gdb_ctx= , void *user_ctx) return; } =20 - if (!process_string_cmd(gdb_ctx->s, NULL, gdb_ctx->params[0].data, + if (!process_string_cmd(NULL, gdb_ctx->params[0].data, gdb_gen_query_set_common_table, ARRAY_SIZE(gdb_gen_query_set_common_table))) { return; } =20 - if (process_string_cmd(gdb_ctx->s, NULL, gdb_ctx->params[0].data, + if (process_string_cmd(NULL, gdb_ctx->params[0].data, gdb_gen_query_table, ARRAY_SIZE(gdb_gen_query_table))) { - put_packet(gdb_ctx->s, ""); + put_packet(""); } } =20 @@ -2352,16 +2347,16 @@ static void handle_gen_set(GdbCmdContext *gdb_ctx, = void *user_ctx) return; } =20 - if (!process_string_cmd(gdb_ctx->s, NULL, gdb_ctx->params[0].data, + if (!process_string_cmd(NULL, gdb_ctx->params[0].data, gdb_gen_query_set_common_table, ARRAY_SIZE(gdb_gen_query_set_common_table))) { return; } =20 - if (process_string_cmd(gdb_ctx->s, NULL, gdb_ctx->params[0].data, + if (process_string_cmd(NULL, gdb_ctx->params[0].data, gdb_gen_set_table, ARRAY_SIZE(gdb_gen_set_table))) { - put_packet(gdb_ctx->s, ""); + put_packet(""); } } =20 @@ -2369,11 +2364,11 @@ static void handle_target_halt(GdbCmdContext *gdb_c= tx, void *user_ctx) { char thread_id[16]; =20 - gdb_fmt_thread_id(gdb_ctx->s, gdb_ctx->s->c_cpu, thread_id, + gdb_fmt_thread_id(gdbserver_state.c_cpu, thread_id, sizeof(thread_id)); snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "T%02xthread:%s;", GDB_SIGNAL_TRAP, thread_id); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); /* * Remove all the breakpoints when this query is issued, * because gdb is doing an initial connect and the state @@ -2382,7 +2377,7 @@ static void handle_target_halt(GdbCmdContext *gdb_ctx= , void *user_ctx) gdb_breakpoint_remove_all(); } =20 -static int gdb_handle_packet(GDBState *s, const char *line_buf) +static int gdb_handle_packet(const char *line_buf) { const GdbCmdParseEntry *cmd_parser =3D NULL; =20 @@ -2390,7 +2385,7 @@ static int gdb_handle_packet(GDBState *s, const char = *line_buf) =20 switch (line_buf[0]) { case '!': - put_packet(s, "OK"); + put_packet("OK"); break; case '?': { @@ -2605,12 +2600,12 @@ static int gdb_handle_packet(GDBState *s, const cha= r *line_buf) break; default: /* put empty packet */ - put_packet(s, ""); + put_packet(""); break; } =20 if (cmd_parser) { - run_cmd_parser(s, line_buf, cmd_parser); + run_cmd_parser(line_buf, cmd_parser); } =20 return RS_IDLE; @@ -2618,7 +2613,7 @@ static int gdb_handle_packet(GDBState *s, const char = *line_buf) =20 void gdb_set_stop_cpu(CPUState *cpu) { - GDBProcess *p =3D gdb_get_cpu_process(&gdbserver_state, cpu); + GDBProcess *p =3D gdb_get_cpu_process(cpu); =20 if (!p->attached) { /* @@ -2635,19 +2630,18 @@ void gdb_set_stop_cpu(CPUState *cpu) #ifndef CONFIG_USER_ONLY static void gdb_vm_state_change(void *opaque, int running, RunState state) { - GDBState *s =3D &gdbserver_state; - CPUState *cpu =3D s->c_cpu; + CPUState *cpu =3D gdbserver_state.c_cpu; char buf[256]; char thread_id[16]; const char *type; int ret; =20 - if (running || s->state =3D=3D RS_INACTIVE) { + if (running || gdbserver_state.state =3D=3D RS_INACTIVE) { return; } /* Is there a GDB syscall waiting to be sent? */ - if (s->current_syscall_cb) { - put_packet(s, s->syscall_buf); + if (gdbserver_state.current_syscall_cb) { + put_packet(gdbserver_state.syscall_buf); return; } =20 @@ -2656,7 +2650,7 @@ static void gdb_vm_state_change(void *opaque, int run= ning, RunState state) return; } =20 - gdb_fmt_thread_id(s, cpu, thread_id, sizeof(thread_id)); + gdb_fmt_thread_id(cpu, thread_id, sizeof(thread_id)); =20 switch (state) { case RUN_STATE_DEBUG: @@ -2721,7 +2715,7 @@ static void gdb_vm_state_change(void *opaque, int run= ning, RunState state) snprintf(buf, sizeof(buf), "T%02xthread:%s;", ret, thread_id); =20 send_packet: - put_packet(s, buf); + put_packet(buf); =20 /* disable single step if it was enabled */ cpu_single_step(cpu, 0); @@ -2740,8 +2734,9 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, cons= t char *fmt, va_list va) target_ulong addr; uint64_t i64; =20 - if (!gdbserver_state.init) + if (!gdbserver_state.init) { return; + } =20 gdbserver_state.current_syscall_cb =3D cb; #ifndef CONFIG_USER_ONLY @@ -2781,7 +2776,7 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, cons= t char *fmt, va_list va) } *p =3D 0; #ifdef CONFIG_USER_ONLY - put_packet(&gdbserver_state, gdbserver_state.syscall_buf); + put_packet(gdbserver_state.syscall_buf); /* Return control to gdb for it to process the syscall request. * Since the protocol requires that gdb hands control back to us * using a "here are the results" F packet, we don't need to check @@ -2809,17 +2804,17 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, con= st char *fmt, ...) va_end(va); } =20 -static void gdb_read_byte(GDBState *s, uint8_t ch) +static void gdb_read_byte(uint8_t ch) { uint8_t reply; =20 #ifndef CONFIG_USER_ONLY - if (s->last_packet_len) { + if (gdbserver_state.last_packet_len) { /* Waiting for a response to the last packet. If we see the start of a new command then abandon the previous response. */ if (ch =3D=3D '-') { trace_gdbstub_err_got_nack(); - put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len); + put_buffer((uint8_t *)gdbserver_state.last_packet, gdbserver_s= tate.last_packet_len); } else if (ch =3D=3D '+') { trace_gdbstub_io_got_ack(); } else { @@ -2827,7 +2822,7 @@ static void gdb_read_byte(GDBState *s, uint8_t ch) } =20 if (ch =3D=3D '+' || ch =3D=3D '$') - s->last_packet_len =3D 0; + gdbserver_state.last_packet_len =3D 0; if (ch !=3D '$') return; } @@ -2838,13 +2833,13 @@ static void gdb_read_byte(GDBState *s, uint8_t ch) } else #endif { - switch(s->state) { + switch(gdbserver_state.state) { case RS_IDLE: if (ch =3D=3D '$') { /* start of command packet */ - s->line_buf_index =3D 0; - s->line_sum =3D 0; - s->state =3D RS_GETLINE; + gdbserver_state.line_buf_index =3D 0; + gdbserver_state.line_sum =3D 0; + gdbserver_state.state =3D RS_GETLINE; } else { trace_gdbstub_err_garbage(ch); } @@ -2852,37 +2847,37 @@ static void gdb_read_byte(GDBState *s, uint8_t ch) case RS_GETLINE: if (ch =3D=3D '}') { /* start escape sequence */ - s->state =3D RS_GETLINE_ESC; - s->line_sum +=3D ch; + gdbserver_state.state =3D RS_GETLINE_ESC; + gdbserver_state.line_sum +=3D ch; } else if (ch =3D=3D '*') { /* start run length encoding sequence */ - s->state =3D RS_GETLINE_RLE; - s->line_sum +=3D ch; + gdbserver_state.state =3D RS_GETLINE_RLE; + gdbserver_state.line_sum +=3D ch; } else if (ch =3D=3D '#') { /* end of command, start of checksum*/ - s->state =3D RS_CHKSUM1; - } else if (s->line_buf_index >=3D sizeof(s->line_buf) - 1) { + gdbserver_state.state =3D RS_CHKSUM1; + } else if (gdbserver_state.line_buf_index >=3D sizeof(gdbserve= r_state.line_buf) - 1) { trace_gdbstub_err_overrun(); - s->state =3D RS_IDLE; + gdbserver_state.state =3D RS_IDLE; } else { /* unescaped command character */ - s->line_buf[s->line_buf_index++] =3D ch; - s->line_sum +=3D ch; + gdbserver_state.line_buf[gdbserver_state.line_buf_index++]= =3D ch; + gdbserver_state.line_sum +=3D ch; } break; case RS_GETLINE_ESC: if (ch =3D=3D '#') { /* unexpected end of command in escape sequence */ - s->state =3D RS_CHKSUM1; - } else if (s->line_buf_index >=3D sizeof(s->line_buf) - 1) { + gdbserver_state.state =3D RS_CHKSUM1; + } else if (gdbserver_state.line_buf_index >=3D sizeof(gdbserve= r_state.line_buf) - 1) { /* command buffer overrun */ trace_gdbstub_err_overrun(); - s->state =3D RS_IDLE; + gdbserver_state.state =3D RS_IDLE; } else { /* parse escaped character and leave escape state */ - s->line_buf[s->line_buf_index++] =3D ch ^ 0x20; - s->line_sum +=3D ch; - s->state =3D RS_GETLINE; + gdbserver_state.line_buf[gdbserver_state.line_buf_index++]= =3D ch ^ 0x20; + gdbserver_state.line_sum +=3D ch; + gdbserver_state.state =3D RS_GETLINE; } break; case RS_GETLINE_RLE: @@ -2893,25 +2888,25 @@ static void gdb_read_byte(GDBState *s, uint8_t ch) if (ch < ' ' || ch =3D=3D '#' || ch =3D=3D '$' || ch > 126) { /* invalid RLE count encoding */ trace_gdbstub_err_invalid_repeat(ch); - s->state =3D RS_GETLINE; + gdbserver_state.state =3D RS_GETLINE; } else { /* decode repeat length */ int repeat =3D ch - ' ' + 3; - if (s->line_buf_index + repeat >=3D sizeof(s->line_buf) - = 1) { + if (gdbserver_state.line_buf_index + repeat >=3D sizeof(gd= bserver_state.line_buf) - 1) { /* that many repeats would overrun the command buffer = */ trace_gdbstub_err_overrun(); - s->state =3D RS_IDLE; - } else if (s->line_buf_index < 1) { + gdbserver_state.state =3D RS_IDLE; + } else if (gdbserver_state.line_buf_index < 1) { /* got a repeat but we have nothing to repeat */ trace_gdbstub_err_invalid_rle(); - s->state =3D RS_GETLINE; + gdbserver_state.state =3D RS_GETLINE; } else { /* repeat the last character */ - memset(s->line_buf + s->line_buf_index, - s->line_buf[s->line_buf_index - 1], repeat); - s->line_buf_index +=3D repeat; - s->line_sum +=3D ch; - s->state =3D RS_GETLINE; + memset(gdbserver_state.line_buf + gdbserver_state.line= _buf_index, + gdbserver_state.line_buf[gdbserver_state.line_b= uf_index - 1], repeat); + gdbserver_state.line_buf_index +=3D repeat; + gdbserver_state.line_sum +=3D ch; + gdbserver_state.state =3D RS_GETLINE; } } break; @@ -2919,33 +2914,33 @@ static void gdb_read_byte(GDBState *s, uint8_t ch) /* get high hex digit of checksum */ if (!isxdigit(ch)) { trace_gdbstub_err_checksum_invalid(ch); - s->state =3D RS_GETLINE; + gdbserver_state.state =3D RS_GETLINE; break; } - s->line_buf[s->line_buf_index] =3D '\0'; - s->line_csum =3D fromhex(ch) << 4; - s->state =3D RS_CHKSUM2; + gdbserver_state.line_buf[gdbserver_state.line_buf_index] =3D '= \0'; + gdbserver_state.line_csum =3D fromhex(ch) << 4; + gdbserver_state.state =3D RS_CHKSUM2; break; case RS_CHKSUM2: /* get low hex digit of checksum */ if (!isxdigit(ch)) { trace_gdbstub_err_checksum_invalid(ch); - s->state =3D RS_GETLINE; + gdbserver_state.state =3D RS_GETLINE; break; } - s->line_csum |=3D fromhex(ch); + gdbserver_state.line_csum |=3D fromhex(ch); =20 - if (s->line_csum !=3D (s->line_sum & 0xff)) { - trace_gdbstub_err_checksum_incorrect(s->line_sum, s->line_= csum); + if (gdbserver_state.line_csum !=3D (gdbserver_state.line_sum &= 0xff)) { + trace_gdbstub_err_checksum_incorrect(gdbserver_state.line_= sum, gdbserver_state.line_csum); /* send NAK reply */ reply =3D '-'; - put_buffer(s, &reply, 1); - s->state =3D RS_IDLE; + put_buffer(&reply, 1); + gdbserver_state.state =3D RS_IDLE; } else { /* send ACK reply */ reply =3D '+'; - put_buffer(s, &reply, 1); - s->state =3D gdb_handle_packet(s, s->line_buf); + put_buffer(&reply, 1); + gdbserver_state.state =3D gdb_handle_packet(gdbserver_stat= e.line_buf); } break; default: @@ -2971,7 +2966,7 @@ void gdb_exit(CPUArchState *env, int code) trace_gdbstub_op_exiting((uint8_t)code); =20 snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code); - put_packet(&gdbserver_state, buf); + put_packet(buf); =20 #ifndef CONFIG_USER_ONLY qemu_chr_fe_deinit(&gdbserver_state.chr, true); @@ -2988,7 +2983,7 @@ static void create_default_process(GDBState *s) GDBProcess *process; int max_pid =3D 0; =20 - if (s->process_num) { + if (gdbserver_state.process_num) { max_pid =3D s->processes[s->process_num - 1].pid; } =20 @@ -3020,7 +3015,7 @@ gdb_handlesig(CPUState *cpu, int sig) =20 if (sig !=3D 0) { snprintf(buf, sizeof(buf), "S%02x", target_signal_to_gdb(sig)); - put_packet(&gdbserver_state, buf); + put_packet(buf); } /* put_packet() might have detected that the peer terminated the connection. */ @@ -3037,7 +3032,7 @@ gdb_handlesig(CPUState *cpu, int sig) int i; =20 for (i =3D 0; i < n; i++) { - gdb_read_byte(&gdbserver_state, buf[i]); + gdb_read_byte(buf[i]); } } else { /* XXX: Connection closed. Should probably wait for another @@ -3064,7 +3059,7 @@ void gdb_signalled(CPUArchState *env, int sig) } =20 snprintf(buf, sizeof(buf), "X%02x", target_signal_to_gdb(sig)); - put_packet(&gdbserver_state, buf); + put_packet(buf); } =20 static bool gdb_accept(void) @@ -3095,7 +3090,7 @@ static bool gdb_accept(void) init_gdbserver_state(); create_default_process(&gdbserver_state); gdbserver_state.processes[0].attached =3D true; - gdbserver_state.c_cpu =3D gdb_first_attached_cpu(&gdbserver_state); + gdbserver_state.c_cpu =3D gdb_first_attached_cpu(); gdbserver_state.g_cpu =3D gdbserver_state.c_cpu; gdbserver_state.fd =3D fd; gdb_has_xml =3D false; @@ -3172,7 +3167,7 @@ static void gdb_chr_receive(void *opaque, const uint8= _t *buf, int size) int i; =20 for (i =3D 0; i < size; i++) { - gdb_read_byte(&gdbserver_state, buf[i]); + gdb_read_byte(buf[i]); } } =20 @@ -3188,7 +3183,7 @@ static void gdb_chr_event(void *opaque, int event) s->processes[i].attached =3D !i; } =20 - s->c_cpu =3D gdb_first_attached_cpu(s); + s->c_cpu =3D gdb_first_attached_cpu(); s->g_cpu =3D s->c_cpu; =20 vm_stop(RUN_STATE_PAUSED); @@ -3199,7 +3194,7 @@ static void gdb_chr_event(void *opaque, int event) } } =20 -static void gdb_monitor_output(GDBState *s, const char *msg, int len) +static void gdb_monitor_output(const char *msg, int len) { char buf[MAX_PACKET_LENGTH]; =20 @@ -3207,7 +3202,7 @@ static void gdb_monitor_output(GDBState *s, const cha= r *msg, int len) if (len > (MAX_PACKET_LENGTH/2) - 1) len =3D (MAX_PACKET_LENGTH/2) - 1; memtohex(buf + 1, (uint8_t *)msg, len); - put_packet(s, buf); + put_packet(buf); } =20 static int gdb_monitor_write(Chardev *chr, const uint8_t *buf, int len) @@ -3218,10 +3213,10 @@ static int gdb_monitor_write(Chardev *chr, const ui= nt8_t *buf, int len) max_sz =3D (sizeof(gdbserver_state.last_packet) - 2) / 2; for (;;) { if (len <=3D max_sz) { - gdb_monitor_output(&gdbserver_state, p, len); + gdb_monitor_output(p, len); break; } - gdb_monitor_output(&gdbserver_state, p, max_sz); + gdb_monitor_output(p, max_sz); p +=3D max_sz; len -=3D max_sz; } @@ -3305,9 +3300,9 @@ static void create_processes(GDBState *s) { object_child_foreach(object_get_root(), find_cpu_clusters, s); =20 - if (s->processes) { + if (gdbserver_state.processes) { /* Sort by PID */ - qsort(s->processes, s->process_num, sizeof(s->processes[0]), pid_o= rder); + qsort(gdbserver_state.processes, gdbserver_state.process_num, size= of(gdbserver_state.processes[0]), pid_order); } =20 create_default_process(s); @@ -3387,7 +3382,7 @@ int gdbserver_start(const char *device) void gdbserver_cleanup(void) { if (gdbserver_state.init) { - put_packet(&gdbserver_state, "W00"); + put_packet("W00"); } } =20 --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576843626; cv=none; d=zohomail.com; s=zohoarc; b=LdD1ISwGQSuvt0jxv+kgE8JQs05hNJXj01kbLTYZxxwRt1RfBS+Amgb7y6lz4uKSmL3iS7B6vjUzyDpRDrG2CunOZJPesDzS+fS2A9l7D1tlAVUBjbeU3zrjDzWs16G387PIdVXZySvpF3Mel0NJ7iwQBPOpiYrDMBgeiOxy+wQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576843626; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RRppQbj+sXywUjOQA2w87Jf3PtvabL0PQyQmHfRcQXo=; b=jeE55gr8x4kTTkusro3x6P+AneJt+80qSU1/kUb9PqljkQJIB9wVkL1QevpG5zViqHzSdhl1U5+9xLrgD0ugYQNaku8ioZYrukN95hDR/Hu5Ww7UAUMokx791bauIRAa/VTQC7KClvfVVPuvYRCuHWWhIZAHUC+oo54uTZBqER4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576843626539276.41218127434365; Fri, 20 Dec 2019 04:07:06 -0800 (PST) Received: from localhost ([::1]:53986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH3h-0006SZ-6C for importer@patchew.org; Fri, 20 Dec 2019 07:07:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52356) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1V-0004eJ-V0 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1T-0007VF-DJ for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:49 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:35139) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1S-0007Qn-ST for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:47 -0500 Received: by mail-wm1-x341.google.com with SMTP id p17so8999928wmb.0 for ; Fri, 20 Dec 2019 04:04:46 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id f127sm8140798wma.4.2019.12.20.04.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:41 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 28A871FF90; Fri, 20 Dec 2019 12:04:39 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RRppQbj+sXywUjOQA2w87Jf3PtvabL0PQyQmHfRcQXo=; b=q7TmYNKWU5PtbBxYlqGHX6d0UF1Sh7xr+8MrmolwyK49r9W619SkSTzjX7n7pza6Qn rc6dlJRvCwuv7vZZKgoQjqwdk9GDmcCDGMyqMaPUlXHMjIHD1eO6xCeZ/5GzVnWqBWFR R67PHSNxpCl538ZmulzmByvFlfEArdGpp1Kv0F+k3AYeXKGBaBp54Z7gtliSW9kodAfW Xhi3iYVX2bJJDQ9S6BmfDyC87Y+T7AL2yIFdGIZ3c6TjAz4EAaJ0X30RNFtuok7EaIS1 IDK28rwAlmGhVhbac7W20dKldP5bll3A1ivN3LVQRWAyPoV2Yk9BpqRXiCNPkRj/9/DD LjvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RRppQbj+sXywUjOQA2w87Jf3PtvabL0PQyQmHfRcQXo=; b=tioB8MUbcpD+Dd0nYCqa85faHbvoLHpKgS2hxZc6799C1Fuq1A545kbACUjMGEjUYB Y658zcNYiIbCRS99gI/zccsyvzR8udOydJq6obOK5oNZBx1PRvtaGc5k9q3ksLX5H0km x42p1A75fy7Mb30QJ30Mn62nKdbHmHXqw4/yMu3KDFzxwW38XN2J0TXqOUdOevYyk/8r j8DQQ6QSLowWnR7JLGprZxF+r3QfVHaIfo9G+uzInD9YLFaWnJyCzF/bPmb9CKie2XGE SyOel7z126Pi10UnePgcOTHdDNaLcukqsRBNoYnjHBkJeLxZoHpzYlFTZgcO3aEUx38x FhEw== X-Gm-Message-State: APjAAAUaTBiglyE4tpj4a9cnJBuTDiO15fLxSOb+Dp3VkyTivMRwOVxZ It4lTtOulbdaScqx6nnY23+LrA== X-Google-Smtp-Source: APXvYqxcj6F8n7bdIfN6gUK+BGICtvt74k7ruuQbt83/rQtZY5QtDAT3V62xP1bPpGMRoJXAUDZDKg== X-Received: by 2002:a1c:20d3:: with SMTP id g202mr16307905wmg.169.1576843485550; Fri, 20 Dec 2019 04:04:45 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 03/21] gdbstub: move str_buf to GDBState and use GString Date: Fri, 20 Dec 2019 12:04:20 +0000 Message-Id: <20191220120438.16114-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, luis.machado@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , alan.hayward@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Rather than having a static buffer replace str_buf with a GString which we know can grow on demand. Convert the internal functions to take a GString instead of a char * and length. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson Reviewed-by: Damien Hedde Tested-by: Damien Hedde --- v2 - fix conflict from status gdbserver_state - add put_strbuf helper v3 - remove double ;; --- gdbstub.c | 195 +++++++++++++++++++++++++----------------------------- 1 file changed, 90 insertions(+), 105 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 85ef7d37e08..80d99c209ff 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -366,6 +366,7 @@ typedef struct GDBState { int process_num; char syscall_buf[256]; gdb_syscall_complete_cb current_syscall_cb; + GString *str_buf; } GDBState; =20 /* By default use no IRQs and no timers while single stepping so as to @@ -380,6 +381,7 @@ static void init_gdbserver_state(void) g_assert(!gdbserver_state.init); memset(&gdbserver_state, 0, sizeof(GDBState)); gdbserver_state.init =3D true; + gdbserver_state.str_buf =3D g_string_new(NULL); } =20 #ifndef CONFIG_USER_ONLY @@ -563,17 +565,15 @@ static inline int tohex(int v) } =20 /* writes 2*len+1 bytes in buf */ -static void memtohex(char *buf, const uint8_t *mem, int len) +static void memtohex(GString *buf, const uint8_t *mem, int len) { int i, c; - char *q; - q =3D buf; for(i =3D 0; i < len; i++) { c =3D mem[i]; - *q++ =3D tohex(c >> 4); - *q++ =3D tohex(c & 0xf); + g_string_append_c(buf, tohex(c >> 4)); + g_string_append_c(buf, tohex(c & 0xf)); } - *q =3D '\0'; + g_string_append_c(buf, '\0'); } =20 static void hextomem(uint8_t *mem, const char *buf, int len) @@ -667,25 +667,28 @@ static int put_packet(const char *buf) return put_packet_binary(buf, strlen(buf), false); } =20 +static void put_strbuf(void) +{ + put_packet(gdbserver_state.str_buf->str); +} + /* Encode data using the encoding for 'x' packets. */ -static int memtox(char *buf, const char *mem, int len) +static void memtox(GString *buf, const char *mem, int len) { - char *p =3D buf; char c; =20 while (len--) { c =3D *(mem++); switch (c) { case '#': case '$': case '*': case '}': - *(p++) =3D '}'; - *(p++) =3D c ^ 0x20; + g_string_append_c(buf, '}'); + g_string_append_c(buf, c ^ 0x20); break; default: - *(p++) =3D c; + g_string_append_c(buf, c); break; } } - return p - buf; } =20 static uint32_t gdb_get_cpu_pid(CPUState *cpu) @@ -1109,16 +1112,14 @@ static void gdb_set_cpu_pc(target_ulong pc) cpu_set_pc(cpu, pc); } =20 -static char *gdb_fmt_thread_id(CPUState *cpu, char *buf, size_t buf_size) +static void gdb_append_thread_id(CPUState *cpu, GString *buf) { if (gdbserver_state.multiprocess) { - snprintf(buf, buf_size, "p%02x.%02x", - gdb_get_cpu_pid(cpu), cpu_gdb_index(cpu)); + g_string_append_printf(buf, "p%02x.%02x", + gdb_get_cpu_pid(cpu), cpu_gdb_index(cpu)); } else { - snprintf(buf, buf_size, "%02x", cpu_gdb_index(cpu)); + g_string_append_printf(buf, "%02x", cpu_gdb_index(cpu)); } - - return buf; } =20 typedef enum GDBThreadIdKind { @@ -1412,7 +1413,6 @@ typedef struct GdbCmdContext { GdbCmdVariant *params; int num_params; uint8_t mem_buf[MAX_PACKET_LENGTH]; - char str_buf[MAX_PACKET_LENGTH + 1]; } GdbCmdContext; =20 typedef void (*GdbCmdHandler)(GdbCmdContext *gdb_ctx, void *user_ctx); @@ -1502,6 +1502,8 @@ static void run_cmd_parser(const char *data, const Gd= bCmdParseEntry *cmd) return; } =20 + g_string_set_size(gdbserver_state.str_buf, 0); + /* In case there was an error during the command parsing we must * send a NULL packet to indicate the command is not supported */ if (process_string_cmd(NULL, data, cmd, 1)) { @@ -1740,8 +1742,8 @@ static void handle_get_reg(GdbCmdContext *gdb_ctx, vo= id *user_ctx) return; } =20 - memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, reg_size); - put_packet(gdb_ctx->str_buf); + memtohex(gdbserver_state.str_buf, gdb_ctx->mem_buf, reg_size); + put_strbuf(); } =20 static void handle_write_mem(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1789,8 +1791,8 @@ static void handle_read_mem(GdbCmdContext *gdb_ctx, v= oid *user_ctx) return; } =20 - memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, gdb_ctx->params[1].val_ul= l); - put_packet(gdb_ctx->str_buf); + memtohex(gdbserver_state.str_buf, gdb_ctx->mem_buf, gdb_ctx->params[1]= .val_ull); + put_strbuf(); } =20 static void handle_write_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1827,8 +1829,8 @@ static void handle_read_all_regs(GdbCmdContext *gdb_c= tx, void *user_ctx) addr); } =20 - memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, len); - put_packet(gdb_ctx->str_buf); + memtohex(gdbserver_state.str_buf, gdb_ctx->mem_buf, len); + put_strbuf(); } =20 static void handle_file_io(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1889,9 +1891,8 @@ static void handle_v_attach(GdbCmdContext *gdb_ctx, v= oid *user_ctx) { GDBProcess *process; CPUState *cpu; - char thread_id[16]; =20 - pstrcpy(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "E22"); + g_string_assign(gdbserver_state.str_buf, "E22"); if (!gdb_ctx->num_params) { goto cleanup; } @@ -1910,11 +1911,11 @@ static void handle_v_attach(GdbCmdContext *gdb_ctx,= void *user_ctx) gdbserver_state.g_cpu =3D cpu; gdbserver_state.c_cpu =3D cpu; =20 - gdb_fmt_thread_id(cpu, thread_id, sizeof(thread_id)); - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "T%02xthread:%s;", - GDB_SIGNAL_TRAP, thread_id); + g_string_printf(gdbserver_state.str_buf, "T%02xthread:", GDB_SIGNAL_TR= AP); + gdb_append_thread_id(cpu, gdbserver_state.str_buf); + g_string_append_c(gdbserver_state.str_buf, ';'); cleanup: - put_packet(gdb_ctx->str_buf); + put_strbuf(); } =20 static void handle_v_kill(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1966,10 +1967,9 @@ static void handle_v_commands(GdbCmdContext *gdb_ctx= , void *user_ctx) =20 static void handle_query_qemu_sstepbits(GdbCmdContext *gdb_ctx, void *user= _ctx) { - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), - "ENABLE=3D%x,NOIRQ=3D%x,NOTIMER=3D%x", SSTEP_ENABLE, - SSTEP_NOIRQ, SSTEP_NOTIMER); - put_packet(gdb_ctx->str_buf); + g_string_printf(gdbserver_state.str_buf, "ENABLE=3D%x,NOIRQ=3D%x,NOTIM= ER=3D%x", + SSTEP_ENABLE, SSTEP_NOIRQ, SSTEP_NOTIMER); + put_strbuf(); } =20 static void handle_set_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1984,15 +1984,14 @@ static void handle_set_qemu_sstep(GdbCmdContext *gd= b_ctx, void *user_ctx) =20 static void handle_query_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) { - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "0x%x", sstep_fla= gs); - put_packet(gdb_ctx->str_buf); + g_string_printf(gdbserver_state.str_buf, "0x%x", sstep_flags); + put_strbuf(); } =20 static void handle_query_curr_tid(GdbCmdContext *gdb_ctx, void *user_ctx) { CPUState *cpu; GDBProcess *process; - char thread_id[16]; =20 /* * "Current thread" remains vague in the spec, so always return @@ -2001,24 +2000,21 @@ static void handle_query_curr_tid(GdbCmdContext *gd= b_ctx, void *user_ctx) */ process =3D gdb_get_cpu_process(gdbserver_state.g_cpu); cpu =3D get_first_cpu_in_process(process); - gdb_fmt_thread_id(cpu, thread_id, sizeof(thread_id)); - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "QC%s", thread_id= ); - put_packet(gdb_ctx->str_buf); + g_string_assign(gdbserver_state.str_buf, "QC"); + gdb_append_thread_id(cpu, gdbserver_state.str_buf); + put_strbuf(); } =20 static void handle_query_threads(GdbCmdContext *gdb_ctx, void *user_ctx) { - char thread_id[16]; - if (!gdbserver_state.query_cpu) { put_packet("l"); return; } =20 - gdb_fmt_thread_id(gdbserver_state.query_cpu, thread_id, - sizeof(thread_id)); - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "m%s", thread_id); - put_packet(gdb_ctx->str_buf); + g_string_assign(gdbserver_state.str_buf, "m"); + gdb_append_thread_id(gdbserver_state.query_cpu, gdbserver_state.str_bu= f); + put_strbuf(); gdbserver_state.query_cpu =3D gdb_next_attached_cpu(gdbserver_state.qu= ery_cpu); } =20 @@ -2030,8 +2026,8 @@ static void handle_query_first_threads(GdbCmdContext = *gdb_ctx, void *user_ctx) =20 static void handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_c= tx) { + g_autoptr(GString) rs =3D g_string_new(NULL); CPUState *cpu; - int len; =20 if (!gdb_ctx->num_params || gdb_ctx->params[0].thread_id.kind =3D=3D GDB_READ_THREAD_ERR) { @@ -2051,20 +2047,17 @@ static void handle_query_thread_extra(GdbCmdContext= *gdb_ctx, void *user_ctx) /* Print the CPU model and name in multiprocess mode */ ObjectClass *oc =3D object_get_class(OBJECT(cpu)); const char *cpu_model =3D object_class_get_name(oc); - char *cpu_name =3D object_get_canonical_path_component(OBJECT(cpu)= ); - len =3D snprintf((char *)gdb_ctx->mem_buf, sizeof(gdb_ctx->str_buf= ) / 2, - "%s %s [%s]", cpu_model, cpu_name, - cpu->halted ? "halted " : "running"); - g_free(cpu_name); + g_autofree char *cpu_name; + cpu_name =3D object_get_canonical_path_component(OBJECT(cpu)); + g_string_printf(rs, "%s %s [%s]", cpu_model, cpu_name, + cpu->halted ? "halted " : "running"); } else { - /* memtohex() doubles the required space */ - len =3D snprintf((char *)gdb_ctx->mem_buf, sizeof(gdb_ctx->str_buf= ) / 2, - "CPU#%d [%s]", cpu->cpu_index, + g_string_printf(rs, "CPU#%d [%s]", cpu->cpu_index, cpu->halted ? "halted " : "running"); } - trace_gdbstub_op_extra_info((char *)gdb_ctx->mem_buf); - memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, len); - put_packet(gdb_ctx->str_buf); + trace_gdbstub_op_extra_info(rs->str); + memtohex(gdbserver_state.str_buf, (uint8_t *)rs->str, rs->len); + put_strbuf(); } =20 #ifdef CONFIG_USER_ONLY @@ -2073,13 +2066,14 @@ static void handle_query_offsets(GdbCmdContext *gdb= _ctx, void *user_ctx) TaskState *ts; =20 ts =3D gdbserver_state.c_cpu->opaque; - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), - "Text=3D" TARGET_ABI_FMT_lx ";Data=3D" TARGET_ABI_FMT_lx - ";Bss=3D" TARGET_ABI_FMT_lx, - ts->info->code_offset, - ts->info->data_offset, - ts->info->data_offset); - put_packet(gdb_ctx->str_buf); + g_string_printf(gdbserver_state.str_buf, + "Text=3D" TARGET_ABI_FMT_lx + ";Data=3D" TARGET_ABI_FMT_lx + ";Bss=3D" TARGET_ABI_FMT_lx, + ts->info->code_offset, + ts->info->data_offset, + ts->info->data_offset); + put_strbuf(); } #else static void handle_query_rcmd(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -2110,12 +2104,10 @@ static void handle_query_supported(GdbCmdContext *g= db_ctx, void *user_ctx) { CPUClass *cc; =20 - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "PacketSize=3D%x", - MAX_PACKET_LENGTH); + g_string_printf(gdbserver_state.str_buf, "PacketSize=3D%x", MAX_PACKET= _LENGTH); cc =3D CPU_GET_CLASS(first_cpu); if (cc->gdb_core_xml_file) { - pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), - ";qXfer:features:read+"); + g_string_append(gdbserver_state.str_buf, ";qXfer:features:read+"); } =20 if (gdb_ctx->num_params && @@ -2123,8 +2115,8 @@ static void handle_query_supported(GdbCmdContext *gdb= _ctx, void *user_ctx) gdbserver_state.multiprocess =3D true; } =20 - pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), ";multiprocess+"); - put_packet(gdb_ctx->str_buf); + g_string_append(gdbserver_state.str_buf, ";multiprocess+"); + put_strbuf(); } =20 static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_= ctx) @@ -2168,14 +2160,15 @@ static void handle_query_xfer_features(GdbCmdContex= t *gdb_ctx, void *user_ctx) } =20 if (len < total_len - addr) { - gdb_ctx->str_buf[0] =3D 'm'; - len =3D memtox(gdb_ctx->str_buf + 1, xml + addr, len); + g_string_assign(gdbserver_state.str_buf, "m"); + memtox(gdbserver_state.str_buf, xml + addr, len); } else { - gdb_ctx->str_buf[0] =3D 'l'; - len =3D memtox(gdb_ctx->str_buf + 1, xml + addr, total_len - addr); + g_string_assign(gdbserver_state.str_buf, "l"); + memtox(gdbserver_state.str_buf, xml + addr, total_len - addr); } =20 - put_packet_binary(gdb_ctx->str_buf, len + 1, true); + put_packet_binary(gdbserver_state.str_buf->str, + gdbserver_state.str_buf->len, true); } =20 static void handle_query_attached(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -2185,19 +2178,19 @@ static void handle_query_attached(GdbCmdContext *gd= b_ctx, void *user_ctx) =20 static void handle_query_qemu_supported(GdbCmdContext *gdb_ctx, void *user= _ctx) { - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "sstepbits;sstep"= ); + g_string_printf(gdbserver_state.str_buf, "sstepbits;sstep"); #ifndef CONFIG_USER_ONLY - pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), ";PhyMemMode"); + g_string_append(gdbserver_state.str_buf, ";PhyMemMode"); #endif - put_packet(gdb_ctx->str_buf); + put_strbuf(); } =20 #ifndef CONFIG_USER_ONLY static void handle_query_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *user_ctx) { - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "%d", phy_memory_= mode); - put_packet(gdb_ctx->str_buf); + g_string_printf(gdbserver_state.str_buf, "%d", phy_memory_mode); + put_strbuf(); } =20 static void handle_set_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *use= r_ctx) @@ -2362,13 +2355,10 @@ static void handle_gen_set(GdbCmdContext *gdb_ctx, = void *user_ctx) =20 static void handle_target_halt(GdbCmdContext *gdb_ctx, void *user_ctx) { - char thread_id[16]; - - gdb_fmt_thread_id(gdbserver_state.c_cpu, thread_id, - sizeof(thread_id)); - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "T%02xthread:%s;", - GDB_SIGNAL_TRAP, thread_id); - put_packet(gdb_ctx->str_buf); + g_string_printf(gdbserver_state.str_buf, "T%02xthread:", GDB_SIGNAL_TR= AP); + gdb_append_thread_id(gdbserver_state.c_cpu, gdbserver_state.str_buf); + g_string_append_c(gdbserver_state.str_buf, ';'); + put_strbuf(); /* * Remove all the breakpoints when this query is issued, * because gdb is doing an initial connect and the state @@ -2631,8 +2621,8 @@ void gdb_set_stop_cpu(CPUState *cpu) static void gdb_vm_state_change(void *opaque, int running, RunState state) { CPUState *cpu =3D gdbserver_state.c_cpu; - char buf[256]; - char thread_id[16]; + g_autoptr(GString) buf =3D g_string_new(NULL); + g_autoptr(GString) tid =3D g_string_new(NULL); const char *type; int ret; =20 @@ -2650,7 +2640,7 @@ static void gdb_vm_state_change(void *opaque, int run= ning, RunState state) return; } =20 - gdb_fmt_thread_id(cpu, thread_id, sizeof(thread_id)); + gdb_append_thread_id(cpu, tid); =20 switch (state) { case RUN_STATE_DEBUG: @@ -2668,10 +2658,9 @@ static void gdb_vm_state_change(void *opaque, int ru= nning, RunState state) } trace_gdbstub_hit_watchpoint(type, cpu_gdb_index(cpu), (target_ulong)cpu->watchpoint_hit->vaddr); - snprintf(buf, sizeof(buf), - "T%02xthread:%s;%swatch:" TARGET_FMT_lx ";", - GDB_SIGNAL_TRAP, thread_id, type, - (target_ulong)cpu->watchpoint_hit->vaddr); + g_string_printf(buf, "T%02xthread:%s;%swatch:" TARGET_FMT_lx "= ;", + GDB_SIGNAL_TRAP, tid->str, type, + (target_ulong)cpu->watchpoint_hit->vaddr); cpu->watchpoint_hit =3D NULL; goto send_packet; } else { @@ -2712,10 +2701,10 @@ static void gdb_vm_state_change(void *opaque, int r= unning, RunState state) break; } gdb_set_stop_cpu(cpu); - snprintf(buf, sizeof(buf), "T%02xthread:%s;", ret, thread_id); + g_string_printf(buf, "T%02xthread:%s;", ret, tid->str); =20 send_packet: - put_packet(buf); + put_packet(buf->str); =20 /* disable single step if it was enabled */ cpu_single_step(cpu, 0); @@ -3196,13 +3185,9 @@ static void gdb_chr_event(void *opaque, int event) =20 static void gdb_monitor_output(const char *msg, int len) { - char buf[MAX_PACKET_LENGTH]; - - buf[0] =3D 'O'; - if (len > (MAX_PACKET_LENGTH/2) - 1) - len =3D (MAX_PACKET_LENGTH/2) - 1; - memtohex(buf + 1, (uint8_t *)msg, len); - put_packet(buf); + g_autoptr(GString) buf =3D g_string_new("O"); + memtohex(buf, (uint8_t *)msg, len); + put_packet(buf->str); } =20 static int gdb_monitor_write(Chardev *chr, const uint8_t *buf, int len) --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576843889; cv=none; d=zohomail.com; s=zohoarc; b=na2Iea0rlRUHFbHFoHDuVC65Dt50M6eDSMQeBMSL/03E5ps6+5JQhJXW+Rly6l6l6hiwND/jWv4lc4qgZXY4hKjt9E19B1Qh5pz1PMjQ9t/OLg8+EYswPwD5fMoxzm+mhwRVbo3cKAG3v7fydd2IRDVq4PCFGyQjVh3PHlaYmpM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576843889; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Zc6kvGdtDLz2ojH8CUPfJdv2oY/VOoynhGQP1OaS620=; b=Uf+NVm2ui58q05xqGfrZzDBGUZ5rp9Pn8CPdM6wYjzerAZRL77tKTgp+X4dXam3WXnnbbvTPuV5eJEpMDfNs1SBnqRZyIui5r0gsa3lZbMB1B6DAsW01ez0w3E5C+yC61LN4dY9mXVUpRYGJNF8mzJKNi3B+2kCnzg8Ks3EjMc4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576843889812324.0574746919049; Fri, 20 Dec 2019 04:11:29 -0800 (PST) Received: from localhost ([::1]:54078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH7w-0004VE-GS for importer@patchew.org; Fri, 20 Dec 2019 07:11:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52571) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1Y-0004gw-1D for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1W-0007fw-1a for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:51 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:36430) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1V-0007ak-FF for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:49 -0500 Received: by mail-wm1-x344.google.com with SMTP id p17so8990524wma.1 for ; Fri, 20 Dec 2019 04:04:49 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id b67sm10038051wmc.38.2019.12.20.04.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:42 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 3F9AB1FF91; Fri, 20 Dec 2019 12:04:39 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Zc6kvGdtDLz2ojH8CUPfJdv2oY/VOoynhGQP1OaS620=; b=UGdI7+HZhPUey0/nxd9li+tSmYYOvpsFqXiegs2Ajtxn22KbYgx4qIgI6tgHjfgv6o bHUPldO21h6X3LfUDZsdKmuXS8KS5fKVtUkQtJYsEeIxZtOoJ+mxyDexX6eGnrw676DL IRCT+a85SxMC1ovNXUlZ9dm2nbDP6qpnxGlOIlPemgZegV6bpX/5MKrTRgYCqtLqUpsl RnD9WV/px5dQjDlYwxEK+2/j7+QtBBALzrM7bOPfAWwTEFvIZ2XSlFLApbqwxCeameBr gYp6I9DJ07y46Ntyz+VuQl1nP7KXv3s6e3u56v+hN6N0xyjAY60cgpiuaUXNajzuZPFa beew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Zc6kvGdtDLz2ojH8CUPfJdv2oY/VOoynhGQP1OaS620=; b=e6c3EJfZ1wjLBJ6uZoGdjLl9gGPrYagn9J+Uoc7S3+h26Tb7Qo0SNY0G6jeMkerSVK I9VQoQjYsuG0aAO6ZMKYLzORCzJL3kPRNaAGh/IKfK8Kd3SRiA3l2c+mOC4cef9qYRLv XG7WXxp8eWK1uudA6LADDPYqa7v9EtpSzoJDhREhKL4dKFS7dFi8AuB4agk808yJAKIt 1yhHIE38obQoHm1Xg32TKqS9vUF5xyeb0wI4iMyBSmmQMt336yBis/aec8x3PwXEHV+C wEg4JtB7ORT8TgyvoM0vknDCfgfuGtVFyN1YNtyXcfQ6yEODz9XZK/A1FqpuLLGIIeB5 cbfA== X-Gm-Message-State: APjAAAWI8KGOmeeD2H06XjrtP5dfHvaE3zlaEMdPMII3t2yVmiVoTzuT Fy72ZX7t+0q88RPp00i6g+PQ5TyT1Cg= X-Google-Smtp-Source: APXvYqz2Q786Jp6y8vbE/GFJ2slj+nnK9ojQMu6WXCzUuq3ADFMzewMcezwn3l502hfb48g4/VNpDQ== X-Received: by 2002:a7b:c346:: with SMTP id l6mr3426414wmj.100.1576843488144; Fri, 20 Dec 2019 04:04:48 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 04/21] gdbstub: move mem_buf to GDBState and use GByteArray Date: Fri, 20 Dec 2019 12:04:21 +0000 Message-Id: <20191220120438.16114-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, luis.machado@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , alan.hayward@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This is in preparation for further re-factoring of the register API with the rest of the code. Theoretically the read register function could overwrite the MAX_PACKET_LENGTH buffer although currently all registers are well within the size range. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson Reviewed-by: Damien Hedde Tested-by: Damien Hedde --- v4 - don't set_set to len on rcmd (it's zeroed before we get here) v3 - fixed up email on Damien's tags --- gdbstub.c | 56 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 80d99c209ff..736e3cc1052 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -367,6 +367,7 @@ typedef struct GDBState { char syscall_buf[256]; gdb_syscall_complete_cb current_syscall_cb; GString *str_buf; + GByteArray *mem_buf; } GDBState; =20 /* By default use no IRQs and no timers while single stepping so as to @@ -382,6 +383,7 @@ static void init_gdbserver_state(void) memset(&gdbserver_state, 0, sizeof(GDBState)); gdbserver_state.init =3D true; gdbserver_state.str_buf =3D g_string_new(NULL); + gdbserver_state.mem_buf =3D g_byte_array_sized_new(MAX_PACKET_LENGTH); } =20 #ifndef CONFIG_USER_ONLY @@ -576,12 +578,13 @@ static void memtohex(GString *buf, const uint8_t *mem= , int len) g_string_append_c(buf, '\0'); } =20 -static void hextomem(uint8_t *mem, const char *buf, int len) +static void hextomem(GByteArray *mem, const char *buf, int len) { int i; =20 for(i =3D 0; i < len; i++) { - mem[i] =3D (fromhex(buf[0]) << 4) | fromhex(buf[1]); + guint8 byte =3D fromhex(buf[0]) << 4 | fromhex(buf[1]); + g_byte_array_append(mem, &byte, 1); buf +=3D 2; } } @@ -1412,7 +1415,6 @@ static int cmd_parse_params(const char *data, const c= har *schema, typedef struct GdbCmdContext { GdbCmdVariant *params; int num_params; - uint8_t mem_buf[MAX_PACKET_LENGTH]; } GdbCmdContext; =20 typedef void (*GdbCmdHandler)(GdbCmdContext *gdb_ctx, void *user_ctx); @@ -1503,6 +1505,7 @@ static void run_cmd_parser(const char *data, const Gd= bCmdParseEntry *cmd) } =20 g_string_set_size(gdbserver_state.str_buf, 0); + g_byte_array_set_size(gdbserver_state.mem_buf, 0); =20 /* In case there was an error during the command parsing we must * send a NULL packet to indicate the command is not supported */ @@ -1715,8 +1718,8 @@ static void handle_set_reg(GdbCmdContext *gdb_ctx, vo= id *user_ctx) } =20 reg_size =3D strlen(gdb_ctx->params[1].data) / 2; - hextomem(gdb_ctx->mem_buf, gdb_ctx->params[1].data, reg_size); - gdb_write_register(gdbserver_state.g_cpu, gdb_ctx->mem_buf, + hextomem(gdbserver_state.mem_buf, gdb_ctx->params[1].data, reg_size); + gdb_write_register(gdbserver_state.g_cpu, gdbserver_state.mem_buf->dat= a, gdb_ctx->params[0].val_ull); put_packet("OK"); } @@ -1735,14 +1738,17 @@ static void handle_get_reg(GdbCmdContext *gdb_ctx, = void *user_ctx) return; } =20 - reg_size =3D gdb_read_register(gdbserver_state.g_cpu, gdb_ctx->mem_buf, + reg_size =3D gdb_read_register(gdbserver_state.g_cpu, + gdbserver_state.mem_buf->data, gdb_ctx->params[0].val_ull); if (!reg_size) { put_packet("E14"); return; + } else { + g_byte_array_set_size(gdbserver_state.mem_buf, reg_size); } =20 - memtohex(gdbserver_state.str_buf, gdb_ctx->mem_buf, reg_size); + memtohex(gdbserver_state.str_buf, gdbserver_state.mem_buf->data, reg_s= ize); put_strbuf(); } =20 @@ -1759,11 +1765,11 @@ static void handle_write_mem(GdbCmdContext *gdb_ctx= , void *user_ctx) return; } =20 - hextomem(gdb_ctx->mem_buf, gdb_ctx->params[2].data, + hextomem(gdbserver_state.mem_buf, gdb_ctx->params[2].data, gdb_ctx->params[1].val_ull); if (target_memory_rw_debug(gdbserver_state.g_cpu, gdb_ctx->params[0].v= al_ull, - gdb_ctx->mem_buf, - gdb_ctx->params[1].val_ull, true)) { + gdbserver_state.mem_buf->data, + gdbserver_state.mem_buf->len, true)) { put_packet("E14"); return; } @@ -1784,14 +1790,17 @@ static void handle_read_mem(GdbCmdContext *gdb_ctx,= void *user_ctx) return; } =20 + g_byte_array_set_size(gdbserver_state.mem_buf, gdb_ctx->params[1].val_= ull); + if (target_memory_rw_debug(gdbserver_state.g_cpu, gdb_ctx->params[0].v= al_ull, - gdb_ctx->mem_buf, - gdb_ctx->params[1].val_ull, false)) { + gdbserver_state.mem_buf->data, + gdbserver_state.mem_buf->len, false)) { put_packet("E14"); return; } =20 - memtohex(gdbserver_state.str_buf, gdb_ctx->mem_buf, gdb_ctx->params[1]= .val_ull); + memtohex(gdbserver_state.str_buf, gdbserver_state.mem_buf->data, + gdbserver_state.mem_buf->len); put_strbuf(); } =20 @@ -1806,9 +1815,9 @@ static void handle_write_all_regs(GdbCmdContext *gdb_= ctx, void *user_ctx) } =20 cpu_synchronize_state(gdbserver_state.g_cpu); - registers =3D gdb_ctx->mem_buf; len =3D strlen(gdb_ctx->params[0].data) / 2; - hextomem(registers, gdb_ctx->params[0].data, len); + hextomem(gdbserver_state.mem_buf, gdb_ctx->params[0].data, len); + registers =3D gdbserver_state.mem_buf->data; for (addr =3D 0; addr < gdbserver_state.g_cpu->gdb_num_g_regs && len >= 0; addr++) { reg_size =3D gdb_write_register(gdbserver_state.g_cpu, registers, = addr); @@ -1825,11 +1834,14 @@ static void handle_read_all_regs(GdbCmdContext *gdb= _ctx, void *user_ctx) cpu_synchronize_state(gdbserver_state.g_cpu); len =3D 0; for (addr =3D 0; addr < gdbserver_state.g_cpu->gdb_num_g_regs; addr++)= { - len +=3D gdb_read_register(gdbserver_state.g_cpu, gdb_ctx->mem_buf= + len, + len +=3D gdb_read_register(gdbserver_state.g_cpu, + gdbserver_state.mem_buf->data + len, addr); } + /* FIXME: This is after the fact sizing */ + g_byte_array_set_size(gdbserver_state.mem_buf, len); =20 - memtohex(gdbserver_state.str_buf, gdb_ctx->mem_buf, len); + memtohex(gdbserver_state.str_buf, gdbserver_state.mem_buf->data, len); put_strbuf(); } =20 @@ -2078,6 +2090,7 @@ static void handle_query_offsets(GdbCmdContext *gdb_c= tx, void *user_ctx) #else static void handle_query_rcmd(GdbCmdContext *gdb_ctx, void *user_ctx) { + const guint8 zero =3D 0; int len; =20 if (!gdb_ctx->num_params) { @@ -2091,12 +2104,13 @@ static void handle_query_rcmd(GdbCmdContext *gdb_ct= x, void *user_ctx) return; } =20 + g_assert(gdbserver_state.mem_buf->len =3D=3D 0); len =3D len / 2; - hextomem(gdb_ctx->mem_buf, gdb_ctx->params[0].data, len); - gdb_ctx->mem_buf[len++] =3D 0; - qemu_chr_be_write(gdbserver_state.mon_chr, gdb_ctx->mem_buf, len); + hextomem(gdbserver_state.mem_buf, gdb_ctx->params[0].data, len); + g_byte_array_append(gdbserver_state.mem_buf, &zero, 1); + qemu_chr_be_write(gdbserver_state.mon_chr, gdbserver_state.mem_buf->da= ta, + gdbserver_state.mem_buf->len); put_packet("OK"); - } #endif =20 --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576844288; cv=none; d=zohomail.com; s=zohoarc; b=CyTrfXPap/6haqxi5sJmbBalMHeXARcv6VkLQgm4S7RuK8McMEPK06JqYhLdJUeT6A1zyyusHQn+pqR68XCahrvx2A9QORNyJ+D3YAzTJ54loH9sJoD4Ir4NASOHtfTp42oCxXxIpMUrYCHFF/i7zTfkb8imX1kcG6LPXKCso68= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576844288; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KcowZQvidWsL6K9vNr5PA0mK1ZdxCgzSQNRXFm9TCF8=; b=NDO1tlUfKwr7GPBGfD7b3mfXmvLZfrC1sn6ZP2YtH3WvKi/6QR9b4SdsqfJ2SY5+4plmlfXLweLC5IZ56SB+fq187C5KXY1nMzv+LgMLaTLTC03LoNduhimO7NNVTydNc4n+auLxoU7a2SRzgVDDarnSNYgT3NG7mN4vZKcc+/8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576844288133370.98118874739487; Fri, 20 Dec 2019 04:18:08 -0800 (PST) Received: from localhost ([::1]:54238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHEM-0004fT-Pb for importer@patchew.org; Fri, 20 Dec 2019 07:18:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52346) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1V-0004eB-UH for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1U-0007ZT-Ey for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:49 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:37078) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1U-0007UX-28 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:48 -0500 Received: by mail-wr1-x442.google.com with SMTP id w15so9212200wru.4 for ; Fri, 20 Dec 2019 04:04:47 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id u22sm9804594wru.30.2019.12.20.04.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:46 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 5367F1FF92; Fri, 20 Dec 2019 12:04:39 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KcowZQvidWsL6K9vNr5PA0mK1ZdxCgzSQNRXFm9TCF8=; b=irOjJcd5Hps147k7K/cpd9lmlTA7CoOSFEYeMIn3AxcVDzfW/1bPFDx7d1OyfT9u0j 08aW6EQExY29yRo7vbR8MqtFEScD9Jm7yu7bq6l2uN7lEfrVaNQmAv1HsTAYgByEnp0d x7VcJoGuW2RKtf2RVKxUlBLmzxL/hQ+VurnkW+IQcoI4R58hRpMX+LHxfbmhGIceJyOB pRU06rLCKUl0wBQyAJraU1pDP4tZq3LYPl6q54TvIJ914Ik3ABTp+N4JQJpy/IJCox9D EmNdJFZ8EMy8W2V7rJpjy8bBL5cy0Vz4x7CAAiBWn/lEvmbScYag7nUWlc6SF0SzuWYr 2YjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KcowZQvidWsL6K9vNr5PA0mK1ZdxCgzSQNRXFm9TCF8=; b=JCDEShW6mHNHKZvS2lonAbiKedIO3hLJ7fBLtptxJlLkiMWlqA3nIgba6OeUMInM4d sG2joAMYu3Qf7zKAVV7FwsHeOcySbN1ri7FMVYIeTOECwHuYFNbc+tfV+J/0rmdhXJNt uADEc17BJP2kz4CFuGmRksF3hoagSKV6kdnLmbU+4/uXtCRpQp8Zp1AKxzue4KMbmE0+ YxLo5FwaajDUDzUOgCikn4m0WZLQlf/BIb+1ngb7g+eSbGXIb/uygDZk57KNBjPfaifj r28foXqQO3oCANFzjrs4vv3mRPw1rn4Vg0r/2rdccfM10MwYG3Gf/Cw8FaYJQUB0nflB BA2A== X-Gm-Message-State: APjAAAXmFkdSdgVWxmIsM32M2rq1khjtqJwF03vHmQDT3IWsT5m2F3ND fbTR3ELqSVXdaQrL2L9ywwg6hIpvSaI= X-Google-Smtp-Source: APXvYqwZedeq56y5ptMtDO7Pj6gwgnXhmslFk8lijGsWEpWYOrwyHZtxT+ihtS5SAoejiT8UwvW8IA== X-Received: by 2002:adf:f78d:: with SMTP id q13mr15035764wrp.365.1576843486808; Fri, 20 Dec 2019 04:04:46 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 05/21] gdbstub: add helper for 128 bit registers Date: Fri, 20 Dec 2019 12:04:22 +0000 Message-Id: <20191220120438.16114-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, luis.machado@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , alan.hayward@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- v2 - take care of endianess of the whole 128 bit word --- include/exec/gdbstub.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 08363969c14..59e366ba3af 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -102,6 +102,19 @@ static inline int gdb_get_reg64(uint8_t *mem_buf, uint= 64_t val) return 8; } =20 +static inline int gdb_get_reg128(uint8_t *mem_buf, uint64_t val_hi, + uint64_t val_lo) +{ +#ifdef TARGET_WORDS_BIGENDIAN + stq_p(mem_buf, val_hi); + stq_p(mem_buf + 8, val_lo); +#else + stq_p(mem_buf, val_lo); + stq_p(mem_buf + 8, val_hi); +#endif + return 16; +} + #if TARGET_LONG_BITS =3D=3D 64 #define gdb_get_regl(buf, val) gdb_get_reg64(buf, val) #define ldtul_p(addr) ldq_p(addr) --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576844392; cv=none; d=zohomail.com; s=zohoarc; b=hmRlgW5vbZ2F0NdqwnFrBBAMj/UwEky1KHH6L6ek9pLr6uaj3SqmwuiZmdUabL3uz4yT/kYco6BrwvaQjGh4N4ATEoFWbaqOronArwuiakQs3mKxVVfeAmPiI7CVKvtzKlOKY6CbVCzFx/s8L5y5nW5wSaoXAuZSLiuUNm/O3VY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576844392; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yP04C6ThOAXjLefYFBP1Rp4bmt2cBEv6NwVmKqtKkDw=; b=nDGH1rWBJ9f5JCiNSvHJNA05NkPrFN05xnk/R2zqw2ytAY2j0H0OF0QEsU2ucsxsK4Ws4SwJln9Jdq0YFcm0wSsLmdaMRy5+YwPYV7CRChsNauBDunPphM6Xqa5dhpPMcCqtuReKjqxrb/5Pa71UeEEZS0Q0xKDdzf3R0agTt0M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157684439231249.349670117100686; Fri, 20 Dec 2019 04:19:52 -0800 (PST) Received: from localhost ([::1]:54282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHG2-0007QQ-St for importer@patchew.org; Fri, 20 Dec 2019 07:19:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52860) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1a-0004k6-G9 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1Z-0007nz-2H for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:54 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:51606) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1Y-0007k4-Hg for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:52 -0500 Received: by mail-wm1-x342.google.com with SMTP id d73so8695432wmd.1 for ; Fri, 20 Dec 2019 04:04:52 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id m7sm9462105wrr.40.2019.12.20.04.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:46 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 6B5541FF93; Fri, 20 Dec 2019 12:04:39 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yP04C6ThOAXjLefYFBP1Rp4bmt2cBEv6NwVmKqtKkDw=; b=LuPL37ZAkEEmEi+yqJ9WADzmqnLZrz+RJ1ojuwkeqTFWjZWglfHrlUo+yK37mRjyZ0 uHIir3/Jqn78UzcjUndn5Dw4i4rDuovNnUx/XgHE6FGoCZEqX3Arh6JLtcbTr5tmFQG5 SKAj2i6eGnLxfltMBbkJF4Vnboz5XMFC5EyBKkorUm016VRyd2n5d1Z+Kx9HSGZjoJId WolhnPylDDM/imY+lIo2y/AAJKdfo+TwTDgKBEFZy4rEFNEpXDwRjmq+zrnaZSMMvag0 lP14JfWmS/CWyFwt0nZwkPI9vPzT81ub4r78E2S7+TR0TIkqU4gK+JzJlf65b2kZXCE6 Qsrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yP04C6ThOAXjLefYFBP1Rp4bmt2cBEv6NwVmKqtKkDw=; b=hR+iXuwuK/gQQe5lleWcy+Vcfp+NbSNk6fE93K7MJquOOdgVCzPyIWEAayw/zgNqqY DkWAPO2uC78V/+PxEu75IS/XAzx1Q/SbRQsN+2pZ6OKF2Su0b89HIm4Qi1w7VsqVUE2t rYrtydCHDj01LJ0Anlgp38dp59OCvhIAijsTAUqYzhlxX2bMKwsJWBoposZSMkOw221k vsIIalmZuHvOFcBF/DhnbLvqZMnQGfNGiH5TGdMoqatfKIM5yeQ5NjpL7RVxwt2SHMDi 7e+pq3iKdHbRmDSeK9D8CNAeYpFRxraNJ8lvZo21Dk+vIR41y6wCs2zldwF5OIW6RRNh 0LhQ== X-Gm-Message-State: APjAAAXzI6afax/JQvPq0YFmRf5ffBJXrp7wdLJQ6nvj86k34cWb7YHN oT2qpXc3qNpTwW2sBeDGKo3VNpLakjk= X-Google-Smtp-Source: APXvYqyvumcnFZnL/JzZ9GcYtuAspnT5f62Y+tBwsLNxOJYXcjvMrNznje1K7Sso/vTenmXWRmlVrA== X-Received: by 2002:a1c:e108:: with SMTP id y8mr15629231wmg.147.1576843491069; Fri, 20 Dec 2019 04:04:51 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 06/21] target/arm: use gdb_get_reg helpers Date: Fri, 20 Dec 2019 12:04:23 +0000 Message-Id: <20191220120438.16114-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This is cleaner than poking memory directly and will make later clean-ups easier. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- v2 - make sure we pass hi/lo correctly as quads are stored in LE order --- target/arm/helper.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 5074b5f69ca..6f3b6ca7d3f 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -105,21 +105,17 @@ static int aarch64_fpu_gdb_get_reg(CPUARMState *env, = uint8_t *buf, int reg) { switch (reg) { case 0 ... 31: - /* 128 bit FP register */ - { - uint64_t *q =3D aa64_vfp_qreg(env, reg); - stq_le_p(buf, q[0]); - stq_le_p(buf + 8, q[1]); - return 16; - } + { + /* 128 bit FP register - quads are in LE order */ + uint64_t *q =3D aa64_vfp_qreg(env, reg); + return gdb_get_reg128(buf, q[1], q[0]); + } case 32: /* FPSR */ - stl_p(buf, vfp_get_fpsr(env)); - return 4; + return gdb_get_reg32(buf, vfp_get_fpsr(env)); case 33: /* FPCR */ - stl_p(buf, vfp_get_fpcr(env)); - return 4; + return gdb_get_reg32(buf,vfp_get_fpcr(env)); default: return 0; } --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576843760; cv=none; d=zohomail.com; s=zohoarc; b=eg0rOX89WlLfllRIjer9lLXJoQMQIRZbg6Qu502T/OQjKawN1t1WiimOY3McDq+ZdC9eA4yyXwdz7QAdHprBal+B3t4vrchgESjiBFdxbFu0hZMcFWVBc1Nprp53bRfHG56g8HnpiAXViLaAdOURbe/EvSTBmTk1fzEXrAOeTfw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576843760; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Bqp2vY6ZYjqYdoh+7hv2voXM8FmNpL/WqUxsGE1oBh8=; b=Zc2sips7P5sqHuTHqlHBCIuRDEhhUvPuFjfeRF6tey/6mru48KcECvwvnugmyHPYqxSdhf4e9lQQM8Ek4/9bTw3NdxG+T5zfCWTWbKXJvVtRAPkMDnZAA7X3smzSozVngxPcRU6Iz3jaNx4iZfGkWZ8cNpoSiKI8Zzu6nStMXtc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576843760413575.2286381923285; Fri, 20 Dec 2019 04:09:20 -0800 (PST) Received: from localhost ([::1]:54018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH5q-0001OY-Lf for importer@patchew.org; Fri, 20 Dec 2019 07:09:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53166) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1c-0004ms-Eu for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1b-0007wr-8t for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:56 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:42434) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1a-0007sC-QU for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:54 -0500 Received: by mail-wr1-x441.google.com with SMTP id q6so9153864wro.9 for ; Fri, 20 Dec 2019 04:04:54 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id t1sm9542565wma.43.2019.12.20.04.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:48 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 80C9C1FF96; Fri, 20 Dec 2019 12:04:39 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bqp2vY6ZYjqYdoh+7hv2voXM8FmNpL/WqUxsGE1oBh8=; b=Rl7Mtd+wYfO2sBYfYEwqUKijA39big+VB1gytaYA6V223uSnjIWRdhlnwGBl05XELM 8zDC72ZTf7xpCVG2BCGDO6vn9NBoepPAsMzU2X/PAE8hZfFR6+FQf3XKS4Usae/B4XNr oB4Y23OV/6G8SpDEDTlMiOxLzeHD8RWQrRQhUUHGSipZItC8IzezEcehAuLxKcFX6sjt +GGDbr5CaRyRyRGwRMMvBbGph3NE8EYxPBrMShKkNYIeFtbIeSC2VKdH0qwbaI2zjFYf KslAxqlsuFJcchaEhVPaywhjTNoyUSSZMbn4ppPMkVg/xCb76M7KsHPfpIvI8zoue8SL cFSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bqp2vY6ZYjqYdoh+7hv2voXM8FmNpL/WqUxsGE1oBh8=; b=Ob2kKkBQlFvnrrBzwIeifC12yKIe0IqG0CF6iY+P+U8UsTKf9dCzOBM86Wpz7aQXBt Xi0/t/tOYpPF4z5GJfnmnQ20KJ7yCB0tUdAnDITE9VCiBqok2t6sfXZ/vc3NmQN8HYM5 pQUvCm14E7+y8ti8cdDa1o4hODtWLlGsbpsv4NE8gM/Q5uu6nqo2N0OHhCrWkfMLEO6l u3G8RQGAutIhayQpTyA3bVUErVHruFTDJw58NuvsGV4UJCO5uLnsQHrLSFX+6PsB590p moTTObkxNZLkBfEgFSvqmOM/MWqFwMjf4INdP3kAPP5X2nwyh/yU5ed6yQNKEhizYF0F ULeA== X-Gm-Message-State: APjAAAWzHf7IdFpk4ttnDW+xipF9Ge/Y+4OQk9BgG1DamY2NJ+dezAYE P0h3hwW0MjeRSM6UFDlPAnC7hQ== X-Google-Smtp-Source: APXvYqxnDgfTdZCHAK78YzWv8LiD4DZJkiTplUF4zDx3TfTfRHF3rSfLEEv1iLr9Jgq6DXA/+shJrw== X-Received: by 2002:a5d:4481:: with SMTP id j1mr15500657wrq.348.1576843493629; Fri, 20 Dec 2019 04:04:53 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 07/21] target/m68k: use gdb_get_reg helpers Date: Fri, 20 Dec 2019 12:04:24 +0000 Message-Id: <20191220120438.16114-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, luis.machado@linaro.org, Richard Henderson , Laurent Vivier , alan.hayward@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This is cleaner than poking memory directly and will make later clean-ups easier. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson Reviewed-by: Laurent Vivier --- v3 - fix mem_buf references - fix mem_buf + len cases --- target/m68k/helper.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/target/m68k/helper.c b/target/m68k/helper.c index ae766a6cb0b..2573ee7a535 100644 --- a/target/m68k/helper.c +++ b/target/m68k/helper.c @@ -72,19 +72,15 @@ static int cf_fpu_gdb_get_reg(CPUM68KState *env, uint8_= t *mem_buf, int n) { if (n < 8) { float_status s; - stfq_p(mem_buf, floatx80_to_float64(env->fregs[n].d, &s)); - return 8; + return gdb_get_reg64(mem_buf, floatx80_to_float64(env->fregs[n].d,= &s)); } switch (n) { case 8: /* fpcontrol */ - stl_be_p(mem_buf, env->fpcr); - return 4; + return gdb_get_reg32(mem_buf, env->fpcr); case 9: /* fpstatus */ - stl_be_p(mem_buf, env->fpsr); - return 4; + return gdb_get_reg32(mem_buf, env->fpsr); case 10: /* fpiar, not implemented */ - memset(mem_buf, 0, 4); - return 4; + return gdb_get_reg32(mem_buf, 0); } return 0; } @@ -112,21 +108,18 @@ static int cf_fpu_gdb_set_reg(CPUM68KState *env, uint= 8_t *mem_buf, int n) static int m68k_fpu_gdb_get_reg(CPUM68KState *env, uint8_t *mem_buf, int n) { if (n < 8) { - stw_be_p(mem_buf, env->fregs[n].l.upper); - memset(mem_buf + 2, 0, 2); - stq_be_p(mem_buf + 4, env->fregs[n].l.lower); - return 12; + int len =3D gdb_get_reg16(mem_buf, env->fregs[n].l.upper); + len +=3D gdb_get_reg16(mem_buf + len, 0); + len +=3D gdb_get_reg64(mem_buf + len, env->fregs[n].l.lower); + return len; } switch (n) { case 8: /* fpcontrol */ - stl_be_p(mem_buf, env->fpcr); - return 4; + return gdb_get_reg32(mem_buf, env->fpcr); case 9: /* fpstatus */ - stl_be_p(mem_buf, env->fpsr); - return 4; + return gdb_get_reg32(mem_buf, env->fpsr); case 10: /* fpiar, not implemented */ - memset(mem_buf, 0, 4); - return 4; + return gdb_get_reg32(mem_buf, 0); } return 0; } --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576844539; cv=none; d=zohomail.com; s=zohoarc; b=oCbpkuajmDxb1tB3HkvMjR074D4EHWycRXmJqq6MWxBxR7lS8Y9GHYStj2CaYLDllzhk5YziYfaH0JHIpfMi3+whmTbuIrhUUz+rY3rAK0ThuvSHvRW7k/e2d3RU2lkDAhKON/ewfKCgM6l/5tHzAlkUj+YXhXmkp4B1bRyYur8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576844539; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2Gl3w5dXDGfherWie7OLbv8FKPkn1YuYJp7v+pvZORo=; b=GRpY8tO5OVqa5wuKoAtsd6GvUBWKv1B1Ti+SxAwfaNneBgjAMa33Gx7/uFTMWozENEttBLL6TSXXrLFPQwxOr7YyEcubIbpMkpu0WiS4vSRC8YUZ7myNfyPnfSBhWy22RdF+Rv8sRRo2P4TWil4+deLV+OsIhsObi/NRbRrln/c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576844539626642.788618083022; Fri, 20 Dec 2019 04:22:19 -0800 (PST) Received: from localhost ([::1]:54344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHIQ-0002Fk-9A for importer@patchew.org; Fri, 20 Dec 2019 07:22:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54303) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1s-00052B-R8 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1l-0008Jz-7j for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:12 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:38617) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1k-0008Fl-28 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:04 -0500 Received: by mail-wm1-x344.google.com with SMTP id u2so8971468wmc.3 for ; Fri, 20 Dec 2019 04:05:02 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id n10sm9391168wrt.14.2019.12.20.04.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:48 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id DB0F01FF98; Fri, 20 Dec 2019 12:04:39 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2Gl3w5dXDGfherWie7OLbv8FKPkn1YuYJp7v+pvZORo=; b=LFMRgoeWys+pvnbQppS+YEGIwEHjaSatO55vdZpNde/OjlaBnTP/yOn7Lf90yFFmHb Ee8iiOHVFuLLg3SvVLG/Q/BMzXaURmiyjaBBSNPVN+jATv0rYZ1VWZ/4HQkkmOFhW+jY xpmqbeXEQ+DMrVNW2AyE4B88/Iu25U7bSNypIJld6YIWeNqJX+PFUbsRMsNZf6HfOn6z u05hAns0bVKuXY4eBk8tJHFrCNncPElZm/xRUnRqQUJOFgs7vdLJLVm2rOSC7YG51/Dj NJp0g4cnVVyi2yKV8ce8sNmW56+WWH9AQh3d9aDqKd1SLyYbPc+muTPFQ56gg74Ih41K h8vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2Gl3w5dXDGfherWie7OLbv8FKPkn1YuYJp7v+pvZORo=; b=QgpwawOJwVa1MTZnH6ZrrqOH80f3luNpxlUmxj+NlVC45vCS0zb+Qxpdj31Xj/1psV idErh6KpJL83gVRbBcKFSxLQrnwse43FMrEk/8W2fPUzr/z7dpEEGoMf6hEr28BI3e+n K+rXEqN5CGBThPjLLR4GVzjPdFFN2cFctCRfyBhpRcr5CnSaUorp3CK9HZto87kutyqu pxZ8C2DMH6m/6Q+0NBAjipaKRXq+mFO2egJITBQVMq3KlY8MUvG3bBNF2xbT4h1Zql8T gZyXTjsTHfXtPvlbLyipVtWTSXjclBf84GHwuewRGiE/cSYtB4VjwrLj1HD8dZ/ZnpnV 2Rgg== X-Gm-Message-State: APjAAAVKBlxEvnKplJEFnTe9vZh0WMsxvMf3vrdBJm7ozNMGwqYu1iT2 heKppBxZR0RRRm9D0j8ezN9Bzg== X-Google-Smtp-Source: APXvYqxjXrvhvVExYz5ZSrkSgagoDXlpydAPBsjXoMs8DQ6Bn5Qqu0LX3K5txkplxWF2vLLsm8QuNQ== X-Received: by 2002:a1c:7901:: with SMTP id l1mr15695925wme.67.1576843500868; Fri, 20 Dec 2019 04:05:00 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 08/21] gdbstub: extend GByteArray to read register helpers Date: Fri, 20 Dec 2019 12:04:25 +0000 Message-Id: <20191220120438.16114-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , luis.machado@linaro.org, Sagar Karandikar , David Hildenbrand , Mark Cave-Ayland , Max Filippov , Alistair Francis , "Edgar E. Iglesias" , Marek Vasut , alan.hayward@arm.com, "open list:PowerPC TCG CPUs" , Aleksandar Rikalo , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Artyom Tarasenko , Eduardo Habkost , "open list:S390 general arch..." , "open list:ARM TCG CPUs" , Stafford Horne , =?UTF-8?q?Alex=20Benn=C3=A9e?= , David Gibson , damien.hedde@greensocs.com, "open list:RISC-V TCG CPUs" , Bastian Koppelmann , Chris Wulff , Laurent Vivier , Michael Walle , Palmer Dabbelt , Aleksandar Markovic , Paolo Bonzini , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Instead of passing a pointer to memory now just extend the GByteArray to all the read register helpers. They can then safely append their data through the normal way. We don't bother with this abstraction for write registers as we have already ensured the buffer being copied from is the correct size. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Damien Hedde --- v4 - fix mem_buf calculation for ppc_maybe_bswap_register --- include/exec/gdbstub.h | 46 +++++++++++++++++----------- include/hw/core/cpu.h | 2 +- target/alpha/cpu.h | 2 +- target/arm/cpu.h | 4 +-- target/cris/cpu.h | 4 +-- target/hppa/cpu.h | 2 +- target/i386/cpu.h | 2 +- target/lm32/cpu.h | 2 +- target/m68k/cpu.h | 2 +- target/microblaze/cpu.h | 2 +- target/mips/internal.h | 2 +- target/openrisc/cpu.h | 2 +- target/ppc/cpu.h | 4 +-- target/riscv/cpu.h | 2 +- target/s390x/internal.h | 2 +- target/sh4/cpu.h | 2 +- target/sparc/cpu.h | 2 +- target/xtensa/cpu.h | 2 +- gdbstub.c | 20 ++++++------ hw/core/cpu.c | 2 +- target/alpha/gdbstub.c | 2 +- target/arm/gdbstub.c | 2 +- target/arm/gdbstub64.c | 2 +- target/arm/helper.c | 19 +++++------- target/cris/gdbstub.c | 4 +-- target/hppa/gdbstub.c | 2 +- target/i386/gdbstub.c | 2 +- target/lm32/gdbstub.c | 2 +- target/m68k/gdbstub.c | 2 +- target/m68k/helper.c | 4 +-- target/microblaze/gdbstub.c | 2 +- target/mips/gdbstub.c | 2 +- target/nios2/cpu.c | 2 +- target/openrisc/gdbstub.c | 2 +- target/ppc/gdbstub.c | 48 +++++++++++++++-------------- target/ppc/translate_init.inc.c | 54 ++++++++++++++++++--------------- target/riscv/gdbstub.c | 18 +++++------ target/s390x/gdbstub.c | 30 +++++++++--------- target/sh4/gdbstub.c | 2 +- target/sparc/gdbstub.c | 2 +- target/xtensa/gdbstub.c | 2 +- 41 files changed, 165 insertions(+), 148 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 59e366ba3af..ef79e32708c 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -68,49 +68,59 @@ void gdb_signalled(CPUArchState *, int); void gdbserver_fork(CPUState *); #endif /* Get or set a register. Returns the size of the register. */ -typedef int (*gdb_reg_cb)(CPUArchState *env, uint8_t *buf, int reg); +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_reg_cb get_reg, gdb_reg_cb set_reg, + gdb_get_reg_cb get_reg, gdb_set_reg_cb set_r= eg, int num_regs, const char *xml, int g_pos); =20 -/* The GDB remote protocol transfers values in target byte order. This me= ans - * we can use the raw memory access routines to access the value buffer. - * Conveniently, these also handle the case where the buffer is mis-aligne= d. +/* + * 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. */ =20 -static inline int gdb_get_reg8(uint8_t *mem_buf, uint8_t val) +static inline int gdb_get_reg8(GByteArray *buf, uint8_t val) { - stb_p(mem_buf, val); + g_byte_array_append(buf, &val, 1); return 1; } =20 -static inline int gdb_get_reg16(uint8_t *mem_buf, uint16_t val) +static inline int gdb_get_reg16(GByteArray *buf, uint16_t val) { - stw_p(mem_buf, val); + uint16_t to_word =3D tswap16(val); + g_byte_array_append(buf, (uint8_t *) &to_word, 2); return 2; } =20 -static inline int gdb_get_reg32(uint8_t *mem_buf, uint32_t val) +static inline int gdb_get_reg32(GByteArray *buf, uint32_t val) { - stl_p(mem_buf, val); + uint32_t to_long =3D tswap32(val); + g_byte_array_append(buf, (uint8_t *) &to_long, 4); return 4; } =20 -static inline int gdb_get_reg64(uint8_t *mem_buf, uint64_t val) +static inline int gdb_get_reg64(GByteArray *buf, uint64_t val) { - stq_p(mem_buf, val); + uint64_t to_quad =3D tswap64(val); + g_byte_array_append(buf, (uint8_t *) &to_quad, 8); return 8; } =20 -static inline int gdb_get_reg128(uint8_t *mem_buf, uint64_t val_hi, +static inline int gdb_get_reg128(GByteArray *buf, uint64_t val_hi, uint64_t val_lo) { + uint64_t to_quad; #ifdef TARGET_WORDS_BIGENDIAN - stq_p(mem_buf, val_hi); - stq_p(mem_buf + 8, val_lo); + to_quad =3D tswap64(val_hi); + g_byte_array_append(buf, (uint8_t *) &to_quad, 8); + to_quad =3D tswap64(val_lo); + g_byte_array_append(buf, (uint8_t *) &to_quad, 8); #else - stq_p(mem_buf, val_lo); - stq_p(mem_buf + 8, val_hi); + to_quad =3D tswap64(val_lo); + g_byte_array_append(buf, (uint8_t *) &to_quad, 8); + to_quad =3D tswap64(val_hi); + g_byte_array_append(buf, (uint8_t *) &to_quad, 8); #endif return 16; } diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 77c6f052990..e85ec519add 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -195,7 +195,7 @@ typedef struct CPUClass { hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu, vaddr addr, MemTxAttrs *attrs); int (*asidx_from_attrs)(CPUState *cpu, MemTxAttrs attrs); - int (*gdb_read_register)(CPUState *cpu, uint8_t *buf, int reg); + int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg); int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg); bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp); void (*debug_excp_handler)(CPUState *cpu); diff --git a/target/alpha/cpu.h b/target/alpha/cpu.h index a530249a5bf..faa09768424 100644 --- a/target/alpha/cpu.h +++ b/target/alpha/cpu.h @@ -282,7 +282,7 @@ void alpha_cpu_do_interrupt(CPUState *cpu); bool alpha_cpu_exec_interrupt(CPUState *cpu, int int_req); void alpha_cpu_dump_state(CPUState *cs, FILE *f, int flags); hwaddr alpha_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int alpha_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int alpha_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int alpha_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void alpha_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type, diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 5f70e9e0438..19b3ac32113 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -949,7 +949,7 @@ bool arm_cpu_exec_interrupt(CPUState *cpu, int int_req); hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr, MemTxAttrs *attrs); =20 -int arm_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int arm_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int arm_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); =20 /* Dynamically generates for gdb stub an XML description of the sysregs fr= om @@ -969,7 +969,7 @@ int arm_cpu_write_elf32_note(WriteCoreDumpFunction f, C= PUState *cs, int cpuid, void *opaque); =20 #ifdef TARGET_AARCH64 -int aarch64_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int aarch64_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int aarch64_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void aarch64_sve_narrow_vq(CPUARMState *env, unsigned vq); void aarch64_sve_change_el(CPUARMState *env, int old_el, diff --git a/target/cris/cpu.h b/target/cris/cpu.h index aba0a664744..333ee5b171a 100644 --- a/target/cris/cpu.h +++ b/target/cris/cpu.h @@ -194,8 +194,8 @@ void cris_cpu_dump_state(CPUState *cs, FILE *f, int fla= gs); =20 hwaddr cris_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); =20 -int crisv10_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); -int cris_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int crisv10_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); +int cris_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int cris_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); =20 /* you can call this signal handler from your SIGBUS and SIGSEGV diff --git a/target/hppa/cpu.h b/target/hppa/cpu.h index 6713d04f111..801a4fb1bae 100644 --- a/target/hppa/cpu.h +++ b/target/hppa/cpu.h @@ -321,7 +321,7 @@ void cpu_hppa_change_prot_id(CPUHPPAState *env); =20 int cpu_hppa_signal_handler(int host_signum, void *pinfo, void *puc); hwaddr hppa_cpu_get_phys_page_debug(CPUState *cs, vaddr addr); -int hppa_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int hppa_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int hppa_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void hppa_cpu_do_interrupt(CPUState *cpu); bool hppa_cpu_exec_interrupt(CPUState *cpu, int int_req); diff --git a/target/i386/cpu.h b/target/i386/cpu.h index af282936a78..63b0031c5bf 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1760,7 +1760,7 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int fl= ags); hwaddr x86_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr, MemTxAttrs *attrs); =20 -int x86_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int x86_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int x86_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); =20 void x86_cpu_exec_enter(CPUState *cpu); diff --git a/target/lm32/cpu.h b/target/lm32/cpu.h index 064c6b1267e..01d408eb55d 100644 --- a/target/lm32/cpu.h +++ b/target/lm32/cpu.h @@ -202,7 +202,7 @@ void lm32_cpu_do_interrupt(CPUState *cpu); bool lm32_cpu_exec_interrupt(CPUState *cs, int int_req); void lm32_cpu_dump_state(CPUState *cpu, FILE *f, int flags); hwaddr lm32_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int lm32_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int lm32_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int lm32_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); =20 typedef enum { diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h index 20de3c379aa..cdb08c269f6 100644 --- a/target/m68k/cpu.h +++ b/target/m68k/cpu.h @@ -168,7 +168,7 @@ void m68k_cpu_do_interrupt(CPUState *cpu); bool m68k_cpu_exec_interrupt(CPUState *cpu, int int_req); void m68k_cpu_dump_state(CPUState *cpu, FILE *f, int flags); hwaddr m68k_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int m68k_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int m68k_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int m68k_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); =20 void m68k_tcg_init(void); diff --git a/target/microblaze/cpu.h b/target/microblaze/cpu.h index 95773089aa3..987e4629b0a 100644 --- a/target/microblaze/cpu.h +++ b/target/microblaze/cpu.h @@ -313,7 +313,7 @@ void mb_cpu_do_interrupt(CPUState *cs); bool mb_cpu_exec_interrupt(CPUState *cs, int int_req); void mb_cpu_dump_state(CPUState *cpu, FILE *f, int flags); hwaddr mb_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int mb_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int mb_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int mb_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); =20 void mb_tcg_init(void); diff --git a/target/mips/internal.h b/target/mips/internal.h index 3f435b5e631..c5ae86360f5 100644 --- a/target/mips/internal.h +++ b/target/mips/internal.h @@ -82,7 +82,7 @@ void mips_cpu_do_interrupt(CPUState *cpu); bool mips_cpu_exec_interrupt(CPUState *cpu, int int_req); void mips_cpu_dump_state(CPUState *cpu, FILE *f, int flags); hwaddr mips_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int mips_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int mips_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int mips_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void mips_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type, diff --git a/target/openrisc/cpu.h b/target/openrisc/cpu.h index 0ad02eab794..d9484b802f3 100644 --- a/target/openrisc/cpu.h +++ b/target/openrisc/cpu.h @@ -320,7 +320,7 @@ void openrisc_cpu_do_interrupt(CPUState *cpu); bool openrisc_cpu_exec_interrupt(CPUState *cpu, int int_req); void openrisc_cpu_dump_state(CPUState *cpu, FILE *f, int flags); hwaddr openrisc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int openrisc_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int openrisc_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg= ); int openrisc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void openrisc_translate_init(void); bool openrisc_cpu_tlb_fill(CPUState *cs, vaddr address, int size, diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 103bfe9dc27..41e009ae3c9 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1256,8 +1256,8 @@ bool ppc_cpu_exec_interrupt(CPUState *cpu, int int_re= q); void ppc_cpu_dump_state(CPUState *cpu, FILE *f, int flags); void ppc_cpu_dump_statistics(CPUState *cpu, int flags); hwaddr ppc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int ppc_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); -int ppc_cpu_gdb_read_register_apple(CPUState *cpu, uint8_t *buf, int reg); +int ppc_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); +int ppc_cpu_gdb_read_register_apple(CPUState *cpu, GByteArray *buf, int re= g); int ppc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); int ppc_cpu_gdb_write_register_apple(CPUState *cpu, uint8_t *buf, int reg); #ifndef CONFIG_USER_ONLY diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index e59343e13c0..fe0b8861021 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -243,7 +243,7 @@ extern const char * const riscv_excp_names[]; extern const char * const riscv_intr_names[]; =20 void riscv_cpu_do_interrupt(CPUState *cpu); -int riscv_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int riscv_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int riscv_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); bool riscv_cpu_exec_interrupt(CPUState *cs, int interrupt_request); bool riscv_cpu_fp_enabled(CPURISCVState *env); diff --git a/target/s390x/internal.h b/target/s390x/internal.h index d37816104dd..8c95c734dbe 100644 --- a/target/s390x/internal.h +++ b/target/s390x/internal.h @@ -292,7 +292,7 @@ uint16_t float128_dcmask(CPUS390XState *env, float128 f= 1); =20 =20 /* gdbstub.c */ -int s390_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int s390_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int s390_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void s390_cpu_gdb_init(CPUState *cs); =20 diff --git a/target/sh4/cpu.h b/target/sh4/cpu.h index ecaa7a18a94..d7a1bffd600 100644 --- a/target/sh4/cpu.h +++ b/target/sh4/cpu.h @@ -208,7 +208,7 @@ void superh_cpu_do_interrupt(CPUState *cpu); bool superh_cpu_exec_interrupt(CPUState *cpu, int int_req); void superh_cpu_dump_state(CPUState *cpu, FILE *f, int flags); hwaddr superh_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int superh_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int superh_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int superh_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void superh_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type, diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h index ae97c7d9f79..b9369398f24 100644 --- a/target/sparc/cpu.h +++ b/target/sparc/cpu.h @@ -571,7 +571,7 @@ extern const VMStateDescription vmstate_sparc_cpu; void sparc_cpu_do_interrupt(CPUState *cpu); void sparc_cpu_dump_state(CPUState *cpu, FILE *f, int flags); hwaddr sparc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int sparc_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int sparc_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int sparc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void QEMU_NORETURN sparc_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type, diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h index b363ffcf106..b20be1f5814 100644 --- a/target/xtensa/cpu.h +++ b/target/xtensa/cpu.h @@ -569,7 +569,7 @@ void xtensa_cpu_dump_state(CPUState *cpu, FILE *f, int = flags); hwaddr xtensa_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); void xtensa_count_regs(const XtensaConfig *config, unsigned *n_regs, unsigned *n_core_regs); -int xtensa_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int xtensa_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int xtensa_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void xtensa_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type, diff --git a/gdbstub.c b/gdbstub.c index 736e3cc1052..287d0535b12 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -319,8 +319,8 @@ static int gdb_signal_to_target (int sig) typedef struct GDBRegisterState { int base_reg; int num_regs; - gdb_reg_cb get_reg; - gdb_reg_cb set_reg; + gdb_get_reg_cb get_reg; + gdb_set_reg_cb set_reg; const char *xml; struct GDBRegisterState *next; } GDBRegisterState; @@ -905,19 +905,19 @@ static const char *get_feature_xml(const char *p, con= st char **newp, return name ? xml_builtin[i][1] : NULL; } =20 -static int gdb_read_register(CPUState *cpu, uint8_t *mem_buf, int reg) +static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg) { CPUClass *cc =3D CPU_GET_CLASS(cpu); CPUArchState *env =3D cpu->env_ptr; GDBRegisterState *r; =20 if (reg < cc->gdb_num_core_regs) { - return cc->gdb_read_register(cpu, mem_buf, reg); + return cc->gdb_read_register(cpu, buf, reg); } =20 for (r =3D cpu->gdb_regs; r; r =3D r->next) { if (r->base_reg <=3D reg && reg < r->base_reg + r->num_regs) { - return r->get_reg(env, mem_buf, reg - r->base_reg); + return r->get_reg(env, buf, reg - r->base_reg); } } return 0; @@ -948,7 +948,7 @@ static int gdb_write_register(CPUState *cpu, uint8_t *m= em_buf, int reg) */ =20 void gdb_register_coprocessor(CPUState *cpu, - gdb_reg_cb get_reg, gdb_reg_cb set_reg, + gdb_get_reg_cb get_reg, gdb_set_reg_cb set_r= eg, int num_regs, const char *xml, int g_pos) { GDBRegisterState *s; @@ -1739,7 +1739,7 @@ static void handle_get_reg(GdbCmdContext *gdb_ctx, vo= id *user_ctx) } =20 reg_size =3D gdb_read_register(gdbserver_state.g_cpu, - gdbserver_state.mem_buf->data, + gdbserver_state.mem_buf, gdb_ctx->params[0].val_ull); if (!reg_size) { put_packet("E14"); @@ -1832,14 +1832,14 @@ static void handle_read_all_regs(GdbCmdContext *gdb= _ctx, void *user_ctx) target_ulong addr, len; =20 cpu_synchronize_state(gdbserver_state.g_cpu); + g_byte_array_set_size(gdbserver_state.mem_buf, 0); len =3D 0; for (addr =3D 0; addr < gdbserver_state.g_cpu->gdb_num_g_regs; addr++)= { len +=3D gdb_read_register(gdbserver_state.g_cpu, - gdbserver_state.mem_buf->data + len, + gdbserver_state.mem_buf, addr); } - /* FIXME: This is after the fact sizing */ - g_byte_array_set_size(gdbserver_state.mem_buf, len); + g_assert(len =3D=3D gdbserver_state.mem_buf->len); =20 memtohex(gdbserver_state.str_buf, gdbserver_state.mem_buf->data, len); put_strbuf(); diff --git a/hw/core/cpu.c b/hw/core/cpu.c index db1a03c6bbb..9cd1a2a54fb 100644 --- a/hw/core/cpu.c +++ b/hw/core/cpu.c @@ -177,7 +177,7 @@ static int cpu_common_write_elf64_note(WriteCoreDumpFun= ction f, } =20 =20 -static int cpu_common_gdb_read_register(CPUState *cpu, uint8_t *buf, int r= eg) +static int cpu_common_gdb_read_register(CPUState *cpu, GByteArray *buf, in= t reg) { return 0; } diff --git a/target/alpha/gdbstub.c b/target/alpha/gdbstub.c index 7f9cc092a9c..0cd76ddaa9e 100644 --- a/target/alpha/gdbstub.c +++ b/target/alpha/gdbstub.c @@ -21,7 +21,7 @@ #include "cpu.h" #include "exec/gdbstub.h" =20 -int alpha_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int alpha_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { AlphaCPU *cpu =3D ALPHA_CPU(cs); CPUAlphaState *env =3D &cpu->env; diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index 1239abd9842..4557775d245 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -32,7 +32,7 @@ typedef struct RegisterSysregXmlParam { We hack round this by giving the FPA regs zero size when talking to a newer gdb. */ =20 -int arm_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int arm_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { ARMCPU *cpu =3D ARM_CPU(cs); CPUARMState *env =3D &cpu->env; diff --git a/target/arm/gdbstub64.c b/target/arm/gdbstub64.c index 665ebb3ef64..35d0b80c2de 100644 --- a/target/arm/gdbstub64.c +++ b/target/arm/gdbstub64.c @@ -20,7 +20,7 @@ #include "cpu.h" #include "exec/gdbstub.h" =20 -int aarch64_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int aarch64_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { ARMCPU *cpu =3D ARM_CPU(cs); CPUARMState *env =3D &cpu->env; diff --git a/target/arm/helper.c b/target/arm/helper.c index 6f3b6ca7d3f..36872627a5d 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -47,30 +47,27 @@ static bool get_phys_addr_lpae(CPUARMState *env, target= _ulong address, =20 static void switch_mode(CPUARMState *env, int mode); =20 -static int vfp_gdb_get_reg(CPUARMState *env, uint8_t *buf, int reg) +static int vfp_gdb_get_reg(CPUARMState *env, GByteArray *buf, int reg) { int nregs; =20 /* VFP data registers are always little-endian. */ nregs =3D arm_feature(env, ARM_FEATURE_VFP3) ? 32 : 16; if (reg < nregs) { - stq_le_p(buf, *aa32_vfp_dreg(env, reg)); - return 8; + return gdb_get_reg64(buf, *aa32_vfp_dreg(env, reg)); } if (arm_feature(env, ARM_FEATURE_NEON)) { /* Aliases for Q regs. */ nregs +=3D 16; if (reg < nregs) { uint64_t *q =3D aa32_vfp_qreg(env, reg - 32); - stq_le_p(buf, q[0]); - stq_le_p(buf + 8, q[1]); - return 16; + return gdb_get_reg128(buf, q[0], q[1]); } } switch (reg - nregs) { - case 0: stl_p(buf, env->vfp.xregs[ARM_VFP_FPSID]); return 4; - case 1: stl_p(buf, vfp_get_fpscr(env)); return 4; - case 2: stl_p(buf, env->vfp.xregs[ARM_VFP_FPEXC]); return 4; + case 0: return gdb_get_reg32(buf, env->vfp.xregs[ARM_VFP_FPSID]); brea= k; + case 1: return gdb_get_reg32(buf, vfp_get_fpscr(env)); break; + case 2: return gdb_get_reg32(buf, env->vfp.xregs[ARM_VFP_FPEXC]); brea= k; } return 0; } @@ -101,7 +98,7 @@ static int vfp_gdb_set_reg(CPUARMState *env, uint8_t *bu= f, int reg) return 0; } =20 -static int aarch64_fpu_gdb_get_reg(CPUARMState *env, uint8_t *buf, int reg) +static int aarch64_fpu_gdb_get_reg(CPUARMState *env, GByteArray *buf, int = reg) { switch (reg) { case 0 ... 31: @@ -204,7 +201,7 @@ static void write_raw_cp_reg(CPUARMState *env, const AR= MCPRegInfo *ri, } } =20 -static int arm_gdb_get_sysreg(CPUARMState *env, uint8_t *buf, int reg) +static int arm_gdb_get_sysreg(CPUARMState *env, GByteArray *buf, int reg) { ARMCPU *cpu =3D env_archcpu(env); const ARMCPRegInfo *ri; diff --git a/target/cris/gdbstub.c b/target/cris/gdbstub.c index a3d76d2e8c2..b01b2aa0811 100644 --- a/target/cris/gdbstub.c +++ b/target/cris/gdbstub.c @@ -21,7 +21,7 @@ #include "cpu.h" #include "exec/gdbstub.h" =20 -int crisv10_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int crisv10_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { CRISCPU *cpu =3D CRIS_CPU(cs); CPUCRISState *env =3D &cpu->env; @@ -53,7 +53,7 @@ int crisv10_cpu_gdb_read_register(CPUState *cs, uint8_t *= mem_buf, int n) return 0; } =20 -int cris_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int cris_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { CRISCPU *cpu =3D CRIS_CPU(cs); CPUCRISState *env =3D &cpu->env; diff --git a/target/hppa/gdbstub.c b/target/hppa/gdbstub.c index 341888a9da0..a6428a2893f 100644 --- a/target/hppa/gdbstub.c +++ b/target/hppa/gdbstub.c @@ -21,7 +21,7 @@ #include "cpu.h" #include "exec/gdbstub.h" =20 -int hppa_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int hppa_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { HPPACPU *cpu =3D HPPA_CPU(cs); CPUHPPAState *env =3D &cpu->env; diff --git a/target/i386/gdbstub.c b/target/i386/gdbstub.c index aef25b70f10..38324498f33 100644 --- a/target/i386/gdbstub.c +++ b/target/i386/gdbstub.c @@ -79,7 +79,7 @@ static const int gpr_map32[8] =3D { 0, 1, 2, 3, 4, 5, 6, = 7 }; #endif =20 =20 -int x86_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; diff --git a/target/lm32/gdbstub.c b/target/lm32/gdbstub.c index 82ede436e12..b6fe12e1d61 100644 --- a/target/lm32/gdbstub.c +++ b/target/lm32/gdbstub.c @@ -22,7 +22,7 @@ #include "exec/gdbstub.h" #include "hw/lm32/lm32_pic.h" =20 -int lm32_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int lm32_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { LM32CPU *cpu =3D LM32_CPU(cs); CPULM32State *env =3D &cpu->env; diff --git a/target/m68k/gdbstub.c b/target/m68k/gdbstub.c index fdc96f57fff..eb2d030e148 100644 --- a/target/m68k/gdbstub.c +++ b/target/m68k/gdbstub.c @@ -21,7 +21,7 @@ #include "cpu.h" #include "exec/gdbstub.h" =20 -int m68k_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int m68k_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { M68kCPU *cpu =3D M68K_CPU(cs); CPUM68KState *env =3D &cpu->env; diff --git a/target/m68k/helper.c b/target/m68k/helper.c index 2573ee7a535..6f9099cd937 100644 --- a/target/m68k/helper.c +++ b/target/m68k/helper.c @@ -68,7 +68,7 @@ void m68k_cpu_list(void) g_slist_free(list); } =20 -static int cf_fpu_gdb_get_reg(CPUM68KState *env, uint8_t *mem_buf, int n) +static int cf_fpu_gdb_get_reg(CPUM68KState *env, GByteArray *mem_buf, int = n) { if (n < 8) { float_status s; @@ -105,7 +105,7 @@ static int cf_fpu_gdb_set_reg(CPUM68KState *env, uint8_= t *mem_buf, int n) return 0; } =20 -static int m68k_fpu_gdb_get_reg(CPUM68KState *env, uint8_t *mem_buf, int n) +static int m68k_fpu_gdb_get_reg(CPUM68KState *env, GByteArray *mem_buf, in= t n) { if (n < 8) { int len =3D gdb_get_reg16(mem_buf, env->fregs[n].l.upper); diff --git a/target/microblaze/gdbstub.c b/target/microblaze/gdbstub.c index 30677b6d1f4..f41ebf1f33b 100644 --- a/target/microblaze/gdbstub.c +++ b/target/microblaze/gdbstub.c @@ -21,7 +21,7 @@ #include "cpu.h" #include "exec/gdbstub.h" =20 -int mb_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int mb_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { MicroBlazeCPU *cpu =3D MICROBLAZE_CPU(cs); CPUMBState *env =3D &cpu->env; diff --git a/target/mips/gdbstub.c b/target/mips/gdbstub.c index bbb25449391..98f56e660d2 100644 --- a/target/mips/gdbstub.c +++ b/target/mips/gdbstub.c @@ -22,7 +22,7 @@ #include "internal.h" #include "exec/gdbstub.h" =20 -int mips_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int mips_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { MIPSCPU *cpu =3D MIPS_CPU(cs); CPUMIPSState *env =3D &cpu->env; diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c index ca9c7a6df5d..17d868421ed 100644 --- a/target/nios2/cpu.c +++ b/target/nios2/cpu.c @@ -124,7 +124,7 @@ static void nios2_cpu_disas_set_info(CPUState *cpu, dis= assemble_info *info) #endif } =20 -static int nios2_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int= n) +static int nios2_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, = int n) { Nios2CPU *cpu =3D NIOS2_CPU(cs); CPUClass *cc =3D CPU_GET_CLASS(cs); diff --git a/target/openrisc/gdbstub.c b/target/openrisc/gdbstub.c index 0fcdb79668c..095bf76c12c 100644 --- a/target/openrisc/gdbstub.c +++ b/target/openrisc/gdbstub.c @@ -21,7 +21,7 @@ #include "cpu.h" #include "exec/gdbstub.h" =20 -int openrisc_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int openrisc_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int = n) { OpenRISCCPU *cpu =3D OPENRISC_CPU(cs); CPUOpenRISCState *env =3D &cpu->env; diff --git a/target/ppc/gdbstub.c b/target/ppc/gdbstub.c index 823759c92e7..eb362dd9aec 100644 --- a/target/ppc/gdbstub.c +++ b/target/ppc/gdbstub.c @@ -114,10 +114,11 @@ void ppc_maybe_bswap_register(CPUPPCState *env, uint8= _t *mem_buf, int len) * the FP regs zero size when talking to a newer gdb. */ =20 -int ppc_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int ppc_cpu_gdb_read_register(CPUState *cs, GByteArray *buf, int n) { PowerPCCPU *cpu =3D POWERPC_CPU(cs); CPUPPCState *env =3D &cpu->env; + uint8_t *mem_buf; int r =3D ppc_gdb_register_len(n); =20 if (!r) { @@ -126,17 +127,17 @@ int ppc_cpu_gdb_read_register(CPUState *cs, uint8_t *= mem_buf, int n) =20 if (n < 32) { /* gprs */ - gdb_get_regl(mem_buf, env->gpr[n]); + gdb_get_regl(buf, env->gpr[n]); } else if (n < 64) { /* fprs */ - stfq_p(mem_buf, *cpu_fpr_ptr(env, n - 32)); + gdb_get_reg64(buf, *cpu_fpr_ptr(env, n - 32)); } else { switch (n) { case 64: - gdb_get_regl(mem_buf, env->nip); + gdb_get_regl(buf, env->nip); break; case 65: - gdb_get_regl(mem_buf, env->msr); + gdb_get_regl(buf, env->msr); break; case 66: { @@ -145,31 +146,33 @@ int ppc_cpu_gdb_read_register(CPUState *cs, uint8_t *= mem_buf, int n) for (i =3D 0; i < 8; i++) { cr |=3D env->crf[i] << (32 - ((i + 1) * 4)); } - gdb_get_reg32(mem_buf, cr); + gdb_get_reg32(buf, cr); break; } case 67: - gdb_get_regl(mem_buf, env->lr); + gdb_get_regl(buf, env->lr); break; case 68: - gdb_get_regl(mem_buf, env->ctr); + gdb_get_regl(buf, env->ctr); break; case 69: - gdb_get_reg32(mem_buf, env->xer); + gdb_get_reg32(buf, env->xer); break; case 70: - gdb_get_reg32(mem_buf, env->fpscr); + gdb_get_reg32(buf, env->fpscr); break; } } + mem_buf =3D buf->data + buf->len - r; ppc_maybe_bswap_register(env, mem_buf, r); return r; } =20 -int ppc_cpu_gdb_read_register_apple(CPUState *cs, uint8_t *mem_buf, int n) +int ppc_cpu_gdb_read_register_apple(CPUState *cs, GByteArray *buf, int n) { PowerPCCPU *cpu =3D POWERPC_CPU(cs); CPUPPCState *env =3D &cpu->env; + uint8_t *mem_buf; int r =3D ppc_gdb_register_len_apple(n); =20 if (!r) { @@ -178,21 +181,21 @@ int ppc_cpu_gdb_read_register_apple(CPUState *cs, uin= t8_t *mem_buf, int n) =20 if (n < 32) { /* gprs */ - gdb_get_reg64(mem_buf, env->gpr[n]); + gdb_get_reg64(buf, env->gpr[n]); } else if (n < 64) { /* fprs */ - stfq_p(mem_buf, *cpu_fpr_ptr(env, n - 32)); + gdb_get_reg64(buf, *cpu_fpr_ptr(env, n - 32)); } else if (n < 96) { /* Altivec */ - stq_p(mem_buf, n - 64); - stq_p(mem_buf + 8, 0); + gdb_get_reg64(buf, n - 64); + gdb_get_reg64(buf, 0); } else { switch (n) { case 64 + 32: - gdb_get_reg64(mem_buf, env->nip); + gdb_get_reg64(buf, env->nip); break; case 65 + 32: - gdb_get_reg64(mem_buf, env->msr); + gdb_get_reg64(buf, env->msr); break; case 66 + 32: { @@ -201,23 +204,24 @@ int ppc_cpu_gdb_read_register_apple(CPUState *cs, uin= t8_t *mem_buf, int n) for (i =3D 0; i < 8; i++) { cr |=3D env->crf[i] << (32 - ((i + 1) * 4)); } - gdb_get_reg32(mem_buf, cr); + gdb_get_reg32(buf, cr); break; } case 67 + 32: - gdb_get_reg64(mem_buf, env->lr); + gdb_get_reg64(buf, env->lr); break; case 68 + 32: - gdb_get_reg64(mem_buf, env->ctr); + gdb_get_reg64(buf, env->ctr); break; case 69 + 32: - gdb_get_reg32(mem_buf, env->xer); + gdb_get_reg32(buf, env->xer); break; case 70 + 32: - gdb_get_reg64(mem_buf, env->fpscr); + gdb_get_reg64(buf, env->fpscr); break; } } + mem_buf =3D buf->data + buf->len - r; ppc_maybe_bswap_register(env, mem_buf, r); return r; } diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.in= c.c index d33d65dff70..ca241d7f5e6 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -9845,7 +9845,7 @@ static int gdb_find_spr_idx(CPUPPCState *env, int n) return -1; } =20 -static int gdb_get_spr_reg(CPUPPCState *env, uint8_t *mem_buf, int n) +static int gdb_get_spr_reg(CPUPPCState *env, GByteArray *buf, int n) { int reg; int len; @@ -9856,8 +9856,8 @@ static int gdb_get_spr_reg(CPUPPCState *env, uint8_t = *mem_buf, int n) } =20 len =3D TARGET_LONG_SIZE; - stn_p(mem_buf, len, env->spr[reg]); - ppc_maybe_bswap_register(env, mem_buf, len); + gdb_get_regl(buf, env->spr[reg]); + ppc_maybe_bswap_register(env, buf->data - len, len); return len; } =20 @@ -9879,15 +9879,18 @@ static int gdb_set_spr_reg(CPUPPCState *env, uint8_= t *mem_buf, int n) } #endif =20 -static int gdb_get_float_reg(CPUPPCState *env, uint8_t *mem_buf, int n) +static int gdb_get_float_reg(CPUPPCState *env, GByteArray *buf, int n) { + uint8_t *mem_buf; if (n < 32) { - stfq_p(mem_buf, *cpu_fpr_ptr(env, n)); + gdb_get_reg64(buf, *cpu_fpr_ptr(env, n)); + mem_buf =3D buf->data - 8; ppc_maybe_bswap_register(env, mem_buf, 8); return 8; } if (n =3D=3D 32) { - stl_p(mem_buf, env->fpscr); + gdb_get_reg32(buf, env->fpscr); + mem_buf =3D buf->data - 4; ppc_maybe_bswap_register(env, mem_buf, 4); return 4; } @@ -9909,28 +9912,31 @@ static int gdb_set_float_reg(CPUPPCState *env, uint= 8_t *mem_buf, int n) return 0; } =20 -static int gdb_get_avr_reg(CPUPPCState *env, uint8_t *mem_buf, int n) +static int gdb_get_avr_reg(CPUPPCState *env, GByteArray *buf, int n) { + uint8_t *mem_buf; + if (n < 32) { ppc_avr_t *avr =3D cpu_avr_ptr(env, n); if (!avr_need_swap(env)) { - stq_p(mem_buf, avr->u64[0]); - stq_p(mem_buf + 8, avr->u64[1]); + gdb_get_reg128(buf, avr->u64[0] , avr->u64[1]); } else { - stq_p(mem_buf, avr->u64[1]); - stq_p(mem_buf + 8, avr->u64[0]); + gdb_get_reg128(buf, avr->u64[1] , avr->u64[0]); } + mem_buf =3D buf->data - 16; ppc_maybe_bswap_register(env, mem_buf, 8); ppc_maybe_bswap_register(env, mem_buf + 8, 8); return 16; } if (n =3D=3D 32) { - stl_p(mem_buf, helper_mfvscr(env)); + gdb_get_reg32(buf, helper_mfvscr(env)); + mem_buf =3D buf->data - 4; ppc_maybe_bswap_register(env, mem_buf, 4); return 4; } if (n =3D=3D 33) { - stl_p(mem_buf, (uint32_t)env->spr[SPR_VRSAVE]); + gdb_get_reg32(buf, (uint32_t)env->spr[SPR_VRSAVE]); + mem_buf =3D buf->data - 4; ppc_maybe_bswap_register(env, mem_buf, 4); return 4; } @@ -9965,25 +9971,25 @@ static int gdb_set_avr_reg(CPUPPCState *env, uint8_= t *mem_buf, int n) return 0; } =20 -static int gdb_get_spe_reg(CPUPPCState *env, uint8_t *mem_buf, int n) +static int gdb_get_spe_reg(CPUPPCState *env, GByteArray *buf, int n) { if (n < 32) { #if defined(TARGET_PPC64) - stl_p(mem_buf, env->gpr[n] >> 32); - ppc_maybe_bswap_register(env, mem_buf, 4); + gdb_get_reg32(buf, env->gpr[n] >> 32); + ppc_maybe_bswap_register(env, buf->data - 4, 4); #else - stl_p(mem_buf, env->gprh[n]); + gdb_get_reg32(buf, env->gprh[n]); #endif return 4; } if (n =3D=3D 32) { - stq_p(mem_buf, env->spe_acc); - ppc_maybe_bswap_register(env, mem_buf, 8); + gdb_get_reg64(buf, env->spe_acc); + ppc_maybe_bswap_register(env, buf->data - 8, 8); return 8; } if (n =3D=3D 33) { - stl_p(mem_buf, env->spe_fscr); - ppc_maybe_bswap_register(env, mem_buf, 4); + gdb_get_reg32(buf, env->spe_fscr); + ppc_maybe_bswap_register(env, buf->data - 4, 4); return 4; } return 0; @@ -10018,11 +10024,11 @@ static int gdb_set_spe_reg(CPUPPCState *env, uint= 8_t *mem_buf, int n) return 0; } =20 -static int gdb_get_vsx_reg(CPUPPCState *env, uint8_t *mem_buf, int n) +static int gdb_get_vsx_reg(CPUPPCState *env, GByteArray *buf, int n) { if (n < 32) { - stq_p(mem_buf, *cpu_vsrl_ptr(env, n)); - ppc_maybe_bswap_register(env, mem_buf, 8); + gdb_get_reg64(buf, *cpu_vsrl_ptr(env, n)); + ppc_maybe_bswap_register(env, buf->data - 8, 8); return 8; } return 0; diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c index 1a7947e0198..05442215a4b 100644 --- a/target/riscv/gdbstub.c +++ b/target/riscv/gdbstub.c @@ -269,7 +269,7 @@ static int csr_register_map[] =3D { CSR_MHCOUNTEREN, }; =20 -int riscv_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int riscv_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { RISCVCPU *cpu =3D RISCV_CPU(cs); CPURISCVState *env =3D &cpu->env; @@ -300,10 +300,10 @@ int riscv_cpu_gdb_write_register(CPUState *cs, uint8_= t *mem_buf, int n) return 0; } =20 -static int riscv_gdb_get_fpu(CPURISCVState *env, uint8_t *mem_buf, int n) +static int riscv_gdb_get_fpu(CPURISCVState *env, GByteArray *buf, int n) { if (n < 32) { - return gdb_get_reg64(mem_buf, env->fpr[n]); + return gdb_get_reg64(buf, env->fpr[n]); /* there is hole between ft11 and fflags in fpu.xml */ } else if (n < 36 && n > 32) { target_ulong val =3D 0; @@ -316,7 +316,7 @@ static int riscv_gdb_get_fpu(CPURISCVState *env, uint8_= t *mem_buf, int n) result =3D riscv_csrrw_debug(env, n - 33 + csr_register_map[8], &v= al, 0, 0); if (result =3D=3D 0) { - return gdb_get_regl(mem_buf, val); + return gdb_get_regl(buf, val); } } return 0; @@ -345,7 +345,7 @@ static int riscv_gdb_set_fpu(CPURISCVState *env, uint8_= t *mem_buf, int n) return 0; } =20 -static int riscv_gdb_get_csr(CPURISCVState *env, uint8_t *mem_buf, int n) +static int riscv_gdb_get_csr(CPURISCVState *env, GByteArray *buf, int n) { if (n < ARRAY_SIZE(csr_register_map)) { target_ulong val =3D 0; @@ -353,7 +353,7 @@ static int riscv_gdb_get_csr(CPURISCVState *env, uint8_= t *mem_buf, int n) =20 result =3D riscv_csrrw_debug(env, csr_register_map[n], &val, 0, 0); if (result =3D=3D 0) { - return gdb_get_regl(mem_buf, val); + return gdb_get_regl(buf, val); } } return 0; @@ -373,13 +373,13 @@ static int riscv_gdb_set_csr(CPURISCVState *env, uint= 8_t *mem_buf, int n) return 0; } =20 -static int riscv_gdb_get_virtual(CPURISCVState *cs, uint8_t *mem_buf, int = n) +static int riscv_gdb_get_virtual(CPURISCVState *cs, GByteArray *buf, int n) { if (n =3D=3D 0) { #ifdef CONFIG_USER_ONLY - return gdb_get_regl(mem_buf, 0); + return gdb_get_regl(buf, 0); #else - return gdb_get_regl(mem_buf, cs->priv); + return gdb_get_regl(buf, cs->priv); #endif } return 0; diff --git a/target/s390x/gdbstub.c b/target/s390x/gdbstub.c index e24a49f4a91..d6fce5ff1e1 100644 --- a/target/s390x/gdbstub.c +++ b/target/s390x/gdbstub.c @@ -27,7 +27,7 @@ #include "sysemu/hw_accel.h" #include "sysemu/tcg.h" =20 -int s390_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int s390_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { S390CPU *cpu =3D S390_CPU(cs); CPUS390XState *env =3D &cpu->env; @@ -82,11 +82,11 @@ int s390_cpu_gdb_write_register(CPUState *cs, uint8_t *= mem_buf, int n) /* total number of registers in s390-acr.xml */ #define S390_NUM_AC_REGS 16 =20 -static int cpu_read_ac_reg(CPUS390XState *env, uint8_t *mem_buf, int n) +static int cpu_read_ac_reg(CPUS390XState *env, GByteArray *buf, int n) { switch (n) { case S390_A0_REGNUM ... S390_A15_REGNUM: - return gdb_get_reg32(mem_buf, env->aregs[n]); + return gdb_get_reg32(buf, env->aregs[n]); default: return 0; } @@ -111,13 +111,13 @@ static int cpu_write_ac_reg(CPUS390XState *env, uint8= _t *mem_buf, int n) /* total number of registers in s390-fpr.xml */ #define S390_NUM_FP_REGS 17 =20 -static int cpu_read_fp_reg(CPUS390XState *env, uint8_t *mem_buf, int n) +static int cpu_read_fp_reg(CPUS390XState *env, GByteArray *buf, int n) { switch (n) { case S390_FPC_REGNUM: - return gdb_get_reg32(mem_buf, env->fpc); + return gdb_get_reg32(buf, env->fpc); case S390_F0_REGNUM ... S390_F15_REGNUM: - return gdb_get_reg64(mem_buf, *get_freg(env, n - S390_F0_REGNUM)); + return gdb_get_reg64(buf, *get_freg(env, n - S390_F0_REGNUM)); default: return 0; } @@ -145,17 +145,17 @@ static int cpu_write_fp_reg(CPUS390XState *env, uint8= _t *mem_buf, int n) /* total number of registers in s390-vx.xml */ #define S390_NUM_VREGS 32 =20 -static int cpu_read_vreg(CPUS390XState *env, uint8_t *mem_buf, int n) +static int cpu_read_vreg(CPUS390XState *env, GByteArray *buf, int n) { int ret; =20 switch (n) { case S390_V0L_REGNUM ... S390_V15L_REGNUM: - ret =3D gdb_get_reg64(mem_buf, env->vregs[n][1]); + ret =3D gdb_get_reg64(buf, env->vregs[n][1]); break; case S390_V16_REGNUM ... S390_V31_REGNUM: - ret =3D gdb_get_reg64(mem_buf, env->vregs[n][0]); - ret +=3D gdb_get_reg64(mem_buf + 8, env->vregs[n][1]); + ret =3D gdb_get_reg64(buf, env->vregs[n][0]); + ret +=3D gdb_get_reg64(buf, env->vregs[n][1]); break; default: ret =3D 0; @@ -186,11 +186,11 @@ static int cpu_write_vreg(CPUS390XState *env, uint8_t= *mem_buf, int n) #define S390_NUM_C_REGS 16 =20 #ifndef CONFIG_USER_ONLY -static int cpu_read_c_reg(CPUS390XState *env, uint8_t *mem_buf, int n) +static int cpu_read_c_reg(CPUS390XState *env, GByteArray *buf, int n) { switch (n) { case S390_C0_REGNUM ... S390_C15_REGNUM: - return gdb_get_regl(mem_buf, env->cregs[n]); + return gdb_get_regl(buf, env->cregs[n]); default: return 0; } @@ -223,7 +223,7 @@ static int cpu_write_c_reg(CPUS390XState *env, uint8_t = *mem_buf, int n) /* total number of registers in s390-virt.xml */ #define S390_NUM_VIRT_REGS 8 =20 -static int cpu_read_virt_reg(CPUS390XState *env, uint8_t *mem_buf, int n) +static int cpu_read_virt_reg(CPUS390XState *env, GByteArray *mem_buf, int = n) { switch (n) { case S390_VIRT_CKC_REGNUM: @@ -296,9 +296,9 @@ static int cpu_write_virt_reg(CPUS390XState *env, uint8= _t *mem_buf, int n) /* total number of registers in s390-gs.xml */ #define S390_NUM_GS_REGS 4 =20 -static int cpu_read_gs_reg(CPUS390XState *env, uint8_t *mem_buf, int n) +static int cpu_read_gs_reg(CPUS390XState *env, GByteArray *buf, int n) { - return gdb_get_regl(mem_buf, env->gscb[n]); + return gdb_get_regl(buf, env->gscb[n]); } =20 static int cpu_write_gs_reg(CPUS390XState *env, uint8_t *mem_buf, int n) diff --git a/target/sh4/gdbstub.c b/target/sh4/gdbstub.c index 44c1679e9db..49fc4a0cc69 100644 --- a/target/sh4/gdbstub.c +++ b/target/sh4/gdbstub.c @@ -24,7 +24,7 @@ /* Hint: Use "set architecture sh4" in GDB to see fpu registers */ /* FIXME: We should use XML for this. */ =20 -int superh_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int superh_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { SuperHCPU *cpu =3D SUPERH_CPU(cs); CPUSH4State *env =3D &cpu->env; diff --git a/target/sparc/gdbstub.c b/target/sparc/gdbstub.c index 8be742b5a3d..78dc8dcc980 100644 --- a/target/sparc/gdbstub.c +++ b/target/sparc/gdbstub.c @@ -27,7 +27,7 @@ #define gdb_get_rega(buf, val) gdb_get_regl(buf, val) #endif =20 -int sparc_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int sparc_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { SPARCCPU *cpu =3D SPARC_CPU(cs); CPUSPARCState *env =3D &cpu->env; diff --git a/target/xtensa/gdbstub.c b/target/xtensa/gdbstub.c index 54727881f38..0ee3feabe54 100644 --- a/target/xtensa/gdbstub.c +++ b/target/xtensa/gdbstub.c @@ -63,7 +63,7 @@ void xtensa_count_regs(const XtensaConfig *config, } } =20 -int xtensa_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int xtensa_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { XtensaCPU *cpu =3D XTENSA_CPU(cs); CPUXtensaState *env =3D &cpu->env; --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576844864; cv=none; d=zohomail.com; s=zohoarc; b=mNIqVBSpQ9A3v6ilSsOAvuUo5+IL/4/ueo8Oo/u6b3IwjiS4lnSYSGSwTl1ei8K6cI517lbuI0OdKbkcDMt+4l8fXRz+4gL4qwxiDXNrXYXwxIs8IRVylu0+yMegB2T5kAVEecHm5NuHDJfQlGd51pzgo+4Q+/JNyWmM790meFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576844864; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=czanuspGcHlKRukvMkLTGjn1x611kvgV7PuFbsiK1Pk=; b=Gu7fIPtcj9WgiblIxqyOSw30JnrDuGny9VLpqsvk7p5uy3oBSN6CsSpFD+Bw8jYSFXP02PkopUnGEFLltw0bAtxYHcJSOCP2LiVBqqr4zsBQYk+bdehDjcAFunuLeZe2NxVAuCHuoWYjGZtz8Cfx0HW+LIeFlcQHx/9yrJJVMKo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576844864834381.9051994655997; Fri, 20 Dec 2019 04:27:44 -0800 (PST) Received: from localhost ([::1]:54486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHNf-0001dD-Fk for importer@patchew.org; Fri, 20 Dec 2019 07:27:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53709) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1k-0004rp-0y for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1e-000881-3N for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:03 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:34372) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1d-00084q-OA for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:57 -0500 Received: by mail-wr1-x443.google.com with SMTP id t2so9205406wrr.1 for ; Fri, 20 Dec 2019 04:04:57 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id v22sm8994211wml.11.2019.12.20.04.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:48 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 00A051FF99; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=czanuspGcHlKRukvMkLTGjn1x611kvgV7PuFbsiK1Pk=; b=zf7pxHfwzEDlsgRvDI3Gpj1CcG5uUIUIUl+xMsUxnlOyJB36nmqqsRU13tXmumM6wE ermA5ztZ5EUFjEwiltk/zFWK3SlxhyX9NJsWvpHaE8oHnMt5cXPwt5jie6ltUhWb7nIN NE8ASZTwlhjYp94hG0KAiDQ5YFbGwqN8KzMUmh9z1U/0rkyZVVunc4wcXd+DMOxg97F1 u/Vi0PHP0FMuyTN7kpVMfztgcnollB369IYvxO+giX790Q/vYNln4EyPNbdnDXLnc7FR xsyHzvmM3OV5qSpFFTJQ0yzREZTUR5eTaOk2YiJecv5szmGQf3N3yJ+QyDRQNsFKwIgW KSCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=czanuspGcHlKRukvMkLTGjn1x611kvgV7PuFbsiK1Pk=; b=MkpkYyMS+kbaXYbOpRhGd6GsxNDOzdVPtwNilADR4D5taaEZWS5371pFIAY+bWlYTs BZpsfvZ98CpJUjz+wYlDiPPTFgAhgho3vIwtK/uFCzUuUxx35M8v2SzvclIk0JaIjODb j24u0W+6w3soeGY9wG5rXbnL9eX6kGpkrAXPsy89EdFzOlyc0y2OxnlxCnaY48lfL998 8PK7N7KeO/28kep5BU0LYOPiiBrHVGBQBPwifSHJpKJVJx61s3SztSAZS049g/47E3mm cQKC5czAzBeUModM1o1MyeAPu6hvtEyjwpRbwnBFnVMP4asJ+lfJTnALGE/eNQapaJSJ tPnA== X-Gm-Message-State: APjAAAVyAxbWtaxjGUQVwsuHEmSeHP7RFSNBqRdqs2DqCuGSri6LpxSu 9HSXRmenn4dyAlrNHdWshs7XEQ== X-Google-Smtp-Source: APXvYqwW8fe0/xNziM0ZOCOgjAW9iOuK8v7BwY08j3wDMTtO7/hIhiK820+uRKoDbduZ354IXct4Yw== X-Received: by 2002:a5d:690e:: with SMTP id t14mr14764377wru.65.1576843496579; Fri, 20 Dec 2019 04:04:56 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 09/21] target/arm: prepare for multiple dynamic XMLs Date: Fri, 20 Dec 2019 12:04:26 +0000 Message-Id: <20191220120438.16114-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We will want to generate similar dynamic XML for gdbstub support of SVE registers (the upstream doesn't use XML). To that end lightly rename a few things to make the distinction. Signed-off-by: Alex Benn=C3=A9e --- target/arm/cpu.h | 20 +++++++++++++------- target/arm/gdbstub.c | 30 +++++++++++++++--------------- target/arm/helper.c | 4 ++-- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 19b3ac32113..59d5dbae31f 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -128,14 +128,20 @@ enum { /** * DynamicGDBXMLInfo: * @desc: Contains the XML descriptions. - * @num_cpregs: Number of the Coprocessor registers seen by GDB. - * @cpregs_keys: Array that contains the corresponding Key of - * a given cpreg with the same order of the cpreg in the XML description. + * @num: Number of the registers in this XML seen by GDB. + * @data: A union with data specific to the set of registers + * @cpregs_keys: Array that contains the corresponding Key of + * a given cpreg with the same order of the cpreg + * in the XML description. */ typedef struct DynamicGDBXMLInfo { char *desc; - int num_cpregs; - uint32_t *cpregs_keys; + int num; + union { + struct { + uint32_t *keys; + } cpregs; + } data; } DynamicGDBXMLInfo; =20 /* CPU state for each instance of a generic timer (in cp15 c14) */ @@ -748,7 +754,7 @@ struct ARMCPU { uint64_t *cpreg_vmstate_values; int32_t cpreg_vmstate_array_len; =20 - DynamicGDBXMLInfo dyn_xml; + DynamicGDBXMLInfo dyn_sysreg_xml; =20 /* Timers used by the generic (architected) timer */ QEMUTimer *gt_timer[NUM_GTIMERS]; @@ -955,7 +961,7 @@ int arm_cpu_gdb_write_register(CPUState *cpu, uint8_t *= buf, int reg); /* Dynamically generates for gdb stub an XML description of the sysregs fr= om * the cp_regs hashtable. Returns the registered sysregs number. */ -int arm_gen_dynamic_xml(CPUState *cpu); +int arm_gen_dynamic_sysreg_xml(CPUState *cpu); =20 /* Returns the dynamically generated XML for the gdb stub. * Returns a pointer to the XML contents for the specified XML file or NULL diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index 4557775d245..1f68ab98c3b 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -106,15 +106,15 @@ int arm_cpu_gdb_write_register(CPUState *cs, uint8_t = *mem_buf, int n) return 0; } =20 -static void arm_gen_one_xml_reg_tag(GString *s, DynamicGDBXMLInfo *dyn_xml, - ARMCPRegInfo *ri, uint32_t ri_key, - int bitsize) +static void arm_gen_one_xml_sysreg_tag(GString *s, DynamicGDBXMLInfo *dyn_= xml, + ARMCPRegInfo *ri, uint32_t ri_key, + int bitsize) { g_string_append_printf(s, "name); g_string_append_printf(s, " bitsize=3D\"%d\"", bitsize); g_string_append_printf(s, " group=3D\"cp_regs\"/>"); - dyn_xml->num_cpregs++; - dyn_xml->cpregs_keys[dyn_xml->num_cpregs - 1] =3D ri_key; + dyn_xml->data.cpregs.keys[dyn_xml->num] =3D ri_key; + dyn_xml->num++; } =20 static void arm_register_sysreg_for_xml(gpointer key, gpointer value, @@ -126,12 +126,12 @@ static void arm_register_sysreg_for_xml(gpointer key,= gpointer value, GString *s =3D param->s; ARMCPU *cpu =3D ARM_CPU(param->cs); CPUARMState *env =3D &cpu->env; - DynamicGDBXMLInfo *dyn_xml =3D &cpu->dyn_xml; + DynamicGDBXMLInfo *dyn_xml =3D &cpu->dyn_sysreg_xml; =20 if (!(ri->type & (ARM_CP_NO_RAW | ARM_CP_NO_GDB))) { if (arm_feature(env, ARM_FEATURE_AARCH64)) { if (ri->state =3D=3D ARM_CP_STATE_AA64) { - arm_gen_one_xml_reg_tag(s , dyn_xml, ri, ri_key, 64); + arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 64); } } else { if (ri->state =3D=3D ARM_CP_STATE_AA32) { @@ -140,30 +140,30 @@ static void arm_register_sysreg_for_xml(gpointer key,= gpointer value, return; } if (ri->type & ARM_CP_64BIT) { - arm_gen_one_xml_reg_tag(s , dyn_xml, ri, ri_key, 64); + arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 64= ); } else { - arm_gen_one_xml_reg_tag(s , dyn_xml, ri, ri_key, 32); + arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 32= ); } } } } } =20 -int arm_gen_dynamic_xml(CPUState *cs) +int arm_gen_dynamic_sysreg_xml(CPUState *cs) { ARMCPU *cpu =3D ARM_CPU(cs); GString *s =3D g_string_new(NULL); RegisterSysregXmlParam param =3D {cs, s}; =20 - cpu->dyn_xml.num_cpregs =3D 0; - cpu->dyn_xml.cpregs_keys =3D g_new(uint32_t, g_hash_table_size(cpu->cp= _regs)); + cpu->dyn_sysreg_xml.num =3D 0; + cpu->dyn_sysreg_xml.data.cpregs.keys =3D g_new(uint32_t, g_hash_table_= size(cpu->cp_regs)); g_string_printf(s, ""); g_string_append_printf(s, "= "); g_string_append_printf(s, ""); g_hash_table_foreach(cpu->cp_regs, arm_register_sysreg_for_xml, ¶m= ); g_string_append_printf(s, ""); - cpu->dyn_xml.desc =3D g_string_free(s, false); - return cpu->dyn_xml.num_cpregs; + cpu->dyn_sysreg_xml.desc =3D g_string_free(s, false); + return cpu->dyn_sysreg_xml.num; } =20 const char *arm_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname) @@ -171,7 +171,7 @@ const char *arm_gdb_get_dynamic_xml(CPUState *cs, const= char *xmlname) ARMCPU *cpu =3D ARM_CPU(cs); =20 if (strcmp(xmlname, "system-registers.xml") =3D=3D 0) { - return cpu->dyn_xml.desc; + return cpu->dyn_sysreg_xml.desc; } return NULL; } diff --git a/target/arm/helper.c b/target/arm/helper.c index 36872627a5d..0a3bc53124e 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -207,7 +207,7 @@ static int arm_gdb_get_sysreg(CPUARMState *env, GByteAr= ray *buf, int reg) const ARMCPRegInfo *ri; uint32_t key; =20 - key =3D cpu->dyn_xml.cpregs_keys[reg]; + key =3D cpu->dyn_sysreg_xml.data.cpregs.keys[reg]; ri =3D get_arm_cp_reginfo(cpu->cp_regs, key); if (ri) { if (cpreg_field_is_64bit(ri)) { @@ -7129,7 +7129,7 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *c= pu) 19, "arm-vfp.xml", 0); } gdb_register_coprocessor(cs, arm_gdb_get_sysreg, arm_gdb_set_sysreg, - arm_gen_dynamic_xml(cs), + arm_gen_dynamic_sysreg_xml(cs), "system-registers.xml", 0); } =20 --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576844107; cv=none; d=zohomail.com; s=zohoarc; b=j7bNMM74u6HaKVoXDSYS1u+UWZTbtXuS/CQnUH0R3cNgQHEmvM+0m3Y+GvfcBpppLOZZhy3kjfoNkxI9qYABBKvXSq5J/2P4S/r5Yjw/dF5EzAhabmPSvel8UbLrqd63f0NNGBBBj1piPhnNGfHkXvpVgBnS0XIh86wW1QA89Mk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576844107; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=frx1aURZvMjiv5Ib6mAusHFiIu8eDIVWmRgHjBz837s=; b=H213GkTrLQcQ5mVqgMR7xiNRa06/MvIwBV74dVJNAYAeYQI0XSDL0Twq7X4x+XZJGFc+l8RIE7PmlkfbVkCnHrceCTnt1VQS9R01RPfskvTuuXzKOna9kKY+P13geh+2wSUqUkZMBnmjP/Hf9/zW/2WwYwmx0xetRxEILVWPQu0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576844107408654.5744875002503; Fri, 20 Dec 2019 04:15:07 -0800 (PST) Received: from localhost ([::1]:54178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHBR-00012L-Pl for importer@patchew.org; Fri, 20 Dec 2019 07:15:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53713) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1k-0004rq-0x for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1f-0008E2-JN for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:03 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:38697) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1f-00089i-6k for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:59 -0500 Received: by mail-wr1-x442.google.com with SMTP id y17so9206945wrh.5 for ; Fri, 20 Dec 2019 04:04:59 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id u14sm9777423wrm.51.2019.12.20.04.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:48 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 1760C1FF9A; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=frx1aURZvMjiv5Ib6mAusHFiIu8eDIVWmRgHjBz837s=; b=zEOXQ3ypHQuLtrfxR0Q4lqmX6p8ZLE7D8i/NgyItrA85Sd5CnbuDRtnX/v6nyC1FNl 1ohtO6OhK3Q0MR40wRBO8MKy3joQ8oEDDPikRjMUnL98n8OQ6/2zHHUXJ4fmJdnglmm4 BozmDTsyik1HEiw8HwQCWTN686TTKefXkG0Y0aPHRRooslhCiygnDqpuoQQj9yXWxkaY BOZCO2XmC3KFLaeUh87M1qduz0TQozDEFGLJl6cmfSLmf77fZHq4q8K22pTbxr2T2ji5 tUEqqNaf6vRkiM/KJXPe/JbzcPmt6Hw3bTjdOaq/F0zcBMgopWD3+n3Jn8kHw1x3Q8W9 as3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=frx1aURZvMjiv5Ib6mAusHFiIu8eDIVWmRgHjBz837s=; b=TVa5PeiCMmrrr5c6gmZihSalVN97zrTgfdVzvA5liVlQLAOdV/Z0fa9QyMo31DHveR TWyuZNEB1aJwO8o6aVNfnQlQbyKFdwdaC8zf9yzDF2cOtbmlNHeQAtzhzO/bEbLkmIeQ SDXKrfUEkyRiYkglROK55GnTFm1DWyiv+LE/vp2aqH/sSe4obLjHbKaDLKm1AvskyG21 /Ckygw4GqkvNQX0P90vGuIiNvd4PufFLbTtiw2J5XEi/txqX7l9+ggrJuY2Bp85AkFtR 1kA4r6S0KO3JZFu6A7SpJ4HQqmOiiVbdsvKjiU3MVF3dwC9R4YRmuEYogf8Pi0YM/xO0 ZbPg== X-Gm-Message-State: APjAAAWgSD/peroCD8iqrq8Jg1MiNlxqaZXhd9h/VBbr9NnOsJCMFI6d NyMlJaJ3hEMUMWQXYHCgal1E+g== X-Google-Smtp-Source: APXvYqx+Wq3ggHBCk2QFZd1OjG8r7kEdZieoC2zqIdFZBrZcyHVMn9G0UdJGj3lSzucmhQdBiJnDxw== X-Received: by 2002:a5d:4847:: with SMTP id n7mr14991390wrs.30.1576843498083; Fri, 20 Dec 2019 04:04:58 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 10/21] target/arm: explicitly encode regnum in our XML Date: Fri, 20 Dec 2019 12:04:27 +0000 Message-Id: <20191220120438.16114-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, Richard Henderson , "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This is described as optional but I'm not convinced of the numbering when multiple target fragments are sent. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- v2 - post inc param->n in place so we don't get out count wrong --- target/arm/cpu.h | 2 +- target/arm/gdbstub.c | 17 +++++++++++------ target/arm/helper.c | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 59d5dbae31f..40591b5dc70 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -961,7 +961,7 @@ int arm_cpu_gdb_write_register(CPUState *cpu, uint8_t *= buf, int reg); /* Dynamically generates for gdb stub an XML description of the sysregs fr= om * the cp_regs hashtable. Returns the registered sysregs number. */ -int arm_gen_dynamic_sysreg_xml(CPUState *cpu); +int arm_gen_dynamic_sysreg_xml(CPUState *cpu, int base_reg); =20 /* Returns the dynamically generated XML for the gdb stub. * Returns a pointer to the XML contents for the specified XML file or NULL diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index 1f68ab98c3b..69c35462a63 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -24,6 +24,7 @@ typedef struct RegisterSysregXmlParam { CPUState *cs; GString *s; + int n; } RegisterSysregXmlParam; =20 /* Old gdb always expect FPA registers. Newer (xml-aware) gdb only expect @@ -108,10 +109,11 @@ int arm_cpu_gdb_write_register(CPUState *cs, uint8_t = *mem_buf, int n) =20 static void arm_gen_one_xml_sysreg_tag(GString *s, DynamicGDBXMLInfo *dyn_= xml, ARMCPRegInfo *ri, uint32_t ri_key, - int bitsize) + int bitsize, int regnum) { g_string_append_printf(s, "name); g_string_append_printf(s, " bitsize=3D\"%d\"", bitsize); + g_string_append_printf(s, " regnum=3D\"%d\"", regnum); g_string_append_printf(s, " group=3D\"cp_regs\"/>"); dyn_xml->data.cpregs.keys[dyn_xml->num] =3D ri_key; dyn_xml->num++; @@ -131,7 +133,8 @@ static void arm_register_sysreg_for_xml(gpointer key, g= pointer value, if (!(ri->type & (ARM_CP_NO_RAW | ARM_CP_NO_GDB))) { if (arm_feature(env, ARM_FEATURE_AARCH64)) { if (ri->state =3D=3D ARM_CP_STATE_AA64) { - arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 64); + arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 64, + param->n++); } } else { if (ri->state =3D=3D ARM_CP_STATE_AA32) { @@ -140,20 +143,22 @@ static void arm_register_sysreg_for_xml(gpointer key,= gpointer value, return; } if (ri->type & ARM_CP_64BIT) { - arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 64= ); + arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 64, + param->n++); } else { - arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 32= ); + arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 32, + param->n++); } } } } } =20 -int arm_gen_dynamic_sysreg_xml(CPUState *cs) +int arm_gen_dynamic_sysreg_xml(CPUState *cs, int base_reg) { ARMCPU *cpu =3D ARM_CPU(cs); GString *s =3D g_string_new(NULL); - RegisterSysregXmlParam param =3D {cs, s}; + RegisterSysregXmlParam param =3D {cs, s, base_reg}; =20 cpu->dyn_sysreg_xml.num =3D 0; cpu->dyn_sysreg_xml.data.cpregs.keys =3D g_new(uint32_t, g_hash_table_= size(cpu->cp_regs)); diff --git a/target/arm/helper.c b/target/arm/helper.c index 0a3bc53124e..488fdbf61a9 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -7129,7 +7129,7 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *c= pu) 19, "arm-vfp.xml", 0); } gdb_register_coprocessor(cs, arm_gdb_get_sysreg, arm_gdb_set_sysreg, - arm_gen_dynamic_sysreg_xml(cs), + arm_gen_dynamic_sysreg_xml(cs, cs->gdb_num_re= gs), "system-registers.xml", 0); } =20 --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576844412; cv=none; d=zohomail.com; s=zohoarc; b=kKJsBBdBz5SE72csVEY7zrvJcO5OV5dAMLD940Der/Gtd4Nr9EsaZYPoPpe5p/N3KyufFkvnyV+xue2PWkYEb1oER/6VXyJ1lIGyRDT7PyYCcExYjoVdA42gSYMJ+mtM5w3Jk58sj1+lhf4smHSfxkFy4CM45dwDaTIUBBRfJy0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576844412; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YX/3QlJb96xuPlFrDu4WTqDveBFpdotwZIYVwV0XY7M=; b=kox8DrufVSSWEmRTmPRlpDd6kwLTtCF9fBz8r8l9wraKr3HhD3O5sAOnUkm7gSfYLmJ14RxIEpGWhYgYyFtysDJhuH5voRkncN1dAxzZ89eMGB1yDB2PrVpViOWOD8lvXi2wiC/K2xeQIp+L7i79cCF+qk2y00vHS/iDvKHcv5k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576844412737558.3277163067548; Fri, 20 Dec 2019 04:20:12 -0800 (PST) Received: from localhost ([::1]:54286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHGN-0007rB-Cg for importer@patchew.org; Fri, 20 Dec 2019 07:20:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54443) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1y-000587-SF for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1q-0008SZ-5X for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:15 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:52406) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1o-0008Oj-O0 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:09 -0500 Received: by mail-wm1-x341.google.com with SMTP id p9so8694650wmc.2 for ; Fri, 20 Dec 2019 04:05:08 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id x18sm9681364wrr.75.2019.12.20.04.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:51 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 2C4A81FF9B; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YX/3QlJb96xuPlFrDu4WTqDveBFpdotwZIYVwV0XY7M=; b=KZafxjOH1S30qEh72GnMUHe2Au3BKIRFNGoG+fusNFoSXd61bMzh2txwNDqIhUrWQ8 lsrFGNfq94RRztbZSLmBp1IZazWVx1xgFb4Nlu+kauZ+ZoCEoh6d2zZZOjzPf3q7sGH+ fupYZcO6tS99qPBjwTnrreimuBWw6KkOc4ym3r07qndFNjQxi9h2UMruWlaTDBeWXBL7 d5Wahcms/WP45ndLpzTUGYw9DXWohfk2QxMDaFzg2w7VMtCgvwHYZ7NkCNbFc/Sk5nvU LOMfb3qzVxp09VdCibz878qyKu36LPWOMQaBj9tr0luSw6I4m4xUGuo0h5KYP/enWVb/ F3Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YX/3QlJb96xuPlFrDu4WTqDveBFpdotwZIYVwV0XY7M=; b=AkBNO/DlnZBChzzVyYVoDLQOnVs2dHj+8/HzhXpfRNGxMoL9CFKBb8+9FcwliaNlYu HeqzF4O1zNIt+un/468R2GcJm8RQUhDoPEAsF+DT2Vafr/cejJmGnssOQwqOVoAjdheL ugnpSWjdiMhMSsxwubQK1e+J/7rECyatC5rStDIVTR2LsALu9GCCBiamZJvXwhRd4cbN lCK4OkpRh7Omkigb30i/wt4xaj15R3AVOIp9CmZSjToT+On5VE8CN1cw2c6bAgjqwXyx oxGdzfZSltKpZltWD66vT45gEkZYZUijnS0rR+RwFWTcodRtUnPeAm0wcps7Bc2zTz9u hu8g== X-Gm-Message-State: APjAAAWM7rbgDVEg7W/GQ/4vwt5sDpo6mbmoxnKHccqok2dGiLDYIPIq fN/t4WloUK7CUVidAKuSEZtwVA== X-Google-Smtp-Source: APXvYqzMteUC02PV+0/r2/S45UUYqfEQ/Cs/MC4qnm8xsmsJqbt8UeCUp4Q1YJDZu8bB2u+RzfAxMA== X-Received: by 2002:a1c:7419:: with SMTP id p25mr15515137wmc.129.1576843507082; Fri, 20 Dec 2019 04:05:07 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 11/21] target/arm: default SVE length to 64 bytes for linux-user Date: Fri, 20 Dec 2019 12:04:28 +0000 Message-Id: <20191220120438.16114-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, Richard Henderson , "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The Linux kernel chooses the default of 64 bytes for SVE registers on the basis that it is the largest size on known hardware that won't grow the signal frame. We still honour the sve-max-vq property and userspace can expand the number of lanes by calling PR_SVE_SET_VL. This should not make any difference to SVE enabled software as the SVE is of course vector length agnostic. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- v2 - tweak zcr_el[1] instead --- target/arm/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index dd51adac059..2d2e786245b 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -199,9 +199,9 @@ static void arm_cpu_reset(CPUState *s) /* and to the SVE instructions */ env->cp15.cpacr_el1 =3D deposit64(env->cp15.cpacr_el1, 16, 2, 3); env->cp15.cptr_el[3] |=3D CPTR_EZ; - /* with maximum vector length */ + /* with reasonable vector length */ env->vfp.zcr_el[1] =3D cpu_isar_feature(aa64_sve, cpu) ? - cpu->sve_max_vq - 1 : 0; + MIN(cpu->sve_max_vq - 1, 3) : 0; env->vfp.zcr_el[2] =3D env->vfp.zcr_el[1]; env->vfp.zcr_el[3] =3D env->vfp.zcr_el[1]; /* --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576844642; cv=none; d=zohomail.com; s=zohoarc; b=hbcj02MJkpoeEtlnMq9fqnpd7/RXLD2GKpGidXWhj21OFe1B8U5J/b8RzI+sUGT5K1ScerAs/EjvehNyU3fdYM6soAEEzoziqAP+wF4uAXoVFhvJBvLvucsSRCRGwUncppcCvt78Wft6g7WtASe6vlC+14aF1a8GxJZnYqCFb3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576844642; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0lj3FMjn35XuuJVdZtoKvCODlvGJ+nX8a+H04fPMgEc=; b=YvGdrLG6IPfKJpqzxD/KBqD7q6yjapwMDJ+FNPa3+jvgY/VBqnUnNM4sEne089JsdFCEkBWFZQ2Q/eg+YmyRq5/jT0OYVfvspcqHRTjWMWIEdztDtpx1xU1/6c/DYBfFTuv6juxALsyQLypGDsx3jh94bTr9kRkyzDYfpPP5gRs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576844642300769.0553760416667; Fri, 20 Dec 2019 04:24:02 -0800 (PST) Received: from localhost ([::1]:54382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHK4-00051p-SQ for importer@patchew.org; Fri, 20 Dec 2019 07:24:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54467) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1z-00058v-8S for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1u-00005q-Mo for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:18 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:55562) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1s-0008TU-DM for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:12 -0500 Received: by mail-wm1-x343.google.com with SMTP id q9so8693662wmj.5 for ; Fri, 20 Dec 2019 04:05:10 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id u24sm9396531wml.10.2019.12.20.04.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:51 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 44E8A1FF9C; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0lj3FMjn35XuuJVdZtoKvCODlvGJ+nX8a+H04fPMgEc=; b=SMtfPsTri149jjIu+UJkvmetbIcnvlz9/IeVCHdGENCRiTHpdWtE/kSy0FPYebdvTc PDrpwOROaPUEz94UI9WSyvujhD0kxkTzhLT5ZjCzA5kkp7W+8xu9VW3Dw4dwHGekvzvz Hogtk/oHNAphBnalwXb6DPpCtv1q6vQJ0WLY/r2IG7cYh/m4Yu1nfmmAVbJd6Nyiyof9 8jMhX5MjH2sGXWymoTZLqZ5GlySwChV2xFT4frb9MZtu9KI/HxXmNA3H9hascAN1xdIX glXJ8xHG9z3q6vFxdYuwamyJp2uJJB1oBXRE88ai/bNt6BNEGUj1ct459UPFmvg7plfk mggw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0lj3FMjn35XuuJVdZtoKvCODlvGJ+nX8a+H04fPMgEc=; b=QlmeGzvUDARBAMoLQJ2I9gsW0JhbUBxehewEIGSQVf9HO3GNiE+QUs6G8vxl4KYGtY T87eRuyIxMU2T6IEJFdV0DErdHhOwzNYD5gtLpP5XMecD5BfU9R4AHO3lQ9UdEchJRbM kcfO7X10ZcenZY2Bj7DIL/6u8JY/IPe5YToSec70/sRzC6NoGYicZjbA7dQJgaT7UEx9 n5x/ODnQ/CyGIB6Wh8AYHBzI6Clzs5gzlqTOJW9wzXA0WubfO+OJPrtCF/zps9lxXXgr 8JUJRmfoJN2H9fpr1ZfONrjmFsh1MT9wLWr9h0FJqSXYxTSfe6rjYnCi/ja2TCIaeO6y Bo9w== X-Gm-Message-State: APjAAAUR8EexgXzq2MRwp+embZqYmnTPvConUkrbl+33xcTU9atK+Hxn eAh90igowirRwm0fjbr3x58hpw== X-Google-Smtp-Source: APXvYqzpV4awE89TbmSLI8/ojbpKOoLcmWHykuKSqA7RBqJGeONu/kPofrzATq7yB3/GNM0wTpTH6w== X-Received: by 2002:a05:600c:409:: with SMTP id q9mr15852063wmb.19.1576843509874; Fri, 20 Dec 2019 04:05:09 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 12/21] target/arm: generate xml description of our SVE registers Date: Fri, 20 Dec 2019 12:04:29 +0000 Message-Id: <20191220120438.16114-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We also expose a the helpers to read/write the the registers. Signed-off-by: Alex Benn=C3=A9e --- v2 - instead of zNpM expose zN at sve_max_vq width - wrap union in union q(us), d(usf), s(usf), h(usf), b(us) v3 - add a vg pseudo register for current width - spacing fixes - use switch/case for whole group - drop fpsr_pos marker - remove unused variables v4 - const-ify vec_lanes - drop vg --- target/arm/cpu.h | 7 ++- target/arm/gdbstub.c | 129 +++++++++++++++++++++++++++++++++++++++++++ target/arm/helper.c | 113 ++++++++++++++++++++++++++++++++++++- 3 files changed, 244 insertions(+), 5 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 40591b5dc70..33b96a0c066 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -755,6 +755,7 @@ struct ARMCPU { int32_t cpreg_vmstate_array_len; =20 DynamicGDBXMLInfo dyn_sysreg_xml; + DynamicGDBXMLInfo dyn_svereg_xml; =20 /* Timers used by the generic (architected) timer */ QEMUTimer *gt_timer[NUM_GTIMERS]; @@ -958,10 +959,12 @@ hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cp= u, vaddr addr, int arm_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int arm_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); =20 -/* Dynamically generates for gdb stub an XML description of the sysregs fr= om - * the cp_regs hashtable. Returns the registered sysregs number. +/* + * Helpers to dynamically generates XML descriptions of the sysregs + * and SVE registers. Returns the number of registers in each set. */ int arm_gen_dynamic_sysreg_xml(CPUState *cpu, int base_reg); +int arm_gen_dynamic_svereg_xml(CPUState *cpu, int base_reg); =20 /* Returns the dynamically generated XML for the gdb stub. * Returns a pointer to the XML contents for the specified XML file or NULL diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index 69c35462a63..d9dc6b3fb41 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -171,12 +171,141 @@ int arm_gen_dynamic_sysreg_xml(CPUState *cs, int bas= e_reg) return cpu->dyn_sysreg_xml.num; } =20 +struct TypeSize { + const char *gdb_type; + int size; + const char sz, suffix; +}; + +static const struct TypeSize vec_lanes[] =3D { + /* quads */ + { "uint128", 128, 'q', 'u' }, + { "int128", 128, 'q', 's' }, + /* 64 bit */ + { "uint64", 64, 'd', 'u' }, + { "int64", 64, 'd', 's' }, + { "ieee_double", 64, 'd', 'f' }, + /* 32 bit */ + { "uint32", 32, 's', 'u' }, + { "int32", 32, 's', 's' }, + { "ieee_single", 32, 's', 'f' }, + /* 16 bit */ + { "uint16", 16, 'h', 'u' }, + { "int16", 16, 'h', 's' }, + { "ieee_half", 16, 'h', 'f' }, + /* bytes */ + { "uint8", 8, 'b', 'u' }, + { "int8", 8, 'b', 's' }, +}; + + +int arm_gen_dynamic_svereg_xml(CPUState *cs, int base_reg) +{ + ARMCPU *cpu =3D ARM_CPU(cs); + GString *s =3D g_string_new(NULL); + DynamicGDBXMLInfo *info =3D &cpu->dyn_svereg_xml; + g_autoptr(GString) ts =3D g_string_new(""); + int i, bits, reg_width =3D (cpu->sve_max_vq * 128); + info->num =3D 0; + g_string_printf(s, ""); + g_string_append_printf(s, "= "); + g_string_append_printf(s, ""); + + /* First define types and totals in a whole VL */ + for (i =3D 0; i < ARRAY_SIZE(vec_lanes); i++) { + int count =3D reg_width / vec_lanes[i].size; + g_string_printf(ts, "vq%d%c%c", count, + vec_lanes[i].sz, vec_lanes[i].suffix); + g_string_append_printf(s, + "", + ts->str, vec_lanes[i].gdb_type, count); + } + /* + * Now define a union for each size group containing unsigned and + * signed and potentially float versions of each size from 128 to + * 8 bits. + */ + for (bits =3D 128; bits >=3D 8; bits /=3D 2) { + int count =3D reg_width / bits; + g_string_append_printf(s, "", count); + for (i =3D 0; i < ARRAY_SIZE(vec_lanes); i++) { + if (vec_lanes[i].size =3D=3D bits) { + g_string_append_printf(s, "", + vec_lanes[i].suffix, + count, + vec_lanes[i].sz, vec_lanes[i].suffi= x); + } + } + g_string_append(s, ""); + } + /* And now the final union of unions */ + g_string_append(s, ""); + for (bits =3D 128; bits >=3D 8; bits /=3D 2) { + int count =3D reg_width / bits; + for (i =3D 0; i < ARRAY_SIZE(vec_lanes); i++) { + if (vec_lanes[i].size =3D=3D bits) { + g_string_append_printf(s, "", + vec_lanes[i].sz, count); + break; + } + } + } + g_string_append(s, ""); + + /* Then define each register in parts for each vq */ + for (i =3D 0; i < 32; i++) { + g_string_append_printf(s, + "", + i, reg_width, base_reg++); + info->num++; + } + /* fpscr & status registers */ + g_string_append_printf(s, "", base_reg++); + g_string_append_printf(s, "", base_reg++); + info->num +=3D 2; + /* + * Predicate registers aren't so big they are worth splitting up + * but we do need to define a type to hold the array of quad + * references. + */ + g_string_append_printf(s, + "", + cpu->sve_max_vq); + for (i =3D 0; i < 16; i++) { + g_string_append_printf(s, + "", + i, cpu->sve_max_vq * 16, base_reg++); + info->num++; + } + g_string_append_printf(s, + "", + cpu->sve_max_vq * 16, base_reg++); + info->num +=3D 1; + g_string_append_printf(s, ""); + cpu->dyn_svereg_xml.desc =3D g_string_free(s, false); + + return cpu->dyn_svereg_xml.num; +} + + const char *arm_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname) { ARMCPU *cpu =3D ARM_CPU(cs); =20 if (strcmp(xmlname, "system-registers.xml") =3D=3D 0) { return cpu->dyn_sysreg_xml.desc; + } else if (strcmp(xmlname, "sve-registers.xml") =3D=3D 0) { + return cpu->dyn_svereg_xml.desc; } return NULL; } diff --git a/target/arm/helper.c b/target/arm/helper.c index 488fdbf61a9..857581feba4 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -201,6 +201,15 @@ static void write_raw_cp_reg(CPUARMState *env, const A= RMCPRegInfo *ri, } } =20 +/** + * arm_get/set_gdb_*: get/set a gdb register + * @env: the CPU state + * @buf: a buffer to copy to/from + * @reg: register number (offset from start of group) + * + * We return the number of bytes copied + */ + static int arm_gdb_get_sysreg(CPUARMState *env, GByteArray *buf, int reg) { ARMCPU *cpu =3D env_archcpu(env); @@ -224,6 +233,90 @@ static int arm_gdb_set_sysreg(CPUARMState *env, uint8_= t *buf, int reg) return 0; } =20 +#ifdef TARGET_AARCH64 +static int arm_gdb_get_svereg(CPUARMState *env, GByteArray *buf, int reg) +{ + ARMCPU *cpu =3D env_archcpu(env); + + switch (reg) { + /* The first 32 registers are the zregs */ + case 0 ... 31: + { + int vq, len =3D 0; + for (vq =3D 0; vq < cpu->sve_max_vq; vq++) { + len +=3D gdb_get_reg128(buf, + env->vfp.zregs[reg].d[vq * 2 + 1], + env->vfp.zregs[reg].d[vq * 2]); + } + return len; + } + case 32: + return gdb_get_reg32(buf, vfp_get_fpsr(env)); + case 33: + return gdb_get_reg32(buf, vfp_get_fpcr(env)); + /* then 16 predicates and the ffr */ + case 34 ... 50: + { + int preg =3D reg - 34; + int vq, len =3D 0; + for (vq =3D 0; vq < cpu->sve_max_vq; vq =3D vq + 4) { + len +=3D gdb_get_reg64(buf, env->vfp.pregs[preg].p[vq / 4]); + } + return len; + } + default: + /* gdbstub asked for something out our range */ + qemu_log_mask(LOG_UNIMP, "%s: out of range register %d", __func__,= reg); + break; + } + + return 0; +} + +static int arm_gdb_set_svereg(CPUARMState *env, uint8_t *buf, int reg) +{ + ARMCPU *cpu =3D env_archcpu(env); + + /* The first 32 registers are the zregs */ + switch (reg) { + /* The first 32 registers are the zregs */ + case 0 ... 31: + { + int vq, len =3D 0; + uint64_t *p =3D (uint64_t *) buf; + for (vq =3D 0; vq < cpu->sve_max_vq; vq++) { + env->vfp.zregs[reg].d[vq * 2 + 1] =3D *p++; + env->vfp.zregs[reg].d[vq * 2] =3D *p++; + len +=3D 16; + } + return len; + } + case 32: + vfp_set_fpsr(env, *(uint32_t *)buf); + return 4; + case 33: + vfp_set_fpcr(env, *(uint32_t *)buf); + return 4; + case 34 ... 50: + { + int preg =3D reg - 34; + int vq, len =3D 0; + uint64_t *p =3D (uint64_t *) buf; + for (vq =3D 0; vq < cpu->sve_max_vq; vq =3D vq + 4) { + env->vfp.pregs[preg].p[vq / 4] =3D *p++; + len +=3D 8; + } + return len; + } + default: + /* gdbstub asked for something out our range */ + break; + } + + return 0; +} +#endif /* TARGET_AARCH64 */ + static bool raw_accessors_invalid(const ARMCPRegInfo *ri) { /* Return true if the regdef would cause an assertion if you called @@ -7115,9 +7208,22 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *= cpu) CPUARMState *env =3D &cpu->env; =20 if (arm_feature(env, ARM_FEATURE_AARCH64)) { - gdb_register_coprocessor(cs, aarch64_fpu_gdb_get_reg, - aarch64_fpu_gdb_set_reg, - 34, "aarch64-fpu.xml", 0); + /* + * The lower part of each SVE register aliases to the FPU + * registers so we don't need to include both. + */ +#ifdef TARGET_AARCH64 + if (isar_feature_aa64_sve(&cpu->isar)) { + gdb_register_coprocessor(cs, arm_gdb_get_svereg, arm_gdb_set_s= vereg, + arm_gen_dynamic_svereg_xml(cs, cs->gd= b_num_regs), + "sve-registers.xml", 0); + } else +#endif + { + gdb_register_coprocessor(cs, aarch64_fpu_gdb_get_reg, + aarch64_fpu_gdb_set_reg, + 34, "aarch64-fpu.xml", 0); + } } else if (arm_feature(env, ARM_FEATURE_NEON)) { gdb_register_coprocessor(cs, vfp_gdb_get_reg, vfp_gdb_set_reg, 51, "arm-neon.xml", 0); @@ -7131,6 +7237,7 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *c= pu) gdb_register_coprocessor(cs, arm_gdb_get_sysreg, arm_gdb_set_sysreg, arm_gen_dynamic_sysreg_xml(cs, cs->gdb_num_re= gs), "system-registers.xml", 0); + } =20 /* Sort alphabetically by type name, except for "any". */ --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576844187; cv=none; d=zohomail.com; s=zohoarc; b=nqfwlf1STQL0bX1VdfAznTnq29JaYH8ItOXJx1LU6S4iqqpLlReOvlXCaNd1trrpk6LaoSDiuEjpPgu94zPEvzMJVPIxpN365Z+D/4KlG2ru8r8XP/15QlqGQwYg+TT1G8VD/PFYOaMWLhTfihRnbBWqjDhbCEqHA/3IOnSPisw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576844187; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Mqhw4oMb9/NPBlcysMR2z8rn68YPooniQZ6sAVo6tJ0=; b=Uy04lJoGBjXraaSYd6lI030O7Pot/FSNwvfz2q9PkK3xrN7jEoZ9UKxnxHCNW6S21eLlfPVy9EWDHa+pWhg0vhrYQg4V25f5lZ1QVV5YhKPJ3tDYxLRamKPEvffYqmVhQZDJKKDkQVsSV7Y0UJF1q/r9Vtt1KromZL1npOnj7zg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576844187881613.285678064053; Fri, 20 Dec 2019 04:16:27 -0800 (PST) Received: from localhost ([::1]:54210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHCk-0002qU-46 for importer@patchew.org; Fri, 20 Dec 2019 07:16:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36324) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHAs-0000eI-41 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiHAq-0001Hi-Rc for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:29 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:55698) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiHAq-0001D4-DQ for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:28 -0500 Received: by mail-wm1-x342.google.com with SMTP id q9so8723044wmj.5 for ; Fri, 20 Dec 2019 04:14:28 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id o4sm9334239wrx.25.2019.12.20.04.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:14:25 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 585F51FF9D; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Mqhw4oMb9/NPBlcysMR2z8rn68YPooniQZ6sAVo6tJ0=; b=ZjNjiRx8twV7r7+gDAfFetdXMlwhJqPIbx6ucz1bkg2WTBQ65zsfXdZ6bWzGg75osI RveYQ69dK0KRWzVlr3gAANejDTCO64FH6EL9b2yVg0r6cxKTVjJmKgalnVs/ItXs/ntF ZiVEUaxfhtoseX0kfUa/hRkvCcR850ZvKCguWrAhZVzC29VPnHB+5/+aRgH82mguyjlZ l7tTyKH0C6cpSl16+rcUKLr+yPYwZQXlNJ2j2gff//6IOWb+yDcTnM105NcBEpg8gxNW Xrst8kRSTF6jTMtz0VrZrKr2LG83544ls95VrKT5lihLI9ozgPGjgPR/9S0TFyHcgQVc NQ3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Mqhw4oMb9/NPBlcysMR2z8rn68YPooniQZ6sAVo6tJ0=; b=PeNL8FJUbIDxiZ8cnwsvwjygV8fT6pakWnCNNrAdnVJTqvzCwgmuzKOUkwAf/lfnE2 8DLahxGOU2VQqWGL96YxAvmoSwLM7ujWAiSOYwPvKBkeC4Cb5bNKpWEhAxHxT0bXSZN/ r2oLndpNA460N5TxCZExYPjfe0S/B6ui/HzLU/gk0oT53cUnbvhiWNUX1S6d1cXMcimX JqIBg44Z1jsL05Es4BlqWpzyBvYLQpQDzeL8BVBrZ5iWblUxgj0EjvXfPOU5or8dnDRn TaxWxBSLkaY+QX8IEo6ZfJwDZkoniOShWzM2bvBz6b4H+hJcowMWa8nKD6hyACnnbtVJ kc3g== X-Gm-Message-State: APjAAAUTvKpQS9mMGQuls4NP/dBiU3XasGFq0e+p0lglbkBrs3X/WmFE l78EVlufT1aYZtqX5eK/yspJqQ== X-Google-Smtp-Source: APXvYqz3zKpcyP9wMce69R4A7l/cxBKZ8dSDb/dkeA+A0nj9+W4tUOSWZQkpxTtcP1Y+94wzhehxkw== X-Received: by 2002:a05:600c:54b:: with SMTP id k11mr15752965wmc.63.1576844067287; Fri, 20 Dec 2019 04:14:27 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 13/21] tests/tcg: add a configure compiler check for ARMv8.1 and SVE Date: Fri, 20 Dec 2019 12:04:30 +0000 Message-Id: <20191220120438.16114-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , luis.machado@linaro.org, alan.hayward@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We will need this for some tests later. The docker images already support it by default. Signed-off-by: Alex Benn=C3=A9e --- tests/tcg/configure.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh index 210e68396f2..e0d1fbb182f 100755 --- a/tests/tcg/configure.sh +++ b/tests/tcg/configure.sh @@ -216,6 +216,20 @@ for target in $target_list; do echo "CROSS_CC_GUEST_STATIC=3Dy" >> $config_target_mak fi echo "CROSS_CC_GUEST=3D$target_compiler" >> $config_target_mak + + # Test for compiler features for optional tests. We only do this + # for cross compilers because ensuring the docker containers based + # compilers is a requirememt for adding a new test that needs a + # compiler feature. + case $target in + aarch64-*) + if do_compiler "$target_compiler" $target_compiler_cflags \ + -march=3Darmv8.1-a+sve -o $TMPE $TMPC; then + echo "CROSS_CC_HAS_SVE=3Dy" >> $config_target_mak + fi + ;; + esac + enabled_cross_compilers=3D"$enabled_cross_compilers $target_compiler" got_cross_cc=3Dyes break --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576844616; cv=none; d=zohomail.com; s=zohoarc; b=F82FcfnoRVXZwr0FJ1zRJR9DWPynENlYnBpMB4MUIqFZkrDKjxyPL0LW6Bf+6ek2y2S2oEHAct73fbvXOO3I18u25i8u3qBZJ30I7ADzb6etyLeMjVeEh8CRw1MPpV6HkjPdJEeYM8sijfJcw9JckLjMLfBz84Ys/NajyzQxhGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576844616; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KRu49EbgGVQ7V2rxhXNHs855imxrN5MTwZSo9giC7oo=; b=eW5q7DkXScv5+oW2ae+qSvv9yNmBOJ2gg2aX50ahteBqYr/IRYRxjHnDrH5gfbvGXnmImXJUQp9xLTUPUaCB8X8JN1p+bHXWOHXPZ9zAn0n5Izo/o82RYBD28jFKin1+yzkL5kPjbVXSO9hayNJNrvDWh62MqgheBDkpXPVYq4A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576844616557359.3552880848457; Fri, 20 Dec 2019 04:23:36 -0800 (PST) Received: from localhost ([::1]:54376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHJf-00046V-CW for importer@patchew.org; Fri, 20 Dec 2019 07:23:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36283) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHAr-0000dv-VU for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiHAq-0001FF-9b for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:29 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:46382) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiHAp-00019u-Uj for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:28 -0500 Received: by mail-wr1-x443.google.com with SMTP id z7so9163500wrl.13 for ; Fri, 20 Dec 2019 04:14:27 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id f207sm10901781wme.9.2019.12.20.04.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:14:25 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 6CBB11FF9E; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KRu49EbgGVQ7V2rxhXNHs855imxrN5MTwZSo9giC7oo=; b=H7fqNRwdjB5hRPbOqjSzn3+92GkPWo2OL6At9HiFJ849JvF6TXaExMH38Jhn65KSh1 qoPED6b3NLZASeBJKKMcPoWXptmNZglhfPOaQxVR6gLA6Ao5So503ISzRoJZxqKm4PVX X1Qgk/bP5I2fSIFfCxTWiKGLvuYlkan7LYKxQDYCVj+hibAwZ6oThn5C9j5xoh9Wjvl0 3Y60fPxB28nL2F0HMdn1xQgKBOy1ofEXAuapr+thnXdzyMidic8Y125WGysvN1pAD57m PGNArncAjLnLlNYOD2qlV7DZcPbfZHvlNNQGfjXfAqHmBS/35mG2COdGwcLe3XzjFhP9 D1qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KRu49EbgGVQ7V2rxhXNHs855imxrN5MTwZSo9giC7oo=; b=J74Qu25/7jnSjsjQK0SLThR53zaEekvqv1Q6NjXmgMt+3sLVjeM/622eWWQ2ZrZgUv QIvK/17m9qoLLnqeSrugxU24Ot1xPGHSdBy06HuHEgg/GRrhxhEdzADprYP7v+tprFGE O2kpBXubVHVjjEAimpd9JZ/2VJXDebmxzH5zanNDwIMhcJDl4RdMh1SYHPa66juhfwld s19iJzypHqgwRuaz7AL7X0k6xA4cOOgTUDfHLcgXKIeDsHTJAEv6npwHEPtXNxI8KQ4b SgAx5AWUnzMxgPyEkVUD8XJwgs4qiJ53jNSsme2g/tE8bAaLyYxFFZBT6hlosIRt2tJH mbbA== X-Gm-Message-State: APjAAAVlDOGmmH/Mh03qwFpmq7Haj7SHgeVzzOnYkPU0LOV1ZZetbYpZ RmI0DoThcwu2/iDLk0weY6Mwsg== X-Google-Smtp-Source: APXvYqwG1E79S18wR/U2W5oNawtlyC/jVDVN0LjN5nXvRKi5Yb44+oYVxdxib3HrqULreqS1hJ/W0A== X-Received: by 2002:adf:93c5:: with SMTP id 63mr15130458wrp.236.1576844066353; Fri, 20 Dec 2019 04:14:26 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 14/21] target/arm: don't bother with id_aa64pfr0_read for USER_ONLY Date: Fri, 20 Dec 2019 12:04:31 +0000 Message-Id: <20191220120438.16114-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, Richard Henderson , "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) For system emulation we need to check the state of the GIC before we report the value. However this isn't relevant to exporting of the value to linux-user and indeed breaks the exported value as set by modify_arm_cp_regs. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- v2 - extend the ifdef and make type CONST with no accessfn --- target/arm/helper.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 857581feba4..23de21f8820 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -5912,6 +5912,7 @@ static uint64_t id_pfr1_read(CPUARMState *env, const = ARMCPRegInfo *ri) return pfr1; } =20 +#ifndef CONFIG_USER_ONLY static uint64_t id_aa64pfr0_read(CPUARMState *env, const ARMCPRegInfo *ri) { ARMCPU *cpu =3D env_archcpu(env); @@ -5922,6 +5923,7 @@ static uint64_t id_aa64pfr0_read(CPUARMState *env, co= nst ARMCPRegInfo *ri) } return pfr0; } +#endif =20 /* Shared logic between LORID and the rest of the LOR* registers. * Secure state has already been delt with. @@ -6414,16 +6416,24 @@ void register_cp_regs_for_features(ARMCPU *cpu) * define new registers here. */ ARMCPRegInfo v8_idregs[] =3D { - /* ID_AA64PFR0_EL1 is not a plain ARM_CP_CONST because we don't - * know the right value for the GIC field until after we - * define these regs. + /* + * ID_AA64PFR0_EL1 is not a plain ARM_CP_CONST in system + * emulation because we don't know the right value for the + * GIC field until after we define these regs. */ { .name =3D "ID_AA64PFR0_EL1", .state =3D ARM_CP_STATE_AA64, .opc0 =3D 3, .opc1 =3D 0, .crn =3D 0, .crm =3D 4, .opc2 =3D = 0, - .access =3D PL1_R, .type =3D ARM_CP_NO_RAW, + .access =3D PL1_R, +#ifdef CONFIG_USER_ONLY + .type =3D ARM_CP_CONST, + .resetvalue =3D cpu->isar.id_aa64pfr0 +#else + .type =3D ARM_CP_NO_RAW, .accessfn =3D access_aa64_tid3, .readfn =3D id_aa64pfr0_read, - .writefn =3D arm_cp_write_ignore }, + .writefn =3D arm_cp_write_ignore +#endif + }, { .name =3D "ID_AA64PFR1_EL1", .state =3D ARM_CP_STATE_AA64, .opc0 =3D 3, .opc1 =3D 0, .crn =3D 0, .crm =3D 4, .opc2 =3D = 1, .access =3D PL1_R, .type =3D ARM_CP_CONST, --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576844506; cv=none; d=zohomail.com; s=zohoarc; b=gPha8evaYn6wkGZu/luH7X6T4MMHun0jSE/aBED/JFonF9CIWHUVQOPEIvVsYrgW9raAoYIkF6i+1zYNtH//czckWjrmzAeBp0X6UupOsKtMOMoQltu0xCtBb1cJmgfOts076ovjVcWSXiPT4y29s0Q5txF3+KkegaFUTZ3BfjY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576844506; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=w/xx1ZZFQsqOfvn/N8QKFZGLl1ALeRRvJF9s6yRLgdQ=; b=kHt9hzVgfykmZqtmU0cXeEoo7LYvggkNo37xe7nhustQocfuYA8FxK0amGLW4tZE1NoHTyFrcqzChDwYdCUnULaGziEFVDiCFxnvf8Pv57chAz+NGk6Fs0124Auoydcc6w3xD+f93HZcYJwxWk2z48XYRF8C+GPYWIWfP+ItwRU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576844506747742.108516435745; Fri, 20 Dec 2019 04:21:46 -0800 (PST) Received: from localhost ([::1]:54334 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHHt-0001S5-AJ for importer@patchew.org; Fri, 20 Dec 2019 07:21:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54444) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1y-000588-Q8 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1u-000061-Jv for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:16 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:40708) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1s-0008Uc-HB for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:12 -0500 Received: by mail-wr1-x441.google.com with SMTP id c14so9163218wrn.7 for ; Fri, 20 Dec 2019 04:05:12 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id s10sm9492391wrw.12.2019.12.20.04.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:53 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 83A771FF9F; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w/xx1ZZFQsqOfvn/N8QKFZGLl1ALeRRvJF9s6yRLgdQ=; b=xp2dTBBxeYLwe+ePHeCjDEsBDmrLqff8Ct7NLrRv580181LOcouvQFzBCjPWpop+Al zix0jHpEbkh3zsxkGOdeldbrtHA1sjbSiCDcUG1N86lUm1k+gRgh8rXg2WwpgP48sNZB B4aSpnM7jzj0zoNHwAkWK32bJBwsVVk5ngpiSIMtZaZLGY++jRIYqsTXXmSwXsyQZSqX x4aP4psHYfCsSZW3V4+3HBkT3Sgxbff2/27GoOCA/dMUc+OOX8Oxlh8ddTvPGMEY7VHw 0LZCNvKhvLgvom3CARLrzILt3F2OL00jm7SvRj9zlyRNCRuLYfGfQQ07Z6EKwpnEBkba FnnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w/xx1ZZFQsqOfvn/N8QKFZGLl1ALeRRvJF9s6yRLgdQ=; b=f3wcqO/6asi84S5FJbS2zbeSGW2Lj047aziyD1NB1gy5yVMjtDQhVrtG8FE8DmitFy hhYWhG4D+D8oG7GgUSQ2RpCtAHQI7xWM+dQULpcVWDH3salVus66zSuiZGlx7779UlM9 PtRC8wKxOf9h94/d8Fz62GUMDM2uuMw6v+ovRg5BrRhUEAnzIikmGY+wGJ4LcH0Y0RgR 8CCN0yVTckpV+sc33p7aEJ6a0VNTyxL8izhOdlkVVr3LOoddqOAJcLQyzALWqYJU+Ncy EpMMB/dExzLbiyAHePlbtx0UH5QeM/vWBZAV/HRNQD+I84zkmnNMunQkKrmtJb1o0akO +oqw== X-Gm-Message-State: APjAAAXHfou0wMbNOAnBntx/bqbzgxRToee7G5uzEKRMjIxR+RcNOrE2 vbrwaUkJR0lBcjvHhYlpUU+4sQ== X-Google-Smtp-Source: APXvYqxtd7Ue/f70rhfX2Ml/lrQufVqvEdmfQWJATcERzLvKOHakuAbTdsl9pUPCMu6lpxvuw40R9A== X-Received: by 2002:a05:6000:11c5:: with SMTP id i5mr14711263wrx.102.1576843511336; Fri, 20 Dec 2019 04:05:11 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 15/21] tests/tcg/aarch64: userspace system register test Date: Fri, 20 Dec 2019 12:04:32 +0000 Message-Id: <20191220120438.16114-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This tests a bunch of registers that the kernel allows userspace to read including the CPUID registers. We need a SVE aware compiler as we are testing the id_aa64zfr0_el1 register in the set. Signed-off-by: Alex Benn=C3=A9e Message-Id: <20190205190224.2198-7-alex.bennee@linaro.org> --- vgdbstub - don't build unless using docker or CROSS_CC_HAS_SVE --- tests/tcg/aarch64/sysregs.c | 172 ++++++++++++++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 6 ++ 2 files changed, 178 insertions(+) create mode 100644 tests/tcg/aarch64/sysregs.c diff --git a/tests/tcg/aarch64/sysregs.c b/tests/tcg/aarch64/sysregs.c new file mode 100644 index 00000000000..40cf8d2877e --- /dev/null +++ b/tests/tcg/aarch64/sysregs.c @@ -0,0 +1,172 @@ +/* + * Check emulated system register access for linux-user mode. + * + * See: https://www.kernel.org/doc/Documentation/arm64/cpu-feature-registe= rs.txt + * + * Copyright (c) 2019 Linaro + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include +#include +#include +#include + +#ifndef HWCAP_CPUID +#define HWCAP_CPUID (1 << 11) +#endif + +int failed_bit_count; + +/* Read and print system register `id' value */ +#define get_cpu_reg(id) ({ \ + unsigned long __val =3D 0xdeadbeef; \ + asm("mrs %0, "#id : "=3Dr" (__val)); \ + printf("%-20s: 0x%016lx\n", #id, __val); \ + __val; \ + }) + +/* As above but also check no bits outside of `mask' are set*/ +#define get_cpu_reg_check_mask(id, mask) ({ \ + unsigned long __cval =3D get_cpu_reg(id); \ + unsigned long __extra =3D __cval & ~mask; \ + if (__extra) { \ + printf("%-20s: 0x%016lx\n", " !!extra bits!!", __extra); = \ + failed_bit_count++; \ + } \ +}) + +/* As above but check RAZ */ +#define get_cpu_reg_check_zero(id) ({ \ + unsigned long __val =3D 0xdeadbeef; \ + asm("mrs %0, "#id : "=3Dr" (__val)); \ + if (__val) { \ + printf("%-20s: 0x%016lx (not RAZ!)\n", #id, __val); = \ + failed_bit_count++; \ + } \ +}) + +/* Chunk up mask into 63:48, 47:32, 31:16, 15:0 to ease counting */ +#define _m(a, b, c, d) (0x ## a ## b ## c ## d ##ULL) + +bool should_fail; +int should_fail_count; +int should_not_fail_count; +uintptr_t failed_pc[10]; + +void sigill_handler(int signo, siginfo_t *si, void *data) +{ + ucontext_t *uc =3D (ucontext_t *)data; + + if (should_fail) { + should_fail_count++; + } else { + uintptr_t pc =3D (uintptr_t) uc->uc_mcontext.pc; + failed_pc[should_not_fail_count++] =3D pc; + } + uc->uc_mcontext.pc +=3D 4; +} + +int main(void) +{ + struct sigaction sa; + + /* Hook in a SIGILL handler */ + memset(&sa, 0, sizeof(struct sigaction)); + sa.sa_flags =3D SA_SIGINFO; + sa.sa_sigaction =3D &sigill_handler; + sigemptyset(&sa.sa_mask); + + if (sigaction(SIGILL, &sa, 0) !=3D 0) { + perror("sigaction"); + return 1; + } + + /* Counter values have been exposed since Linux 4.12 */ + printf("Checking Counter registers\n"); + + get_cpu_reg(ctr_el0); + get_cpu_reg(cntvct_el0); + get_cpu_reg(cntfrq_el0); + + /* HWCAP_CPUID indicates we can read feature registers, since Linux 4.= 11 */ + if (!(getauxval(AT_HWCAP) & HWCAP_CPUID)) { + printf("CPUID registers unavailable\n"); + return 1; + } else { + printf("Checking CPUID registers\n"); + } + + /* + * Some registers only expose some bits to user-space. Anything + * that is IMPDEF is exported as 0 to user-space. The _mask checks + * assert no extra bits are set. + * + * This check is *not* comprehensive as some fields are set to + * minimum valid fields - for the purposes of this check allowed + * to have non-zero values. + */ + get_cpu_reg_check_mask(id_aa64isar0_el1, _m(00ff,ffff,f0ff,fff0)); + get_cpu_reg_check_mask(id_aa64isar1_el1, _m(0000,00f0,ffff,ffff)); + /* TGran4 & TGran64 as pegged to -1 */ + get_cpu_reg_check_mask(id_aa64mmfr0_el1, _m(0000,0000,ff00,0000)); + get_cpu_reg_check_zero(id_aa64mmfr1_el1); + /* EL1/EL0 reported as AA64 only */ + get_cpu_reg_check_mask(id_aa64pfr0_el1, _m(000f,000f,00ff,0011)); + get_cpu_reg_check_mask(id_aa64pfr1_el1, _m(0000,0000,0000,00f0)); + /* all hidden, DebugVer fixed to 0x6 (ARMv8 debug architecture) */ + get_cpu_reg_check_mask(id_aa64dfr0_el1, _m(0000,0000,0000,0006)); + get_cpu_reg_check_zero(id_aa64dfr1_el1); + get_cpu_reg_check_zero(id_aa64zfr0_el1); + + get_cpu_reg_check_zero(id_aa64afr0_el1); + get_cpu_reg_check_zero(id_aa64afr1_el1); + + get_cpu_reg_check_mask(midr_el1, _m(0000,0000,ffff,ffff)); + /* mpidr sets bit 31, everything else hidden */ + get_cpu_reg_check_mask(mpidr_el1, _m(0000,0000,8000,0000)); + /* REVIDR is all IMPDEF so should be all zeros to user-space */ + get_cpu_reg_check_zero(revidr_el1); + + /* + * There are a block of more registers that are RAZ in the rest of + * the Op0=3D3, Op1=3D0, CRn=3D0, CRm=3D0,4,5,6,7 space. However for + * brevity we don't check stuff that is currently un-allocated + * here. Feel free to add them ;-) + */ + + printf("Remaining registers should fail\n"); + should_fail =3D true; + + /* Unexposed register access causes SIGILL */ + get_cpu_reg(id_mmfr0_el1); + get_cpu_reg(id_mmfr1_el1); + get_cpu_reg(id_mmfr2_el1); + get_cpu_reg(id_mmfr3_el1); + + get_cpu_reg(mvfr0_el1); + get_cpu_reg(mvfr1_el1); + + if (should_not_fail_count > 0) { + int i; + for (i =3D 0; i < should_not_fail_count; i++) { + uintptr_t pc =3D failed_pc[i]; + uint32_t insn =3D *(uint32_t *) pc; + printf("insn %#x @ %#lx unexpected FAIL\n", insn, pc); + } + return 1; + } + + if (failed_bit_count > 0) { + printf("Extra information leaked to user-space!\n"); + return 1; + } + + return should_fail_count =3D=3D 6 ? 0 : 1; +} diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile= .target index 96d2321045a..3f8783ada5c 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -32,4 +32,10 @@ run-plugin-semihosting-with-%: $(call strip-plugin,$<) 2> $<.err, \ "$< on $(TARGET_NAME) with $*") =20 +ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_SVE),) +# System Registers Tests +AARCH64_TESTS +=3D sysregs +sysregs: CFLAGS+=3D-march=3Darmv8.1-a+sve +endif + TESTS +=3D $(AARCH64_TESTS) --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576844944; cv=none; d=zohomail.com; s=zohoarc; b=MXgAVzhZ02R2yBXPK9xtgYV7W2B/ptSDv1JTB0dtSRLZbYHV7Boojl5g62cT9twL0Uc1i6QjBWOOYSMyrznkU2pdXDrVvdaP/5wBxO9CkCWFRMru6B3NBlOc8X1KKtQdaGqBedO4CZx5uP2RqfNRG7YIUN+s5KBAwGgAHaOq/5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576844944; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Fd9ZwTx/nGTAxWisTrByxsrJjTVOwFrJUX5QQ3jkZWE=; b=DG0Ox/xlf6K4hYcrZczN3U/kUbpiHPxCTz1AoLrGjXUqZIuLUvyspbGl27AXr+B+gGvlBf02h8uPL9IWFBq43wrf6LEe3uo0936TkhYM9b57+InKL3LGYf95Yws7j93vYK6OwjPT7DylYWKr3WVopF2KFRit3SORPDbzF8FQ970= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576844944644448.66451246987765; Fri, 20 Dec 2019 04:29:04 -0800 (PST) Received: from localhost ([::1]:54498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHOx-0002bq-CU for importer@patchew.org; Fri, 20 Dec 2019 07:29:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54392) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1v-00055K-Ax for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1r-0008UH-SW for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:14 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:34209) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1q-0008Qy-1x for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:10 -0500 Received: by mail-wr1-x434.google.com with SMTP id t2so9206000wrr.1 for ; Fri, 20 Dec 2019 04:05:09 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id k19sm9331183wmi.42.2019.12.20.04.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:53 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 9850E1FFA3; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Fd9ZwTx/nGTAxWisTrByxsrJjTVOwFrJUX5QQ3jkZWE=; b=PnGgh0R+FuLJoLXgbUOqWoo88UXexq87sfNDL34DCTUZmg70y4egxTu3eHegGz20LV DdBYyM0xfslU5mbvOGCwgn7/Us1mj7ZodKEknlgvGeY9EH5/muHQ9d584zBBYpLozkT+ 03dTcXtXQvytcRaFRgad8ywVZzSoWz4MHdLbYRlvhJ9qJO2ilVc/divVDsG9qWUbc1nU xQdhTadQOHjXsDcdqm1R8YBQwPbGYTBMJoT1Boti1EJXjMDzll5iu0tRys5zm3SVaQhA yx2/zsP4BZzohxRkz/jNon4qKSYrv/nh+zhHQfvnZ9gcEiwaBpDRfC9iQTV5zvqobcDR PwPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Fd9ZwTx/nGTAxWisTrByxsrJjTVOwFrJUX5QQ3jkZWE=; b=CSkdT2/0HkxwhJORyHOf7XxuqtCWf4KtaiKufSVPEqxE2uOd9XNLFAk24PoV/pgoSJ M3FSaWi/ku+5nva7r+1lFT/IBT24o3GA9DP2sbvF+tAAK61r4npFND8DNGVGaE5CSShS mYelVdsXmYC12dEaP78hLZcmsI5/qQdv8FMlDhXonJuCD6PEVByCT3laUpHoJ1bkjVVm A+w/mqIUF91OLUl2GBJp9QKeMOWJcBB769xsBcIyjRstgduVQShKTC4JhaXGg8aDeIuy v6R41apMBUwFmif0V6UT5UUhdtTeTiY1kmhk+rXzzou0W/1WliESB70R+fDzuTu7TZiy 4ffw== X-Gm-Message-State: APjAAAWPQjByVwaMlbgo5F0PthjUsebIGXmHG9D+UPi30s8bg0nnqaft haeuaDIg0G0eVkqrYMhVUmFBnQ== X-Google-Smtp-Source: APXvYqzGi3Nnh+YR3AB4Dukt69vquhS0ioJb7+ZUiMFWOTrJuFgJh1ZCMHRwl7Z2cLRWgO8JdH/M9w== X-Received: by 2002:a5d:548e:: with SMTP id h14mr15983487wrv.380.1576843508480; Fri, 20 Dec 2019 04:05:08 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 16/21] tests/guest-debug: add a simple test runner Date: Fri, 20 Dec 2019 12:04:33 +0000 Message-Id: <20191220120438.16114-17-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::434 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , luis.machado@linaro.org, alan.hayward@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The test runners job is to start QEMU with guest debug enabled and then spawn a gdb process running a test script that exercises the functionality it wants to test. Signed-off-by: Alex Benn=C3=A9e --- tests/guest-debug/run-test.py | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 tests/guest-debug/run-test.py diff --git a/tests/guest-debug/run-test.py b/tests/guest-debug/run-test.py new file mode 100755 index 00000000000..8c49ee2f225 --- /dev/null +++ b/tests/guest-debug/run-test.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +# +# Run a gdbstub test case +# +# Copyright (c) 2019 Linaro +# +# Author: Alex Benn=C3=A9e +# +# 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 subprocess +import shutil +import shlex + +def get_args(): + parser =3D argparse.ArgumentParser(description=3D"A gdbstub test runne= r") + parser.add_argument("--qemu", help=3D"Qemu binary for test", + required=3DTrue) + parser.add_argument("--qargs", help=3D"Qemu arguments for test") + parser.add_argument("--binary", help=3D"Binary to debug", + required=3DTrue) + parser.add_argument("--test", help=3D"GDB test script", + required=3DTrue) + parser.add_argument("--gdb", help=3D"The gdb binary to use", default= =3DNone) + + return parser.parse_args() + +if __name__ =3D=3D '__main__': + args =3D get_args() + + # Search for a gdb we can use + if not args.gdb: + args.gdb =3D shutil.which("gdb-multiarch") + if not args.gdb: + args.gdb =3D shutil.which("gdb") + if not args.gdb: + print("We need gdb to run the test") + exit(-1) + + # Launch QEMU with binary + if "system" in args.qemu: + cmd =3D "%s %s %s -s -S" % (args.qemu, args.qargs, args.binary) + else: + cmd =3D "%s %s -g 1234 %s" % (args.qemu, args.qargs, args.binary) + + inferior =3D subprocess.Popen(shlex.split(cmd)) + + # Now launch gdb with our test and collect the result + gdb_cmd =3D "%s %s -ex 'target remote localhost:1234' -x %s" % (args.g= db, args.binary, args.test) + + result =3D subprocess.call(gdb_cmd, shell=3DTrue); + + exit(result) --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576844285; cv=none; d=zohomail.com; s=zohoarc; b=J4dcpwJZ+fZWFwBgwoGUaiGRTduYJ3RFbEvjP2LEGSwLjNViSRlv3Ic4teWTZZgJ5MjpB6Me56e3L7nqE+2kCZvANSoOS/de2Lql5ZRuwMfs29Kq0mihxCigmTgJfwEom5tPx8NtWcmbTqt9wpJwtS05cZxDSUAyciRkrH91FGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576844285; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0hbLzhNEhCkMRqzYtd3EEZ7EkJxE7ghYQ9NzTVxAhLY=; b=Wiwf9otIh7oAovEpe3OinXkeOkh6JLI5KgFMcMkBjU0mgp2k5NGTYD5NHanMYChJrKwk5sBhFAfcMWMHJV+kvukj2KShhI3VAYdYNid1aPw6fZWRaGEaberNie8aO2ZycqiJMU3cx88qybLlw3zSQFHRn1XqSyVNDI9MAC+rOag= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576844285084768.832281280218; Fri, 20 Dec 2019 04:18:05 -0800 (PST) Received: from localhost ([::1]:54234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHEI-0004Va-R6 for importer@patchew.org; Fri, 20 Dec 2019 07:18:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54274) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1s-00051x-JR for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1o-0008Px-Iw for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:11 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:41086) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1o-0008Mv-0o for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:08 -0500 Received: by mail-wr1-x431.google.com with SMTP id c9so9181934wrw.8 for ; Fri, 20 Dec 2019 04:05:07 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id s128sm9713941wme.39.2019.12.20.04.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:53 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id AF5D61FFA5; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0hbLzhNEhCkMRqzYtd3EEZ7EkJxE7ghYQ9NzTVxAhLY=; b=A4H6UdB2S/92fnWU47nEN9m9Bh7bPxF+RJJFgzvQ4fOYUptOB8ZpYYtR+DmKDQm47l iCMacMxkIhA3qGQiS0J154sHigRiXYwQSI3IgjloX8DCq0ZxnL6Dquh6j2t+t7/vSlkC siLoqhVr1KUINloRsgyCwzzhkVq9ldeHXO/J86PFms6wsBcQ9Zj38QUTCkGgR3u64S4i vN7c+AG6ET+xD6ChpMJB2xhJQxHEs8A7xEfin/iNCt1ulKetW1KwoWAJWhwht9z++vAh wxReIq7I7KnF24EvL/S8/46wHa+pff5kumdlN1Y4b1yG8pTl4H8lEkZMfDqjzsz4bkAR hcZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0hbLzhNEhCkMRqzYtd3EEZ7EkJxE7ghYQ9NzTVxAhLY=; b=GxC8bHC++ShKF+KerpLBQcRQvmNkkrS7AIRaorNpqXB+e8kxE8DQZk7FWerE/k/LqP 3jGTgxefdUi/LjAMlmF4JzdDeGgLvQPlsyMP+wwGh/lhtVqXrfsXjNamibpe5dMquViq d8t9o/D6v94kCAkOqghqzqT2C1Vo9G2qGkbcvElMVu9LYaaq90jyNOcbuYXXupoM3b16 WV/HUAIKtJwV3Bdf4YVCxSPyuIpoxsoEFYJQTH4NvTk1gdzVFS8fxE6Slm9h/bQIevLY dDiwme/Njknbu/HQsbv5Vx9EeHV7qVRbTY8QpL2SaCt7ZpOt8CQY4B+pBj+RIee2K7cR og5g== X-Gm-Message-State: APjAAAWug4kwx70D1ZD5ltvEuH0a7JDyKJ8DmYUC8gcX57cx8s8n6LwG qZCoAd1s3lCto2gbZJRks1y2Cg== X-Google-Smtp-Source: APXvYqxGJ1T4j1mvQjmf99AqecCv0QI1ym7PpPewJNJazc81ar+W1Ju9bk3vCVDz9g2E7iU1Zb37QQ== X-Received: by 2002:a5d:4651:: with SMTP id j17mr15576168wrs.237.1576843505701; Fri, 20 Dec 2019 04:05:05 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 17/21] tests/tcg/aarch64: add a gdbstub testcase for SVE registers Date: Fri, 20 Dec 2019 12:04:34 +0000 Message-Id: <20191220120438.16114-18-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::431 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We don't plumb this in yet as there are complications involved with binutils and cross-architectiure debugging but it is one step closer. Example: ./tests/guest-debug/run-test.py \ --qemu ./aarch64-linux-user/qemu-aarch64 \ --qargs "-cpu max" \ --bin ./tests/tcg/aarch64-linux-user/hello \ --test ~/lsrc/qemu.git/tests/tcg/aarch64/gdbstub/test-sve.py \ --gdb /home/alex/src/tools/binutils-gdb.git/install/bin/gdb Signed-off-by: Alex Benn=C3=A9e --- tests/.gitignore | 1 + tests/tcg/aarch64/gdbstub/test-sve.py | 75 +++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 tests/tcg/aarch64/gdbstub/test-sve.py diff --git a/tests/.gitignore b/tests/.gitignore index f9c01708812..8cc428b58bb 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -10,6 +10,7 @@ qht-bench rcutorture test-* !test-*.c +!test-*.py !docker/test-* test-qapi-commands.[ch] include/test-qapi-commands-sub-module.[ch] diff --git a/tests/tcg/aarch64/gdbstub/test-sve.py b/tests/tcg/aarch64/gdbs= tub/test-sve.py new file mode 100644 index 00000000000..11bc96fc06d --- /dev/null +++ b/tests/tcg/aarch64/gdbstub/test-sve.py @@ -0,0 +1,75 @@ +from __future__ import print_function +# +# Test the SVE registers are visable and changeable via gdbstub +# +# This is launched via tests/guest-debug/run-test.py +# + +import gdb + +MAGIC =3D 0xDEADBEEF + +failcount =3D 0 + +def report(cond, msg): + "Report success/fail of test" + if cond: + print ("PASS: %s" % (msg)) + else: + print ("FAIL: %s" % (msg)) + global failcount + failcount +=3D 1 + +def run_test(): + "Run through the tests one by one" + + gdb.execute("info registers") + report(True, "info registers") + + gdb.execute("info registers vector") + report(True, "info registers vector") + + # Now all the zregs + frame =3D gdb.selected_frame() + for i in range(0, 32): + rname =3D "z%d" % (i) + zreg =3D frame.read_register(rname) + report(True, "Reading %s" % rname) + for j in range(0, 4): + cmd =3D "set $%s.q.u[%d] =3D 0x%x" % (rname, j, MAGIC) + gdb.execute(cmd) + report(True, "%s" % cmd) + for j in range(0, 4): + reg =3D "$%s.q.u[%d]" % (rname, j) + v =3D gdb.parse_and_eval(reg) + report(str(v.type) =3D=3D "uint128_t", "size of %s" % (reg)) + for j in range(0, 8): + cmd =3D "set $%s.d.u[%d] =3D 0x%x" % (rname, j, MAGIC) + gdb.execute(cmd) + report(True, "%s" % cmd) + for j in range(0, 8): + reg =3D "$%s.d.u[%d]" % (rname, j) + v =3D gdb.parse_and_eval(reg) + report(str(v.type) =3D=3D "uint64_t", "size of %s" % (reg)) + report(int(v) =3D=3D MAGIC, "%s is 0x%x" % (reg, MAGIC)) + +# +# This runs as the script it sourced (via -x, via run-test.py) +# + +try: + # These are not very useful in scripts + gdb.execute("set pagination off") + gdb.execute("set confirm off") + + # Run the actual tests + run_test() +except: + print ("GDB Exception: %s" % (sys.exc_info()[0])) + failcount +=3D 1 + +print("All tests complete: %d failures" % failcount) + +# Finally kill the inferior and exit gdb with a count of failures +gdb.execute("kill") +exit(failcount) --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576845014; cv=none; d=zohomail.com; s=zohoarc; b=Z4RG7L83jGTCCPV5e6vnGbg6VEEki5/1qy58QHlxjD9UH1IvDvUHxUz+RNJS4bt8L/7ewUXQ/0e7vZgqn7ekff+lxJQXj6+C5oBNLM20cqhSDJkKPkaZ6a9/LO73cEldeyvGTqCYTDbM9BKsBEWA0BDkl00gYpd/OMHtX9yieHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576845014; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YCeE2L0TGRZ8+dNyp7Q4Gn+JUeo73/cxEQroPrtcLoY=; b=Rl6bkhnnAWtgdm2QwF1MSdFHyFwZc27JPjk6idqfBSkOcHzlftVhmb4fG2DwJv1EmGpYlsAETfsJ1QkcLVgbmTk3wrUi05BIqI/IIn/SU/57pexXVlF6tDODqmw07K7SKs2F9CyGqHd56uwFc/evpWP+OiOmNdAIH4DihzvOIaM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576845014553233.8487976918923; Fri, 20 Dec 2019 04:30:14 -0800 (PST) Received: from localhost ([::1]:54516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHQ5-0003aL-BU for importer@patchew.org; Fri, 20 Dec 2019 07:30:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54579) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH20-0005Ay-Ow for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1y-00008E-Mj for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:20 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:40902) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1u-00005D-HB for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:15 -0500 Received: by mail-wm1-x342.google.com with SMTP id t14so8962161wmi.5 for ; Fri, 20 Dec 2019 04:05:13 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id w19sm9049230wmc.22.2019.12.20.04.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:53 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C87411FFA6; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YCeE2L0TGRZ8+dNyp7Q4Gn+JUeo73/cxEQroPrtcLoY=; b=yI7t60CnVL6775T9HfpwZA3JM2Ww2nGwXk9wQf/Ypb7fNkwzX+m52h10d9jRRnXBya XtYqIFdAykWjmTzycIW/c/RiDs5I4DmrZ+PyF52wbASybJ9vnOMHRQjQLs0RZj2OgVcN qt0l/i6uUw+OrzikFCRkpFwXCvpdCPUvZKp8yAVYHhqSDU/Eqvtq4XLShjbUA0UspFz8 tCtsTKwC+StyPh9tBAWbPD7rTJF+r/vNl1aVVPk0cmyxytcHXPszDPLxEPsndED/mBgZ /ppdIn0RI2sipaptiB+REpow0ZZLIoHo8mhSLJyH3J34FFC2Zl/qt4Nfpp3dCgzI/eZC WsJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YCeE2L0TGRZ8+dNyp7Q4Gn+JUeo73/cxEQroPrtcLoY=; b=mSJpVtJ08RxJauewysP51eNxXYbiCVvuE4lDzfQHt/z1YYtvhm0bVBqif7oUV+n6L9 BreXSXSncnSTjY8JqKpBMwTGw5yIWz9+iBon2vQPiWQs0P72VjWoPt5nj3/NLRozBdtl wNOhog/ya2KtECAzm0weJA2JCL88A5jkdaynEH/c7u8SSxxt+5xyuUEEF7HD/QkPFgXe oSnViPc7gZM+uTLno3Eam0MlB9NfBkb1lZaNUSjWVYvOhM4JSEu/iF8HpOByJ0pR2eUY qbDAFtlb54gkcV/5f9yrRFnBT/j3Rv00xF07oNz5xoc2hDj3Qt0oRdYELyfiRMC4eAH1 ZiQA== X-Gm-Message-State: APjAAAUxCVUX8oBwCcpwXwMu60hclHIszkV1MNhgWsWD59eBbiRHayV5 OdzwAekTs9fQuS16J+9tCXV1sg== X-Google-Smtp-Source: APXvYqwdD1HGd1CIxdZAvFuFWZjH7igpkAqbrE7iiRgqBzBqeDjYFHjWlGJR/EbuFzkSROczZqyQDQ== X-Received: by 2002:a7b:c183:: with SMTP id y3mr16211076wmi.0.1576843512480; Fri, 20 Dec 2019 04:05:12 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 18/21] tests/tcg/aarch64: add SVE iotcl test Date: Fri, 20 Dec 2019 12:04:35 +0000 Message-Id: <20191220120438.16114-19-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This is a fairly bare-bones test of setting the various vector sizes for SVE which will only fail if the PR_SVE_SET_VL can't reduce the user-space vector length by powers of 2. However we will also be able to use it in a future test which exercises the GDB stub. Signed-off-by: Alex Benn=C3=A9e --- v3 - use index to fill zreg - CROSS_CC_HAS_SVE --- tests/tcg/aarch64/sve-ioctls.c | 77 +++++++++++++++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 4 ++ 2 files changed, 81 insertions(+) create mode 100644 tests/tcg/aarch64/sve-ioctls.c diff --git a/tests/tcg/aarch64/sve-ioctls.c b/tests/tcg/aarch64/sve-ioctls.c new file mode 100644 index 00000000000..d7bb64d53f9 --- /dev/null +++ b/tests/tcg/aarch64/sve-ioctls.c @@ -0,0 +1,77 @@ +/* + * SVE ioctls tests + * + * Test the SVE width setting ioctls work and provide a base for + * testing the gdbstub. + * + * Copyright (c) 2019 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include +#include +#include +#include +#include +#include + +#ifndef HWCAP_CPUID +#define HWCAP_CPUID (1 << 11) +#endif + +#define SVE_MAX_QUADS (2048 / 128) +#define BYTES_PER_QUAD (128 / 8) + +#define get_cpu_reg(id) ({ \ + unsigned long __val; \ + asm("mrs %0, "#id : "=3Dr" (__val)); \ + __val; \ + }) + +static int do_sve_ioctl_test(void) +{ + int i, res, init_vq; + + res =3D prctl(PR_SVE_GET_VL, 0, 0, 0, 0); + if (res < 0) { + printf("FAILED to PR_SVE_GET_VL (%d)", res); + return -1; + } + init_vq =3D res & PR_SVE_VL_LEN_MASK; + + for (i =3D init_vq; i > 15; i /=3D 2) { + printf("Checking PR_SVE_SET_VL=3D%d\n", i); + res =3D prctl(PR_SVE_SET_VL, i, 0, 0, 0, 0); + if (res < 0) { + printf("FAILED to PR_SVE_SET_VL (%d)", res); + return -1; + } + asm("index z0.b, #0, #1\n" + ".global __sve_ld_done\n" + "__sve_ld_done:\n" + "mov z0.b, #0\n" + : /* no outputs kept */ + : /* no inputs */ + : "memory", "z0"); + } + printf("PASS\n"); + return 0; +} + +int main(int argc, char **argv) +{ + unsigned int sve_feature =3D (get_cpu_reg(ID_AA64PFR0_EL1) >> 32) & 0x= f; + /* Exit early if we don't support SVE at all */ + if (sve_feature =3D=3D 0x1) { + /* we also need to probe for the ioctl support */ + if (getauxval(AT_HWCAP) & HWCAP_SVE) { + return do_sve_ioctl_test(); + } else { + printf("SKIP: no HWCAP_SVE on this system\n"); + return 0; + } + } else { + printf("SKIP: no SVE on this system\n"); + return 0; + } +} diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile= .target index 3f8783ada5c..209c79a1ddb 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -36,6 +36,10 @@ ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_SVE),) # System Registers Tests AARCH64_TESTS +=3D sysregs sysregs: CFLAGS+=3D-march=3Darmv8.1-a+sve + +# SVE ioctl test +AARCH64_TESTS +=3D sve-ioctls +sve-ioctls: CFLAGS+=3D-march=3Darmv8.1-a+sve endif =20 TESTS +=3D $(AARCH64_TESTS) --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576845308; cv=none; d=zohomail.com; s=zohoarc; b=lQ8CtBYvoDLLYC69h5RwNONhQVb09ykd9JaGgrc+A5GOU6HPE3rGn3n5pCiDFpoQk6XHs7BD5+VW7S6Jjw4zXN+n4vW+p8eJsyfOIaFAfGtemV0CfpZZD4IpXwc6KT46aWmvz3o85VCTrGu1dGYC+y949hTbPPE9skc9KRh1v6g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576845308; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=r6DZWz56Ou8zN9swvxhZLHdPuxthEvVWZNmtroVIhWQ=; b=nGFgBPukLmNJIwOva1umHvKHhULWsnxCeoXpNYxZQVUHCSPE/JCH3ZtegVIRq4jhYjLTEB/tpe05uxq64R9bH+wqA2fqynTl4/PfWevp8/SX8llTgiKKzwog4iaEgUk8NiLAx8WptlEh3AmCzbuV9ORwC/PQExK8WaCdR6IMZVc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576845308447696.1263388342122; Fri, 20 Dec 2019 04:35:08 -0800 (PST) Received: from localhost ([::1]:54596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHUp-0000fn-4D for importer@patchew.org; Fri, 20 Dec 2019 07:35:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36486) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHAt-0000g6-8z for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiHAr-0001LX-Pt for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:31 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:36580) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiHAr-0001Gz-Dq for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:29 -0500 Received: by mail-wm1-x341.google.com with SMTP id p17so9020885wma.1 for ; Fri, 20 Dec 2019 04:14:29 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id x10sm10077775wrp.58.2019.12.20.04.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:14:25 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id DE3101FFA9; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r6DZWz56Ou8zN9swvxhZLHdPuxthEvVWZNmtroVIhWQ=; b=Lp3dcu100TH5P0m6J/X71PizRAWRciZTSkHXfRhcpa3fQm7p8bAwdiBzCj32BLhj9N f8aj7+iV7C15MrAlH+gQxtnaOjMIDeHZxPlJyaWzYDjUgNUWfZgL+Gr0BFrwUEkAID9p G5ogaOSgyt07L9nCHNGrB3vsOM2aCB/r7AghorMR8EGvWgCRmSAVek4kjvMRTDozO+7x pbuw6bi6CqXKKTd8cnvXie6IJrSVducWBQYDYb5cbnKIOgy6a0V7G66+q+BA9A0/ERTd PNUQXqX1zC0vUhVaNZKzpLCSNgiJD8V4uGhwLyBhaRDKH0FkEE/sILFKY3Ebowk3LZK+ kREA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r6DZWz56Ou8zN9swvxhZLHdPuxthEvVWZNmtroVIhWQ=; b=LKT2V9tC2cDwgY/HlUuOjdk/hCPHVApVTplAiyhG17lsZzAjovzwIqVT8WEeIGg4ir bWnFsmP2gvkOS5cPUAKRokIRx5DjrZ0W6+BwPB6GI7djv9V/NmCRPdksQuLRNyzp5WFS b6F5C5H+hsJNc6ThSjDmUiw1MDnbUSXUPzH+fKfIl/dgrGL1ykdwaLB3pnF5v3IFNhPK Sr7jeHOXDbSCXqDdZ7WMjZ4IB5mEmwOLiFP9vvKeKD5KvB3P67Zxnbt/FWhgOTrvx6wx f9SmlR+/7Po+NQ6CA01v5N5MxuhoaqZpr4IO+iPdm1Nha4CgUEiP/J6aoPOTB+iUDTjP X3LA== X-Gm-Message-State: APjAAAX/Tjmo7hzv1KZV+RerBVXHyVJRXx70BD1R7YMOp0qSopBfzHip Y3Sa8VdJKbRAN+0nYb/xWnYCmP/fcLA= X-Google-Smtp-Source: APXvYqwxmUzS7OCpzZMAX+qzXircRfq6uZ7XzmIFS6VRxGjrIqh2YD1g8XNpZNxRsJLKklLyYcZfew== X-Received: by 2002:a1c:a795:: with SMTP id q143mr15308301wme.52.1576844068237; Fri, 20 Dec 2019 04:14:28 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 19/21] tests/tcg/aarch64: add test-sve-ioctl guest-debug test Date: Fri, 20 Dec 2019 12:04:36 +0000 Message-Id: <20191220120438.16114-20-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This test exercises the gdbstub while runing the sve-iotcl test. I haven't plubmed it into make system as we need a way of verifying if gdb has the right support for SVE. Signed-off-by: Alex Benn=C3=A9e --- v4 - interrogate ZCR_EL1 directly as no longer have vg --- tests/tcg/aarch64/gdbstub/test-sve-ioctl.py | 71 +++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/tcg/aarch64/gdbstub/test-sve-ioctl.py diff --git a/tests/tcg/aarch64/gdbstub/test-sve-ioctl.py b/tests/tcg/aarch6= 4/gdbstub/test-sve-ioctl.py new file mode 100644 index 00000000000..6b6b6c83f2d --- /dev/null +++ b/tests/tcg/aarch64/gdbstub/test-sve-ioctl.py @@ -0,0 +1,71 @@ +from __future__ import print_function +# +# Test the SVE ZReg reports the right amount of data. It uses the +# sve-ioctl test and examines the register data each time the +# __sve_ld_done breakpoint is hit. +# +# This is launched via tests/guest-debug/run-test.py +# + +import gdb + +initial_vlen =3D 0 +failcount =3D 0 + +def report(cond, msg): + "Report success/fail of test" + if cond: + print ("PASS: %s" % (msg)) + else: + print ("FAIL: %s" % (msg)) + global failcount + failcount +=3D 1 + +class TestBreakpoint(gdb.Breakpoint): + def __init__(self, sym_name=3D"__sve_ld_done"): + super(TestBreakpoint, self).__init__(sym_name) + # self.sym, ok =3D gdb.lookup_symbol(sym_name) + + def stop(self): + val_i =3D gdb.parse_and_eval('i') + global initial_vlen + for i in range(0, int(val_i)): + val_z =3D gdb.parse_and_eval("$z0.b.u[%d]" % i) + report(int(val_z) =3D=3D i, "z0.b.u[%d] =3D=3D %d" % (i, i)) + for i in range(i + 1, initial_vlen): + val_z =3D gdb.parse_and_eval("$z0.b.u[%d]" % i) + report(int(val_z) =3D=3D 0, "z0.b.u[%d] =3D=3D 0" % (i)) + + +def run_test(): + "Run through the tests one by one" + + print ("Setup breakpoint") + bp =3D TestBreakpoint() + + global initial_vlen + vg =3D gdb.parse_and_eval("$ZCR_EL1") + initial_vlen =3D int(vg) * 16 + + gdb.execute("c") + +# +# This runs as the script it sourced (via -x, via run-test.py) +# + +try: + # These are not very useful in scripts + gdb.execute("set pagination off") + gdb.execute("set confirm off") + + # Run the actual tests + run_test() +except: + print ("GDB Exception: %s" % (sys.exc_info()[0])) + failcount +=3D 1 + import code + code.InteractiveConsole(locals=3Dglobals()).interact() + raise + +print("All tests complete: %d failures" % failcount) +exit(failcount) --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576845385; cv=none; d=zohomail.com; s=zohoarc; b=Xg/t5uz2O8xx5/a4rSAlhelrJQ+7j8ApmdPLydjBPrUWwQOPiurrvN3cn12OmmRahgWhrnCNIHN4E6Ws3z4tqtqh00Ec1/DA40voiCTNnio3xIsqqAaE/nu2ljFrisxo+SiRAn1Xdbpy35XzgokgMIDELlx+xV6A8tMvQoE3FmU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576845385; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oMQw6t6tRzlw6HQPCH1hJECHMvald9wcRxGqG3qpIY0=; b=Eymr+XIPdvEKHPW4EpohTGs3oAzqmxiocJZdv/jZhZxIbfTGHjF2K2Euf4BW2m999c6CcgYzjeptN42M8toKT7kNQFDHUp969zeZ12ZqSHXy3h+V4w+YFaCQ6ZKx/OxvZm/kIJhjOBchMPSDzdP6iREo9aa5eiMGkISKz+iqgtk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576845385413580.516656679733; Fri, 20 Dec 2019 04:36:25 -0800 (PST) Received: from localhost ([::1]:54636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHW4-0002fr-CW for importer@patchew.org; Fri, 20 Dec 2019 07:36:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36706) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHAu-0000jj-RM for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiHAt-0001Q9-39 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:32 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:34042) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiHAs-0001M9-Oa for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:30 -0500 Received: by mail-wm1-x343.google.com with SMTP id c127so1632092wme.1 for ; Fri, 20 Dec 2019 04:14:30 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id s10sm9517124wrw.12.2019.12.20.04.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:14:25 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 00A021FFAA; Fri, 20 Dec 2019 12:04:41 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oMQw6t6tRzlw6HQPCH1hJECHMvald9wcRxGqG3qpIY0=; b=qA2Nbbnkf7t7LSKkmijtFigfij9EhBRtlf6+zLdSkH420XupqFUbMgVl9WcotKQEir fQYZXiwOwqXHl89D5VpT2YUiZK23e1DYjanfr7ZN4N2+JIOLltDI2tEx+Hel7HmfOakt ngHiiPj1zFQx5T8UFC9WvVXxphsrCHps0FzUznXpSsTf2DUPXut5jBeQQoZMB4i9ELGh rDLF6ELs8bZObKdDbNrU21jjHbV0Bkwjm2Vn36a1zANq2zbvk2xcbraG4XxL5GHhGZyQ Hv1ZiF3c2ReAx3O/Gbi9duUuFjpeaEFKa+ccTVpAPzWlM14mh7zUFzU3ak5iQEW7icOI kNtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oMQw6t6tRzlw6HQPCH1hJECHMvald9wcRxGqG3qpIY0=; b=hXMRQuLQ3FOCB5cdbII9D2bV4o41R+MUwV/L7ZRWLapFUbNrrUkQpZHAsvYv5g+vcy 8buCAuNLLbx4Z6Ql/JlHKYJzcChiqOWMz+s2bZJYZh4ScnEDb7xSkMV4wNoet55GDnDZ oKgvgu/QiotzTqSsgoFuXKG7M+iOfdELz3nHjYgQJLukv8kmwM4Od4w3iwqal7b8Cgtn emk6DeQdePYYYnTcgtqJi8Uadgx2CsOt2KwhIKPMWPWgcyybWnezNgnd6NYUGC4M/QVG pJrFa+aZqCV5BPGA/XdNPz3Yv8O7f8lyEiNDHdi7ppop4Cu2s65Mqrsbaj3T2n8LQYHF b8Vw== X-Gm-Message-State: APjAAAW7tfzy1CtDDcVN1XRtbAvruNf8xvAlsE3uY3DrxDAC/4od7Bo7 I7ZLqQW9nVmfWhWsR7B4z/opaA== X-Google-Smtp-Source: APXvYqz2KFWAVDMx6rIGJxR4Rpz3GK8a75aRWcEmmGM3w2lvzgLhn+N1hOmT4VT+K0VgSWJYqvZr7A== X-Received: by 2002:a7b:cd0a:: with SMTP id f10mr16703426wmj.56.1576844069376; Fri, 20 Dec 2019 04:14:29 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 20/21] gdbstub: change GDBState.last_packet to GByteArray Date: Fri, 20 Dec 2019 12:04:37 +0000 Message-Id: <20191220120438.16114-21-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , luis.machado@linaro.org, alan.hayward@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Damien Hedde Remove the packet size upper limit by using a GByteArray instead of a statically allocated array for last_packet. Thus we can now send big packets. Also remove the last_packet_len field and use last_packet->len instead. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20191211160514.58373-2-damien.hedde@greensocs.com> Signed-off-by: Alex Benn=C3=A9e --- gdbstub.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 287d0535b12..49e760283db 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -351,8 +351,7 @@ typedef struct GDBState { int line_buf_index; int line_sum; /* running checksum */ int line_csum; /* checksum at the end of the packet */ - uint8_t last_packet[MAX_PACKET_LENGTH + 4]; - int last_packet_len; + GByteArray *last_packet; int signal; #ifdef CONFIG_USER_ONLY int fd; @@ -384,6 +383,7 @@ static void init_gdbserver_state(void) gdbserver_state.init =3D true; gdbserver_state.str_buf =3D g_string_new(NULL); gdbserver_state.mem_buf =3D g_byte_array_sized_new(MAX_PACKET_LENGTH); + gdbserver_state.last_packet =3D g_byte_array_sized_new(MAX_PACKET_LENG= TH + 4); } =20 #ifndef CONFIG_USER_ONLY @@ -626,28 +626,29 @@ static void hexdump(const char *buf, int len, static int put_packet_binary(const char *buf, int len, bool dump) { int csum, i; - uint8_t *p; - uint8_t *ps =3D &gdbserver_state.last_packet[0]; + uint8_t footer[3]; =20 if (dump && trace_event_get_state_backends(TRACE_GDBSTUB_IO_BINARYREPL= Y)) { hexdump(buf, len, trace_gdbstub_io_binaryreply); } =20 for(;;) { - p =3D ps; - *(p++) =3D '$'; - memcpy(p, buf, len); - p +=3D len; + g_byte_array_set_size(gdbserver_state.last_packet, 0); + g_byte_array_append(gdbserver_state.last_packet, + (const uint8_t *) "$", 1); + g_byte_array_append(gdbserver_state.last_packet, + (const uint8_t *) buf, len); csum =3D 0; for(i =3D 0; i < len; i++) { csum +=3D buf[i]; } - *(p++) =3D '#'; - *(p++) =3D tohex((csum >> 4) & 0xf); - *(p++) =3D tohex((csum) & 0xf); + footer[0] =3D '#'; + footer[1] =3D tohex((csum >> 4) & 0xf); + footer[2] =3D tohex((csum) & 0xf); + g_byte_array_append(gdbserver_state.last_packet, footer, 3); =20 - gdbserver_state.last_packet_len =3D p - ps; - put_buffer(ps, gdbserver_state.last_packet_len); + put_buffer(gdbserver_state.last_packet->data, + gdbserver_state.last_packet->len); =20 #ifdef CONFIG_USER_ONLY i =3D get_char(); @@ -2812,20 +2813,22 @@ static void gdb_read_byte(uint8_t ch) uint8_t reply; =20 #ifndef CONFIG_USER_ONLY - if (gdbserver_state.last_packet_len) { + if (gdbserver_state.last_packet->len) { /* Waiting for a response to the last packet. If we see the start of a new command then abandon the previous response. */ if (ch =3D=3D '-') { trace_gdbstub_err_got_nack(); - put_buffer((uint8_t *)gdbserver_state.last_packet, gdbserver_s= tate.last_packet_len); + put_buffer(gdbserver_state.last_packet->data, + gdbserver_state.last_packet->len); } else if (ch =3D=3D '+') { trace_gdbstub_io_got_ack(); } else { trace_gdbstub_io_got_unexpected(ch); } =20 - if (ch =3D=3D '+' || ch =3D=3D '$') - gdbserver_state.last_packet_len =3D 0; + if (ch =3D=3D '+' || ch =3D=3D '$') { + g_byte_array_set_size(gdbserver_state.last_packet, 0); + } if (ch !=3D '$') return; } @@ -3209,7 +3212,7 @@ static int gdb_monitor_write(Chardev *chr, const uint= 8_t *buf, int len) const char *p =3D (const char *)buf; int max_sz; =20 - max_sz =3D (sizeof(gdbserver_state.last_packet) - 2) / 2; + max_sz =3D (MAX_PACKET_LENGTH / 2) + 1; for (;;) { if (len <=3D max_sz) { gdb_monitor_output(p, len); --=20 2.20.1 From nobody Fri May 3 06:14:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576844797; cv=none; d=zohomail.com; s=zohoarc; b=Kx3cAbbu4BQHA89aqjDpXv5aBP05ThhUjfusLVkd4UH5OAjaOi5DdWc4Jpr7peWVgkJoX1EaW/jIrZ5+1yXdYGF/EimT+DXiDYcNnC3z268Ju+VtPDefuLRGeYnDioJwYrwJlwQ31EtoiXSstXoBeC0azWABqMud8Zg5jNtxiGE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576844797; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZYdZReL1NF4ccjo0j5hGGmu8VTV/596/vKb83rC+xjU=; b=fKqebXwO+//MqCMkwQZB/x57ORl8zOeuDFCeER/YQN26cZSinY0Uq05X/Nmep5XGeFIu2OU+SdPc3HV/SnzD2ehUKbYPgjQ3ENTTrzq3feHDLozBoBnq8+yHB9LM98wTMB8YjPOhWvFSzV8EHd34QkXBaaX/fWt+0jgThMBPmWI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576844796991928.9251421253452; Fri, 20 Dec 2019 04:26:36 -0800 (PST) Received: from localhost ([::1]:54457 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHMZ-0008Ma-H7 for importer@patchew.org; Fri, 20 Dec 2019 07:26:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36784) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHAv-0000ku-A2 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiHAu-0001U2-2w for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:33 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:39508) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiHAt-0001Q3-Od for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:31 -0500 Received: by mail-wr1-x443.google.com with SMTP id y11so9213129wrt.6 for ; Fri, 20 Dec 2019 04:14:31 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id q3sm9131236wmc.47.2019.12.20.04.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:14:25 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 155C61FFAB; Fri, 20 Dec 2019 12:04:41 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZYdZReL1NF4ccjo0j5hGGmu8VTV/596/vKb83rC+xjU=; b=uKxqL+Hzw4iaAyf2GQL3ih302+LPHD0BDKm0lOAWQE8yHtx4s7INbPSymA8JDx6sRY ET2+uPQ6b5llAglhMnBxJaLv7hWLR2jU4SpfIDU14BPPiP5jYv4UQIxPCR8hd2Cq0wLG cpPufAmiWJQdGs3zH2oF1wf6WRA7vxrqaVxWBYuw5nkSOt9D5Z4GGU+usgVNd2J1mJsu KnGg5matGM04D9YEJgjz7Hyovm1U+y/F8HEW+GVFK/7RMCEheIEx9zTMfhN8eyV5pQC2 yamKp9+uPDrrpklg1VMtp1QFxTYlZJwOMWzKqlX5NgUH1SoX/Pix4cixn/IzZ+bmy/y0 7c1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZYdZReL1NF4ccjo0j5hGGmu8VTV/596/vKb83rC+xjU=; b=pk6HkyTAdFnd+f5ddhMv+XFdqzGkQYXG/BUWfXHg99n+NW4qYll78CYDqnC3Rq3+Cf w0EsWMQp6btcGMaTJeQ3L7N/0XmHi/r9Lp2bfJF9hqtU6i235ssnuLaecS5u0VLGV5GO YxuvspyTmN2V4pVhoR776o9/nAXjS2q0hpIc0+M9YpaFBdFhGUO2KvloZGB1nS6ce4mB +U52WhENvLLG8AOOwVesaJ8n8aT011I2Zm3iPyZDE+SyI+oh/LsZwYJadc3D/BXl5Rcw 7lrmjHsfAAUwHMyxxsX5+O9Xwhm3mQrxwy3fHYXre66MWwXfpWTNDyTp7jUbO7JFQN/s +Npw== X-Gm-Message-State: APjAAAVb73Ze5jpYnxfw0QA6ywIjVAkQrBx0ljhEdyzYxsQMUxpgyIKk xaukQ6pyY06KUMX0LDviwgs40w== X-Google-Smtp-Source: APXvYqyv3bGy7i/LMFHBtU8VHkAV+bq4MRobYOWWRDHBRb17vm0dQtpObxpm5TwrCv/+7rCGh7PsmQ== X-Received: by 2002:adf:f2c1:: with SMTP id d1mr14599626wrp.111.1576844070397; Fri, 20 Dec 2019 04:14:30 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 21/21] gdbstub: do not split gdb_monitor_write payload Date: Fri, 20 Dec 2019 12:04:38 +0000 Message-Id: <20191220120438.16114-22-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, luis.machado@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , alan.hayward@arm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Luc Michel Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Damien Hedde Since we can now send packets of arbitrary length: simplify gdb_monitor_write() and send the whole payload in one packet. Suggested-by: Luc Michel Signed-off-by: Damien Hedde Signed-off-by: Alex Benn=C3=A9e Message-Id: <20191211160514.58373-3-damien.hedde@greensocs.com> --- gdbstub.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 49e760283db..5d0cdb81e4f 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -3200,28 +3200,11 @@ static void gdb_chr_event(void *opaque, int event) } } =20 -static void gdb_monitor_output(const char *msg, int len) -{ - g_autoptr(GString) buf =3D g_string_new("O"); - memtohex(buf, (uint8_t *)msg, len); - put_packet(buf->str); -} - static int gdb_monitor_write(Chardev *chr, const uint8_t *buf, int len) { - const char *p =3D (const char *)buf; - int max_sz; - - max_sz =3D (MAX_PACKET_LENGTH / 2) + 1; - for (;;) { - if (len <=3D max_sz) { - gdb_monitor_output(p, len); - break; - } - gdb_monitor_output(p, max_sz); - p +=3D max_sz; - len -=3D max_sz; - } + g_autoptr(GString) hex_buf =3D g_string_new("O"); + memtohex(hex_buf, buf, len); + put_packet(hex_buf->str); return len; } =20 --=20 2.20.1