From patchwork Mon Jan 20 21:22:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 3514551 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 53FBB9F1C3 for ; Mon, 20 Jan 2014 21:24:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8021B20142 for ; Mon, 20 Jan 2014 21:24:14 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 93CDA2013D for ; Mon, 20 Jan 2014 21:24:13 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W5MJU-0000Id-Cv; Mon, 20 Jan 2014 21:23:20 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1W5MJI-0004Cl-Pr; Mon, 20 Jan 2014 21:23:08 +0000 Received: from mail-ee0-f41.google.com ([74.125.83.41]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W5MIu-00048M-18 for linux-arm-kernel@lists.infradead.org; Mon, 20 Jan 2014 21:22:46 +0000 Received: by mail-ee0-f41.google.com with SMTP id e49so3771676eek.28 for ; Mon, 20 Jan 2014 13:22:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tDFSrjak801DWICo8DLtrlqQRLwNAjaLJMhuT78pwPE=; b=RdBeKCYdt1Bq/ouEHwJftfYk30wpXDlCyHSANfJW1J63QTTtWlf410FwKbc8zLFULI Tc5q2noeInx7+2XcqLX45L7uywpeYqK0NNp8dEMyXk+lN80TF8jyHV9/sqs7x1IHMOkv nLIubFDn0mgD341YFWS2XZ9+A2rlHb8LImmQDkDBUCfTzYvT4YD1RJxqSqNhACCP9nJd LYC+qlooDq094AGnXdjW6MsnefUiezgrfgzbljWcemIRySjyhG5dJKAX2bdUYEbXYAjy 6efqh5Y6vMt8tQwjvlQvTkorUhgmTdBXrxm0gY4J7o0zEN0I51qd1SlKzEpNeDn12adn 9yiQ== X-Gm-Message-State: ALoCoQmHzTcWxvic4OD3gB7wjbWa7uoC5XsMXbFrDPls49XyCgGQl3Ud0fw7iYPdOtT3RUTpABAJ X-Received: by 10.14.122.5 with SMTP id s5mr19777073eeh.28.1390252942141; Mon, 20 Jan 2014 13:22:22 -0800 (PST) Received: from localhost.localdomain (222.28-245-81.adsl-dyn.isp.belgacom.be. [81.245.28.222]) by mx.google.com with ESMTPSA id w4sm7306209eef.20.2014.01.20.13.22.20 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 20 Jan 2014 13:22:21 -0800 (PST) From: Jean Pihet To: libunwind-devel Subject: [PATCH 3/3] Dwarf: unwind the recorded stack frame of different target address sizes Date: Mon, 20 Jan 2014 22:22:02 +0100 Message-Id: <1390252922-25889-4-git-send-email-jean.pihet@linaro.org> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1390252922-25889-1-git-send-email-jean.pihet@linaro.org> References: <1390252922-25889-1-git-send-email-jean.pihet@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140120_162244_235606_2AB28F8E X-CRM114-Status: GOOD ( 12.92 ) X-Spam-Score: -2.6 (--) Cc: patches@linaro.org, Will Deacon , linux-kernel@vger.kernel.org, Jean Pihet , Jiri Olsa , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When in compat mode, correctly unwind the recorded stack frame. The returned pointers are cast to the desired target address size. Signed-off-by: Jean Pihet --- src/dwarf/Gparser.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/dwarf/Gparser.c b/src/dwarf/Gparser.c index b251e31..d676861 100644 --- a/src/dwarf/Gparser.c +++ b/src/dwarf/Gparser.c @@ -706,6 +706,29 @@ eval_location_expr (struct dwarf_cursor *c, unw_addr_space_t as, return 0; } +/* Cast pointer content to the type of target address size */ +static inline int cast_value_to_addr_size(unw_word_t *val, int addr_size) +{ + switch (addr_size) { + /* + * Return the value of the type found at binary load time (e.g. from the + * ELF format)... + */ + case TARGET_ADDR_SIZE_32: + *val = (uint32_t) *val; + break; + case TARGET_ADDR_SIZE_64: + *val = (uint64_t) *val; + break; + /* ... otherwise leave it as is */ + case TARGET_ADDR_SIZE_DEFAULT: + default: + break; + } + + return 0; +} + static int apply_reg_state (struct dwarf_cursor *c, struct dwarf_reg_state *rs) { @@ -743,6 +766,8 @@ apply_reg_state (struct dwarf_cursor *c, struct dwarf_reg_state *rs) regnum = dwarf_to_unw_regnum (rs->reg[DWARF_CFA_REG_COLUMN].val); if ((ret = unw_get_reg ((unw_cursor_t *) c, regnum, &cfa)) < 0) return ret; + /* Cast value to the type as found in the ELF binary format */ + cast_value_to_addr_size(&cfa, as->target_addr_size); } cfa += rs->reg[DWARF_CFA_OFF_COLUMN].val; } @@ -797,6 +822,8 @@ apply_reg_state (struct dwarf_cursor *c, struct dwarf_reg_state *rs) ret = dwarf_get (c, c->loc[c->ret_addr_column], &ip); if (ret < 0) return ret; + /* Cast value to the type as found in the ELF binary format */ + cast_value_to_addr_size(&ip, as->target_addr_size); c->ip = ip; }