Re: [PATCH/arm] Backtrace through exception frames on arm/cortex-m target

Mark Kettenis
2012-11-13T14:27:51Z

> From: Yao Qi <yao@codesourcery.com>
> Date: Tue, 13 Nov 2012 22:15:40 +0800
>
> Hi,
> This patch adds support for backtracing through exceptions on
> M-profile targets. Dan wrote this patch two years ago, tested
> by hand that set a breakpoint on an interrupt handler and GDB will
> show the complete stack frame including the exception handler
> and the source location that caused the fault. I update the patch a
> little for some API changes in GDB trunk.
>
> I considered to write a test case for this, but it hard to write
> single case for different corex-m boards with different system
> libraries. So no test case is included.
>
> Regression tested for arm-none-eabi (-march=armv6-m and -march=armv7-m
> respectively) and arm-none-linux-gnueabi (-marm/-mthumb
> -march=armv4/-mthumb -march=armv7-a). OK to apply?

No. Because...

> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
> index 1a67366..5f22649 100644
> --- a/gdb/arm-tdep.c
> +++ b/gdb/arm-tdep.c
> @@ -448,6 +448,11 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr)
> static CORE_ADDR
> arm_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR 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) == 0xfffffff0)
> + return val;
> +
> if (arm_apcs_32)
> return UNMAKE_THUMB_ADDR (val);
> else
> @@ -2926,6 +2931,103 @@ struct frame_unwind arm_stub_unwind = {
> arm_stub_unwind_sniffer
> };
>
> +static struct arm_prologue_cache *
> +arm_m_exception_cache (struct frame_info *this_frame)
> +{
> + struct gdbarch *gdbarch = get_frame_arch (this_frame);
> + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> + struct arm_prologue_cache *cache;
> + CORE_ADDR unwound_sp;
> + LONGEST xpsr;
> +
> + cache = FRAME_OBSTACK_ZALLOC (struct arm_prologue_cache);
> + cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
> +
> + unwound_sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM);

Calling get_frame_register_unsign(this_frame, ...) in the unwinder
itself is verboten!.