From patchwork Wed Jul 12 10:52:14 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: 107475 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp647257qge; Wed, 12 Jul 2017 03:54:08 -0700 (PDT) X-Received: by 10.237.63.119 with SMTP id q52mr5627555qtf.49.1499856847367; Wed, 12 Jul 2017 03:54:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499856847; cv=none; d=google.com; s=arc-20160816; b=QLNDwTFXhmp1IwDBTM0jHKjSpI/AT0bxFAMCMvCjQPXrKKNW9CxAAD5UarDy3V+ITh TIJJCuvVmP357wN0Y+mAOpFm7Xwf3dUKB42gqOxbN6BXjAk9Z9BeCtEDce3zpP08Yuol Kf840pdiZH3U0yCdy4opHxrXCor7RUihrOafQSX3MapZSepujT3K7wstoDl/WzOpJB5f NiFXj0YylCj8oKaJkRm8h2/j+op9PrlrENfsG2jQXLilzQ+ks2MTlrY/Y1Hgeb38Nw8Q uh9wV5S228kBHSvLq75oi3ao3HScB/uOx+f7KfswcWILviSy8AEcMMrQysPEekuEv3gw ju7A== 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=Qyr74MK/WKlKl4i65M6gkzrmGAnBET1CwJnF1BUvyb0=; b=Y66G0ZWc7RCI2rE2h62lpgp3Db9WPwS+pb0zfht7lWU6wg0TKpeV3nmRRrnv83CNZ2 L8baeaAj6yq+b/dnhqo6YCvi7B3F3+RJ3Uky2vcJdvyvyHudILsFbTIOuCdsQTkWZJkf h39yDY6aflR59TvuFKbVQj5eaTyaWtR2M4MJ4nzBrO73aErEwFTNtOT4r4fmk5AcGMWj n75mTu22MXPiqqo/CRXePU56+lcd28sa6b2+fnNhoNPbNuNbmViBR7pBueVCBSY5BHa1 /KsNflbl8Xzf/mJzPLJXKb2DyiIVqNMTU9w8vCV70pw+qqam4xwUqBrYjR7a+VqSS0qG xW4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.b=Xl+ok4w8; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id h126si1987354qkf.114.2017.07.12.03.54.06 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 12 Jul 2017 03:54:07 -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=@linaro.org header.b=Xl+ok4w8; 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=linaro.org Received: from localhost ([::1]:51690 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVFHQ-00051g-Lh for patch@linaro.org; Wed, 12 Jul 2017 06:54:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60805) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVFFq-0003uF-FN for qemu-devel@nongnu.org; Wed, 12 Jul 2017 06:52:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVFFm-0001YC-E0 for qemu-devel@nongnu.org; Wed, 12 Jul 2017 06:52:26 -0400 Received: from mail-wr0-x233.google.com ([2a00:1450:400c:c0c::233]:36679) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVFFm-0001XU-3z for qemu-devel@nongnu.org; Wed, 12 Jul 2017 06:52:22 -0400 Received: by mail-wr0-x233.google.com with SMTP id c11so28151532wrc.3 for ; Wed, 12 Jul 2017 03:52:21 -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=Qyr74MK/WKlKl4i65M6gkzrmGAnBET1CwJnF1BUvyb0=; b=Xl+ok4w8d3F76HIOW9XcSyIG62MQcxoJoSqr1COiEXHAT4m9MAf0IdMTalWEAB6j4i ydba1jXbltsMjf5TqHHXSMoJ/zw5p8l0wPbSewDm/oQPkVLTRGdAqARBpp55W867eAfn gbrH54+IEloS6xpx5Vj8jCTJllt6fr79YR+Bo= 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=Qyr74MK/WKlKl4i65M6gkzrmGAnBET1CwJnF1BUvyb0=; b=R0D9yjbNeRpDJic3YJUCnIQsrxmFZxbsQhyX0FRygMpkP6jHBDOVan3AktquAnQwJX J7NFR5MBtJ0c83bs5VyNCXidFOf2WYeM768ZrzjTsl6aXH/HwRAkMZU0tCURka3zbcdz vDdtkWd5AWrF0jm+yjrRO4+wlXXqboVX06qq3xjWfpJAPP2PV1eNsCs5R3F0OLyrfdIr NC1iYXMFoK/QOS0zHtnuBDJqZu2KN2JJQUDFJiBRnFmRLvOC4BsOioMyflfMTMAeq5I0 fImt25iYEp/b2HL5z+ZMKYLydNaRRSApfgDqEmlBGkiqkSJC48NfAQa9pVGKwLMh0OW/ Mkqw== X-Gm-Message-State: AIVw110kc/krRGpHg2LBpOzNBggODkiQMtKNetf1rm5TT2aZo9g2hSmd BHQSy0T0NtznmDPk X-Received: by 10.223.151.216 with SMTP id t24mr2660593wrb.40.1499856740903; Wed, 12 Jul 2017 03:52:20 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id j31sm1134618wre.67.2017.07.12.03.52.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jul 2017 03:52:18 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 1E4003E07A1; Wed, 12 Jul 2017 11:52:17 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: pbonzini@redhat.com Date: Wed, 12 Jul 2017 11:52:14 +0100 Message-Id: <20170712105216.747-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170712105216.747-1-alex.bennee@linaro.org> References: <20170712105216.747-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:c0c::233 Subject: [Qemu-devel] [PATCH v4 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 31db2309aa..6b56f55eba 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 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.