From 9a4d6455fc8964a928d94bac6f5db0b8d625b652 Mon Sep 17 00:00:00 2001 From: px4dev Date: Wed, 23 Jan 2013 18:55:23 -0800 Subject: [PATCH] More debug macros. --- Debug/ARMv7M | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++ Debug/PX4 | 1 + 2 files changed, 153 insertions(+) create mode 100644 Debug/ARMv7M diff --git a/Debug/ARMv7M b/Debug/ARMv7M new file mode 100644 index 0000000000..3d96da682d --- /dev/null +++ b/Debug/ARMv7M @@ -0,0 +1,152 @@ +# +# Assorted ARMv7M macros +# + +echo Loading ARMv7M GDB macros. Use 'help armv7m' for more information.\n + +define armv7m + echo Use 'help armv7m' for more information.\n +end + +document armv7m +. Various macros for working with the ARMv7M family of processors. +. +. vecstate +. Print information about the current exception handling state. +. +. Use 'help ' for more specific help. +end + + +define vecstate + set $icsr = *(uint32_t *)0xe000ed04 + set $vect = $icsr & 0x1ff + set $pend = ($icsr & 0x1ff000) >> 12 + set $shcsr = *(uint32_t *)0xe000ed24 + set $cfsr = *(uint32_t *)0xe000ed28 + set $mmfsr = $cfsr & 0xff + set $bfsr = ($cfsr >> 8) & 0xff + set $ufsr = ($cfsr >> 16) & 0xffff + set $hfsr = *(uint32_t *)0xe000ed2c + set $bfar = *(uint32_t *)0xe000ed38 + set $mmfar = *(uint32_t *)0xe000ed34 + + # XXX Currently, rather than look at $vect, we just decode the + # fault status registers directly. + + if $hfsr != 0 + printf "HardFault:" + if $hfsr & (1<<1) + printf " due to vector table read fault\n" + end + if $hfsr & (1<<30) + printf " forced ue to escalated or disabled configurable fault (see below)\n" + end + if $hfsr & (1<<31) + printf " due to an unexpected debug event\n" + end + end + if $mmfsr != 0 + printf "MemManage:" + if $mmfsr & (1<<5) + printf " during lazy FP state save" + end + if $mmfsr & (1<<4) + printf " during exception entry" + end + if $mmfsr & (1<<3) + printf " during exception return" + end + if $mmfsr & (1<<0) + printf " during data access" + end + if $mmfsr & (1<<0) + printf " during instruction prefetch" + end + if $mmfsr & (1<<7) + printf " accessing 0x%08x", $mmfar + end + printf "\n" + end + if $bfsr != 0 + printf "BusFault:" + if $bfsr & (1<<2) + printf " (imprecise)" + end + if $bfsr & (1<<1) + printf " (precise)" + end + if $bfsr & (1<<5) + printf " during lazy FP state save" + end + if $bfsr & (1<<4) + printf " during exception entry" + end + if $bfsr & (1<<3) + printf " during exception return" + end + if $bfsr & (1<<0) + printf " during instruction prefetch" + end + if $bfsr & (1<<7) + printf " accessing 0x%08x", $bfar + end + printf "\n" + end + if $ufsr != 0 + printf "UsageFault" + if $ufsr & (1<<9) + printf " due to divide-by-zero" + end + if $ufsr & (1<<8) + printf " due to unaligned memory access" + end + if $ufsr & (1<<3) + printf " due to access to disabled/absent coprocessor" + end + if $ufsr & (1<<2) + printf " due to a bad EXC_RETURN value" + end + if $ufsr & (1<<1) + printf " due to bad T or IT bits in EPSR" + end + if $ufsr & (1<<0) + printf " due to executing an undefined instruction" + end + printf "\n" + end + if ((uint32_t)$lr & 0xf0000000) == 0xf0000000 + if ($lr & 1) + set $frame_ptr = (uint32_t *)$msp + else + set $frame_ptr = (uint32_t *)$psp + end + printf " r0: %08x r1: %08x r2: %08x r3: %08x\n, $frame_ptr[0], $frame_ptr[1], $frame_ptr[2], $frame_ptr[3] + printf " r4: %08x r5: %08x r6: %08x r7: %08x\n", $r4, $r5, $r6, $r7 + printf " r8: %08x r9: %08x r10: %08x r11: %08x\n", $r8, $r9, $r10, $r11 + printf " r12: $08x lr: %08x pc: %08xx PSR: %08x\n", $frame_ptr[4], $frame_ptr[5], $frame_ptr[6], $frame_ptr[7] + + # Swap to the context of the faulting code and try to print a backtrace + set $saved_sp = $sp + if $lr & 0x10 + set $sp = $frame_ptr + (8 * 4) + else + set $sp = $frame_ptr + (26 * 4) + end + set $saved_lr = $lr + set $lr = $frame_ptr[5] + set $saved_pc = $pc + set $pc = $frame_ptr[6] + bt + set $sp = $saved_sp + set $lr = $saved_lr + set $pc = $saved_pc + else + printf "(not currently in exception state)\n" + end +end + +document vecstate +. vecstate +. Print information about the current exception handling state. +end diff --git a/Debug/PX4 b/Debug/PX4 index 7d59059398..806c495846 100644 --- a/Debug/PX4 +++ b/Debug/PX4 @@ -2,6 +2,7 @@ # Various PX4-specific macros # source Debug/NuttX +source Debug/ARMv7M echo Loading PX4 GDB macros. Use 'help px4' for more information.\n