1 /***************************************************************************
2 * ARM Stack Unwinder, Michael.McTernan.2001@cs.bris.ac.uk
4 * This program is PUBLIC DOMAIN.
5 * This means that there is no copyright and anyone is able to take a copy
6 * for free and use it as they wish, with or without modifications, and in
7 * any context, commercially or otherwise. The only limitation is that I
8 * don't guarantee that the software is fit for any purpose or accept any
9 * liability for it's use or misuse - this software is without warranty.
10 ***************************************************************************
11 * File Description: Unwinder client that reads local memory.
12 * This client reads from local memory and is designed to run on target
13 * along with the unwinder. Memory read requests are implemented by
14 * casting a point to read the memory directly, although checks for
15 * alignment should probably also be made if this is to be used in
16 * production code, as otherwise the ARM may return the memory in a
17 * rotated/rolled format, or the MMU may generate an alignment exception
18 * if present and so configured.
19 **************************************************************************/
21 /***************************************************************************
23 ***************************************************************************/
25 #include "backtrace.h"
27 /***************************************************************************
29 ***************************************************************************/
31 static Boolean
CliReport(void *data
, Int32 address
);
32 static Boolean
CliReadW(Int32 a
, Int32
*v
);
33 static Boolean
CliReadH(Int32 a
, Int16
*v
);
34 static Boolean
CliReadB(Int32 a
, Int8
*v
);
36 /***************************************************************************
38 ***************************************************************************/
40 /* Table of function pointers for passing to the unwinder */
41 const UnwindCallbacks cliCallbacks
=
47 #if defined(UNW_DEBUG)
53 /***************************************************************************
55 ***************************************************************************/
57 /***************************************************************************
61 * Parameters: data - Pointer to data passed to UnwindStart()
62 * address - The return address of a stack frame.
64 * Returns: TRUE if unwinding should continue, otherwise FALSE to
65 * indicate that unwinding should stop.
67 * Description: This function is called from the unwinder each time a stack
68 * frame has been unwound. The LSB of address indicates if
69 * the processor is in ARM mode (LSB clear) or Thumb (LSB
72 ***************************************************************************/
73 static Boolean
CliReport(void *data
, Int32 address
)
75 /* CliStack *s = (CliStack *)data; */
76 unsigned *line
= (unsigned *)data
;
79 lcd_putsf(0, (*line
)++, " %c: 0x%08x",
80 (address
& 0x1) ? 'T' : 'A',
87 static Boolean
CliReadW(const Int32 a
, Int32
*v
)
93 static Boolean
CliReadH(const Int32 a
, Int16
*v
)
99 static Boolean
CliReadB(const Int32 a
, Int8
*v
)
105 Boolean
CliInvalidateW(const Int32 a
)
107 *(Int32
*)a
= 0xdeadbeef;
111 void backtrace(int pcAddr
, int spAddr
, unsigned *line
)
115 lcd_putsf(0, (*line
)++, "bt pc: 0x%08x, sp: 0x%08x", pcAddr
, spAddr
);
118 r
= UnwindStart(pcAddr
, spAddr
, &cliCallbacks
, (void *)line
);
120 lcd_puts(0, (*line
)++, "bt end");