From patchwork Thu Dec 17 15:54:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 1417760 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=BHXOMIgt; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cxc9265dzz9sWD for ; Fri, 18 Dec 2020 02:58:14 +1100 (AEDT) Received: from localhost ([::1]:54760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpvfQ-0008Lg-Oy for incoming@patchwork.ozlabs.org; Thu, 17 Dec 2020 10:58:12 -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 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= 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 X-MC-Unique: DtN1UfY5M6SO-zv4BzgUmw-1 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 impossible 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 = get_jmpbuf_regs(jmpbuf) old = dict() + # remember current stack frame and select the topmost + # so that register modifications don't wreck it + selected_frame = gdb.selected_frame() + gdb.newest_frame().select() + for i in regs: old[i] = gdb.parse_and_eval('(uint64_t)$%s' % i) @@ -81,6 +86,8 @@ def bt_jmpbuf(jmpbuf): for i in regs: gdb.execute('set $%s = %s' % (i, old[i])) + selected_frame.select() + def coroutine_to_jmpbuf(co): coroutine_pointer = co.cast(gdb.lookup_type('CoroutineUContext').pointer()) return coroutine_pointer['env']['__jmpbuf'] From patchwork Thu Dec 17 15:54:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 1417761 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=cuhx/wMT; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cxc9v6bH6z9sWD for ; Fri, 18 Dec 2020 02:58:59 +1100 (AEDT) Received: from localhost ([::1]:56824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpvg9-0000nR-Vc for incoming@patchwork.ozlabs.org; Thu, 17 Dec 2020 10:58:57 -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 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= 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 X-MC-Unique: 2K2ekK7JPWCt122L7ltNUQ-1 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This script first runs the regular gdb's 'bt' command, and then if we are in 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() coroutine.CoroutineSPFunction() coroutine.CoroutinePCFunction() +coroutine.CoroutineBt() # 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): selected_frame.select() +def co_cast(co): + return co.cast(gdb.lookup_type('CoroutineUContext').pointer()) + def coroutine_to_jmpbuf(co): - coroutine_pointer = co.cast(gdb.lookup_type('CoroutineUContext').pointer()) + coroutine_pointer = co_cast(co) return coroutine_pointer['env']['__jmpbuf'] @@ -107,6 +110,29 @@ class CoroutineCommand(gdb.Command): bt_jmpbuf(coroutine_to_jmpbuf(gdb.parse_and_eval(argv[0]))) +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()") == False: + return + + co_ptr = gdb.parse_and_eval("qemu_coroutine_self()") + + while True: + co = co_cast(co_ptr) + co_ptr = co["base"]["caller"] + if co_ptr == 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')