From nobody Sat May 18 21:00:25 2024 Delivered-To: importer@patchew.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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608221613; cv=none; d=zohomail.com; s=zohoarc; b=QUABFhq9RJiKROxxOkA4Za8DourM3hw7saRxzbgvEuISKvS04aTRV9bH37yCJFTOIXCv9faZC1vp0nY4j8lL5M95SJY3UuKAp38+83KXbvFInYgifGL86ZOaLxtxS38N8JjX1yD2W/+CGUCgcczmlxDRS2Hf0hucfBJhq2ZLlN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608221613; 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=uB8t/ed0eWCpzbMtlZyPmvfm1sd0uT7mTQgP7lht7Fc=; b=WwM5OpUAC4F8NvIzPtJGCEcXBmao9KvoV/PIQVyzEYcxIrbFRRonFO7hmmLPQeAcXyqA8eBa8LuSNBYT0+7KOksYMI17Cgp2gjBRr0gx1xH8T4g0VW+JWIOAhShUworRoZvaKWPIO91b72hvNsXEaU3lD3DhW5Bq97OaLi2tIvs= 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 16082216088361017.3499263908628; Thu, 17 Dec 2020 08:13:28 -0800 (PST) Received: from localhost ([::1]:56740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpvg4-0000lH-0G for importer@patchew.org; Thu, 17 Dec 2020 10:58:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpvc8-0005O4-Mf for qemu-devel@nongnu.org; Thu, 17 Dec 2020 10:54:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40901) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpvc6-0000ke-TV for qemu-devel@nongnu.org; Thu, 17 Dec 2020 10:54:48 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-369-DtN1UfY5M6SO-zv4BzgUmw-1; Thu, 17 Dec 2020 10:54:44 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 916E4192296B; Thu, 17 Dec 2020 15:54:43 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B0941F055; Thu, 17 Dec 2020 15:54:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608220486; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uB8t/ed0eWCpzbMtlZyPmvfm1sd0uT7mTQgP7lht7Fc=; b=BHXOMIgtbWEDJKuPQ8U8d5iOK5ctE9sdC31+EqIl8K1OntO3rvgG+rwv5oDZxnNzcfONCs HenMDR4IFnNWVMoxEjwT5gqZ8I8eXA25F0VNM09j0w6Fn9l9ebphXU/ol9zRCnr/0Zxnr+ swjVlwLnKkQ9dV97jWd8P3zOc1yH2kk= X-MC-Unique: DtN1UfY5M6SO-zv4BzgUmw-1 From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v2 1/2] scripts/gdb: fix 'qemu coroutine' when users selects a non topmost stack frame Date: Thu, 17 Dec 2020 17:54:35 +0200 Message-Id: <20201217155436.927320-2-mlevitsk@redhat.com> In-Reply-To: <20201217155436.927320-1-mlevitsk@redhat.com> References: <20201217155436.927320-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mlevitsk@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=mlevitsk@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-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: Fam Zheng , Paolo Bonzini , Maxim Levitsky , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The code that dumps the stack frame works like that: * save current registers * overwrite current registers (including rip/rsp) with coroutine snapshot in the jmpbuf * print backtrace * restore the saved registers. If the user has currently selected a non topmost stack frame in gdb, the above code will still restore the selected frame registers, but the gdb will then lose the selected frame index, which makes it impossi= ble to switch back to frame 0, to continue debugging the executable. Therefore switch temporarily to the topmost frame of the stack for the above code. Signed-off-by: Maxim Levitsky --- scripts/qemugdb/coroutine.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/qemugdb/coroutine.py b/scripts/qemugdb/coroutine.py index db61389022..e1399211e6 100644 --- a/scripts/qemugdb/coroutine.py +++ b/scripts/qemugdb/coroutine.py @@ -70,6 +70,11 @@ def bt_jmpbuf(jmpbuf): regs =3D get_jmpbuf_regs(jmpbuf) old =3D dict() =20 + # remember current stack frame and select the topmost + # so that register modifications don't wreck it + selected_frame =3D gdb.selected_frame() + gdb.newest_frame().select() + for i in regs: old[i] =3D gdb.parse_and_eval('(uint64_t)$%s' % i) =20 @@ -81,6 +86,8 @@ def bt_jmpbuf(jmpbuf): for i in regs: gdb.execute('set $%s =3D %s' % (i, old[i])) =20 + selected_frame.select() + def coroutine_to_jmpbuf(co): coroutine_pointer =3D co.cast(gdb.lookup_type('CoroutineUContext').poi= nter()) return coroutine_pointer['env']['__jmpbuf'] --=20 2.26.2 From nobody Sat May 18 21:00:25 2024 Delivered-To: importer@patchew.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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608247825; cv=none; d=zohomail.com; s=zohoarc; b=MkTeUYLkVWmNBNl52vAtepnUC9mWLuhGWSR2x4c+ZBw6K7W/qgRuPrncZx5HSiVr5TFYuAvudik/fXnW1OIXiY/DvVDMTmlyaTTdXVXJ23rQtA/kv99OffDoSq5tye87apUei/O6QEOAmxT4EEXYfMPjsYXZNpoqKsr5nuByEw0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608247825; 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=CR5OU/vWaTbG82/mqChLOHmk101aowjVba1VRcxA3Y0=; b=OwKHFltq6qSuNbU1JHG2dOv8VCEGYb8rYxWY4UkjHSYL6iPizo3TblcB4GhtmFoI9Gvkyjzr5y2bVZoZmGs7M0whB20Fdju84Ylfo4edf7vGrO3upOyWnS53FHK3CVGV5qbDh44fuG5YyLy84xWeWj4D0v2ItidFWZO93HUksTM= 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 160824782561566.60338499145382; Thu, 17 Dec 2020 15:30:25 -0800 (PST) Received: from localhost ([::1]:58896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpvgr-0001gI-5b for importer@patchew.org; Thu, 17 Dec 2020 10:59:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpvcE-0005Sh-Em for qemu-devel@nongnu.org; Thu, 17 Dec 2020 10:54:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48962) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpvcB-0000lV-27 for qemu-devel@nongnu.org; Thu, 17 Dec 2020 10:54:53 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-498-2K2ekK7JPWCt122L7ltNUQ-1; Thu, 17 Dec 2020 10:54:48 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7204F107ACE6; Thu, 17 Dec 2020 15:54:46 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2CDBE1C934; Thu, 17 Dec 2020 15:54:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608220490; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CR5OU/vWaTbG82/mqChLOHmk101aowjVba1VRcxA3Y0=; b=cuhx/wMTpAavsFxYofFW2BWAjJezYq+tq8TgGnnjjw7Kxf69B9p4kQ19SrfKZP1FUC7Ah1 lPNe2Wi7eN7DnP5DNLsl9V8mK+0XAMqIt/7TXg1MF6RFquuug8nUV+vfBrTRPLPcqNo+94 wcUUQiAGaM8LVmtrIl5/d/l7SSJb0pE= X-MC-Unique: 2K2ekK7JPWCt122L7ltNUQ-1 From: Maxim Levitsky To: qemu-devel@nongnu.org Subject: [PATCH v2 2/2] scripts/gdb: implement 'qemu bt' Date: Thu, 17 Dec 2020 17:54:36 +0200 Message-Id: <20201217155436.927320-3-mlevitsk@redhat.com> In-Reply-To: <20201217155436.927320-1-mlevitsk@redhat.com> References: <20201217155436.927320-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mlevitsk@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=63.128.21.124; envelope-from=mlevitsk@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-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: Fam Zheng , Paolo Bonzini , Maxim Levitsky , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This script first runs the regular gdb's 'bt' command, and then if we are i= n a coroutine it prints the coroutines backtraces in the order in which they were called. Signed-off-by: Maxim Levitsky --- scripts/qemu-gdb.py | 1 + scripts/qemugdb/coroutine.py | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/scripts/qemu-gdb.py b/scripts/qemu-gdb.py index e0bfa7b5a4..4d2a9f6c43 100644 --- a/scripts/qemu-gdb.py +++ b/scripts/qemu-gdb.py @@ -40,6 +40,7 @@ timers.TimersCommand() =20 coroutine.CoroutineSPFunction() coroutine.CoroutinePCFunction() +coroutine.CoroutineBt() =20 # Default to silently passing through SIGUSR1, because QEMU sends it # to itself a lot. diff --git a/scripts/qemugdb/coroutine.py b/scripts/qemugdb/coroutine.py index e1399211e6..7db46d4b68 100644 --- a/scripts/qemugdb/coroutine.py +++ b/scripts/qemugdb/coroutine.py @@ -88,8 +88,11 @@ def bt_jmpbuf(jmpbuf): =20 selected_frame.select() =20 +def co_cast(co): + return co.cast(gdb.lookup_type('CoroutineUContext').pointer()) + def coroutine_to_jmpbuf(co): - coroutine_pointer =3D co.cast(gdb.lookup_type('CoroutineUContext').poi= nter()) + coroutine_pointer =3D co_cast(co) return coroutine_pointer['env']['__jmpbuf'] =20 =20 @@ -107,6 +110,29 @@ class CoroutineCommand(gdb.Command): =20 bt_jmpbuf(coroutine_to_jmpbuf(gdb.parse_and_eval(argv[0]))) =20 +class CoroutineBt(gdb.Command): + '''Display backtrace including coroutine switches''' + def __init__(self): + gdb.Command.__init__(self, 'qemu bt', gdb.COMMAND_STACK, + gdb.COMPLETE_NONE) + + def invoke(self, arg, from_tty): + + gdb.execute("bt") + + if gdb.parse_and_eval("qemu_in_coroutine()") =3D=3D False: + return + + co_ptr =3D gdb.parse_and_eval("qemu_coroutine_self()") + + while True: + co =3D co_cast(co_ptr) + co_ptr =3D co["base"]["caller"] + if co_ptr =3D=3D 0: + break + gdb.write("Coroutine at " + str(co_ptr) + ":\n") + bt_jmpbuf(coroutine_to_jmpbuf(co_ptr)) + class CoroutineSPFunction(gdb.Function): def __init__(self): gdb.Function.__init__(self, 'qemu_coroutine_sp') --=20 2.26.2