From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 45608 invoked by alias); 26 Sep 2016 02:47:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 45594 invoked by uid 89); 26 Sep 2016 02:47:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=no version=3.3.2 spammy=H*RU:209.85.220.68, Hx-spam-relays-external:209.85.220.68, Manuals, 4656 X-HELO: mail-pa0-f68.google.com Received: from mail-pa0-f68.google.com (HELO mail-pa0-f68.google.com) (209.85.220.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 26 Sep 2016 02:47:40 +0000 Received: by mail-pa0-f68.google.com with SMTP id hm5so994015pac.1 for ; Sun, 25 Sep 2016 19:47:40 -0700 (PDT) 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:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=WNcQ7t4wG79kHq94zP9TSfmA69qm4gBh8WCOSmwFRIQ=; b=YtWotuSWNDiK99L0hf8bhVYtYyyL1cs67RkYs6yP6wOaRAmEPXHbye/hzvsFa4o7Sl 3H56K25ElqT0cO9rU7BNA2vSWf01rjC1OsHB39uuWnwyCpf6m97mkIllX2xtZeYgZPUR jjIcO0AVG6p6t6iKKG3l7BOFjZaidZoSaPOu0nJ2qk/ss56fuU61h6QhMGwh5dg8f7d4 uE6npJYbtQSME8CAhvGZF+N+Zc8njR/782Eoptiw7ZMYi4mlgGL/oQjkaI5fHMPB28II 3swQfwphfX3HODB96liyLUFQEeWPFSJpfLNIVFRgYPYrEzQyyKCs+wI6NQWSucD/g04T 0tLg== X-Gm-Message-State: AE9vXwOE9L9sIeznPW+kxf0+Jr9wdLW0ms8JYwVf8T/aJNNXMftl+S2O4pUU/k+vquftpg== X-Received: by 10.66.230.228 with SMTP id tb4mr34252651pac.99.1474858058994; Sun, 25 Sep 2016 19:47:38 -0700 (PDT) Received: from E107787-LIN (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id t6sm26295370paa.45.2016.09.25.19.47.36 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sun, 25 Sep 2016 19:47:38 -0700 (PDT) From: Yao Qi To: Adam Renquinha Cc: Yao Qi , Fredrik Hederstierna , "gdb-patches\@sourceware.org" Subject: Re: [PATCH] Fix exception unwinding for ARM Cortex-M References: <672a4613-af2e-14cf-f30f-dd90471f16de@cimeq.qc.ca> <2ed4bdc4-3168-acba-0382-9cea822c7032@cimeq.qc.ca> Date: Mon, 26 Sep 2016 03:03:00 -0000 In-Reply-To: <2ed4bdc4-3168-acba-0382-9cea822c7032@cimeq.qc.ca> (Adam Renquinha's message of "Fri, 23 Sep 2016 12:37:12 -0400") Message-ID: <86zimvjs1l.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2016-09/txt/msg00331.txt.bz2 Adam Renquinha writes: > FYI, the assignment process is done for me as well as for Fredrik. The > patch can be submitted. OK, I rebased Fredrik's patch https://sourceware.org/ml/gdb-patches/2016-08/msg00050.html, add some commit log, and adjust the comment format a little bit. What do you think of the patch below? If this is OK, I'll push it in to master and 7.12 branch. --=20 Yao (=E9=BD=90=E5=B0=A7) =46rom 7b10ca5f8650e9050c7211702c0a5b9cb0937722 Mon Sep 17 00:00:00 2001 From: Fredrik Hederstierna Date: Mon, 26 Sep 2016 03:32:21 +0100 Subject: [PATCH] Detect the magic address of EXC_RETURN in ARM coretx-m profile On ARMv6-M and ARMv7-M, the exception return address is sort of magic address defined by the manual. This patch is to let GDB well handle these magic addresses. 2016-09-25 Fredrik Hederstierna * arm-tdep.c (arm_m_addr_is_magic): New function. (arm_addr_bits_remove): Call arm_m_addr_is_magic. (arm_m_exception_unwind_sniffer): Likewise. diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 4dfd76b..a07d93b 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -465,6 +465,62 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR me= maddr) return 0; } =20 +/* Determine if the address specified equals any of these magic return + values, called EXC_RETURN, defined by the ARM v6-M and v7-M + architectures. + + From ARMv6-M Reference Manual B1.5.8 + Table B1-5 Exception return behavior + + EXC_RETURN Return To Return Stack + 0xFFFFFFF1 Handler mode Main + 0xFFFFFFF9 Thread mode Main + 0xFFFFFFFD Thread mode Process + + From ARMv7-M Reference Manual B1.5.8 + Table B1-8 EXC_RETURN definition of exception return behavior, no FP + + EXC_RETURN Return To Return Stack + 0xFFFFFFF1 Handler mode Main + 0xFFFFFFF9 Thread mode Main + 0xFFFFFFFD Thread mode Process + + Table B1-9 EXC_RETURN definition of exception return behavior, with + FP + + EXC_RETURN Return To Return Stack Frame Type + 0xFFFFFFE1 Handler mode Main Extended + 0xFFFFFFE9 Thread mode Main Extended + 0xFFFFFFED Thread mode Process Extended + 0xFFFFFFF1 Handler mode Main Basic + 0xFFFFFFF9 Thread mode Main Basic + 0xFFFFFFFD Thread mode Process Basic + + For more details see "B1.5.8 Exception return behavior" + in both ARMv6-M and ARMv7-M Architecture Reference Manuals. */ + +static int +arm_m_addr_is_magic (CORE_ADDR addr) +{ + switch (addr) + { + /* Values from Tables in B1.5.8 the EXC_RETURN definitions of + the exception return behavior. */ + case 0xffffffe1: + case 0xffffffe9: + case 0xffffffed: + case 0xfffffff1: + case 0xfffffff9: + case 0xfffffffd: + /* Address is magic. */ + return 1; + + default: + /* Address is not magic. */ + return 0; + } +} + /* Remove useless bits from addresses in a running program. */ static CORE_ADDR arm_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR val) @@ -472,7 +528,7 @@ arm_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADD= R val) /* On M-profile devices, do not strip the low bit from EXC_RETURN (the magic exception return address). */ if (gdbarch_tdep (gdbarch)->is_m - && (val & 0xfffffff0) =3D=3D 0xfffffff0) + && arm_m_addr_is_magic (val)) return val; =20 if (arm_apcs_32) @@ -2991,14 +3047,8 @@ arm_m_exception_unwind_sniffer (const struct frame_u= nwind *self, /* No need to check is_m; this sniffer is only registered for M-profile architectures. */ =20 - /* Exception frames return to one of these magic PCs. Other values - are not defined as of v7-M. See details in "B1.5.8 Exception - return behavior" in "ARMv7-M Architecture Reference Manual". */ - if (this_pc =3D=3D 0xfffffff1 || this_pc =3D=3D 0xfffffff9 - || this_pc =3D=3D 0xfffffffd) - return 1; - - return 0; + /* Check if exception frame returns to a magic PC value. */ + return arm_m_addr_is_magic (this_pc); } =20 /* Frame unwinder for M-profile exceptions. */