4 * Copyright (C) 2009-2009, Eric Pouech.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define WIN32_NO_STATUS
25 #include "dbghelp_private.h"
26 #include "wine/winbase16.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp
);
32 static unsigned x86_64_get_addr(HANDLE hThread
, const CONTEXT
* ctx
,
33 enum cpu_addr ca
, ADDRESS64
* addr
)
35 addr
->Mode
= AddrModeFlat
;
39 case cpu_addr_pc
: addr
->Segment
= ctx
->SegCs
; addr
->Offset
= ctx
->Rip
; return TRUE
;
40 case cpu_addr_stack
: addr
->Segment
= ctx
->SegSs
; addr
->Offset
= ctx
->Rsp
; return TRUE
;
41 case cpu_addr_frame
: addr
->Segment
= ctx
->SegSs
; addr
->Offset
= ctx
->Rbp
; return TRUE
;
43 default: addr
->Mode
= -1;
48 enum st_mode
{stm_start
, stm_64bit
, stm_done
};
50 /* indexes in Reserved array */
51 #define __CurrentMode 0
52 #define __CurrentSwitch 1
53 #define __NextSwitch 2
55 #define curr_mode (frame->Reserved[__CurrentMode])
56 #define curr_switch (frame->Reserved[__CurrentSwitch])
57 #define next_switch (frame->Reserved[__NextSwitch])
59 static BOOL
x86_64_stack_walk(struct cpu_stack_walk
* csw
, LPSTACKFRAME64 frame
)
62 if (curr_mode
>= stm_done
) return FALSE
;
65 TRACE("Enter: PC=%s Frame=%s Return=%s Stack=%s Mode=%s\n",
66 wine_dbgstr_addr(&frame
->AddrPC
),
67 wine_dbgstr_addr(&frame
->AddrFrame
),
68 wine_dbgstr_addr(&frame
->AddrReturn
),
69 wine_dbgstr_addr(&frame
->AddrStack
),
70 curr_mode
== stm_start
? "start" : "64bit");
72 if (curr_mode
== stm_start
)
74 if ((frame
->AddrPC
.Mode
== AddrModeFlat
) &&
75 (frame
->AddrFrame
.Mode
!= AddrModeFlat
))
77 WARN("Bad AddrPC.Mode / AddrFrame.Mode combination\n");
82 curr_mode
= stm_64bit
;
84 frame
->AddrReturn
.Mode
= frame
->AddrStack
.Mode
= AddrModeFlat
;
85 /* don't set up AddrStack on first call. Either the caller has set it up, or
86 * we will get it in the next frame
88 memset(&frame
->AddrBStore
, 0, sizeof(frame
->AddrBStore
));
92 if (frame
->AddrReturn
.Offset
== 0) goto done_err
;
93 frame
->AddrPC
= frame
->AddrReturn
;
96 if (!sw_read_mem(csw
, frame
->AddrStack
.Offset
,
97 &frame
->AddrReturn
.Offset
, sizeof(DWORD64
)))
99 WARN("Cannot read new frame offset %s\n",
100 wine_dbgstr_longlong(frame
->AddrFrame
.Offset
+ sizeof(DWORD64
)));
103 /* FIXME: simplistic stuff... need to handle both dwarf & PE stack information */
104 frame
->AddrStack
.Offset
+= sizeof(DWORD64
);
105 memset(&frame
->Params
, 0, sizeof(frame
->Params
));
108 frame
->Virtual
= TRUE
;
109 if (frame
->AddrPC
.Offset
&& sw_module_base(csw
, frame
->AddrPC
.Offset
))
110 frame
->FuncTableEntry
= sw_table_access(csw
, frame
->AddrPC
.Offset
);
112 frame
->FuncTableEntry
= NULL
;
114 TRACE("Leave: PC=%s Frame=%s Return=%s Stack=%s Mode=%s FuncTable=%p\n",
115 wine_dbgstr_addr(&frame
->AddrPC
),
116 wine_dbgstr_addr(&frame
->AddrFrame
),
117 wine_dbgstr_addr(&frame
->AddrReturn
),
118 wine_dbgstr_addr(&frame
->AddrStack
),
119 curr_mode
== stm_start
? "start" : "64bit",
120 frame
->FuncTableEntry
);
124 curr_mode
= stm_done
;
128 struct cpu cpu_x86_64
= {
129 IMAGE_FILE_MACHINE_AMD64
,