From nobody Sun May 19 06:50:43 2024 Delivered-To: importer@patchew.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 ARC-Seal: i=1; a=rsa-sha256; t=1594928576; cv=none; d=zohomail.com; s=zohoarc; b=kIf5XAN1g+IjpugUiMtiKGYvQedAHC/XPjB2hUBZteRIRuIBG95IKgB7VZP5PbKwtyccCcsG+5oEpk1kfqd+utgEJdP3PZ9G9iY2kffroVbX2JGqtR3PaFQOActsBggD0s00btXdRgQX0I1koTetpuskaI6oAgUR3W8d14ZqJ6M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594928576; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=8yKJ3PFfRI1+4hdxMcLpTHdA+dqcY8u/Hk+IgJron20=; b=kUdBEz+p4RstGtJoGb5TKBJHxGuwyAfNMrm2Zm9KVykASsqqydQxZrP/qnAiiC7ljGkntlTSAbAl2auy1Vv9hz+qNXYHDpf5zEzVOUMwWAbztbXLlmzt/K8xN1/ebxfyyGuGgaF6z3+U/uqwwDhYWnrrIs3KmE49Yy1M+h4zk28= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1594928576026836.3492704424182; Thu, 16 Jul 2020 12:42:56 -0700 (PDT) Received: from localhost ([::1]:56800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jw9mQ-0005r6-4r for importer@patchew.org; Thu, 16 Jul 2020 15:42:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jw9je-0005FF-LF for qemu-devel@nongnu.org; Thu, 16 Jul 2020 15:40:02 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:36864) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jw9jc-0002j8-IQ for qemu-devel@nongnu.org; Thu, 16 Jul 2020 15:40:02 -0400 Received: from michell-laptop.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 368B0219CA; Thu, 16 Jul 2020 19:39:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1594928397; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=8yKJ3PFfRI1+4hdxMcLpTHdA+dqcY8u/Hk+IgJron20=; b=Nn08U9gskGvg6smP/O8ft5DnS3ptuncHzyICAaPYg7i4TUiaNGGUg3egxQckIv3moBk/bV r+7APE2D3gcXyRmCzq7j4ZGDcvB+7TowZRuxQ0oapsFBLvREiOCPvcMEW9VEHb+xa2+X0i h0h75GljY9fz6oSF5gOk4fExOOvQrw8= From: Luc Michel To: qemu-devel@nongnu.org, Paolo Bonzini , Richard Henderson Subject: [PATCH v2] tcg/cpu-exec: precise single-stepping after an exception Date: Thu, 16 Jul 2020 21:39:47 +0200 Message-Id: <20200716193947.3058389-1-luc.michel@greensocs.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=5.135.226.135; envelope-from=luc.michel@greensocs.com; helo=beetle.greensocs.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/16 15:39:58 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Luc Michel Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @greensocs.com) Content-Type: text/plain; charset="utf-8" When single-stepping with a debugger attached to QEMU, and when an exception is raised, the debugger misses the first instruction after the exception: $ qemu-system-aarch64 -M virt -display none -cpu cortex-a53 -s -S $ aarch64-linux-gnu-gdb GNU gdb (GDB) 9.2 [...] (gdb) tar rem :1234 Remote debugging using :1234 warning: No executable has been specified and target does not support determining executable automatically. Try using the "file" command. 0x0000000000000000 in ?? () (gdb) # writing nop insns to 0x200 and 0x204 (gdb) set *0x200 =3D 0xd503201f (gdb) set *0x204 =3D 0xd503201f (gdb) # 0x0 address contains 0 which is an invalid opcode. (gdb) # The CPU should raise an exception and jump to 0x200 (gdb) si 0x0000000000000204 in ?? () With this commit, the same run steps correctly on the first instruction of the exception vector: (gdb) si 0x0000000000000200 in ?? () Signed-off-by: Luc Michel --- v2: - remove RFC tag - inline the recursive call to cpu_handle_exception [Richard] --- accel/tcg/cpu-exec.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index d95c4848a4..59b1b5fe76 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -502,10 +502,22 @@ static inline bool cpu_handle_exception(CPUState *cpu= , int *ret) CPUClass *cc =3D CPU_GET_CLASS(cpu); qemu_mutex_lock_iothread(); cc->do_interrupt(cpu); qemu_mutex_unlock_iothread(); cpu->exception_index =3D -1; + + if (unlikely(cpu->singlestep_enabled)) { + /* + * After processing the exception, ensure an EXCP_DEBUG is + * raised when single-stepping so that GDB doesn't miss the + * next instruction. + */ + *ret =3D EXCP_DEBUG; + cpu_handle_debug_exception(cpu); + return true; + } + } else if (!replay_has_interrupt()) { /* give a chance to iothread in replay mode */ *ret =3D EXCP_INTERRUPT; return true; } --=20 2.27.0