From patchwork Fri Jun 28 04:20:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1123928 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45ZkC20PWQz9s9G for ; Fri, 28 Jun 2019 14:22:54 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="NZrpIiDt"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 45ZkC15z4bzDqpB for ; Fri, 28 Jun 2019 14:22:53 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::542; helo=mail-pg1-x542.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="NZrpIiDt"; dkim-atps=neutral Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 45Zk8M5FlszDq5b for ; Fri, 28 Jun 2019 14:20:35 +1000 (AEST) Received: by mail-pg1-x542.google.com with SMTP id w10so1990237pgj.7 for ; Thu, 27 Jun 2019 21:20:35 -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:mime-version :content-transfer-encoding; bh=Owq7AMkxW7GURHzSo1bwK+QzGOPb7Ntgz79xM/RPYX0=; b=NZrpIiDtlLo2fpSt1EFa0l0sYiTVXxhTvMQnEiUBexE30nwD1onoRd120dzuV0EGAG SyXHEgygpozoia8z1zv6X+EXwnRhuz1P9dsTYWqiPjmrFwh0br5vKgPFvU/3ylKedz0T w5M1cC5AfwsXz7Kqkpj3xPUa/5zTxr4HNoai81DdZRy2XhnJOS1XvyH/ytHDmkRbqEJj izZVEi+2zgYEz01rXqeTeEWrxP9bO/RdSeQrnYzy+ogB8A3xH0YFInS3usAyFKPuwG0f MBQsSYnObtbKsYvm7EGwp6rynEDo67KJeRNGVshycXZuf7FWBQOgDiIpoMmeUGgG1vAR K4WA== 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:mime-version :content-transfer-encoding; bh=Owq7AMkxW7GURHzSo1bwK+QzGOPb7Ntgz79xM/RPYX0=; b=o57QyHBhPw/Ks0dxg3w5y6BT5Pxd0ZreE00YpEw6GywfoEEUyHRvH9TDB6LnJ0Ph+O 8mqj6IDhOUhBrkti3MEJDgsRpa6GXVS0mrSmHzjjaMPvvU884lFeAgJnXh2IWkO3dX1G t20EIideqD2Z9dWPmBdLai5DxWuhKSCzMWiN5DINgu+FKTl12iUhRK007IuuVuLnpFJa dFOWHfuPtKakpgWbi1mNd1f0hR5HXlb7wPOuvlyWXacBrQiuafjc6v+h2X9PjzngUUDA v2ElueQueslijxZd8CLjSh0TtKVhWUjpiDotL3nnp9UkWXxixP0JNw4UQPNvkiW9ZwsM hcjQ== X-Gm-Message-State: APjAAAXxeVuuuHfvotwpX2XL1UE7a1XsXqwGdAypehrjs81rD3y4M9bv lH5s9IvWVyMzfAZCRIwrSr/vwc/k X-Google-Smtp-Source: APXvYqw+jGqabWXR1XvY0wM3egSCV0wSXJf/UecT/CB2Jm4D6rZQ9pw0dxK8vHrEBQIzEV7Gk2NmxQ== X-Received: by 2002:a63:6155:: with SMTP id v82mr7139284pgb.304.1561695627476; Thu, 27 Jun 2019 21:20:27 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id y22sm607719pgj.38.2019.06.27.21.20.25 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 21:20:26 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Fri, 28 Jun 2019 14:20:38 +1000 Message-Id: <20190628042038.5862-1-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [Pdbg] [PATCH] stack: unwinder fix endian heuristic at top of stack X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" When the stack is followed to the top and the next backpointer is zero, the endian guess for the frame does not work properly. This changes it to remember the previous endianness and use that. Signed-off-by: Nicholas Piggin Acked-by: Alistair Popple --- This stack unwinder is becoming a proper Rube Goldberg machine, it can probably be rewritten sanely and more reliably, but here's one last little fix I've been carrying around for a while that helps things. src/thread.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/thread.c b/src/thread.c index 8f34233..ede797a 100644 --- a/src/thread.c +++ b/src/thread.c @@ -57,6 +57,7 @@ static int dump_stack(struct thread_regs *regs, struct pdbg_target *adu) uint64_t next_sp = regs->gprs[1]; uint64_t pc; bool finished = false; + bool prev_flip = false; printf("STACK: SP NIA\n"); if (!(next_sp && is_real_address(regs, next_sp))) { @@ -82,13 +83,17 @@ static int dump_stack(struct thread_regs *regs, struct pdbg_target *adu) if (!load8(adu, sp + 16, &pc)) return 1; - tmp2 = flip_endian(tmp); - if (!tmp) { finished = true; - goto no_flip; + flip = prev_flip; + if (flip) + be = !be; + next_sp = 0; + goto do_pc; } + tmp2 = flip_endian(tmp); + /* * Basic endian detection. * Stack grows down, so as we unwind it we expect to see @@ -130,11 +135,14 @@ no_flip: next_sp = tmp; } +do_pc: if (flip) pc = flip_endian(pc); printf(" 0x%016" PRIx64 " 0x%016" PRIx64 " (%s)\n", sp, pc, be ? "big-endian" : "little-endian"); + + prev_flip = flip; } printf(" 0x%016" PRIx64 "\n", next_sp);