From patchwork Thu Jul 13 14:24:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 107694 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2297846qge; Thu, 13 Jul 2017 07:38:12 -0700 (PDT) X-Received: by 10.55.118.66 with SMTP id r63mr4912130qkc.234.1499956692286; Thu, 13 Jul 2017 07:38:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499956692; cv=none; d=google.com; s=arc-20160816; b=efI7STIN0bkJoabegigs27L4Hc9R0p8nxC8qaCWtFYsfCmTOWGfIJmHWBqIWnjeO07 aCZVrFzPaV8rTYFNJ+RdiTjh6BXk6Zdf1WcBOonc6j50WNNl2j3YksTURMLp2KQve/vK h0rxxGpD/lJ3gT8WKK7kQ0k7bWCHiGWSkDYhlG/pEjRuYNpGgQPksTVOUBsBPAKMEP38 hhc2bldC8HrY+j8mH0UJ1uTNXwhHUB+VMTsix1rPNmPLYYsP52ldwmUEYrUH1EmynHW8 7a3yqCRNej8v6r4DeiAfXjxx/JJ0Wk1eAdYsE1lIpb/60OOCdmgbz5SwTplTlluriZhQ gonw== 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=5VxhkUvYqbtgQVQ0wVb8zX32heZrIbbUlUoJMa3P708=; b=hlbgOLQeCPNoeyxbNCEWaVoRy6crXrSv3dWl691Ya2Zd7Snw9Bd/pqe24H/js5gMUs ynxlJLUPbeu1fcsPICXfIzQLrU8w2vlN7sniAb46QhKbWHcASrnkCkS/ZvWYzdeYjgbq +jT1SB0IhEvAR19sjYwua/bTyYzszsnKz+fuaJwrlbjIAWs/ibkUtWL1WWxOunVEmDFi Rbdt+KCBWgcP1rjxbMY6kqGHZgEz9jDpGZFVKdVDUa6ZVrUVCaULA1KD2cw6TUn8dnpr e41qCt0VfgrKCDeaErt5gK8QWEd688AOT4Xru2ay/81ogfYrBxdvVDwH5QGzBzQT0mak cp4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.b=soCwjZLR; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id p65si5356537qkp.165.2017.07.13.07.38.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 13 Jul 2017 07:38:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.b=soCwjZLR; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:60421 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVfFp-0003Zd-JE for patch@linaro.org; Thu, 13 Jul 2017 10:38:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVf3R-00010d-AG for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:25:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVf3Q-0002UV-5e for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:25:21 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:34903) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVf3P-0002U3-SQ for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:25:20 -0400 Received: by mail-wm0-x242.google.com with SMTP id u23so5457775wma.2 for ; Thu, 13 Jul 2017 07:25:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5VxhkUvYqbtgQVQ0wVb8zX32heZrIbbUlUoJMa3P708=; b=soCwjZLR3tm8lr5i94xapgJIFCtNt5yKWkvnThrTndSpJ9i+EPaltN6/IOD+eId88I U/PTA7UaXhIvG+WqvrSvb6jQ8SIdGmvFfeTv7Bubm2G9xoezEzbV5299kguEAOwH2Fcu R4lr4Z2s6d0OZCYHZgaqFyELU8wow4z8gjmAHyycgO3xz9Kk7414sKDfVfiHDlISdRXu KPoHFrq3LFjb7EI8if3hIs5Xxxa4IxXLbFdbzSWKE+HNGuAhqfRdSWFwfcDB1BgJ6HMv ArwQYhFUZ9Z4Ruj+z2uF/18goAgziR/pMhxlieRuP+tF9nLDIAhd9nldKRtUREPF/+lb wSuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=5VxhkUvYqbtgQVQ0wVb8zX32heZrIbbUlUoJMa3P708=; b=Jy99okRe7rpdn9gLa/V0dEjT10v6Mt23m+bW926GpzgfBjuwjMr99p99R5KYPJL/vx rWZcNH4jZGLuZ9Hlogl9iLIeSDCeOxwa95EjxJ5a2kaOJNMlWi+z0ARZjXCfQG49sMwC jP3ZEFj5VakTNsOMMuEKyvu2CiTYQrE467XbtXM3Ila2hp8sRYB2gq4qjXVDgJPSqTfB ibEc2srMcCKQOlwhFIiPz8AGO+VamkZ/H4FrMLg3vWAhHVq+yViLR3U0w5hl3uhwOSja m7J92503IS8f4Xa8TmRRwgwvbaugkVOK7lq+6nQJ+lIT0yqVNQrlCjAGm4cfDtYL+s6o MtLw== X-Gm-Message-State: AIVw110uZvwo/WRlKtST5qEyMsX3CmtZXxltqC8Tr19Y+9smsVbrfo+c E1I2hU3haJRM4JNAl50= X-Received: by 10.28.133.76 with SMTP id h73mr2279815wmd.92.1499955918630; Thu, 13 Jul 2017 07:25:18 -0700 (PDT) Received: from 640k.lan (94-39-191-51.adsl-ull.clienti.tiscali.it. [94.39.191.51]) by smtp.gmail.com with ESMTPSA id k75sm6042448wmh.10.2017.07.13.07.25.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2017 07:25:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 13 Jul 2017 16:24:18 +0200 Message-Id: <1499955874-10954-26-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1499955874-10954-1-git-send-email-pbonzini@redhat.com> References: <1499955874-10954-1-git-send-email-pbonzini@redhat.com> 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::242 Subject: [Qemu-devel] [PULL 25/41] 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?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée 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é Message-Id: <20170712105216.747-3-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini --- gdbstub.c | 26 ++++++++++++++++++++------ include/exec/gdbstub.h | 9 --------- 2 files changed, 20 insertions(+), 15 deletions(-) -- 1.8.3.1 diff --git a/gdbstub.c b/gdbstub.c index 3965980..b1efe0b 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -56,6 +56,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, @@ -838,7 +852,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; } } @@ -926,7 +940,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); } /* @@ -976,7 +990,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 @@ -1244,7 +1258,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 @@ -1401,7 +1415,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; @@ -1435,7 +1449,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 f9708bb..9aa7756 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.