From patchwork Fri Jun 2 13:05:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 101248 Delivered-To: patch@linaro.org Received: by 10.182.202.35 with SMTP id kf3csp185419obc; Fri, 2 Jun 2017 06:08:42 -0700 (PDT) X-Received: by 10.200.37.106 with SMTP id 39mr8782670qtn.92.1496408922606; Fri, 02 Jun 2017 06:08:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496408922; cv=none; d=google.com; s=arc-20160816; b=letp302jBf++o8K2BQnC2H1LE0LI5OHKRSlzMbJpjaySUorCHXSrLLVd/A9tQl9pb9 fDuHIIaI2cU7m3snUePVEbkoTO675xlAB+6T3HhIb9jBub7MepDF+awDKgv7Acw879Fs NlhYvN+iyknytB9drVjF2R9lXmsjLvll1ui51FZSEox22ItfbhCbD02D1yJysvrZzlLT CycfZ28MS5xwLvZDqJ8OZPXF61VkssgBwtFvTDMeiJh98ictVvVxSgnQv/snWs35Kuax 8bOk9FKioOQj/QC9LGK32BcDt4K1EwZNdkhcksKJmC7aZh3LkHfLhN8NAP6ljEo9Ya3q pKew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=6sg3kie9Ld0x8HhFkP/i5HCiFXfPvNuO9JNLs6kYBaE=; b=KhQwEqpZMmoapZ+JKMj2K+erQw63CiyRkX4ggcHhUVKPcDfBWaeSAplWGzmhtzKoUl HVFbZ/804EqFF1CyGiOVJ904ceYzY3UHiqwDq7rKteI3nKH+YCS2rS5BlDAnW7zOEK8Z +3rDdQTmkZRMfTMJAydAtysbtPV5m19s/0iz/Up4JrXiyyzDFBb8ye08k1qKAR1eHsV4 etQdCDXDl0G8/CHoJWUncm49SrSs+ZsUlM+5e8p+iMxBJm6jv3ldVZwrmvw7gZm6leGU /DqRjPkyjaCF+xrxwgWzW0+PTb6F8JvMdHH8tUziiu9Ht391pfY2Iln64boJdnY09vRH vlWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id t10si15474195qki.329.2017.06.02.06.08.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 02 Jun 2017 06:08:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49711 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGmJj-0000Y5-Uh for patch@linaro.org; Fri, 02 Jun 2017 09:08:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGmGS-0006Ru-9h for qemu-devel@nongnu.org; Fri, 02 Jun 2017 09:05:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGmGN-0002lj-UL for qemu-devel@nongnu.org; Fri, 02 Jun 2017 09:05:16 -0400 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:35840) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGmGN-0002lJ-Kx for qemu-devel@nongnu.org; Fri, 02 Jun 2017 09:05:11 -0400 Received: by mail-wm0-x236.google.com with SMTP id 7so25271487wmo.1 for ; Fri, 02 Jun 2017 06:05:11 -0700 (PDT) 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=6sg3kie9Ld0x8HhFkP/i5HCiFXfPvNuO9JNLs6kYBaE=; b=bBu0XkNlqIsHBsaK5BessrjHYmFRxR3HFiWeid7O2Q5UNtcKtT4krdF3hH8coWfzMt PdEF5ZsfuibeQWHJLyBZc4hP1P98zJuMGXNmraJ8XBavDR3sXFjBOjCVKGraZA9tgibH GnbF1/E2MiY/jaiuKLH1wnzi7WHjuHGa/k2Wc= 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=6sg3kie9Ld0x8HhFkP/i5HCiFXfPvNuO9JNLs6kYBaE=; b=HjYOElc5+N1y4hMPOACpnUMBe9J6RxkO/SBWOWmmUYXKMgDBWsm8Pz3AtW5oGFjP07 +SrU6/RTq1vlKAmSVvOuUoDmBjUTzaOwtQLgJk7eqP7eEwdQRGOwqHdsBjgzbqWqkOvh xi0YOHt8eFb9RhvwMzrudcecfxMNikoGjWMu2WFIBmp/GRhEhSyNZ9+1RDDcFp+Am8Sz XrFTGd7C27yoF3diOnVDmB02f4wwZRgFY+Gv4huqxYKCSN6t2H/oq4JENIJi1ysSiF6O 2btLeZr9MrGWjHjdkJ6dl1M+v8PAb3lA1fhGHoJDVNViD8HiLJ3SeIYq0fngKLGUatyd cdoQ== X-Gm-Message-State: AODbwcAP5VPtZCa+YhFv+jopwSv7dSOLJA2GwBT59Mu0XhpzcrsERuzD drlsoE+/ExIl8Tmn X-Received: by 10.28.175.84 with SMTP id y81mr3213524wme.25.1496408710476; Fri, 02 Jun 2017 06:05:10 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id t8sm12537944wrc.28.2017.06.02.06.05.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jun 2017 06:05:09 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 0D7AF3E028C; Fri, 2 Jun 2017 14:05:19 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org, pbonzini@redhat.com, doug16k@gmail.com, imbrenda@linux.vnet.ibm.com Date: Fri, 2 Jun 2017 14:05:16 +0100 Message-Id: <20170602130518.22943-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170602130518.22943-1-alex.bennee@linaro.org> References: <20170602130518.22943-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::236 Subject: [Qemu-devel] [PATCH v3 2/4] gdbstub: rename cpu_index -> cpu_gdb_index X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is to make it clear the index is purely a gdbstub function and should not be confused with the value of cpu->cpu_index. At the same time we move the function from the header to gdbstub itself which will help with later changes. Signed-off-by: Alex Bennée Reviewed-by: Greg Kurz Reviewed-by: Claudio Imbrenda Reviewed-by: Philippe Mathieu-Daudé --- v3 - move cpu_gdb_index into gdbstub --- gdbstub.c | 26 ++++++++++++++++++++------ include/exec/gdbstub.h | 9 --------- 2 files changed, 20 insertions(+), 15 deletions(-) -- 2.13.0 diff --git a/gdbstub.c b/gdbstub.c index a249846954..57befe16e2 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -55,6 +55,20 @@ static inline int target_memory_rw_debug(CPUState *cpu, target_ulong addr, return cpu_memory_rw_debug(cpu, addr, buf, len, is_write); } +/* Return the GDB index for a given vCPU state. + * + * For user mode this is simply the thread id. In system mode GDB + * numbers CPUs from 1 as 0 is reserved as an "any cpu" index. + */ +static inline int cpu_gdb_index(CPUState *cpu) +{ +#if defined(CONFIG_USER_ONLY) + return cpu->host_tid; +#else + return cpu->cpu_index + 1; +#endif +} + enum { GDB_SIGNAL_0 = 0, GDB_SIGNAL_INT = 2, @@ -837,7 +851,7 @@ static CPUState *find_cpu(uint32_t thread_id) CPUState *cpu; CPU_FOREACH(cpu) { - if (cpu_index(cpu) == thread_id) { + if (cpu_gdb_index(cpu) == thread_id) { return cpu; } } @@ -925,7 +939,7 @@ static int gdb_handle_vcont(GDBState *s, const char *p) idx = tmp; /* 0 means any thread, so we pick the first valid CPU */ if (!idx) { - idx = cpu_index(first_cpu); + idx = cpu_gdb_index(first_cpu); } /* @@ -975,7 +989,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) case '?': /* TODO: Make this return the correct value for user-mode. */ snprintf(buf, sizeof(buf), "T%02xthread:%02x;", GDB_SIGNAL_TRAP, - cpu_index(s->c_cpu)); + cpu_gdb_index(s->c_cpu)); put_packet(s, buf); /* Remove all the breakpoints when this query is issued, * because gdb is doing and initial connect and the state @@ -1243,7 +1257,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) } else if (strcmp(p,"sThreadInfo") == 0) { report_cpuinfo: if (s->query_cpu) { - snprintf(buf, sizeof(buf), "m%x", cpu_index(s->query_cpu)); + snprintf(buf, sizeof(buf), "m%x", cpu_gdb_index(s->query_cpu)); put_packet(s, buf); s->query_cpu = CPU_NEXT(s->query_cpu); } else @@ -1400,7 +1414,7 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state) } snprintf(buf, sizeof(buf), "T%02xthread:%02x;%swatch:" TARGET_FMT_lx ";", - GDB_SIGNAL_TRAP, cpu_index(cpu), type, + GDB_SIGNAL_TRAP, cpu_gdb_index(cpu), type, (target_ulong)cpu->watchpoint_hit->vaddr); cpu->watchpoint_hit = NULL; goto send_packet; @@ -1434,7 +1448,7 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state) break; } gdb_set_stop_cpu(cpu); - snprintf(buf, sizeof(buf), "T%02xthread:%02x;", ret, cpu_index(cpu)); + snprintf(buf, sizeof(buf), "T%02xthread:%02x;", ret, cpu_gdb_index(cpu)); send_packet: put_packet(s, buf); diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index f9708bbcd6..9aa7756d92 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -58,15 +58,6 @@ void gdb_register_coprocessor(CPUState *cpu, gdb_reg_cb get_reg, gdb_reg_cb set_reg, int num_regs, const char *xml, int g_pos); -static inline int cpu_index(CPUState *cpu) -{ -#if defined(CONFIG_USER_ONLY) - return cpu->host_tid; -#else - return cpu->cpu_index + 1; -#endif -} - /* The GDB remote protocol transfers values in target byte order. This means * we can use the raw memory access routines to access the value buffer. * Conveniently, these also handle the case where the buffer is mis-aligned.