checkwps: harden filename extension checking.
[maemo-rb.git] / lib / unwarminder / backtrace.c
blob47898a905499119fb49dc8f94246fef519f04396
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 /***************************************************************************
22 * Includes
23 ***************************************************************************/
25 #include "backtrace.h"
26 #include "safe_read.h"
28 /***************************************************************************
29 * Prototypes
30 ***************************************************************************/
32 static Boolean CliReport(void *data, Int32 address);
33 static Boolean CliReadW(Int32 a, Int32 *v);
34 static Boolean CliReadH(Int32 a, Int16 *v);
35 static Boolean CliReadB(Int32 a, Int8 *v);
37 /***************************************************************************
38 * Variables
39 ***************************************************************************/
41 /* Table of function pointers for passing to the unwinder */
42 const UnwindCallbacks cliCallbacks =
44 CliReport,
45 CliReadW,
46 CliReadH,
47 CliReadB
48 #if defined(UNW_DEBUG)
49 ,printf
50 #endif
54 /***************************************************************************
55 * Callbacks
56 ***************************************************************************/
58 /***************************************************************************
60 * Function: CliReport
62 * Parameters: data - Pointer to data passed to UnwindStart()
63 * address - The return address of a stack frame.
65 * Returns: TRUE if unwinding should continue, otherwise FALSE to
66 * indicate that unwinding should stop.
68 * Description: This function is called from the unwinder each time a stack
69 * frame has been unwound. The LSB of address indicates if
70 * the processor is in ARM mode (LSB clear) or Thumb (LSB
71 * set).
73 ***************************************************************************/
74 static Boolean CliReport(void *data, Int32 address)
76 /* CliStack *s = (CliStack *)data; */
77 unsigned *line = (unsigned *)data;
80 lcd_putsf(0, (*line)++, " %c: %08x",
81 (address & 0x1) ? 'T' : 'A',
82 address & (~0x1));
83 lcd_update();
85 return TRUE;
88 static Boolean CliReadW(const Int32 a, Int32 *v)
90 return safe_read32((uint32_t *)a, (uint32_t *)v);
93 static Boolean CliReadH(const Int32 a, Int16 *v)
95 return safe_read16((void *)a, (uint16_t *)v);
98 static Boolean CliReadB(const Int32 a, Int8 *v)
100 return safe_read8((void *)a, (uint8_t *)v);
103 Boolean CliInvalidateW(const Int32 a)
105 *(Int32 *)a = 0xdeadbeef;
106 return TRUE;
109 void backtrace(int pcAddr, int spAddr, unsigned *line)
111 UnwResult r;
113 lcd_putsf(0, (*line)++, "bt pc: %08x, sp: %08x", pcAddr, spAddr);
114 lcd_update();
116 r = UnwindStart(pcAddr, spAddr, &cliCallbacks, (void *)line);
118 lcd_puts(0, (*line)++, "bt end");
119 lcd_update();
122 /* END OF FILE */