4 * Copyright (C) 2009 Eric Pouech
5 * Copyright (C) 2010, 2011 André Hentschel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #define WIN32_NO_STATUS
26 #include "dbghelp_private.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp
);
32 static BOOL
arm_get_addr(HANDLE hThread
, const CONTEXT
* ctx
,
33 enum cpu_addr ca
, ADDRESS64
* addr
)
35 addr
->Mode
= AddrModeFlat
;
36 addr
->Segment
= 0; /* don't need segment */
40 case cpu_addr_pc
: addr
->Offset
= ctx
->Pc
; return TRUE
;
41 case cpu_addr_stack
: addr
->Offset
= ctx
->Sp
; return TRUE
;
42 case cpu_addr_frame
: addr
->Offset
= ctx
->R11
; return TRUE
;
44 default: addr
->Mode
= -1;
50 enum st_mode
{stm_start
, stm_arm
, stm_done
};
52 /* indexes in Reserved array */
53 #define __CurrentModeCount 0
55 #define curr_mode (frame->Reserved[__CurrentModeCount] & 0x0F)
56 #define curr_count (frame->Reserved[__CurrentModeCount] >> 4)
58 #define set_curr_mode(m) {frame->Reserved[__CurrentModeCount] &= ~0x0F; frame->Reserved[__CurrentModeCount] |= (m & 0x0F);}
59 #define inc_curr_count() (frame->Reserved[__CurrentModeCount] += 0x10)
63 * modify (at least) context.Pc using unwind information
64 * either out of debug info (dwarf), or simple Lr trace
66 static BOOL
fetch_next_frame(struct cpu_stack_walk
* csw
, union ctx
*pcontext
,
70 CONTEXT
*context
= &pcontext
->ctx
;
71 DWORD oldReturn
= context
->Lr
;
73 if (dwarf2_virtual_unwind(csw
, curr_pc
, pcontext
, &xframe
))
76 context
->Pc
= oldReturn
;
80 if (context
->Pc
== context
->Lr
) return FALSE
;
81 context
->Pc
= oldReturn
;
86 static BOOL
arm_stack_walk(struct cpu_stack_walk
*csw
, STACKFRAME64
*frame
,
89 unsigned deltapc
= curr_count
<= 1 ? 0 : 4;
92 if (curr_mode
>= stm_done
) return FALSE
;
94 TRACE("Enter: PC=%s Frame=%s Return=%s Stack=%s Mode=%s Count=%s\n",
95 wine_dbgstr_addr(&frame
->AddrPC
),
96 wine_dbgstr_addr(&frame
->AddrFrame
),
97 wine_dbgstr_addr(&frame
->AddrReturn
),
98 wine_dbgstr_addr(&frame
->AddrStack
),
99 curr_mode
== stm_start
? "start" : "ARM",
100 wine_dbgstr_longlong(curr_count
));
102 if (curr_mode
== stm_start
)
105 set_curr_mode(stm_arm
);
106 frame
->AddrReturn
.Mode
= frame
->AddrStack
.Mode
= AddrModeFlat
;
107 /* don't set up AddrStack on first call. Either the caller has set it up, or
108 * we will get it in the next frame
110 memset(&frame
->AddrBStore
, 0, sizeof(frame
->AddrBStore
));
114 if (context
->ctx
.Sp
!= frame
->AddrStack
.Offset
) FIXME("inconsistent Stack Pointer\n");
115 if (context
->ctx
.Pc
!= frame
->AddrPC
.Offset
) FIXME("inconsistent Program Counter\n");
117 if (frame
->AddrReturn
.Offset
== 0) goto done_err
;
118 if (!fetch_next_frame(csw
, context
, frame
->AddrPC
.Offset
- deltapc
))
122 memset(&frame
->Params
, 0, sizeof(frame
->Params
));
124 /* set frame information */
125 frame
->AddrStack
.Offset
= context
->ctx
.Sp
;
126 frame
->AddrReturn
.Offset
= context
->ctx
.Lr
;
127 frame
->AddrFrame
.Offset
= context
->ctx
.R11
;
128 frame
->AddrPC
.Offset
= context
->ctx
.Pc
;
131 frame
->Virtual
= TRUE
;
134 TRACE("Leave: PC=%s Frame=%s Return=%s Stack=%s Mode=%s Count=%s FuncTable=%p\n",
135 wine_dbgstr_addr(&frame
->AddrPC
),
136 wine_dbgstr_addr(&frame
->AddrFrame
),
137 wine_dbgstr_addr(&frame
->AddrReturn
),
138 wine_dbgstr_addr(&frame
->AddrStack
),
139 curr_mode
== stm_start
? "start" : "ARM",
140 wine_dbgstr_longlong(curr_count
),
141 frame
->FuncTableEntry
);
145 set_curr_mode(stm_done
);
149 static BOOL
arm_stack_walk(struct cpu_stack_walk
*csw
, STACKFRAME64
*frame
,
156 static unsigned arm_map_dwarf_register(unsigned regno
, const struct module
* module
, BOOL eh_frame
)
158 if (regno
<= 15) return CV_ARM_R0
+ regno
;
159 if (regno
== 128) return CV_ARM_CPSR
;
161 FIXME("Don't know how to map register %d\n", regno
);
165 static void *arm_fetch_context_reg(union ctx
*pctx
, unsigned regno
, unsigned *size
)
168 CONTEXT
*ctx
= &pctx
->ctx
;
172 case CV_ARM_R0
+ 0: *size
= sizeof(ctx
->R0
); return &ctx
->R0
;
173 case CV_ARM_R0
+ 1: *size
= sizeof(ctx
->R1
); return &ctx
->R1
;
174 case CV_ARM_R0
+ 2: *size
= sizeof(ctx
->R2
); return &ctx
->R2
;
175 case CV_ARM_R0
+ 3: *size
= sizeof(ctx
->R3
); return &ctx
->R3
;
176 case CV_ARM_R0
+ 4: *size
= sizeof(ctx
->R4
); return &ctx
->R4
;
177 case CV_ARM_R0
+ 5: *size
= sizeof(ctx
->R5
); return &ctx
->R5
;
178 case CV_ARM_R0
+ 6: *size
= sizeof(ctx
->R6
); return &ctx
->R6
;
179 case CV_ARM_R0
+ 7: *size
= sizeof(ctx
->R7
); return &ctx
->R7
;
180 case CV_ARM_R0
+ 8: *size
= sizeof(ctx
->R8
); return &ctx
->R8
;
181 case CV_ARM_R0
+ 9: *size
= sizeof(ctx
->R9
); return &ctx
->R9
;
182 case CV_ARM_R0
+ 10: *size
= sizeof(ctx
->R10
); return &ctx
->R10
;
183 case CV_ARM_R0
+ 11: *size
= sizeof(ctx
->R11
); return &ctx
->R11
;
184 case CV_ARM_R0
+ 12: *size
= sizeof(ctx
->R12
); return &ctx
->R12
;
186 case CV_ARM_SP
: *size
= sizeof(ctx
->Sp
); return &ctx
->Sp
;
187 case CV_ARM_LR
: *size
= sizeof(ctx
->Lr
); return &ctx
->Lr
;
188 case CV_ARM_PC
: *size
= sizeof(ctx
->Pc
); return &ctx
->Pc
;
189 case CV_ARM_CPSR
: *size
= sizeof(ctx
->Cpsr
); return &ctx
->Cpsr
;
192 FIXME("Unknown register %x\n", regno
);
196 static const char* arm_fetch_regname(unsigned regno
)
200 case CV_ARM_R0
+ 0: return "r0";
201 case CV_ARM_R0
+ 1: return "r1";
202 case CV_ARM_R0
+ 2: return "r2";
203 case CV_ARM_R0
+ 3: return "r3";
204 case CV_ARM_R0
+ 4: return "r4";
205 case CV_ARM_R0
+ 5: return "r5";
206 case CV_ARM_R0
+ 6: return "r6";
207 case CV_ARM_R0
+ 7: return "r7";
208 case CV_ARM_R0
+ 8: return "r8";
209 case CV_ARM_R0
+ 9: return "r9";
210 case CV_ARM_R0
+ 10: return "r10";
211 case CV_ARM_R0
+ 11: return "r11";
212 case CV_ARM_R0
+ 12: return "r12";
214 case CV_ARM_SP
: return "sp";
215 case CV_ARM_LR
: return "lr";
216 case CV_ARM_PC
: return "pc";
217 case CV_ARM_CPSR
: return "cpsr";
219 FIXME("Unknown register %x\n", regno
);
223 static BOOL
arm_fetch_minidump_thread(struct dump_context
* dc
, unsigned index
, unsigned flags
, const CONTEXT
* ctx
)
225 if (ctx
->ContextFlags
&& (flags
& ThreadWriteInstructionWindow
))
227 /* FIXME: crop values across module boundaries, */
229 ULONG base
= ctx
->Pc
<= 0x80 ? 0 : ctx
->Pc
- 0x80;
230 minidump_add_memory_block(dc
, base
, ctx
->Pc
+ 0x80 - base
, 0);
237 static BOOL
arm_fetch_minidump_module(struct dump_context
* dc
, unsigned index
, unsigned flags
)
239 /* FIXME: actually, we should probably take care of FPO data, unless it's stored in
240 * function table minidump stream
245 DECLSPEC_HIDDEN
struct cpu cpu_arm
= {
246 IMAGE_FILE_MACHINE_ARMNT
,
252 arm_map_dwarf_register
,
253 arm_fetch_context_reg
,
255 arm_fetch_minidump_thread
,
256 arm_fetch_minidump_module
,