From patchwork Wed May 1 05:35:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suraj Jitindar Singh X-Patchwork-Id: 10924599 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 89B981398 for ; Wed, 1 May 2019 05:36:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79AD628D22 for ; Wed, 1 May 2019 05:36:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DDD728E27; Wed, 1 May 2019 05:36:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 053BF28D22 for ; Wed, 1 May 2019 05:36:28 +0000 (UTC) Received: from localhost ([127.0.0.1]:36890 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLhuu-0002gl-2k for patchwork-qemu-devel@patchwork.kernel.org; Wed, 01 May 2019 01:36:28 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLhuF-00021v-Rk for qemu-devel@nongnu.org; Wed, 01 May 2019 01:35:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hLhuC-0002a5-Qj for qemu-devel@nongnu.org; Wed, 01 May 2019 01:35:47 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:37847) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hLhuC-0002ZW-GQ; Wed, 01 May 2019 01:35:44 -0400 Received: by mail-pg1-x544.google.com with SMTP id e6so7894518pgc.4; Tue, 30 Apr 2019 22:35:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=kcdLkptqsXnGiIfVd9TJMpZGO5slhgnKysBBCc/BCbg=; b=rPLfDP8nw9w2N8asD7RBnWXAvVdqXWoGub7YfMeFGBvRu9dM/goss+z/G+WXeo4Q6K MkslWAUL75UEou1RTtwQsQBlZxgRZMhoUfY+9+4/pXdMf5lku25mrZgqJAiv8H6g7WIk P4RaRuvhcC2qs3fTbdEtQV26PhLWNLtkQxL5AVhKzj5yXTA7Bra8QVaGTiP+73rlyMye tGBHgpo65EiBRXgG7RxXksad7OEkMpgzaGH6luPMqGUlNyvb1u+g7NN4UJmO+0R3sHPu rJsNpK6AxQOYHowEir4VYypQ51l4yak4qmdalOPjkUNwcTwEsnS3p+0K1Na+980AnQyN Ttug== 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; bh=kcdLkptqsXnGiIfVd9TJMpZGO5slhgnKysBBCc/BCbg=; b=MOh/WmqbTP2XLrfYqdAtbobBQoxwZnSySOLIxkNd10FXH7gdfR1HliI/IHdm/LpVA8 BA236ePVF1Vam8ZlLv4DMv7NYRk6yMtC5oYL1tPQfbbEX2ZjkH3FG2LmgA0t16xEOAzd p57Nk5VooJHl5LhS8taf+fudYjiiI5HZ9ug/8vqqapk2/eE7eqUUvPVcA4NNLjEA5yXU VBVT5MezjmB4/5ru44gZxkyWGi6NXextIK29IVel5QA+JLPuL4PfGF3tXIHqdzUf5h0T ad2ir7FMZSmtVIXsO7PyofL7+xOnFuQ2nCcEEzHJbvOuY9AUToc290f7gDFWbe8qVSIp mivw== X-Gm-Message-State: APjAAAWEtMGTMHjnodMFiS6lWuVFfHhypD/rY/5X8gUqn1rXCFdQ3exa LQ3p4ws6EAwa0z5juquImWZ479Mg X-Google-Smtp-Source: APXvYqzeVKiBhhylXajAba3FMmwgiWAfz4kdXrY78cFwEcPvcn6Jg29JoUjW0kOofEYlkXeOOxl6DQ== X-Received: by 2002:a62:4595:: with SMTP id n21mr77767087pfi.79.1556688942295; Tue, 30 Apr 2019 22:35:42 -0700 (PDT) Received: from surajjs2.ozlabs.ibm.com.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id h19sm62932986pfd.130.2019.04.30.22.35.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Apr 2019 22:35:41 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-devel@nongnu.org Date: Wed, 1 May 2019 15:35:21 +1000 Message-Id: <20190501053522.10967-1-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [PATCH 1/2] monitor: Add dump-stack command 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: david@gibson.dropbear.id.au, qemu-ppc@nongnu.org, dgilbert@redhat.com, Suraj Jitindar Singh , armbru@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add a monitor command "dump-stack" to be used to dump the stack for the current cpu. Signed-off-by: Suraj Jitindar Singh --- hmp-commands.hx | 13 +++++++++++++ hmp.h | 1 + include/qom/cpu.h | 10 ++++++++++ monitor.c | 12 ++++++++++++ qom/cpu.c | 10 ++++++++++ 5 files changed, 46 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 9b4035965c..965ccdea28 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -862,6 +862,19 @@ ETEXI }, STEXI +@item dump-stack +@findex dump-stack +dump stack of the cpu +ETEXI + { + .name = "dump-stack", + .args_type = "", + .params = "", + .help = "dump stack", + .cmd = hmp_dumpstack, + }, + +STEXI @item pmemsave @var{addr} @var{size} @var{file} @findex pmemsave save to disk physical memory dump starting at @var{addr} of size @var{size}. diff --git a/hmp.h b/hmp.h index 43617f2646..e6edf1215c 100644 --- a/hmp.h +++ b/hmp.h @@ -51,6 +51,7 @@ void hmp_announce_self(Monitor *mon, const QDict *qdict); void hmp_cpu(Monitor *mon, const QDict *qdict); void hmp_memsave(Monitor *mon, const QDict *qdict); void hmp_pmemsave(Monitor *mon, const QDict *qdict); +void hmp_dumpstack(Monitor *mon, const QDict *qdict); void hmp_ringbuf_write(Monitor *mon, const QDict *qdict); void hmp_ringbuf_read(Monitor *mon, const QDict *qdict); void hmp_cont(Monitor *mon, const QDict *qdict); diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 08abcbd3fe..f2e83e9918 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -181,6 +181,7 @@ typedef struct CPUClass { int (*memory_rw_debug)(CPUState *cpu, vaddr addr, uint8_t *buf, int len, bool is_write); void (*dump_state)(CPUState *cpu, FILE *, int flags); + void (*dump_stack)(CPUState *cpu, FILE *f); GuestPanicInformation* (*get_crash_info)(CPUState *cpu); void (*dump_statistics)(CPUState *cpu, int flags); int64_t (*get_arch_id)(CPUState *cpu); @@ -568,6 +569,15 @@ enum CPUDumpFlags { void cpu_dump_state(CPUState *cpu, FILE *f, int flags); /** + * cpu_dump_stack: + * @cpu: The CPU whose stack is to be dumped. + * @f: If non-null, dump to this stream, else to current print sink. + * + * Dumps CPU stack. + */ +void cpu_dump_stack(CPUState *cpu, FILE *f); + +/** * cpu_dump_statistics: * @cpu: The CPU whose state is to be dumped. * @flags: Flags what to dump. diff --git a/monitor.c b/monitor.c index 9b5f10b475..dbec2e4376 100644 --- a/monitor.c +++ b/monitor.c @@ -1299,6 +1299,18 @@ static void hmp_info_registers(Monitor *mon, const QDict *qdict) } } +void hmp_dumpstack(Monitor *mon, const QDict *qdict) +{ + CPUState *cs = mon_get_cpu(); + + if (!cs) { + monitor_printf(mon, "No CPU available\n"); + return; + } + + cpu_dump_stack(cs, NULL); +} + #ifdef CONFIG_TCG static void hmp_info_jit(Monitor *mon, const QDict *qdict) { diff --git a/qom/cpu.c b/qom/cpu.c index 3c5493c96c..0dc10004f4 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -230,6 +230,16 @@ void cpu_dump_state(CPUState *cpu, FILE *f, int flags) } } +void cpu_dump_stack(CPUState *cpu, FILE *f) +{ + CPUClass *cc = CPU_GET_CLASS(cpu); + + if (cc->dump_stack) { + cpu_synchronize_state(cpu); + cc->dump_stack(cpu, f); + } +} + void cpu_dump_statistics(CPUState *cpu, int flags) { CPUClass *cc = CPU_GET_CLASS(cpu); From patchwork Wed May 1 05:35:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suraj Jitindar Singh X-Patchwork-Id: 10924601 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4712B1398 for ; Wed, 1 May 2019 05:37:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3313128AC0 for ; Wed, 1 May 2019 05:37:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2044C28DC4; Wed, 1 May 2019 05:37:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 77B4328AC0 for ; Wed, 1 May 2019 05:37:34 +0000 (UTC) Received: from localhost ([127.0.0.1]:36896 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLhvx-0003HZ-Pb for patchwork-qemu-devel@patchwork.kernel.org; Wed, 01 May 2019 01:37:33 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43430) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLhuI-00022w-7d for qemu-devel@nongnu.org; Wed, 01 May 2019 01:35:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hLhuF-0002ah-6E for qemu-devel@nongnu.org; Wed, 01 May 2019 01:35:50 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:35623) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hLhuE-0002aT-Uy; Wed, 01 May 2019 01:35:47 -0400 Received: by mail-pg1-x543.google.com with SMTP id h1so7899804pgs.2; Tue, 30 Apr 2019 22:35:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jMPw4+T1aUXXvMawKhd3pNQEvpVoHaZ7PltWVwe184o=; b=JuFnzhxLa5wHiFRjZR095O2VlJhlehCl4vaITfsyY/BDKtHsgIb+HOTg3nW13A0Rca kUQiDtiDzMZK7FY9DctCY0rT9l8D4VvZzIgxOTUPkJ4wPOLhLcdpLWDnowYE+9n35NOi vZwqbGGhWMo0+MzoIQDdQY5uw+F4RZukZCwNJ+EeaIBLb+yOfW55fLLgu94Nkxhy1oL/ OkjFT7YNrujmXUwPB/uY2NhPs4UkIlrmKXPyXqCDsJaUvM/4aRwLDtOVhErMzm3dqVoO ypynlBSP9HW5yLKbIeOroqPsfCFHsKidz3imekDB3tiIotskThJXH19dYwOBUCzr14IF P8FQ== 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; bh=jMPw4+T1aUXXvMawKhd3pNQEvpVoHaZ7PltWVwe184o=; b=qHtvl2aaTAi9xAWhTOedeopjX3YS2/9Q0QDu0DQby9dyL2EOUJk+S/jN6IAjA83aXq haQe1maNkzoNTu3Eeb2rBt4pmmi8yCvT6AJJe6U5+Gz4XmAV2pvSFFStIezNKu+5nV7I Zux7EjzFG6FUT+EBL77mRvf0WBsWZTeWQIB36o3+A69p2iSrd5VId9d6hb4lai2mLgtx LE6mZPGVwfbsLRXlzxECDev9Ujp9zBrEAU3ygWrsIxybJkjsVEG5n4CLcOG6MApe7Cr3 E5Qk2JI60tzihsibKkq0/hmidLST+2NsyPkVImgXOFTW0Lbl9F+Kv0jB/yf6jv5bCR4s WEAA== X-Gm-Message-State: APjAAAWc1X/eG4+Xi7yNft4MBdwT03ZJSQD2sXLXFAVJaTgn04K507Em D7vM7OMvaeQriPvrprMY1XHuozY5 X-Google-Smtp-Source: APXvYqyKolQw7k+oWyXzPUaN4q/JRwteXrTo4Efo/wXBt7Ibq5sRhdonY9iPEb2cqEb1xjcMUZGbYA== X-Received: by 2002:a63:550c:: with SMTP id j12mr3334248pgb.450.1556688945808; Tue, 30 Apr 2019 22:35:45 -0700 (PDT) Received: from surajjs2.ozlabs.ibm.com.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id h19sm62932986pfd.130.2019.04.30.22.35.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Apr 2019 22:35:45 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-devel@nongnu.org Date: Wed, 1 May 2019 15:35:22 +1000 Message-Id: <20190501053522.10967-2-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190501053522.10967-1-sjitindarsingh@gmail.com> References: <20190501053522.10967-1-sjitindarsingh@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::543 Subject: [Qemu-devel] [PATCH 2/2] ppc: Add dump-stack implementation 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: david@gibson.dropbear.id.au, qemu-ppc@nongnu.org, dgilbert@redhat.com, Suraj Jitindar Singh , armbru@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The monitor function dump-stack is used to dump the stack for a cpu. This can be useful for debugging purposes when the stack cannot be dumped by another means. Add a ppc implementation ppc_cpu_dump_stack(). The stack pointer is stored in R1 with the back pointer at offset 0 and the link register at offset 2. Also dump the registers from the stack frame if the marker "regshere" is found. This only dumps the kernel stack, stopping if a non-kernel address is found in the stack. Sample output: (qemu) dump-stack sp: 0xc00000007bfc5690 lr: 0xc0000000000974b8 sp: 0xc00000007bfc56f0 lr: 0xc00000000065aab4 sp: 0xc00000007bfc5720 lr: 0xc00000000065ab04 sp: 0xc00000007bfc5740 lr: 0xc0000000000c29b8 sp: 0xc00000007bfc57b0 lr: 0xc0000000000bc9e8 sp: 0xc00000007bfc57e0 lr: 0xc0000000000bd584 sp: 0xc00000007bfc5800 lr: 0xc0000000000bee14 sp: 0xc00000007bfc5ac0 lr: 0xc0000000000c2100 sp: 0xc00000007bfc5c60 lr: 0xc000000000029460 sp: 0xc00000007bfc5ca0 lr: 0xc00000000010b5e8 sp: 0xc00000007bfc5d00 lr: 0xc000000000105f34 trap : 0x0000000000000700 pc : 0xc000000000104490 msr : 0x9000000002843003 lr : 0xc000000000103ffc gpr 0: 0x0000000000000001 gpr 1: 0xc00000005051f530 gpr 2: 0xc000000001088200 gpr 3: 0x0000000000000001 gpr 4: 0xc000000032d60000 gpr 5: 0xc0000000014b8f00 gpr 6: 0x0000000000c835e0 gpr 7: 0x0000000000000000 gpr 8: 0x0000000000000000 gpr 9: 0xc000000032f00000 gpr10: 0x9000000002803033 gpr11: 0xc000000000b60f00 gpr12: 0x0000000000002000 gpr13: 0xc000000001250000 gpr14: 0x0000000000000000 gpr15: 0x0000000000000008 gpr16: 0x0000000000000000 gpr17: 0xc00000000114f790 gpr18: 0x00000000ffffffff gpr19: 0xc00000005051f8e8 gpr20: 0x0000000000000001 gpr21: 0x0000000000000000 gpr22: 0x0000000000000001 gpr23: 0x0000000000000001 gpr24: 0x0000000000000001 gpr25: 0xc0000000014b8f70 gpr26: 0x0000000000000000 gpr27: 0x0000000000000001 gpr28: 0x0000000000000001 gpr29: 0x0000000000000000 gpr30: 0xc0000000014b8f00 gpr31: 0xc0000000014b8f00 sp: 0xc00000005051f530 lr: 0x0000000000000000 sp: 0xc00000005051f600 lr: 0xc000000000103ffc sp: 0xc00000005051f670 lr: 0xc0000000000f60a8 sp: 0xc00000005051f850 lr: 0xc0000000000f18c0 sp: 0xc00000005051fa10 lr: 0xc0000000000f5184 sp: 0xc00000005051fae0 lr: 0xc0000000000ddf54 sp: 0xc00000005051fb00 lr: 0xc0000000000dab9c sp: 0xc00000005051fb90 lr: 0xc0000000000cbf88 sp: 0xc00000005051fd00 lr: 0xc0000000003e7480 sp: 0xc00000005051fdb0 lr: 0xc0000000003e7ce4 sp: 0xc00000005051fe00 lr: 0xc0000000003e7d88 sp: 0xc00000005051fe20 lr: 0xc00000000000b3a4 trap : 0x0000000000000c01 pc : 0x00007fffa6c9d8d0 msr : 0x900000000280f033 lr : 0x0000000010090f40 gpr 0: 0x0000000000000036 gpr 1: 0x00007fffa62fdd70 gpr 2: 0x00007fffa6d57300 gpr 3: 0x000000000000000d gpr 4: 0x000000002000ae80 gpr 5: 0x0000000000000000 gpr 6: 0x0000000000000537 gpr 7: 0x0000000000000000 gpr 8: 0x000000000000000d gpr 9: 0x0000000000000000 gpr10: 0x0000000000000000 gpr11: 0x0000000000000000 gpr12: 0x0000000000000000 gpr13: 0x00007fffa6306380 gpr14: 0x0000000000000000 gpr15: 0x0000000000000001 gpr16: 0x0000000039ba6928 gpr17: 0x0000000000000000 gpr18: 0x0000000000000000 gpr19: 0x00007fffa6d702f0 gpr20: 0x00007fffa62fddf0 gpr21: 0x0000000000000080 gpr22: 0x0000000000000004 gpr23: 0x0000000000000000 gpr24: 0x0000000010ac85c0 gpr25: 0x0000000000000008 gpr26: 0x00007fffa62fde10 gpr27: 0x0000000000000000 gpr28: 0x0000000000000002 gpr29: 0x0000000000000000 gpr30: 0x0000000039ba6900 gpr31: 0x0000000010ac85c0 sp: 0x00007fffa62fdd70 Signed-off-by: Suraj Jitindar Singh --- target/ppc/cpu.h | 1 + target/ppc/translate.c | 60 +++++++++++++++++++++++++++++++++++++++++ target/ppc/translate_init.inc.c | 1 + 3 files changed, 62 insertions(+) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 5e7cf54b2f..28c4dffca1 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1284,6 +1284,7 @@ struct PPCVirtualHypervisorClass { void ppc_cpu_do_interrupt(CPUState *cpu); bool ppc_cpu_exec_interrupt(CPUState *cpu, int int_req); void ppc_cpu_dump_state(CPUState *cpu, FILE *f, int flags); +void ppc_cpu_dump_stack(CPUState *cpu, FILE *f); void ppc_cpu_dump_statistics(CPUState *cpu, int flags); hwaddr ppc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); int ppc_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 8d08625c33..b162998ce7 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -7705,6 +7705,66 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags) #undef RFPL } +struct ppc_pt_regs { + unsigned long gpr[32]; + unsigned long nip; + unsigned long msr; + unsigned long orig_gpr3; + unsigned long ctr; + unsigned long link; + unsigned long xer; + unsigned long ccr; + unsigned long softe; + unsigned long trap; + unsigned long dar; + unsigned long dsisr; + unsigned long result; +}; + +void ppc_cpu_dump_stack(CPUState *cs, FILE *f) +{ +#if defined(TARGET_PPC64) + PowerPCCPU *cpu = POWERPC_CPU(cs); + CPUPPCState *env = &cpu->env; + uint64_t sp, next_sp, lr, buf[4]; + + /* stack pointer stored in r1 */ + sp = env->gpr[1]; + + while (sp && (sp & (0xCUL << 60))) { + uint64_t marker = 0UL; + + /* read and print LR */ + cpu_physical_memory_read(sp & ~(0xCUL << 60), buf, sizeof(*buf) * 4); + next_sp = buf[0]; + lr = buf[2]; + qemu_fprintf(f, "sp: 0x%.16lx lr: 0x%.16lx\n", sp, lr); + sp &= ~(0xCUL << 60); + + /* Does the stackframe contain regs? */ + cpu_physical_memory_read(sp + 96, &marker, sizeof(marker)); + if (marker == 0x7265677368657265) { /* regshere */ + struct ppc_pt_regs regs; + int i; + + cpu_physical_memory_read(sp + 112, ®s, sizeof(regs)); + + qemu_fprintf(f, "\ttrap : 0x%.16lx\n", regs.trap); + qemu_fprintf(f, "\tpc : 0x%.16lx\n", regs.nip); + qemu_fprintf(f, "\tmsr : 0x%.16lx\n", regs.msr); + qemu_fprintf(f, "\tlr : 0x%.16lx\n", regs.link); + for (i = 0; i < 32; i++) + qemu_fprintf(f, "\tgpr%2d: 0x%.16lx\n", i, + regs.gpr[i]); + } + + sp = next_sp; + } + + qemu_fprintf(f, "sp: 0x%.16lx\n", sp); +#endif +} + void ppc_cpu_dump_statistics(CPUState *cs, int flags) { #if defined(DO_PPC_STATISTICS) diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.inc.c index 0394a9ddad..3fd24f85cc 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -10587,6 +10587,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) cc->do_interrupt = ppc_cpu_do_interrupt; cc->cpu_exec_interrupt = ppc_cpu_exec_interrupt; cc->dump_state = ppc_cpu_dump_state; + cc->dump_stack = ppc_cpu_dump_stack; cc->dump_statistics = ppc_cpu_dump_statistics; cc->set_pc = ppc_cpu_set_pc; cc->gdb_read_register = ppc_cpu_gdb_read_register;