From nobody Fri Apr 26 04:09:25 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=1579014730; cv=none; d=zohomail.com; s=zohoarc; b=oAVjZczVoeMchoeHjLzbsYcyUBYG/DMg334P4cUAzpp28Ppj2rm76qGKNBjOSBn6WaxMuX8koO0Kb9VH++JzgVEfz3+JFqZDORBv/iGORmCL4fTTaLxQRB2gL/enbwnomXLFwdaEaG10lqT23jezf6kHuNj6lgPPTAY1hz2RTxg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579014730; 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=vtc3IVWwNAXgrW0he3zrv9/gwUpaVA6HdcPZ7f9C7XE=; b=m9mQA/waxq8z8wFopq25uEU5QsvE4lvmsJpMc4Roo9PaD90Zi9oLPjyAUV7BClM3Y8ue5IJB3ek4YxfOipkJjeLT7FzWzltNXmfsbkd3LL34RyXHwshDBzZBblAMyHqGX777LBub/tzenhM2AtCWFQiLqY8sQK2DnfZe0vekTms= 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 1579014730621594.5347926229846; Tue, 14 Jan 2020 07:12:10 -0800 (PST) Received: from localhost ([::1]:41618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNrU-0007Gg-RM for importer@patchew.org; Tue, 14 Jan 2020 10:12:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37594) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpQ-0004sQ-K2 for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpO-0007HC-H4 for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:00 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:35166) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpO-0007G2-9T for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:09:58 -0500 Received: by mail-wr1-x442.google.com with SMTP id g17so12517686wro.2 for ; Tue, 14 Jan 2020 07:09:58 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id o4sm19441416wrx.25.2020.01.14.07.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:09:54 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id A72A51FF8C; Tue, 14 Jan 2020 15:09:53 +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=vtc3IVWwNAXgrW0he3zrv9/gwUpaVA6HdcPZ7f9C7XE=; b=IpREFKF0dAyukgmG1yPeP74BwE5XCCAjiDVL8nejW4wBZvS9OoxAXh2YsQd9fgcQw8 mPZMH0ixV+CisfiY9CdNfHvwJPNfa41b+CcRPS7iV50lpkd0oAq5aVwNQ23hs9iv1H5+ bpckv5jSoKF0riW5UUj8u3c0jwCY3ge2ba6uqE8no//yYimSkEqJBwv5WeAmL10TYl2Z UHahuIDDEw171i3goxot42WvegSnNQtOcIj7KX+eWRHozIGoLN2EcuBpf9kf8UnHPoNK ikpABFhECUoycDvB+znifZa8jlBq8E203QaCrq+omqSzTsn4RbAAx0iDzqWk7CiN6rdf nj/A== 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=vtc3IVWwNAXgrW0he3zrv9/gwUpaVA6HdcPZ7f9C7XE=; b=QwZ3gdAKUIVQdUewGz0XQxhaFPRTxlasWa906dM+lOs9xGgF1L3LOHDLZivqG++XAa oiv0keBuSRC9vj/goqnfBElYK7fv519QSyah2feFjWGH3aYkDiVi/OxclzhtRBhCpy/n E9ibwbCwJoJqyxVe9KHnnDgU8K5iizLUDu8CMe7Ls2LLzYhsdy+XO5Ety7XAC5mLE3YP kL91cGFx+Ql9mQux7UnwJ6SwAdCadTZbEfjUUCpYP9eC324bShchyNWdkgPsmDHzd+Fn V7NxIO0NOM94xH3xXHEU+7xgpzzB48h/JhccbzF27/Ci+WTvfkAwBzY9D8N522r0r4dI gL3Q== X-Gm-Message-State: APjAAAXhH9VY2iUGzePKVzooyz49XuOUqDwzj7TykHLMwpjD4BBT3EcY Hb9zdMq2XQuii89VMqGty7ANRQ== X-Google-Smtp-Source: APXvYqwmY0AqwXYrUbA8MW3IFG0kCpO3XiSPI4Swn7QJ2wQUgHgtPBRMUZfjLvLlC0B82CPEu3Pcqg== X-Received: by 2002:a5d:4752:: with SMTP id o18mr25024967wrs.330.1579014596837; Tue, 14 Jan 2020 07:09:56 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 01/22] gdbstub: make GDBState static and have common init function Date: Tue, 14 Jan 2020 15:09:32 +0000 Message-Id: <20200114150953.27659-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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 , Richard Henderson , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 ce304ff482..3bc90cbde5 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 Apr 26 04:09:25 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=1579015306; cv=none; d=zohomail.com; s=zohoarc; b=e/ou/bg1v75Wig/9qz1oKINio3QypUg8HOZBJPxs3svYZ+j/qDCNxnPigzQ7VeTVVDnSCiorgN5hlHJPj+d1ps2r0AeYfvzpMJ8Kaw33T+SR+qss6mZLo0gqfxw2/BiIk4KUhuJt84jLaXO4sTRSMBcUvr9HzO7XhzACgendgkE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579015306; 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=ZV6dFXU6OUkYz6zwvY83ZV/7/MRSUcaUvltg4MpQ7tE=; b=T7eCHdftKhCfpik0hS2DmkJ5F81IP0AK6ft4WhoBYvpE++t1jOvuML1MWRlToO7aAwEACt8hKBd1+ZjbmbZGaKbLK5pS4CEFE9Tmjex/EiWJB01Pi931imVJrX6ziezmZ00ralfUMOL+QIAjBYB8ekSZ+tWIqJC5Fs0zb1e/m50= 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 157901530638544.62820692682908; Tue, 14 Jan 2020 07:21:46 -0800 (PST) Received: from localhost ([::1]:41908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irO0m-0002o2-Pk for importer@patchew.org; Tue, 14 Jan 2020 10:21:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37764) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpW-00055w-Un for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpP-0007Jb-Uc for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:06 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:51037) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpP-0007IK-HR for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:09:59 -0500 Received: by mail-wm1-x341.google.com with SMTP id a5so14208974wmb.0 for ; Tue, 14 Jan 2020 07:09:59 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id m126sm19466675wmf.7.2020.01.14.07.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:09:55 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D65131FF8F; Tue, 14 Jan 2020 15:09:53 +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=ZV6dFXU6OUkYz6zwvY83ZV/7/MRSUcaUvltg4MpQ7tE=; b=T0Am0i2kISuKw31xEhz6ngesMBPFzVtWAOeT6ZcizpF1fHj4mI+RqEV5oen9PaAeCS KC30xtXPjlszvMuOZl7qPZM3y74siAcwO4+5WlZ2tKQjsceMiZJ+kzmAYd55GHJ0Uvjs RELZrR7mVZD0anQV5erJXWIzkqP12giNwsbbULONlgd08cIsOy8awRhxcNjf0ddWSHaJ TvZHTEQ9TCDvFNLQVqNiU3y9/2BRtUG0fLvAVOxeisbFyS5cctACmcymHKVqgxmYMwbd FsPWzFepeIscBOCy8yyp3gGkde4vcxLYTD2t6mfz3bFyANnyTpfFsjbqR/D9KlcZJP+k ox9A== 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=ZV6dFXU6OUkYz6zwvY83ZV/7/MRSUcaUvltg4MpQ7tE=; b=jomybdEYz+XaYU+GmTVKsb3GJlZwucENqAmqleyPqjL8bjFl4zgu36+RiIq+uEakYZ BgINIS3GmoczErAfJVWt8SGkJgG6yhKMpbS9rBZ3+hKgRum+h5D2c9JIXh+yDCU67VoR 9/LVk4Nm5q/+C+ebvjyBrpYHXPnUKI7eQnS+h8L5jks22qXnymIeAiBKMrkJsQFq56B2 pnGQamakLQClIGCFeMzugnnnpgObJO189Orm/TmRZf21LQJs6+6wjLRDKc/4lLlfyUlE 5ikvNnvj8ZUKL28cI1/+9Y0kx7qMy08KnODQhgmKX6tJEejOx37pHqRgqXUEn9Fs8kva xYSg== X-Gm-Message-State: APjAAAWsvbkHEgm7TXhEM38XFfIOP2rZWEHl8VuV1EmQlHyaNeXcb7xf HOyS6i8WOzrx7ymMCYF98q9Je95gXws= X-Google-Smtp-Source: APXvYqwYMwGIDzmBA+FZxq/941xVpmX0esWPsbyqgp+38YoiWUD4c+rk0BtTnGYN9D9UKRIcqZ/gCw== X-Received: by 2002:a1c:f30e:: with SMTP id q14mr27635282wmq.65.1579014597695; Tue, 14 Jan 2020 07:09:57 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 02/22] gdbstub: stop passing GDBState * around and use global Date: Tue, 14 Jan 2020 15:09:33 +0000 Message-Id: <20200114150953.27659-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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: Richard Henderson , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Reviewed-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 3bc90cbde5..99293bb405 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, QEMUChrEvent = 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, QEMUChrEvent = 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 Apr 26 04:09:25 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=1579014918; cv=none; d=zohomail.com; s=zohoarc; b=nVNMxq0550Pz5MCo5uUnaTWNHShTVwrDpSHgezV5VHtF5WKg6G3GuLfufvx8CWpfIbgyGF/ZuQqu66eNZL1PsugiGBnVSBGM9gnVNE37DJNG3/xT0EjnpACusE8BRwOYM8hmMKxfdRjSQ3Hr/S3NsjVdgyMDL3Ho2x3ji0x3tgA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579014918; 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=rB3pe0hgH0BQismH1RKg981sYWUD10c/7d6+AtGXzf8=; b=TSVArKKNlm4o8Mhn00WwRzspi3DwQ31BRBtlo1GuiZH33BOnDKEaViPPi5TRixTXaW+khJt4w7gzVjcLMRTpUR8an9lu3ncAjDMFS1BDleIhBuAmiH6bd5t+quR7I084vewO0j1XLKzwHqAkfU4iShmYUnubID1r42+2KLH1rZg= 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 1579014918429260.41183349994776; Tue, 14 Jan 2020 07:15:18 -0800 (PST) Received: from localhost ([::1]:41686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNuW-0003BZ-Gt for importer@patchew.org; Tue, 14 Jan 2020 10:15:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37715) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpV-00052I-2i for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpR-0007Mh-Uf for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:04 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:54663) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpR-0007LS-FZ for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:01 -0500 Received: by mail-wm1-x341.google.com with SMTP id b19so14173211wmj.4 for ; Tue, 14 Jan 2020 07:10:01 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id x10sm19663793wrp.58.2020.01.14.07.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:09:56 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 0E9E81FF90; Tue, 14 Jan 2020 15:09:54 +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=rB3pe0hgH0BQismH1RKg981sYWUD10c/7d6+AtGXzf8=; b=UQjwnc6DAffwJlCBZoM7ONpXhMYHXrRw6R16RCDHkK5tVhjmer/9aut4DW7B25D3w6 XhzLJK3euZd8S4jDPLDuSmhfhNcXktjtaHnMy6bc+jncUb3gY1lyVlAQIjVM2bGKtQPc t60qrcT5wBKREDaMW4CYip/BMWpOdfjQgP+0SOxMgnirsUzQl7bGPJYMY+qDf7B6xfE8 SPxJwuEn4/dYoC1FHZZEK0UImW0zTIciGMxtGbwhGfTxQaoNXpxYwZOXfZKwkNvDR3jF Lqw/JYkH9GQ0Ga3KX3Q4Jyxm6lRkWOon57w6qqh7/nWGEh+t1MJWb1SlwGBTVw+Aa2Vu Yvvg== 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=rB3pe0hgH0BQismH1RKg981sYWUD10c/7d6+AtGXzf8=; b=V02t7k0mycZfOROveTDejX3UREwEWuuCpbvhv/dNp12mElVn+FFZb/T0L+0kTfS7vt ObO2O44iANlhb+fD1+9Yz3T8ulwEzLq9Yt+PT3w5AW88WitDotc3P6s63s074ebQcGse 8PsmBHsWvfFSJIO1UgirJzUI3eVkLw+d2oU+fLw0yVFb7mxCxu7u2mtGB5WWRmSyT14k A6e6otAIokSnVmLXrT0IAwSgj4bNV5Bx8xg3MAcHqYQrmOL5/iN7iKYovBlEqhW4Tlja /q09CjBFgV5XhWsFYai5+TBTHgveNJi++tV9gBllT4ntFGfJsx8CSe11xqcDVIlMCG/o 0IwQ== X-Gm-Message-State: APjAAAXgItMHBiXo9phY8YFzgQFN+YoobjFlRju3+q10AvQGIha9cm09 I2ZgC2cjjfNSAZgS9TVfb9FQpA== X-Google-Smtp-Source: APXvYqxXB34rlxIsBNCFnjW83Ax678cJmvqoEhkdd7oCX7lXc0WrBDoHvQukDAwe2Jwps+/gIq2pXA== X-Received: by 2002:a1c:1f51:: with SMTP id f78mr26535176wmf.60.1579014600204; Tue, 14 Jan 2020 07:10:00 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 03/22] gdbstub: move str_buf to GDBState and use GString Date: Tue, 14 Jan 2020 15:09:34 +0000 Message-Id: <20200114150953.27659-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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 , Richard Henderson , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 99293bb405..b6dfeac5d1 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, QEMUChrEvent= 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 Apr 26 04:09:25 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=1579014909; cv=none; d=zohomail.com; s=zohoarc; b=PVDYp70otqLdhfi6QR5q0tG/o9K97NKvgeW1mnacf6Gw72vbJLrO7tBi6KcpFs/IdVGgRHU5VL8WAMw1ofhZ1sI4Jff1n0c/wuyRhtDkrnJrtETzZJbzNjbfWZfhihunsGeoAJlwpOv5oCfxsgQ2xFy8npaGxi/auam0RnGK4P0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579014909; 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=htrqvtKQ2fB8bZcp5vhhVrCm4VHr5qDn3i6b/5DXSww=; b=i0TU1dzjgp916ir3jgzfoBHbhEZHU3u9/cL1espSRTWnHB6cTAnh/DACmTdlfCWWyiwHnWH2bAEqlu/YdGYgUHKccMc7/v+M/34qtJzl9cY5K4fq/sU/aMeR6qHkalCTgCOzQ4b6rq2brT3L2rFc7eSxmjUZuVKQXCIeKjOO00U= 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 1579014909594532.7940995908814; Tue, 14 Jan 2020 07:15:09 -0800 (PST) Received: from localhost ([::1]:41678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNuN-00030B-Ma for importer@patchew.org; Tue, 14 Jan 2020 10:15:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37628) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpS-0004wC-6b for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpQ-0007K9-9j for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:02 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:38583) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpQ-0007J1-3J for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:00 -0500 Received: by mail-wm1-x343.google.com with SMTP id u2so14115826wmc.3 for ; Tue, 14 Jan 2020 07:10:00 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id e16sm20115962wrs.73.2020.01.14.07.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:09:56 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 3643D1FF91; Tue, 14 Jan 2020 15:09:54 +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=htrqvtKQ2fB8bZcp5vhhVrCm4VHr5qDn3i6b/5DXSww=; b=ny1RzRWZxfvLE/PVbURMJyT3I9G4SmELNmRE21I/n1P+wveR9ZESJQUdvQwfKer5F6 sJGVLq4nuPVwiYT6YMc+E2D60FNJD3Bh8u2XeQIGqPPCeSDxI/RuZvDElsxiViYVlUa8 BjtoILHDnsdvccBbq3+6J8n35R6VV5/XeJdWamhAwrVHkcycM7xz1F2uaQCgJMrX0MZI 6u+iWJqWFP/01BtyAt5XcHLbV/pa9q//fk3Ng/ofDEYRApnoilWYnXUDi6zWtZLaPBRO P4Y+CqMKEDCPBmwjfUFOR7nWNdWFMZUTFiMqT50KVqRr0hYX9SZtRWlB7rgcw+lR1niw a5eg== 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=htrqvtKQ2fB8bZcp5vhhVrCm4VHr5qDn3i6b/5DXSww=; b=AJO37r69ghUNjYzwxQdHifArSOvu+RuCCGqTgeYVmL10rvQZ5OTYvvA4Z+qMrmh+dB 2F+uHOYJuXrOmKQu1qUnTIlz/TeAv5otjUxb2Ot8IVfczuQgzYceZwyt6Pq/5mbiPGU9 WEFrjGobvuN9IrYIpdNwb++C5rGtHlqhAQR65U3Ja8qvrBdjmsjlBBwWP6fHvsfujaaW jF98ke9WAe0OWX6ykCg8H8PLwF6iLdvAYpz+UKRIX8AnIOz3VVqzbTdf1/T/BNYW2+Nt 4XOvZXrqn2JLADFm3O+BTd0+EZkCjM4Oi2DfNizO1/yrRePgRbXR4AQvT43a4pT9M1aj F7qA== X-Gm-Message-State: APjAAAV1mxlkXYmi6jk2L8Hr/MXjIg68KTBUN4Xhxct2H53+rL7VJf4/ ZydwQmKxv4215Td2wmcVhWT+hw== X-Google-Smtp-Source: APXvYqzjQ8LEOBH775Cz8du/OcZ94FFe8OsSXHewQV9hvEyGy/288xAUQuFIHIML5GV+0Mco1Oavhw== X-Received: by 2002:a05:600c:218b:: with SMTP id e11mr26093230wme.121.1579014599095; Tue, 14 Jan 2020 07:09:59 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 04/22] gdbstub: move mem_buf to GDBState and use GByteArray Date: Tue, 14 Jan 2020 15:09:35 +0000 Message-Id: <20200114150953.27659-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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 , Richard Henderson , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 b6dfeac5d1..49abd2bdc7 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 Apr 26 04:09:25 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=1579014953; cv=none; d=zohomail.com; s=zohoarc; b=Zzm3faD3bt16CNq3vS5vlxjhSNCXFibJ2zzSsoDCc9DhV5EJD7NrCRQwSW2A7vlbUeeuXTh/LE/3WOEbmcD1MmdFqI8sG8EVkhXHGplPf1vWiLTaB9wDp4qwoi3W2X9HuSa7LEFNXNZ6HpOnak5MAbQUcHUKtNxcJYKCHWHV2AY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579014953; 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=rUFyb2y1MbKjceLsHfsc5550yIlmEuHV9I8+VOakZH4=; b=hp36jp84iNEu0wamarVdHkHDE1kGC8YGIoqlDfPBIa79ctN99OdyWu6N90yJr/nijdCXQzJhNWAERneBE+kfROC3p++qxFWBPNslmYoXgT2/m9OUXjy6TIphk4G4qVqRO+D+sg35fe9Mm2rm1Y8Y8q+hhNcBL8SmHaAdUDycEhE= 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 1579014953941641.5120220528465; Tue, 14 Jan 2020 07:15:53 -0800 (PST) Received: from localhost ([::1]:41700 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNv6-0003xV-4S for importer@patchew.org; Tue, 14 Jan 2020 10:15:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37805) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpY-00059B-L7 for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpT-0007QS-JT for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:08 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:39654) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpT-0007PJ-DZ for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:03 -0500 Received: by mail-wm1-x343.google.com with SMTP id 20so14121583wmj.4 for ; Tue, 14 Jan 2020 07:10:03 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id n10sm19824230wrt.14.2020.01.14.07.09.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:09:58 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 640CB1FF92; Tue, 14 Jan 2020 15:09:54 +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=rUFyb2y1MbKjceLsHfsc5550yIlmEuHV9I8+VOakZH4=; b=kr2JJZ5Qc/xyq/YPtiB+ZBtcQxsje3d4twQIAGLq5Rk8tGDIKL1FM63Udn9wyiOn8L Z1JeJI1RI3VvBnLqxEe1Q12x0ecy2I43g5CX+G1/HBHW44UdK24Vl3R0OfR0m5PWEOMn 9THLulA3wKpM2rB7b4F5FBpNlK1v6LuY9Dzj9VZ52w/vqTM+TBDV+Hsn4WJBueNldBNh yAigllRSru74vr7drS4T+V9j7MgFP1nbrPCw4Z3nI26zLpmuQXFDUdwAlWfC6dbeixPa TeEv/H55uPLEpiWUBsMYBmsZM9RUZp0moXFhU86bQ5aSKQD6DZlI40eamUj2PQTDJRdd 2c6g== 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=rUFyb2y1MbKjceLsHfsc5550yIlmEuHV9I8+VOakZH4=; b=jq2u5L63WVJXkiza652nAwwkaVcn7My0w7c80QcTNuPzUC0dJSNKUnjR+PGIjbPqZf Jvd3XJQHIq5l/L1XFY6DLPGw0ba2j+Ch/7O0EqHCmAM6pQRy4nAX8hTljAQEsKB+5BwL PMBaN9gIwA6pCyUVGeRwmTlZ7RpdCbScSd6QY9oHxJSZxjQTtvaOq+KcbudK8RE7+PfX cu25nLrPLjQJ2fBDJazFtM1Z9AyD+pDta0sUD8qYMYnEevHbR3GJywqxVrXVlxoUOe2Y yYQW3dN5SIaCb/dZvnUZi+HW1EGGzVK2h/FRuX01DCtmTDqCuJpwV0gydIz0GU0qCVcJ tavw== X-Gm-Message-State: APjAAAUErNW8EBgFeEC6kec8lK9YafDKP7xhIyowHUT/VqgwUZ3hJKof /yW2KvF/NmUMminyshWPjw9/4g== X-Google-Smtp-Source: APXvYqyPPfMAK9p2BejuSWjVCkJpSTki8a4BTvUOAtL6SX42UlCZfgSKQvtmJEMtmKmoCy7UNxkDxw== X-Received: by 2002:a7b:c084:: with SMTP id r4mr26314704wmh.99.1579014602497; Tue, 14 Jan 2020 07:10:02 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 05/22] gdbstub: add helper for 128 bit registers Date: Tue, 14 Jan 2020 15:09:36 +0000 Message-Id: <20200114150953.27659-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , qemu-arm@nongnu.org, =?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 08363969c1..59e366ba3a 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 Apr 26 04:09:25 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=1579014773; cv=none; d=zohomail.com; s=zohoarc; b=nomzI7k6iiekD5WWN7zpCm3M7vlB0sDORpE+VxBtt2v+Rd+QM3BZCySrzlXDaZ7XA64QkMeWP0NK05nXEvlC7SJwyHdb7aj9NYUtMBBn8RoyjVhxa1vAJbv1ATlYbHdm0zkWUjKsR+rxMLgZDMvBZM3LKV2upD1QhfNIwCjqQKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579014773; 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=3umaeyZGHx38fKYCe2E4NwESx7BhJFAQKAKH5fWHUFE=; b=MKAaLH9enpwHNxwMeb83EHTN85D6m3xFPrliUftTCubCfX4uT01SPNFcqkB/LdhDfIqJ6/QQ9DPhPtutz86gNqbjbKfuJtLrU9pNpXmcsETaiylzquvwCkd3M5LNaQbxZKQRM1bWoCWB6QYfY14asA9C5Ck3sblLl5r0K8ELkWM= 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 1579014773530954.427028577867; Tue, 14 Jan 2020 07:12:53 -0800 (PST) Received: from localhost ([::1]:41622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNsB-0008KD-Qz for importer@patchew.org; Tue, 14 Jan 2020 10:12:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37671) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpT-0004zb-QQ for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpS-0007Nl-ED for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:03 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:36917) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpS-0007MC-7p for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:02 -0500 Received: by mail-wm1-x344.google.com with SMTP id f129so14148376wmf.2 for ; Tue, 14 Jan 2020 07:10:02 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id q3sm18155025wmj.38.2020.01.14.07.09.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:09:57 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 89F751FF93; Tue, 14 Jan 2020 15:09:54 +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=3umaeyZGHx38fKYCe2E4NwESx7BhJFAQKAKH5fWHUFE=; b=L6rp5JeHaHqlnOc0DFbB5B8hrC9ItnQzDvtijqazK7vSj5Nh8oiMEiLui4SV7hrwjt jEc4tMzlVkqjGrWWVnteEokkuJ9VeNOxCjjsKBnQSlZirWgbFvELVJHJrmK8Lcxw6JHe GlyWw1k4XKx+ELdbtQjVS6GIyPmDTN7BnLgR9DEZRC/D96iE5a8eDKdnsYejWLjGhCBu 5J8QwNpJyfbUbVGHl2X4NE0JBddqJrMdk4+rFuzkvTKNsk+JIBFFgF4NpyOfTE8Vsu3F F+W7yHr2+AAwaQw4MBWdmwv51FW8AQfteqGE1zS5j7ZSG2GQ+AX4UkiA91E8gIisZqQu aO/A== 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=3umaeyZGHx38fKYCe2E4NwESx7BhJFAQKAKH5fWHUFE=; b=FPpJugz7ESTDo0X5gNcUBn1QyQsBpD2QhajQbUctNugH11ODZF0ZM7SqWSIWKUSWJL +qj+fnYMpn6aDc9b3F0C88WrtcnS+RJUs0L3xezDQ8AMoBFHwQjZX7nfDjQcQDywyF2K J5jmkyTxbNNZZdPgf6sBCurNge6bk90ihUus7Ux0h+7pwT61n1xQiKUNYCdX0+wswAGn wrPuqqkyB6bebGGHbpZvjy8Ju6eH9tM2zxBgDX8lNXGq6CX1bNjofWkxpAAp/QKFMAsB S1rvZmKnySLojQ95CsK6ZLGWBghArhjnuJshxJQBx0/kd21XjUxE2vnAEAnq2pQq6wvb p+/g== X-Gm-Message-State: APjAAAUrQefD8bhs3/QJ3omDprYgrMAc2tlk3beJikNmqqubRz3TbsiF yzfFxabYkFl2Uu2OpSvWGWKybg== X-Google-Smtp-Source: APXvYqw8OyjzySR2cvCD+XSKgbesS5nZDahgJbvoqPbg0u3TQMyI/Q/nxDBWf+wFFGKp4aHF8SGCPA== X-Received: by 2002:a05:600c:20f:: with SMTP id 15mr27870690wmi.128.1579014601282; Tue, 14 Jan 2020 07:10:01 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 06/22] target/arm: use gdb_get_reg helpers Date: Tue, 14 Jan 2020 15:09:37 +0000 Message-Id: <20200114150953.27659-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell 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 19a57a17da..b417b33cd3 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 Apr 26 04:09:25 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=1579014795; cv=none; d=zohomail.com; s=zohoarc; b=ays5N5wCvS8v6hLEQ/E2dOaeHt3W9Y+CFKDxX2XXeqnhtSXjmVX6nNsFjMMlqhh7mx1U0BvCctMn7+nibF/zLg0bLyF+8XIumxBY11frJdy1UygrYiGGX/7fMCx55Pi14JhJPY8JWC003Is7ENUMcVaBF5MRPC6V58LtQmZCI4s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579014795; 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=dc2TB96P20SvqSbGdvpR700XiNQtXmvcj8ruUddj/b0=; b=RHTkZ/MBvtCCRuD5oiesFDwZpmvPqTnEHJV1fvlFZqZcNhzNxvolpJa9I+pGAJ8WnxdIrSuBhRQuaSIjYJbsJsR9ic3jQ5SGEWi/x0js+A+uvzCwtEaZQ+pflfU7c6su5NLJ5/yAq8pcJYPjxl53GHaW727cGKYs042APGsJkQY= 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 1579014795149769.1780618412972; Tue, 14 Jan 2020 07:13:15 -0800 (PST) Received: from localhost ([::1]:41630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNsX-0000NL-Gd for importer@patchew.org; Tue, 14 Jan 2020 10:13:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37756) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpW-00054h-FV for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpV-0007Sb-73 for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:06 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:35167) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpV-0007Rl-06 for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:05 -0500 Received: by mail-wr1-x442.google.com with SMTP id g17so12518138wro.2 for ; Tue, 14 Jan 2020 07:10:04 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id t1sm19255049wma.43.2020.01.14.07.09.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:10:00 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B37061FF96; Tue, 14 Jan 2020 15:09:54 +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=dc2TB96P20SvqSbGdvpR700XiNQtXmvcj8ruUddj/b0=; b=E5d4CIr457WSRRiN8poI2FFI5MrAAEL2JP1aKIOMu6l+96xSRKNtJ3yg1G+A5kXR0N FyNs30RD4BABNlN/TZz8D3EGZKmsM9xgK6Aq45AFR3B9/bKXFQWV+6k4mfv4/iofGMzi TkmTow79QX9xQLzKeCqp1+etHBi54aaRotdal7kP0AmQA19gqwgZcdQM8a4jO0jyQl6Q ZS/3XVp41450qkfI7RKYJTg9njnrbL/eBKcV3YZgGM60oAQpihJLHO5VmCuJFIBeevC6 XyVlVWEiiPvDGCJrwIb1UB8cxKz0s0/7HGP+zgPFdqhZ1d65LONu5o4ozHO3MuggYmH8 +ulg== 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=dc2TB96P20SvqSbGdvpR700XiNQtXmvcj8ruUddj/b0=; b=ZdfDtyiJIHQ7tpHcGxlDa6xNicZPyLdjW2QDIOgUFYthRsfT2pRMZLbyOtJ5XeUCFq tHiRXmJLxzQArHNKm5LTzhXm5WeNptolh5iNyxD/OBLqbNeNwqIKhfyL2ro5W30Y7cKw S2KbwMK8UWjuLSSJlFPlZwKnsoEr1XQmawXa7qmSlG1AA6mpknm6KJ75SN3uA9gTIvo0 hbLiG9fLHMUtr+mXHc/bELWXCFyLE7GiCO0lMEfoRe3I0Udy22g/Zkan+CY3Qra7g8Pk 7YXnBwueJwjWs6kDbhujm3WnuJiqaHau9lDg1iQQMvs5UtPcR89wYdW9Vf3+Witx3mu3 qK9g== X-Gm-Message-State: APjAAAXVKLpkB6BdRNRe5v7668RVFM8qvduQGySZYFTskFk80EExvwr1 w49e5dtrUWcTqcUXimjev5CSCA== X-Google-Smtp-Source: APXvYqwCLtaGHWS/Uf4HJLlI1G6cGlx2IGfAXH3HHx3vIz/P2ir2sCIdM4OcttQPMSFeS/4cT5XAeg== X-Received: by 2002:a5d:4481:: with SMTP id j1mr26540999wrq.348.1579014604017; Tue, 14 Jan 2020 07:10:04 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 07/22] target/m68k: use gdb_get_reg helpers Date: Tue, 14 Jan 2020 15:09:38 +0000 Message-Id: <20200114150953.27659-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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: Richard Henderson , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Laurent Vivier 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 baf7729af0..c23b70f854 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 Apr 26 04:09:25 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=1579015698; cv=none; d=zohomail.com; s=zohoarc; b=kTHpAXCwmcNnQvwZBw1joYTFuWz3Pqm48pp/+dK8ZeoZt5vUljoSx+Ex46zx0I2J9PZLK9kwso0UeWnLnf+bNyWDubWAI3PhxsvC3e1P1b+k6leE7FdrWTHsMrNCntSJroWikd3ap23lDvEWPuplQ1I1WJyTxqqrALWSp2FJv7s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579015698; 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=IVCR8L83kCP4d91OfNOrHg+vpIHvjOPU8Pyglf6gkxM=; b=hjy41fdVQ5V93N5dpJCGqObTZncKOjYTFQMcWUwNFxCg8oETeSNeoyvW8YnCjm5dP1FmIF6NgvkmYwEgHG9OtWsnuwEmEvAzXUFlzU8BLtFU3fEyTp1331Mez4iDAJoQHBE2aSaD/aJxOTGnJycZpMGcwnCR008MEgZhoFJqEds= 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 157901569869644.54852831749156; Tue, 14 Jan 2020 07:28:18 -0800 (PST) Received: from localhost ([::1]:42065 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irO77-0003Hk-0G for importer@patchew.org; Tue, 14 Jan 2020 10:28:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37935) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpj-0005PR-B6 for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpX-0007Us-Eu for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:19 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:33989) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpX-0007Tj-0d for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:07 -0500 Received: by mail-wr1-x441.google.com with SMTP id t2so12546794wrr.1 for ; Tue, 14 Jan 2020 07:10:06 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id u14sm19467633wrm.51.2020.01.14.07.09.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:10:00 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 88E791FF98; Tue, 14 Jan 2020 15:09:55 +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=IVCR8L83kCP4d91OfNOrHg+vpIHvjOPU8Pyglf6gkxM=; b=sG56bQlTNJb5f3/RmoV7gO8oie+x2UCIdEp8ZjEbBaPgY42G3+o5Vndec9eQUfC1Zb LQinQIHRZ0EiTGfRYTytmfj+MqxPnzsc5shSyE4xwUkDFc5gRyhT4U5w6nmBU+h5Jv19 NsjLtTKwXlNdJnenrwBb3pQ4xhYoyBzoegQuIjs+hJLxTy670K9Bkfy5ijHA5PX/RrGS BTBz8dP8nIprJFr94Yam7JlOw+digX0/+YnjoDw6jlqVCQekaoEBuCr8PeVlV3QQkWTc P6Mn3ouiLKK/OLPDapRYHaKgsG1tRnG5/fokO0anBhTKg/mDOsYEFeN2o2dG7RIDqxDF EkbA== 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=IVCR8L83kCP4d91OfNOrHg+vpIHvjOPU8Pyglf6gkxM=; b=Bznco2Vwp7A1gtEHHV1ybM9j4o9sAfbWXxSCdz7Ruoxck7AMCn+hittqPq4Dq8XZeT r9sQMeWfuvdE8tNO7e5cX7SnuSYLMgfWQNW0njCSWh2K8TRXJJ/h9D/hDppig6L7XFE2 LsHwtO15VcmTQp6cjYX4h/+eDVU5nPicmv/MncvMjEFQPkimh1lLS0FCQBFDOvbpewCK AqaZAHKDPxeID0WbXOG/Vbgvxt+8Q8dlKKZW3vu8NZkrxlbpoHtVtgwXjhrLsThGInWH pmf35YLNZMNek5zrDgi8p8utEFlLMbPGjndORafvCrGPcR5zBX8Bs1J05bcOdGcf869n ukFA== X-Gm-Message-State: APjAAAXQeoBmE8jJbFZM0huAqxueNZWFZRvv0t43UMc8bdPYEcYjuhvh rKXMj8W0ZuBUbjFNzcNEiO222g== X-Google-Smtp-Source: APXvYqzXmYKKKeS6jVXcImYC4Gn/QJNcMEAKs6QhApWSYRW+fFyj0Zn7WQnTqyYueVndMv1d3sVPCw== X-Received: by 2002:adf:ef49:: with SMTP id c9mr25177563wrp.292.1579014605320; Tue, 14 Jan 2020 07:10:05 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 08/22] gdbstub: extend GByteArray to read register helpers Date: Tue, 14 Jan 2020 15:09:39 +0000 Message-Id: <20200114150953.27659-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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: Peter Maydell , Cornelia Huck , Sagar Karandikar , David Hildenbrand , Mark Cave-Ayland , Max Filippov , Alistair Francis , "Edgar E. Iglesias" , Marek Vasut , "open list:PowerPC TCG CPUs" , Aleksandar Rikalo , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Artyom Tarasenko , Eduardo Habkost , Richard Henderson , "open list:S390 TCG CPUs" , qemu-arm@nongnu.org, Stafford Horne , =?UTF-8?q?Alex=20Benn=C3=A9e?= , David Gibson , "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: Richard Henderson Acked-by: David Gibson Reviewed-by: Damien Hedde --- v4 - fix mem_buf calculation for ppc_maybe_bswap_register v5 - introduce gdb_get_reg_ptr and use for ppc --- include/exec/gdbstub.h | 59 +++++++++++++++++++++++---------- 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, 178 insertions(+), 148 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 59e366ba3a..30b909ebd2 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -68,53 +68,76 @@ 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; } =20 +/** + * gdb_get_reg_ptr: get pointer to start of last element + * @len: length of element + * + * This is a helper function to extract the pointer to the last + * element for additional processing. Some front-ends do additional + * dynamic swapping of the elements based on CPU state. + */ +static inline uint8_t * gdb_get_reg_ptr(GByteArray *buf, int len) +{ + return buf->data + buf->len - len; +} + #if TARGET_LONG_BITS =3D=3D 64 #define gdb_get_regl(buf, val) gdb_get_reg64(buf, val) #define ldtul_p(addr) ldq_p(addr) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 77c6f05299..e85ec519ad 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 a530249a5b..faa0976842 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 40f2c45e17..d44d8282a2 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -954,7 +954,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 @@ -974,7 +974,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 a7c2a8e15b..73ef61a2b3 100644 --- a/target/cris/cpu.h +++ b/target/cris/cpu.h @@ -195,8 +195,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 6713d04f11..801a4fb1ba 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 594326a794..86c2388282 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1763,7 +1763,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 064c6b1267..01d408eb55 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 11c71fa962..36590793b3 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 95773089aa..987e4629b0 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 3f435b5e63..c5ae86360f 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 0ad02eab79..d9484b802f 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 103bfe9dc2..41e009ae3c 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 e59343e13c..fe0b886102 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 d37816104d..8c95c734db 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 ecaa7a18a9..d7a1bffd60 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 ae97c7d9f7..b9369398f2 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 75e65df597..0326eb6888 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 49abd2bdc7..dcfa4f1dd7 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 db1a03c6bb..9cd1a2a54f 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 7f9cc092a9..0cd76ddaa9 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 1239abd984..4557775d24 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 665ebb3ef6..35d0b80c2d 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 b417b33cd3..f6df3735e9 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 a3d76d2e8c..b01b2aa081 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 341888a9da..a6428a2893 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 572ead641c..493e55e2dc 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 82ede436e1..b6fe12e1d6 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 fdc96f57ff..eb2d030e14 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 c23b70f854..014657c637 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 30677b6d1f..f41ebf1f33 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 bbb2544939..98f56e660d 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 ca9c7a6df5..17d868421e 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 0fcdb79668..095bf76c12 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 823759c92e..eb362dd9ae 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 d33d65dff7..aeb022a747 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, gdb_get_reg_ptr(buf, 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 gdb_get_reg_ptr(buf, 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 gdb_get_reg_ptr(buf, 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 gdb_get_reg_ptr(buf, 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 gdb_get_reg_ptr(buf, 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 gdb_get_reg_ptr(buf, 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, gdb_get_reg_ptr(buf, 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, gdb_get_reg_ptr(buf, 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, gdb_get_reg_ptr(buf, 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, gdb_get_reg_ptr(buf, 8), 8); return 8; } return 0; diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c index 1a7947e019..05442215a4 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 e24a49f4a9..d6fce5ff1e 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 44c1679e9d..49fc4a0cc6 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 8be742b5a3..78dc8dcc98 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 54727881f3..0ee3feabe5 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 Apr 26 04:09:25 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=1579015109; cv=none; d=zohomail.com; s=zohoarc; b=fYyvr9IypamqKbriCa+D9Z4x6thSBYsHzKAE9HQiWGCPwJl0guXG95d1AY+dcHuPt0TGHSc/MD09i1xQDFK/BsJwcC60bOqppdiICSJ+Lm9lbGiBVUQDmUdINkbLvfyxUD+zfpUSwr5SSSnAgYahxnuUtKvGY21OmpnEjmHqkgs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579015109; 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=Ch6DCpi+AeeZAWG9eKFNVIGrenNGJRRQr50yqM/8GMU=; b=LZDW4FtflStTejUjX9ihSDlfHa0W2i5fMsXUBjkohFs7yPUZuPtLqjzIhJgRSebyZkPBeQlg7TtfIvstkQU8Ld+lb9/H3//khBSzDMqDi5U7jnXwllvyY3fciVr8IDc5CsFtLTVTSbYqniPHsu/6qgS6coJGGAF0x7ERrmQzYA0= 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 1579015109304106.17096253574937; Tue, 14 Jan 2020 07:18:29 -0800 (PST) Received: from localhost ([::1]:41752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNxa-0006u5-S7 for importer@patchew.org; Tue, 14 Jan 2020 10:18:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37751) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpW-00054G-53 for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpU-0007Rt-EQ for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:05 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:38584) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpU-0007Qd-6Q for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:04 -0500 Received: by mail-wm1-x343.google.com with SMTP id u2so14116046wmc.3 for ; Tue, 14 Jan 2020 07:10:04 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id y17sm19082401wma.36.2020.01.14.07.09.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:10:02 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B51061FF87; Tue, 14 Jan 2020 15:09:55 +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=Ch6DCpi+AeeZAWG9eKFNVIGrenNGJRRQr50yqM/8GMU=; b=CwIVcRn573eAnoApvsDSsnJt30RTfzfZnor/0Yy/FMTF6ABQbfUcv3jpt5IZz0VPRr GK92vPk5F1nScR+d7PG7jlykhk0bFTB024tChMknkYq7TTxt2TZ7NdMQElCVpJoz0dTG xYLmMqpwf4I2EnTYdWaIWUT4qp6Ho/TaGmyYnST0UE1BiTg8yR9gmt/s+ldNg97xx69s OBdUFnwZdLNR+gYaRo2D+apAKsmxfYL2dmZ6EDhf625OqzNBTMe3LETDUcsm541pjJ3j xPFb4la6XsWW7ACA4FBVI34NerECG7kYwd1CHaBIeNamX+CJFZLAreoKwpMnqImaJwc5 a8mA== 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=Ch6DCpi+AeeZAWG9eKFNVIGrenNGJRRQr50yqM/8GMU=; b=Uuyg09ITXlsBx882uJbzmH5ua6eLbEl8ZVNAD87bbPQ3daFrtHO293vnKmvEr7l+ze CohxyiSn8AlP2sRAhOZomvdCpVK5LtKGtb9/+NSI1NsoNinlwWrKiDzYwzfpVopWbVUS 0dwieaMQbihvMXgzm4vsvjFpHdmLjl1/M8m1tqyzjMy9Yw3z99BT1H1u9bFc/cDYcZqo qGtACLa1SzZaTu4zsr3Z2a2SkVTNYdcqn4bHaimGP7AIByhNQhtiQQqzbhgDGXhkQbPE tFhUpBk9Ykkc4CnPzHLnDoAAZo2mPopA3fb6qFn9f/8Q7tGeQh3O0SVj3NUXmpY+6pEd EMew== X-Gm-Message-State: APjAAAXWc+QKE6CciJ9sFk3MWwHONfh4kF6NHhXK4LatatLi3MNn3daZ L+rbG35houdGX2nYqG7EV17oVg== X-Google-Smtp-Source: APXvYqxP0u0rJIt74SxgwunBNt02dysrtLxSgJ2ydF/WGeILGFZVKXRpUqHv/72rjAJVKT6lJl1CNg== X-Received: by 2002:a05:600c:298:: with SMTP id 24mr26779366wmk.141.1579014603261; Tue, 14 Jan 2020 07:10:03 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 09/22] target/arm: prepare for multiple dynamic XMLs Date: Tue, 14 Jan 2020 15:09:40 +0000 Message-Id: <20200114150953.27659-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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: Peter Maydell , qemu-arm@nongnu.org, =?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 Acked-by: Richard Henderson --- 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 d44d8282a2..bd15587305 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]; @@ -960,7 +966,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 4557775d24..1f68ab98c3 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 f6df3735e9..f05bd2fc76 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)) { @@ -7141,7 +7141,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 Apr 26 04:09:25 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=1579015344; cv=none; d=zohomail.com; s=zohoarc; b=YwrwIUcQ6m8zA/l1NQQO1tZ57Obgx677JCRiPpVGAsfCmcOHFPsajtQVEIGSIwW61kcUFFxOWVtt/snCvc0OmrS7YwwCVdybK9e3vZdXxvb4a3V61t+bMdJ4WJkNrLPnBnI8gn1/Yek3rZdmT+qhBILmDm5j/p/2NZFXbUNJneQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579015344; 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=s5gOoMgihpmFE4AT4VWG7sAvxuhwjZxcFhBeC583tSg=; b=VGCfHnj+cuQtASMeEbBoCYCU6XcJe/L9i0scWJ0R5b0zpUVixiNrh4s5VODuc+N0MZ2dfq6Qa7eq92UYJK8SX//3dI9LOXZ59/VigE4zTO01ka641MGZltlhryodOMIIlhB1zW3qUn6OF01CiN9mnY5AqSzlWaZ0bUiHasmvbjE= 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 1579015344117338.73967666648184; Tue, 14 Jan 2020 07:22:24 -0800 (PST) Received: from localhost ([::1]:41924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irO1O-0003hj-Hs for importer@patchew.org; Tue, 14 Jan 2020 10:22:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37904) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpe-0005HH-3E for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpZ-0007XH-7a for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:13 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:46697) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpY-0007WE-WC for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:09 -0500 Received: by mail-wr1-x443.google.com with SMTP id z7so12472064wrl.13 for ; Tue, 14 Jan 2020 07:10:08 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id k8sm19845834wrl.3.2020.01.14.07.09.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:10:02 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id DEBD61FF99; Tue, 14 Jan 2020 15:09:55 +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=s5gOoMgihpmFE4AT4VWG7sAvxuhwjZxcFhBeC583tSg=; b=tWfMb97ZW+U6SQbJcTa9WbfOzFnTId8lHoRjNJfntyyVxq0NbWeCOp7D4oBToBIbMT rXTy2KwSlHkUtGTVVITIoETAE+caHNtADl8B6bZuKuoftL4ZP+1D2gPwq5fVTXz3mjY+ DQBuEXoH+KDvbv8ChP15SDooK3MVw5cMdObKuxS8Q7Te/DO7Z19wlE67TXF2/iRRURI+ /mzbCMM3Vm1YBSMPZX/jhnSSmh5R2ERs3PJEUivxZSBVvFoDPkD/mVow8t6sER8l88ox hCpiAME0iJ8m9OvdbD6uAQyfyt/xSM6BqacaEPuC5IegXKYO3s8fpBOiJOV62++MExoY XoEw== 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=s5gOoMgihpmFE4AT4VWG7sAvxuhwjZxcFhBeC583tSg=; b=tfZv744Gfx8Ed1gcnuCcGC1KShTMPVnonrm7eM/jQVZdhvFalVxvpJF4UHMNUImb6d QZ1mUcUnqX7SRgc2ihR38Q/gysJ3TmCCDP1+6v14YmEKdvYs+bbL6VaxqC/yxNdGwnfh kgiZE7FvmOPAzUGHAn9jIlqRxIGdtSkHdrfKDV14dOrJxe3zX3atxWFr7vYa6Sgw/3HG XjxcExkgfrLipWfYTUGxolfew5JjvR5R+XhL3Jnyv780NhH99AMRYXOGx6ocnVQhrJTb cMltYjFBPOBXKnQPYa0NqQreKFJyc7BxeYCx/HYkuaVs7fkdlFmDOGazVVbfLIl7efp0 BErA== X-Gm-Message-State: APjAAAUe8xXh3hqpEz+9mEMlAb8Qxa0lcZI6S8Y+mN2jpoZiXRpYbSkN yCV5fZJ8DgeNFzxtEM0WhmtKTg== X-Google-Smtp-Source: APXvYqzQVTjIGfrT1jUk3nzPkjgvfwG/MjQi55+dzSoCpkD32uD/qoCczRA/rnhlyYKM8qqAc2QJ6Q== X-Received: by 2002:a05:6000:118d:: with SMTP id g13mr27048661wrx.141.1579014607885; Tue, 14 Jan 2020 07:10:07 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 10/22] target/arm: explicitly encode regnum in our XML Date: Tue, 14 Jan 2020 15:09:41 +0000 Message-Id: <20200114150953.27659-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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: Richard Henderson , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell 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 bd15587305..8a1b0db5ed 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -966,7 +966,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 1f68ab98c3..69c35462a6 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 f05bd2fc76..b35e9d21b4 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -7141,7 +7141,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 Apr 26 04:09:25 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=1579015154; cv=none; d=zohomail.com; s=zohoarc; b=mtSeXogTpckJVaQGDU7j2KMYBLqVngMwqmyvSoVJbNsYPIjV9yyCKehJzAyY3sh8R0FVQq1H1i2xlG0NX0BCSXDvDoudblwGn8ZzgNUEYf6FcQu93SsTmIWum8vCCA9eIOk8+SzV1+rzVCEyd7ito0NiAakFzAOw16i01CCZVG4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579015154; 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=gtTyiABJNzKbT4Hcxk69PnKRIOdsWQYqpdkNpdscjO8=; b=LA4x7fnQsejIp9WRnsG/08xO2Ab4R2EyFjp9UiPyvKKmCQ2tRIx/QLkk5M5vnmjcTZlJQjY/EOSEllrnCO+E9YeYOdfM9+zxUvP/AfyEBbhWoTgHkN9VnbkexpTPgkEO3f/I/aDEkKwbw4jdq07KrXhxseGuJXZpnQ46HFGsru8= 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 1579015154037711.605199774208; Tue, 14 Jan 2020 07:19:14 -0800 (PST) Received: from localhost ([::1]:41770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNyK-0007nI-7h for importer@patchew.org; Tue, 14 Jan 2020 10:19:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37831) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpZ-0005B3-Q6 for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpY-0007W4-5i for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:09 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:36058) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpX-0007UX-Ta for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:08 -0500 Received: by mail-wr1-x441.google.com with SMTP id z3so12530922wru.3 for ; Tue, 14 Jan 2020 07:10:07 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id o15sm20309211wra.83.2020.01.14.07.09.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:10:02 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 0D12D1FF9A; Tue, 14 Jan 2020 15:09:56 +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=gtTyiABJNzKbT4Hcxk69PnKRIOdsWQYqpdkNpdscjO8=; b=fcSKaYL5RIXTOvSeIFKI2+EUmiNjinug2EPGoLbooNYoru9YNGgl1x94qyPf3+AKVB BsattieJNQUdOz5YEZsdsxUbq5c6FtO5M8D9mr7c8vbR0MOcXo3gR9evm0XeUSjB01M4 YhtpqauhM53Gn6c/YzV0rlGcNwKvH5CIYSgHV/RgZl8iNaNdg+MOd5lJUad6dQIgVgxE PeL7wVKIYyUVr7hgsm3HhKbuhh2VH4ypAjiyrzE868oRJKI4D58lGnrAIggDzhBMYOBS qPbay9MLlc1BznwI6AC+LtAoEDjvnFSGMvmzT2JvF/EV6Lh++chbkPMTO6dYaJK63cfO lC5w== 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=gtTyiABJNzKbT4Hcxk69PnKRIOdsWQYqpdkNpdscjO8=; b=bwKSdSrsdBDN1w0FB63ohbFGuMl5FtGOztMoGzPEHwH0iOZnnxdllY3ToTXLcMJQx1 IMgDmGZaa+cVu7C1isodepTpAEAriVU8U5sD77rLeQQb353k2bphXTXOqeoMU3LJ0W++ O2Sy26gti8xSsj8r/S2w/+VhCWThktUoG+HAOGe+ekc8EydCI40VkqvB85UOdh7CUs7E Cpj1ur01OvjByTOH51LMS4R2iLzIDelPBHCMebFiSxESPMcZz86kGxpotcdshvln6yoT s0LfNvWmcWzPUFVvKnyJJiquVvEN0rs9TyrysY+W5/q9yOKCSU70fcHFk+VtDvLLLcOI Wc1g== X-Gm-Message-State: APjAAAVPFtzSiV2NHifNdybWVLYCXQ2pJiG+au4oP6ey57gqAc7uIgiJ pk9x4+Q+mhHu+thQTKlS9ay6qA== X-Google-Smtp-Source: APXvYqz13a11d6b0hnHET0gjRyEJNHXz97y3j8DQkqIRXr8efdvLoGwZzBxc9dV+Ra1TFFJZKpJifw== X-Received: by 2002:a5d:6a02:: with SMTP id m2mr24831190wru.52.1579014606899; Tue, 14 Jan 2020 07:10:06 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 11/22] target/arm: default SVE length to 64 bytes for linux-user Date: Tue, 14 Jan 2020 15:09:42 +0000 Message-Id: <20200114150953.27659-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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: Richard Henderson , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell 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 d62fd5fdc6..1c1f34ee5d 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 Apr 26 04:09:25 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=1579015138; cv=none; d=zohomail.com; s=zohoarc; b=a3Scc/XiLrv52r/aSCVTxYqjaOJ4O8YouQn33j59ztVOa7LsweTiXAhRi14CTpSDPnlC1STzt8FvZbZ/Q0kZX8fMiWEVKxIHl6QEwaDPMztNUjS+V4veUVEt0FyfRDDoBPDUsRcXXOZ9gb6NFvBUW1mabpFzzxCHTX30YtQQuuU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579015138; 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=KMxaLug9goHbZTMmeMgVXMk1KLPtyKP3/eNWcIO1nug=; b=D3RhEha9Fy+ZUEOIH9TqhEPNggKVc5V59Nq8VyoxYD4REnOs5bEvmGVek6no/pBThbPMSj0ddz9jl3CMuopsq7AYOOMAp9EmGZEWEuDxdnRu3Y4D6nZ6NZ5oUpnGTVbHh8yZRdY+w08DntkIKWptkY+7tjeTNSBfmN0kVeIC2F4= 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 1579015138266611.6789836339574; Tue, 14 Jan 2020 07:18:58 -0800 (PST) Received: from localhost ([::1]:41764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNy4-0007db-CM for importer@patchew.org; Tue, 14 Jan 2020 10:18:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37934) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpj-0005PQ-Ca for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpa-0007Ye-Bj for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:19 -0500 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:33458) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpa-0007XV-2s for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:10 -0500 Received: by mail-wr1-x444.google.com with SMTP id b6so12545663wrq.0 for ; Tue, 14 Jan 2020 07:10:09 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id v22sm18781320wml.11.2020.01.14.07.09.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:10:02 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 3A35C1FF9B; Tue, 14 Jan 2020 15:09:56 +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=KMxaLug9goHbZTMmeMgVXMk1KLPtyKP3/eNWcIO1nug=; b=DD2VQxA+RmYH1kj+RHltNUi8ctEOs2ovdCyE2E8GScQZTw4dm8Al4yvvVpff5DgSCi QLM9cZoOM9B/hRxhdpjcexahUaEU22mLFWUsACDZOvSrAOhlihnAgVyH/fWDI6iApAV+ vMmkUrH2iHCCtmf0PXfwQgmdXKdp9ssU5R+CCiFJY2A5DHP9LYUvP75TopzNHjFGQHWD SNF4GfCkbJlmKw9UVRHaKY3E0MZxwGmJBZmKmjZ1JICt791RvrgkUnJZ3RR5D89AgC6J t7SM0kTT3NRiHP9Qi6AB4VbXlHXQ9WjibEfsjIvbA4RoU8zf3V6ma7TqCvkA+JILxF21 cyJQ== 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=KMxaLug9goHbZTMmeMgVXMk1KLPtyKP3/eNWcIO1nug=; b=d6JDmsFGqGd4J8UZtfMF9F290i4cPtFfwy76A//bYHGMcyPVPHdANvJFQ8LHMsmXJA Xd4ZTQ03Y8mBiJjAGa6Wss60wCCcQuiH0f0w4bWH2Yictz7Q49aLYlzFU3j89IHZD/1e mIYeER//5jjDv3AppenCk6xZzySkaxNw+UyGOcgh3WKogpQGPmpSFaUwaUSwiuhpulM6 a0YCOc6Y9MZm0pXjjSvFgyHPJzh7GXiTDF9R98eITEc4KXk6y1iAaRPysKep6r3aVH/D irvbiYeQ3pAbGaz/xxJK0RhaxsRXOqDkld0+8S/CY2MfXN0wGjxs+wXyX/PwRa1OC/kZ pTIw== X-Gm-Message-State: APjAAAWsnF+1hteSmiD4z2dkOmCwuUi7Oo85x+f/4kXgRmt3QJlZBYL8 A43sK5OYRTbsj2c3sZFlUBai3Q== X-Google-Smtp-Source: APXvYqzd6LrGQwqYhsa/ev1cZxkVBQF6eXOZPeTUhDSoJCWuJ6QUVzbRJhFHRyyRhin2i2YnlcGJzw== X-Received: by 2002:a5d:6284:: with SMTP id k4mr25344046wru.398.1579014608737; Tue, 14 Jan 2020 07:10:08 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 12/22] target/arm: generate xml description of our SVE registers Date: Tue, 14 Jan 2020 15:09:43 +0000 Message-Id: <20200114150953.27659-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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::444 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 , qemu-arm@nongnu.org, =?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 Acked-by: Richard Henderson --- 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 8a1b0db5ed..c268b624b8 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]; @@ -963,10 +964,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 69c35462a6..d9dc6b3fb4 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 b35e9d21b4..7dae067b3d 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 @@ -7127,9 +7220,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); @@ -7143,6 +7249,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 Apr 26 04:09:25 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=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1579015482; cv=none; d=zohomail.com; s=zohoarc; b=XH7SD9WFdgxyobtZKCblV+8T1B6lr7sdzdicEZyMxpOUGUliFV26w3PDYuXeYzvFCk0S5p2I4MZKmif5x2bvjEYk8oTcylrLPq0IBsNLi5gNAOIaN5fEXl9C2XqmkBMPls7D3HZiiW2Tm9R+ON3n4J6jZNrUMCxA36UWNrleUm4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579015482; 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=JbtXdfX5swqeAC9KUR1iSEagQ19S2uV9NFabci8QvJo=; b=lLHaaTIkqmyzqdto7J/ZTMkQPEH+aKbg+b2CgUNv2eQiz45BP9wJXfGIo8lgJnBdjlEROdOPTq9M99LniPPKGQiGqe5aufLh7uOtUwDCZWSy59dQEZlEB2fsopLadTuTgRLv6DUOxO0KX9z8xg3LXLSS0RZp8F11lsD11BG8u98= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1579015482243478.6887547134022; Tue, 14 Jan 2020 07:24:42 -0800 (PST) Received: from localhost ([::1]:41970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irO3c-0006h0-W3 for importer@patchew.org; Tue, 14 Jan 2020 10:24:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37994) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpl-0005Ur-Tq for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpk-0007i6-HA for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:21 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:36059) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpj-0007Zd-5x for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:19 -0500 Received: by mail-wr1-x441.google.com with SMTP id z3so12531195wru.3 for ; Tue, 14 Jan 2020 07:10:13 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id t1sm19255221wma.43.2020.01.14.07.10.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:10:05 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 566F91FF9C; Tue, 14 Jan 2020 15:09:56 +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=JbtXdfX5swqeAC9KUR1iSEagQ19S2uV9NFabci8QvJo=; b=xeSSSLHAaYDMNxShQEyr41CzxaTAsIBLo3YS5HxoGOhmEUYRJhlPC22e60/whtZSeI KaMpdeKavvGnU8Y7OBpNPSROdAKdIQr8r+mlv9dnfib34q/O937ha9iLW2ACR6kZiEhi V11FdT/yj5n8e9WFhWEhrql7L8Ey9WqGDCF8N3VowDaGyagwDRBKXnEMUGIKUbE0K+b1 ogBWmXPmMdiDtNcJ0gkpNSqCPQw1oUQL/1/iKFbeHm3tWA9CwLfdwttzRSVU9JdZZg7D TBSiLhHRZbFdHW3KQ+8UrxnhfkTEIavD5ZEI1+ZWkEXEQFAIy4AqJDUon0mxKnoSmIOL /IfQ== 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=JbtXdfX5swqeAC9KUR1iSEagQ19S2uV9NFabci8QvJo=; b=SpQ2OT+cQGwj9WDcJUkBfynhtVea316isi8+Xzzyi4Q7dGr4Dj9TI9tYMlyxGjNYXe K5xQdYa3uyL09PPey1sGbCOnA2We/pMfYc6NeSZZykUxOHtARR70Otmzcl5E1U4fBuOh jnhcTLfwjRcpp/XIVhjCrnYmLdR/4xaK5e3ZgDRP43kuyDVAmUJjq9BuNLPmETc8PiNN Pkgrg+MQHCs06i25K+conJqMoRIOIa1chucQuaj2Pic63YwZRQ2RHqbcjeDnvIfok7UX pajBuRIlHzTA+bxNMJzDAZF5DvHubX2J/Vb1ePODX4yAn7+ebuNOJOS4jbCa45lN1jJB yFZQ== X-Gm-Message-State: APjAAAXzz3PoFb0GCvZHa5zdGdFOQrNSKPjxSgSOI9MEwCHE6QkpnvvR 4w61CdGJqFENfykH+QlNSb2sUqBFLNg= X-Google-Smtp-Source: APXvYqx4b+8I/+Na4RL55vm2z2GMFW3NR6x3tmQDBDKOozY9fJO4Ub3pDk+xhxt2JCtFdYFojccpmg== X-Received: by 2002:adf:e641:: with SMTP id b1mr25603676wrn.34.1579014611004; Tue, 14 Jan 2020 07:10:11 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 13/22] tests/tcg: add a configure compiler check for ARMv8.1 and SVE Date: Tue, 14 Jan 2020 15:09:44 +0000 Message-Id: <20200114150953.27659-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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: qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) We will need this for some tests later. The docker images already support it by default. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- tests/tcg/configure.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh index 210e68396f..e0d1fbb182 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 Apr 26 04:09:25 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=1579015027; cv=none; d=zohomail.com; s=zohoarc; b=DbuGQuzdoC/nf1l9YczpJJTvsov+9JTf3yap/Ep/9o5oM/MqMOHB35uMADM7xoKOR2sDIKWIl6AJwkTXZ71QfX+D4jrnl2FLHTO2erD7nZ2lXrjp/88fPS8LnljBJWgDPRv8me3bQLBl/mF/aEDRy4FGrFIDURMDoEIaaKYw7sQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579015027; 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=anlfnB/asVkTJ6RtskIPp90azP/8H+sHTGGY0UbzreY=; b=SaRoleUT+k2BgHAXKuyWEuEoyWyx2Urp5L9XbpI19Lh5fZZd3U+hUYSqX2c9Zjy9d+iu9NwLJSkuI7yATe/toMeWd1gTGOWjJ7H35tJDnAfDp1eCOilAhO8YsOQ/5QnY7AxpeHanp/Zd4izVZ9efgIVsOemJyejK/7GMI7aT/WA= 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 1579015027373368.2336665647298; Tue, 14 Jan 2020 07:17:07 -0800 (PST) Received: from localhost ([::1]:41732 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNwH-0005KS-Ke for importer@patchew.org; Tue, 14 Jan 2020 10:17:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37962) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpk-0005SF-Ni for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpj-0007go-AA for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:20 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:45515) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpj-0007Yx-15 for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:19 -0500 Received: by mail-wr1-x443.google.com with SMTP id j42so12479288wrj.12 for ; Tue, 14 Jan 2020 07:10:11 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id t81sm18850690wmg.6.2020.01.14.07.10.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:10:05 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 7D5B71FF9D; Tue, 14 Jan 2020 15:09:56 +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=anlfnB/asVkTJ6RtskIPp90azP/8H+sHTGGY0UbzreY=; b=K4bGHv/xQxqrTpz/FO5r/p0qqat5XJ9cHKNgajOby8XNuyQzd3zh1/L4BaTd+6FA6d BxCqzaIoJ9CYKDl12zIL8Odvi7Apzf4oPLoBTRMmqwiOwDv+PKNtAtdfm2vdScNUngmm Q2tg2G/MlG0ZAXugONgei1cQWDlWd/Epzr53yWMKshfhbpIXeYO/w63axPK9JnQpI6q9 /X56kCn/mL0UvgEj37O6Oki8Ro2KLJOebwsAS8aL/hO7c8m2FJoFlIYwPCBuXiGrtNjh StldL2VahypN3idKTPoLJCHhhPrYxFIGH59YgelDmZZqU8IWulR+uYIj6RVGXhIA+p5g YJ9g== 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=anlfnB/asVkTJ6RtskIPp90azP/8H+sHTGGY0UbzreY=; b=e2Cii8XCtSrUEZk3em5QLUcqjWPFitbKaBvskTTz/ynUrAi4f64uuHC38uuWMAAbCZ lcEd88lVLl7A5g7MxAwBFV8X6pbmYWX/OjWUIChrvL/217AahyY8cSJel116vyfR4V9G SoR1JHUvC0MbFPaNBW3F4UIdbeShnEb59tREILau/xdwOuqFlrilOGClr48/Bjmn8UPj /UlfyUgwzSZBzhSUjukOKLYOgEe3CsZTmqeMI2CXgAts1KM1gnjkGygo8z1mdcH4/MxM YVBT0sUscLGn+1bp7Tf1u4zJQG7045CYe5DfNMjPCmp2P71BD3XwBlOMC6HAjJQO8ZmK 4Znw== X-Gm-Message-State: APjAAAXOsKQ71s75pNVIWacdlcLDbez4vX5bpk1M/qUIUokSJx2xokt0 vQfntuEG+PR4DAAyCXUIQCtuGA== X-Google-Smtp-Source: APXvYqx8aPeZAa5gP1bUwmmzsgi2v1cxVe4V+wRbiSJlTrpHfOFGT8ui4x/nRkgJMeERruuPaV6+ig== X-Received: by 2002:a5d:6408:: with SMTP id z8mr25868916wru.122.1579014610055; Tue, 14 Jan 2020 07:10:10 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 14/22] target/arm: don't bother with id_aa64pfr0_read for USER_ONLY Date: Tue, 14 Jan 2020 15:09:45 +0000 Message-Id: <20200114150953.27659-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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: Richard Henderson , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell 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 7dae067b3d..79cad7aad1 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -5924,6 +5924,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); @@ -5934,6 +5935,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. @@ -6426,16 +6428,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 Apr 26 04:09:25 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=1579015892; cv=none; d=zohomail.com; s=zohoarc; b=ONv56yLo3a4VVnBLcmcsJXg6io1TOIVNPqvMHZFvKodLOoIIjZlsQNZbTMSTVMaKH3c5Mesr6ktZj/m0VZTlFDaVcIDTYssRbmqzJrj1Uxz143Boh65TXJgqejn14siNgadrBWdch9yG4UQ/VfB0lcVhTCxdJ/updQcDStODTio= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579015892; 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=e/ywfEymUtAQ+b/LCRs1BmsfC4V13XBWUwEYC3VS5sA=; b=WJIUMPia2lEmlWIRDP4dFrgW8ReA7lZ29t1NVzgz0vd/Y0Ub17ZT6BJAnaCUZm3Ioza6G0s0JwaplR3Dj2Nw6Wdq+8s5p1nnehyvYliQF6LDV9lwQyPFVioeFVZ/gIfZ9Ahv2sReaYs7ParqzBFjfQKy7uKHRDNnFpeVWjwqVow= 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 157901589227876.90388562427313; Tue, 14 Jan 2020 07:31:32 -0800 (PST) Received: from localhost ([::1]:42158 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irOAE-0007IR-Th for importer@patchew.org; Tue, 14 Jan 2020 10:31:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39784) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNxz-0008Sf-LS for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:18:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNxx-00087W-Uo for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:18:51 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:36118) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNxx-00086A-NE for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:18:49 -0500 Received: by mail-wr1-x441.google.com with SMTP id z3so12563582wru.3 for ; Tue, 14 Jan 2020 07:18:49 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id c4sm18991741wml.7.2020.01.14.07.18.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:18:46 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 9FEF81FF9E; Tue, 14 Jan 2020 15:09:56 +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=e/ywfEymUtAQ+b/LCRs1BmsfC4V13XBWUwEYC3VS5sA=; b=WMyeXpl2BCg2CLBBHuFJE+G/M3EeCI4CJSGCjzTGtKwd+B8JD5qzeSMNiQPx5gTkrp imlzrGC8Aaw7PlzUubIqepIObVvBz/WiwekLV8cGPTa7qJobSuKOu8h9VybYwsQeBzrB qmg0jqUuOFcuxBJEjMLPheRza/Rpgi7I4QFY6akS8Pe73BowFAOiovfVaIvSeppLp9tx CFdcLGIgGoBJR3+vbPcPgCNDUrsmZaxf7WHEPFI/IXTW1YswGV52rB+qNFCp2AJ+eCX8 Xth+m2Ui87kpMrfvM/GoNNV5OlCg8X2pI49pplz3hLHJ8hifpj43F9d55ngXzyIM8s8x YF7A== 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=e/ywfEymUtAQ+b/LCRs1BmsfC4V13XBWUwEYC3VS5sA=; b=optUQtkB8SbxgYjyLfZ3NAXbOKvjnLXcK37TV0nV1PVHTUdl3WRv2IOF3Wy6I6rYx5 37JvhibwlRj77JhdYfu1gFtquOYcp9QtWmF0aUX1by0ooemCQEoGFUimVkVRaTFgyo6S XT2KfzitW3rbkAt+EgWG+YD6m27C/SYkKX8IpXAxwY7aMJfR3u5SnnBcSaTxI/fyyTa0 XdkxmsBlMtXmyhU+OE+TJrZ+9z5h08d4sT/AcDGDZzwtDNss/gLLx9yVeHqby5lpiRmq hgrJrFaBPncRnBFp/0N/vPTr/3tPTe7VH8zBB4f1HM5PRmOlBWz3vJIRZcjiZNg+x042 mDrA== X-Gm-Message-State: APjAAAVrzuHemnGRvoXz9WposyMhxGQxnUJGj3aWAZy7tfnSSWznV/h2 mayoZqIgNC744indOh1Z+4NjGw== X-Google-Smtp-Source: APXvYqzPYcPWvGGEfaa/nbxwI3VoZWQxZSFpzcxdowBdvO910pUOBF8IsPusPqhjIapvdqCELqEn3w== X-Received: by 2002:a5d:608a:: with SMTP id w10mr24173141wrt.136.1579015128508; Tue, 14 Jan 2020 07:18:48 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 15/22] tests/tcg/aarch64: userspace system register test Date: Tue, 14 Jan 2020 15:09:46 +0000 Message-Id: <20200114150953.27659-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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: Peter Maydell , qemu-arm@nongnu.org, =?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> Reviewed-by: Richard Henderson --- 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 0000000000..40cf8d2877 --- /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 df3fe8032c..afcbd06467 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -39,4 +39,10 @@ run-semiconsole: semiconsole run-plugin-semiconsole-with-%: $(call skip-test, $<, "MANUAL ONLY") =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 Apr 26 04:09:25 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=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1579015459; cv=none; d=zohomail.com; s=zohoarc; b=Ix/DZCP3okgPWcqoDEKltadE8FLXTAA99YVvd3gtLkANLRkHlA9IL4Z873pBdcJe8UALLmgUX8dHFrocu8rLcne1U5Mf5DzE7WvzbT/0MsrlXIFAITblYKFg90BQKoik/npEWiyNYAWOrhUY0hj65MxE8STxzj7o70Tgy0GRdeI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579015459; 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=NwJkJGKdheizEM/DhEJNn7UgplpcwW/3CxupFcFkyrM=; b=SuVkScnvzuAWk2XOCTlKJXl7QxaFTaeOqx9eR1i166vKtQ+3WJfgZ2vp2fkh4idRGDTUoHA0pCFxk9579fcIoadzrlWPd7+GBkC4WJ47Or8gt+kIQHl9B2UQwTKWEOe0sUsIE/FvnOosCGcCeFYmDOzh6m3evROOnUcPEFENqxE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1579015459828825.1767929720577; Tue, 14 Jan 2020 07:24:19 -0800 (PST) Received: from localhost ([::1]:41962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irO3G-0006A8-7N for importer@patchew.org; Tue, 14 Jan 2020 10:24:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39752) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNxy-0008Qa-8R for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:18:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNxx-00086M-1K for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:18:50 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:35758) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNxw-00084N-QB for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:18:48 -0500 Received: by mail-wr1-x433.google.com with SMTP id g17so12549637wro.2 for ; Tue, 14 Jan 2020 07:18:48 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id b137sm20168534wme.26.2020.01.14.07.18.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:18:46 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id CF17D1FF9F; Tue, 14 Jan 2020 15:09:56 +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=NwJkJGKdheizEM/DhEJNn7UgplpcwW/3CxupFcFkyrM=; b=Otgo+bZSIwT/Co4+uODiZE9Q1nhvPmL6COUYRtPHYY6sEX2Vc8gfC/4jEr37DPKQyd t4xhM5m/QgEfaqT0YRxreIGbqw3G2yyDMUtpARzMxpE3pKQpk/swJkiYR4swLqzrkoYb cCjSQbn0JQbucP2CVcgJGAlXPeRzlx8E7zQ2C+a6HnalurCe1OoewYb++8Oj1JO8Htj7 VXusZr7gGdOWrefaS+eOaoujupci8fHu4hYSK5EbUuRWbqZAH0npSrObUKmGCsAKo1Wa EkVc0AxcMNLlfxoPFPEPlPdg6kPw1yvo+v/UxH8W7wvKaz1yTKx/YQB98fpfX4EabEw+ 7hmA== 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=NwJkJGKdheizEM/DhEJNn7UgplpcwW/3CxupFcFkyrM=; b=Om0pqYEgcectmcYMNPrWwH3usdDQE/vv9pkjUXgFah442eLcGKoqgaDIlXst4YCtWk Ko83d/79d4+f8NyO0vCUhPfuHslUT3/hwWwQJUmp/lz3jZR4OGHgQ0zlacfHcIHEiAec Jj94JWJvPHDIEH8Egv90N6X8/tPd5NXzIXFPR6cqYeZ4czdXg/PC9+pvUo5EpTL6wd/4 PYJPgfOZvRe1wsyZo7yLkeXpV1R6Wa8ID3AKdR333IFSnelISJv5SNhtg4/X4idp5r5i R02FCHenjZ/m5O2lmPduwFsRDqruzvghSTYOdNermT5q2otB4Dqoh9ebH0kW2rHilK3/ sG4g== X-Gm-Message-State: APjAAAUtI9j48DRsB7NOVg6kVUO3RY9CLK4XBmI+1JkzUUv2v1P3zTP0 kFHpqimstAkit7oLt5DIXvjZjQ== X-Google-Smtp-Source: APXvYqyM84CN48MqIEhNJOgzV/0t52+FuI1hb4v/ucQFRXde61cl8h1MC4Kce1rlEteL3+jhLv7qlA== X-Received: by 2002:adf:fac1:: with SMTP id a1mr24883862wrs.376.1579015127408; Tue, 14 Jan 2020 07:18:47 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 16/22] configure: allow user to specify what gdb to use Date: Tue, 14 Jan 2020 15:09:47 +0000 Message-Id: <20200114150953.27659-17-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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::433 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: qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) This is useful, especially when testing relatively new gdbstub features that might not be in distro packages yet. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- configure | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/configure b/configure index 08c3a1c1f0..df702a708f 100755 --- a/configure +++ b/configure @@ -303,6 +303,7 @@ libs_qga=3D"" debug_info=3D"yes" stack_protector=3D"" use_containers=3D"yes" +gdb_bin=3D$(command -v "gdb") =20 if test -e "$source_path/.git" then @@ -1540,6 +1541,8 @@ for opt do ;; --disable-containers) use_containers=3D"no" ;; + --with-gdb=3D*) gdb_bin=3D"$optarg" + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information" @@ -1724,6 +1727,7 @@ Advanced options (experts only): --enable-plugins enable plugins via shared library loading --disable-containers don't use containers for cross-building + --with-gdb=3DGBB-path gdb to use for gdbstub tests [$gdb_bin] =20 Optional features, enabled with --enable-FEATURE and disabled with --disable-FEATURE, default is enabled if available: @@ -6576,6 +6580,7 @@ echo "libpmem support $libpmem" echo "libudev $libudev" echo "default devices $default_devices" echo "plugin support $plugins" +echo "gdb $gdb_bin" =20 if test "$supported_cpu" =3D "no"; then echo @@ -7422,6 +7427,10 @@ if test "$plugins" =3D "yes" ; then fi fi =20 +if test -n "$gdb_bin" ; then + echo "HAVE_GDB_BIN=3D$gdb_bin" >> $config_host_mak +fi + if test "$tcg_interpreter" =3D "yes"; then QEMU_INCLUDES=3D"-iquote \$(SRC_PATH)/tcg/tci $QEMU_INCLUDES" elif test "$ARCH" =3D "sparc64" ; then --=20 2.20.1 From nobody Fri Apr 26 04:09:25 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=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1579016157; cv=none; d=zohomail.com; s=zohoarc; b=O9J10BbLKvASy78qpg1RWpqM+VfUETcN+1AIaRdWksTtfLQ5EuA5KeGqRG5mv6DatzYNuXHQTkuJ3SfKa1L4fIz1BYJgj2fkGno6p/i06V2a8kcBvz78FYWQpRVAB6mT7DbMfRbYHy4cs2vMuuQCj3G7zCV8Ojph/lQd1tIoBnA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579016157; 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=LEKvEpKhHPViJyLx2EXDEbN/QgNSwiOpcgG9WyeULSA=; b=gU0AVOjxzcQdXGTl3QA9YueMovMd5Td9uyY/80cW4cr2NiMWeOcxmUHSuhq/Om4yU+d3/logIkIyJ5y1uAhyL4mx8sGfd3aEpuv6+agmWIU+CeJf0SfZLgGPZ0SjOXIjZ5Y3e4RMPInYQN9dVNjUOfsq08d5Q8eKpAm5GidmXj8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1579016157575673.0092700895464; Tue, 14 Jan 2020 07:35:57 -0800 (PST) Received: from localhost ([::1]:42256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irOEW-0004Qy-7H for importer@patchew.org; Tue, 14 Jan 2020 10:35:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39802) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNy0-0008U8-GU for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:18:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNxz-00089s-9l for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:18:52 -0500 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]:54455) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNxz-00088F-2Y for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:18:51 -0500 Received: by mail-wm1-x32c.google.com with SMTP id b19so14212429wmj.4 for ; Tue, 14 Jan 2020 07:18:50 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id z3sm19933150wrs.94.2020.01.14.07.18.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:18:46 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id F41651FF8C; Tue, 14 Jan 2020 15:09:56 +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=LEKvEpKhHPViJyLx2EXDEbN/QgNSwiOpcgG9WyeULSA=; b=BdV2npNYgh2Or/5VOFsAlYXs1P02sIBeywwV152kmehNM/VCCXY/3EoiiFFRqs45qc GrfrFKNW993M6YQQ+l9xSfhoLi+Rfyx6GTuqYwT4ofm+ipetLinfI4vQo8kjoSyICyE9 xMYUpy2ya+r4yiEjRg3PP6w94Cgv22sqGnBR86FT3WTVQvnVoDqrWhpUVN/SVFQf8rzl BjzzK5n9PxX4XSW2p6pLcxLlMdy5P2bVUUh0jG2dhEwgYLNHKgFK3KNgQpIg1/tLv6Ev DFO/teLflsBHKH5O/T2hVdB0FSjF4XjfrPaW94bhP/5f9Wc3cYswJh2Q5p7opQhBWsTi YecA== 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=LEKvEpKhHPViJyLx2EXDEbN/QgNSwiOpcgG9WyeULSA=; b=nhF9hhoggA+YRAyx/4qwoM+Lh8TKvapl+k0QHlCKQbCgmhXChwAL/5Ck+C/u/s30L1 L7yWH3M/cm7xJHjOfbBvkAfnBYYmg8XendXqcQ8CuZU0BZW6CUsP/D3xThn1zknuE/hw t+mdHZTEEWft8MrOj4ad2FunV8FJt56uWUJgtl9+/h6Qr5APllAm7iuTkbXzrrC2omXF sHAmGoCjgnDrGQkQnXHmOgLREehXA7KmwKJ4ZDB2ZUgIvbmilkrnWQy5C+x9N5DD11MS FaN3Mpbnrz6QErKNlg6JbAniXSBYggx/iibuubRXJ3nR8880MHMYBmhvgpUwzy8/213L YHBA== X-Gm-Message-State: APjAAAV0diqvu57qB7pVvBm4OPTM3sNQTrIJOPKMecF0pTMRy0ceD9Go 51xGkkuXkT/0YjoKbTHq+Crgiw== X-Google-Smtp-Source: APXvYqw+8JsPmqj/MAPAobxevrEsrDxqo5az2CghVZ7uwMAbnjuJJ7eXLKM0ihZ8jaJJdJ+onpu52g== X-Received: by 2002:a1c:66d6:: with SMTP id a205mr27933680wmc.171.1579015130072; Tue, 14 Jan 2020 07:18:50 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 17/22] tests/guest-debug: add a simple test runner Date: Tue, 14 Jan 2020 15:09:48 +0000 Message-Id: <20200114150953.27659-18-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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::32c 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: qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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 Reviewed-by: Richard Henderson --- 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 0000000000..8c49ee2f22 --- /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 Apr 26 04:09:25 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=1579015828; cv=none; d=zohomail.com; s=zohoarc; b=OOOojD58kXfkO4N0aDTuHic6ckcE2niMfpWfbgv+J/D3HqL/qJXa+Q317wsCEI3V48t/Xt9x0/vyb1UVgfSs4XlO7v7JDEzi37gHVwYboz2PSJTcOdjEJWSSt19utVoR40+YYHWvUfwzMQHM1UM/ekp15Iua2PpIDHaM5hO+WE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579015828; 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=RS8nsqaOjTUj87+40p6EqU+Bu6aWQBCN9gEX2YyFJYE=; b=XxYa3dVeztbaPnx6sFHbNlukdW+evdTdp50ukmabneE85e6VBuV9/Jr2pPy5gRLLImcVsxtaAssV5N2/TliYVIoIQykuacZrhogE6/KHOtKXp6Wc4jM27Uwwo03LcoKtQ2FhUt1API5xq5hoVI3sMYhGwTaup6DwiNcZYbzS2+g= 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 15790158286091021.1702305708559; Tue, 14 Jan 2020 07:30:28 -0800 (PST) Received: from localhost ([::1]:42120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irO9C-00067l-Qw for importer@patchew.org; Tue, 14 Jan 2020 10:30:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39893) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNy4-00008n-K3 for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:19:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNy3-0008I1-7l for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:18:56 -0500 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:37766) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNy3-0008Gw-1X for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:18:55 -0500 Received: by mail-wm1-x336.google.com with SMTP id f129so14183226wmf.2 for ; Tue, 14 Jan 2020 07:18:54 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id g7sm20007100wrq.21.2020.01.14.07.18.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:18:52 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 2773C1FFA3; Tue, 14 Jan 2020 15:09:57 +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=RS8nsqaOjTUj87+40p6EqU+Bu6aWQBCN9gEX2YyFJYE=; b=emYzfYx1qwLcpZDbe525DuLuOB+WHytphlRLtN8uyca0lSjjLDPNM0hOxTMtdYioQi embBcDoahMzv8lY/iSNPoh91tljlVog6kj2155i35lms89eADr9HHxy2LAycLLnnjQe1 YUQ8L9vJvnjwrf4wKxTtoYyyxauB3Mp+3jtAztV64Ez4v2ejWka9uMkn6twlp2htgRXi BHmZVZZb0YM+8XaF3PbPVwjj5C9vT8HoB+d9IuhY3cVYfYpw4eyHTcjapqRnUXG40eZA cy4KrUQtp+j7YyTokBbV02RElVsQ4r8J2OtRVQsUDmYYuQB6I3d8h2qvRFCrjTyC9JtB 9BOw== 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=RS8nsqaOjTUj87+40p6EqU+Bu6aWQBCN9gEX2YyFJYE=; b=CLiIj4TQKOPRm+L+oB7hbVqmRWMdXEZHQb4Go2n7RFjQER8z2XlNXEZy0LJyzGWHXl gTOg07xJ5vieQ59p0XTv5Ua3yi0Nr6LothzeVLNWDgk1y/H1IoSE7zICZpaSyXPXG1Pe pqRBYuHh0wff0sjfpZ6j8ZrjySF50CTpQiSpyEogVmxu0xx4nR3CynPpGRUF0s72j5kM dFGFnG8U89N6Ls5w/z7ig1dmXxUoTSCP5ZrctaA7tr2nQXWHYqcpWhToZm62XXhlt/RV v3JbKfPr68h70MbCKvyTo/+2AaYcweA9XMFpOEGcHqTGgyMkCIaC3e62yG+kkSBRggU7 DSbQ== X-Gm-Message-State: APjAAAXcrxB0oa69+nGXmyP6y7TKg92oU4M/O5ceL62hQezUuNe1d8OQ gdwtYzAnH5Kuf1kCZk19luWkKQ== X-Google-Smtp-Source: APXvYqxIYH1YAJJ4aCbxBaYcwxpe05Lp8AeU408aavH37IaE15F9LQFYq7Du957vlD+jB2SeQlgGqA== X-Received: by 2002:a1c:9849:: with SMTP id a70mr26009288wme.76.1579015134028; Tue, 14 Jan 2020 07:18:54 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 18/22] tests/tcg/aarch64: add a gdbstub testcase for SVE registers Date: Tue, 14 Jan 2020 15:09:49 +0000 Message-Id: <20200114150953.27659-19-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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::336 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 , qemu-arm@nongnu.org, =?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) A very simple test case which sets and reads SVE registers while running a test case. We don't really need to compile a SVE binary for this case but we will later so keep it simple for now. Signed-off-by: Alex Benn=C3=A9e --- v5 - properly plumb in - skip if fails to connect --- tests/.gitignore | 1 + tests/tcg/aarch64/Makefile.target | 15 +++++ tests/tcg/aarch64/gdbstub/test-sve.py | 81 +++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 tests/tcg/aarch64/gdbstub/test-sve.py diff --git a/tests/.gitignore b/tests/.gitignore index f9c0170881..8cc428b58b 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/Makefile.target b/tests/tcg/aarch64/Makefile= .target index afcbd06467..aba17881e9 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -43,6 +43,21 @@ ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_SVE),) # System Registers Tests AARCH64_TESTS +=3D sysregs sysregs: CFLAGS+=3D-march=3Darmv8.1-a+sve + +ifneq ($(HAVE_GDB_BIN),) +GDB_SCRIPT=3D$(SRC_PATH)/tests/guest-debug/run-test.py + +AARCH64_TESTS +=3D gdbstub-sysregs + +.PHONY: gdbstub-sysregs +run-gdbstub-sysregs: sysregs + $(call run-test, $@, $(GDB_SCRIPT) \ + --gdb $(HAVE_GDB_BIN) \ + --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \ + --bin $< --test $(AARCH64_SRC)/gdbstub/test-sve.py, \ + "basic gdbstub SVE support") +endif + endif =20 TESTS +=3D $(AARCH64_TESTS) diff --git a/tests/tcg/aarch64/gdbstub/test-sve.py b/tests/tcg/aarch64/gdbs= tub/test-sve.py new file mode 100644 index 0000000000..90201d8009 --- /dev/null +++ b/tests/tcg/aarch64/gdbstub/test-sve.py @@ -0,0 +1,81 @@ +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 +import sys + +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: + inferior =3D gdb.selected_inferior() + arch =3D inferior.architecture() + report(arch.name() =3D=3D "aarch64", "connected to aarch64") +except (gdb.error, AttributeError): + print("SKIPPING (not connected)", file=3Dsys.stderr) + exit(0) + +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) + +exit(failcount) --=20 2.20.1 From nobody Fri Apr 26 04:09:25 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=1579016096; cv=none; d=zohomail.com; s=zohoarc; b=Czn3s9WpO1LsAylrnMdoqufXodh+AR6kQC03BCwK0nnpXVSkImBhPPY6Xf9umo66LqkWTjd4M87docQZCHdvpp2yVYoQ7k2hTj/1lOUZi8FkLCEDel25rM+s/VaEo6ia2eKSI2GEmCUpwmlH8ml+As02Zb7WXQTjwUvyv9r1wRw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579016096; 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=xrL98QqACLXFusR89lTBCTfiY5Snnqcv9MdmoeZvdOo=; b=LHIoEPI266HvHt9espajA0cyK8TZ6LJs8PtZSkDOujrFCb37f8vF8c5cfcVN1Ux1A73xP5q+J3Tgmcg2AJCDXmgkKhNDhuejJUXzlkEfcPSLvXhn/teXqWU6Fc9nUyArlLxDTIvwDtnWwEdckY0ttwXLpYQytuTVI1nfXxAmSec= 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 1579016096278624.591659447042; Tue, 14 Jan 2020 07:34:56 -0800 (PST) Received: from localhost ([::1]:42202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irODW-0002u7-Mq for importer@patchew.org; Tue, 14 Jan 2020 10:34:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39836) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNy1-0008Ve-MF for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:18:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNy0-0008CJ-92 for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:18:53 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:34218) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNy0-0008AM-1m for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:18:52 -0500 Received: by mail-wm1-x341.google.com with SMTP id w5so2542662wmi.1 for ; Tue, 14 Jan 2020 07:18:51 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id e12sm20071276wrn.56.2020.01.14.07.18.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:18:46 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 4C9141FFA5; Tue, 14 Jan 2020 15:09:57 +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=xrL98QqACLXFusR89lTBCTfiY5Snnqcv9MdmoeZvdOo=; b=NkuuiJr266TnnVPr6qsppAHjvQeT4H7FxJV+ZaH5d9qQ7h/rhsLtxftFLSG9ZghxUl tCa63adg9CEC0hEr1FXhiZgtQXfIjPWLL64NXOEaJ4eq4qqdWCy9Ej5huL74YbN8frLm +KCVUmOqhFBPG6XkBcGb0Jzi6abxhOahUapxoJ5hZ8BoUweg8POoZk3dHSt1K7tJLtAQ hf7w8lnBzn7+K5Jp2cLn5CxHddrpWxUJOzJo3j+Q2ZDQyrY7sBp7MCIXdXUxaXXFqlaP H+kXUoStt/kK/S6WODZ9ml/qdNafrFDQo9Hwwucq518kA4mOw64XAYChQRzYjSNhjYX9 p9TQ== 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=xrL98QqACLXFusR89lTBCTfiY5Snnqcv9MdmoeZvdOo=; b=HAsyVH+nA9U7HcsVMxAm8pw0m9zv2U5SU7ZJNELeGSRHD7DDz2VTKl6HTsNCEVuDqZ tMP7tc/MAOsopFGTjsI67+v9oXOB23cRwoHgM3nOq20qpN9hHTL48UEp9Ja5JlvHU1pR Gx5E1pi6H6k4n0xQunFOvYv+TzLaUaVNnUQTZeVJS6kb+46EgETyzPMPKkgeipG27HQm sktrgXyZDzFZKuhIeZb6A2G48CERfUIIDPvbxE477IJcr+kcgCw+9wzU9N5WI52TcqC2 F+5HELAiH+8GmyHf6rXxv8B1GLSsnOffA5qdGgLaGVohjBHRPGLWYQtdTaCEKzWQbCyU stRA== X-Gm-Message-State: APjAAAXubXYo3YGUWWvaSoiIk6eZpnbKM+okclr4IvBgmgzeR/07mylh uabmdj0MY6I6/yz92cW/t6AMl5slZiA= X-Google-Smtp-Source: APXvYqyE4P1iWZZcynEvHUw0hu6tvepVJWJncA7lu8wLuIWRtcBv8PKkSSnBPQMXBhrG8Ujc1LMSHA== X-Received: by 2002:a1c:6707:: with SMTP id b7mr28589201wmc.54.1579015131028; Tue, 14 Jan 2020 07:18:51 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 19/22] tests/tcg/aarch64: add SVE iotcl test Date: Tue, 14 Jan 2020 15:09:50 +0000 Message-Id: <20200114150953.27659-20-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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: Peter Maydell , qemu-arm@nongnu.org, =?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 v5 - merge conflicts --- 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 0000000000..d7bb64d53f --- /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 aba17881e9..66addbc52f 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -44,6 +44,10 @@ ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_SVE),) AARCH64_TESTS +=3D sysregs sysregs: CFLAGS+=3D-march=3Darmv8.1-a+sve =20 +# SVE ioctl test +AARCH64_TESTS +=3D sve-ioctls +sve-ioctls: CFLAGS+=3D-march=3Darmv8.1-a+sve + ifneq ($(HAVE_GDB_BIN),) GDB_SCRIPT=3D$(SRC_PATH)/tests/guest-debug/run-test.py =20 --=20 2.20.1 From nobody Fri Apr 26 04:09:25 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=1579015634; cv=none; d=zohomail.com; s=zohoarc; b=brkX+g2/7Mnm6keI+ZxDpkJBrYMCvK8D1cwKfqoMGpiNreIvuHhfdDQAxJ7PfmdcCGp8rT5cV8ZIFuLYTbn0OtaWCnHTti0QvCK87SmO1MyISPg591Wwk8t3xMrgXNQBsyWw3m3D3q7CIXmFwjlf4gtz6AAvMHRi8IEKiZSv/vI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579015634; 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=EPas9RAwcTKazprjvyJbjCOrku4t6UH+C/f0DKBx7ts=; b=KSI+SC4U1ujZ/DOJenByCDTwt1XtscftOOqaTNg15gdFk6FZmypAQLKwSceOxOr8t/4nxH7OxDXHyKRKJAPsKeXt8AeYDNNC9d6JYukpSN+uD4Pff0zlmEVOCPjdgj82otRn6rKfCAftaja7V2bceOPgZB1V9+M7QIg6lwTZXVk= 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 15790156340631012.2912193814566; Tue, 14 Jan 2020 07:27:14 -0800 (PST) Received: from localhost ([::1]:42052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irO64-0001vw-FD for importer@patchew.org; Tue, 14 Jan 2020 10:27:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39859) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNy2-00005Q-Ks for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:18:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNy1-0008Dj-6p for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:18:54 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:43600) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNy1-0008Ch-0F for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:18:53 -0500 Received: by mail-wr1-x441.google.com with SMTP id d16so12547791wre.10 for ; Tue, 14 Jan 2020 07:18:52 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id p7sm18489517wmp.31.2020.01.14.07.18.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:18:46 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 7B9FE1FFA6; Tue, 14 Jan 2020 15:09:57 +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=EPas9RAwcTKazprjvyJbjCOrku4t6UH+C/f0DKBx7ts=; b=jZba/916s27vJxQX6tojUJvd9miShs2H21F/VFJSHsQh1ZPii9oX2mV3bBJnQGs58C 721/cD0XHGZzLOdHfWz8CqZBvnPex0osMKPqBISShzHptPT7ulc8vL7y533EwtzmlwOo auzRL7sx5UkgMqF93OYerFCG6jMuY5cBYsTEdXWnprMouAB/D7jbsddm84tyqdjFaDuO SxTUGkqb/+aJEAMpwvqqrQ4BwilgmeMr8uNq6uzZ6XauKk/xcuqXFxsc6Rn8o2By+n31 AyVe5DFO1s8QiLsjdIqjCMXU1Z8Ro7aOhbJZKpnpbFRDGDo36LrEbX/ufmphIrymnT7+ Ultw== 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=EPas9RAwcTKazprjvyJbjCOrku4t6UH+C/f0DKBx7ts=; b=Q1vB3lP3foMhx3NXZJ81tm0ryPIPe4yc1fTCgN7TSOc5cg1gO650s8I4vqifMJhqi3 UGjWRz6QTXu7S1aHrGAs/WgxrX90I/1sLfxLjTgA/fuBdJrwYE/wlaT5jKgGPIM66xPU e17rw/a/ky9oa4cDDvYAC5df1i0xczQZB4HYMNcXZVigJiEOuH9RPbFUZHqiNh/SKOuX W/S2o//Xl6fEQmyabsBbVSdsVgnmAaOGsrVKtYpgGi8cKowe2ZV9z4+S7OZfoIrcwVsz Au8RCmfN0Y7DLJ3oS00YUVcjvZcxuA9kFU2GR0CimDEQAR5YjhNNnUnGL+2HSL2G9maq VZpw== X-Gm-Message-State: APjAAAVD9tJN/VVkOOcnSyRkPwUjiB7SaxvRvyKDU3pC4L5W7VbG6iz5 PUqvykufIp6WzJvYW1sLlk4ckM80d7M= X-Google-Smtp-Source: APXvYqxk1TmKtIQ/jyOmo3K9b1B5va53z3+zwsjFrrGOsKUdjmmr4pha8E20Ve2w0M7lfq427aG81Q== X-Received: by 2002:a5d:4651:: with SMTP id j17mr26704257wrs.237.1579015132009; Tue, 14 Jan 2020 07:18:52 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 20/22] tests/tcg/aarch64: add test-sve-ioctl guest-debug test Date: Tue, 14 Jan 2020 15:09:51 +0000 Message-Id: <20200114150953.27659-21-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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: Peter Maydell , qemu-arm@nongnu.org, =?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 v5 - plumb in - skip if fails to connect --- tests/tcg/aarch64/Makefile.target | 11 ++- tests/tcg/aarch64/gdbstub/test-sve-ioctl.py | 79 +++++++++++++++++++++ 2 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 tests/tcg/aarch64/gdbstub/test-sve-ioctl.py diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile= .target index 66addbc52f..914ab81872 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -51,15 +51,22 @@ sve-ioctls: CFLAGS+=3D-march=3Darmv8.1-a+sve ifneq ($(HAVE_GDB_BIN),) GDB_SCRIPT=3D$(SRC_PATH)/tests/guest-debug/run-test.py =20 -AARCH64_TESTS +=3D gdbstub-sysregs +AARCH64_TESTS +=3D gdbstub-sysregs gdbstub-sve-ioctls =20 -.PHONY: gdbstub-sysregs +.PHONY: gdbstub-sysregs gdbstub-sve-ioctls run-gdbstub-sysregs: sysregs $(call run-test, $@, $(GDB_SCRIPT) \ --gdb $(HAVE_GDB_BIN) \ --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \ --bin $< --test $(AARCH64_SRC)/gdbstub/test-sve.py, \ "basic gdbstub SVE support") + +run-gdbstub-sve-ioctls: sve-ioctls + $(call run-test, $@, $(GDB_SCRIPT) \ + --gdb $(HAVE_GDB_BIN) \ + --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \ + --bin $< --test $(AARCH64_SRC)/gdbstub/test-sve-ioctl.py, \ + "basic gdbstub SVE ZLEN support") endif =20 endif 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 0000000000..6f4f429cf2 --- /dev/null +++ b/tests/tcg/aarch64/gdbstub/test-sve-ioctl.py @@ -0,0 +1,79 @@ +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 +import sys + +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: + inferior =3D gdb.selected_inferior() + arch =3D inferior.architecture() + report(arch.name() =3D=3D "aarch64", "connected to aarch64") +except (gdb.error, AttributeError): + print("SKIPPING (not connected)", file=3Dsys.stderr) + exit(0) + +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 Apr 26 04:09:25 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=1579015641; cv=none; d=zohomail.com; s=zohoarc; b=IeB9d9cy0wfOUZWDrVFg2IBV53xt7YEF+ugPkiUAnBNCcDOfhHqHnIxB6kK/r/TgQw3tg7Lk+PhbUGlQ5vFqcocu5ox/9PQHALWYd3PVXaFUCGvGerRzr+RXGd23CcwwI7uasTD20RzZbzEqKpgRtq61vGHnBhGj7UNPB8/NnWc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579015641; 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=gTJwX5kWJGCh9oDjiYMqf+cesP2bniT5/YT9g0RKUr8=; b=eWXzCVRGYWPxykrBZFdUXmt9SVTkmAdIw/qenKh8AG65P6dO+50I+lRU2/afUMhvbrMLnREiYtSoCGYVGl0/fLavlyvN1HkX8inou/9yTT6yv7+Ww3fYyzESaxSV7Ym3kF1yxq2InIoyoqd0LV+tkCfSEjDvyjSiiYx3MstYSKs= 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 1579015641268820.4368123408395; Tue, 14 Jan 2020 07:27:21 -0800 (PST) Received: from localhost ([::1]:42056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irO6C-00026a-76 for importer@patchew.org; Tue, 14 Jan 2020 10:27:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38008) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpm-0005Uu-7t for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpk-0007iN-JM for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:22 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:51042) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpj-0007Zo-6u for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:20 -0500 Received: by mail-wm1-x343.google.com with SMTP id a5so14210057wmb.0 for ; Tue, 14 Jan 2020 07:10:12 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id y6sm19661497wrl.17.2020.01.14.07.10.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:10:07 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B24B71FFA9; Tue, 14 Jan 2020 15:09:57 +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=gTJwX5kWJGCh9oDjiYMqf+cesP2bniT5/YT9g0RKUr8=; b=rP4mPkWWfOjtPv7lRbz3RJYmwDAnVsmCCYYDVva8UXUG7rbSBqmm2L+mITM1iIcxiP 87886LCapsDL1pZuhnCItDpQ2Lq3AjYObfk1q1JVFjBRYPrwUl+Vf1f0WUa0DKH2XXZb bbzZee86Oi7Ot8pRdb2EHSwyaM8NxlUntmqHUyNGujaQkVxaTwhXRth0ojKYg0NidfwP xb6brQ1tlML5FABsHTMu3DaoYVnMJ35JxHHkq0OUc0O37I7FZfNGMTTZQDEQae1mXPt/ 4HgJnEjUvuXaeY8u2NILROxCiOMDbOipG6E0nV9X3IQDU7c/JjW0MEg8+674MagOZTgL pWnw== 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=gTJwX5kWJGCh9oDjiYMqf+cesP2bniT5/YT9g0RKUr8=; b=UzDrVIwsSSwbKUDSkuv17j57UTm6hehCRI2g+KftXJd9vCE0YSS3XRgpax4WCc3TAY GO7BUZoK3/Y8mofcc3H91WFUYM6YNixjLVRVsxvpPtWgj99asprVL5HzHgJ1atgWQgK3 yWP1zuuCWI6TSTGy+FRcLJxXRzrRRHy5BJrZ8jlRhJfcbvOFMFkSe7vRahH3c9L/mRB/ QKaIgzDHPEaLQTu+7nkJtGJx05XwUOZUQ0eYubribd50hwQQYgha3NjJXUXt9pz/Mjqd eZH5zYV+8Btx46uALpe2+eci3IYy2GgT/5tl+L+Tn2UGsuzlG4YDSSGxzjgrCUNMjsV5 jPew== X-Gm-Message-State: APjAAAVyWPUMvDYjaZ9KiFlQCW6hva3eW1MADEClXHtpKDLJ3WEi9ni3 udTV25r/DoubxF8imfTP7o4GXg== X-Google-Smtp-Source: APXvYqz+LpsChzstUjIprs1+gIZGbO/09Rj9rBC+/uDZi6zfmwLUZGKNjl9RsGmYOuac1/SDMGxMUg== X-Received: by 2002:a7b:ca4c:: with SMTP id m12mr26723126wml.176.1579014612025; Tue, 14 Jan 2020 07:10:12 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 21/22] gdbstub: change GDBState.last_packet to GByteArray Date: Tue, 14 Jan 2020 15:09:52 +0000 Message-Id: <20200114150953.27659-22-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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 , =?UTF-8?q?Alex=20Benn=C3=A9e?= , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Reviewed-by: Richard Henderson --- gdbstub.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index dcfa4f1dd7..b9fb8c0a95 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 Apr 26 04:09:25 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=1579015237; cv=none; d=zohomail.com; s=zohoarc; b=gqUYnZHiAO9kqjr2My1xNAXHNW6J+6WD8NXyFVwPYPWztmAG2km0iCyHJwaOJxcMTyLzueCzDLf1DfzuA1/vMHm7ItPmN7L6sWshAoIngaKwf3w/6g6qqh+tjl2VXTftmdkr11CyTF472uRTp6sVGw33QXxNVVsWdE7qW/q8Y20= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579015237; 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=9o0h/AvlZG4OInglAABEjBAMRDTZzGfk2bscVX4lDdE=; b=YWoE093Z+0oYqnXj60WLHaH0xw9G1rx811xS23tJG7I/CLdlEem4LdS6ImSoGAqwmWpRQ+Yh+5K5dsxmBtvRr5LpBycuiJiH08Gc1xVBIJ/Jklc8+ncpwAhf3Y2+2qNjqkKN6EwJQUBmNnSuiXjSWJumM3gYbtqcwz7SUL/5YFY= 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 1579015237032561.5289365371383; Tue, 14 Jan 2020 07:20:37 -0800 (PST) Received: from localhost ([::1]:41870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNzf-0001PS-3Z for importer@patchew.org; Tue, 14 Jan 2020 10:20:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37996) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNpl-0005Us-UC for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNpk-0007iI-IM for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:21 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:38851) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNpj-0007b2-90 for qemu-devel@nongnu.org; Tue, 14 Jan 2020 10:10:20 -0500 Received: by mail-wr1-x441.google.com with SMTP id y17so12536863wrh.5 for ; Tue, 14 Jan 2020 07:10:14 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id q3sm18155438wmj.38.2020.01.14.07.10.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:10:08 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D306C1FF8F; Tue, 14 Jan 2020 15:09:57 +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=9o0h/AvlZG4OInglAABEjBAMRDTZzGfk2bscVX4lDdE=; b=B/gINsO/LWdL9RseVZOoQpoYVgFjbPv2x+l0FYIU0LhMwv6OXDxRo4Nt9xh8Ynjwt8 ZX/UGXyuual9QzI1Ht/ZUl0V3gBgRXHrjr/4Uyta6TWSy9zIS6pz6FhPfcHcmRs/2SKo 9QFBXUVbvNRjt6WX8rEDdydqEBqJdcQSQVkVgCUgeIpibXnAOr6P2pZrUxMw5bAKg9NO Ws3VojqO6KpxCYP1bSZhA5d9ZJowdNi0FhvKFPUv6TKpfH9ZEGKtCyn1OPZQqVF5ozIf bzmk1BkbzuNbH2BtenRFt5K3t7i43HiVBvwHQjVLk6+Y0OC6EjKdYuZMzdql+93siPpc gVyQ== 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=9o0h/AvlZG4OInglAABEjBAMRDTZzGfk2bscVX4lDdE=; b=X03XGWIYMjLfOGOeoOVgS2Ftuw+CR/buwfk2ZBRapYbZOqFS+ZhmadQH47fPVWks/a tTm+tuc1h1f1Ia+oOOSqakJsU7oreR3KKbHykUaktHi2EodhxoFb2KP6PN7lsu8FTqKy PxBt/IdUEVGVAo/Pijh6MIbBTfDnfhQ35zEEvgeEnpfW8D4drXMIkh5JeFuUaAHeOz7a 0JPWedyTlfNCpMftEwPq70RkaXum3eS39lBmYdaHvl4Gy5V95a4lTlfXUsxikkwdFAwI 51UUuvXjaqOaL3Iqz/pb4Z8yWWZ1V0bE7YdOpaICdKu3BTpH+KKwTCBMut+2SdL8v9+a YEgw== X-Gm-Message-State: APjAAAWtmrNkihAP5TWpsL1Rl8DkrDKG0ShGkh6+UvrkS2eYfPW5n8Yy T07rjDf5x/yCqqmS73p2RO58UsYxFPc= X-Google-Smtp-Source: APXvYqyEFrJcgAfh9ObIQ6GwwCF7MJn74L4u61KdOMByxGKrBhGy5BtUtD6Y4qp/CIHxcl+lwjjByg== X-Received: by 2002:adf:dcc2:: with SMTP id x2mr24217264wrm.24.1579014613066; Tue, 14 Jan 2020 07:10:13 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 22/22] gdbstub: do not split gdb_monitor_write payload Date: Tue, 14 Jan 2020 15:09:53 +0000 Message-Id: <20200114150953.27659-23-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200114150953.27659-1-alex.bennee@linaro.org> References: <20200114150953.27659-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 , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, =?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> Reviewed-by: Richard Henderson --- gdbstub.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index b9fb8c0a95..6e461d871e 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -3200,28 +3200,11 @@ static void gdb_chr_event(void *opaque, QEMUChrEven= t 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