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"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
31 static unsigned x86_64_get_addr(HANDLE hThread, const CONTEXT* ctx,
32 enum cpu_addr ca, ADDRESS64* addr)
34 addr->Mode = AddrModeFlat;
38 case cpu_addr_pc: addr->Segment = ctx->SegCs; addr->Offset = ctx->Rip; return TRUE;
39 case cpu_addr_stack: addr->Segment = ctx->SegSs; addr->Offset = ctx->Rsp; return TRUE;
40 case cpu_addr_frame: addr->Segment = ctx->SegSs; addr->Offset = ctx->Rbp; return TRUE;
42 default: addr->Mode = -1;
47 enum st_mode {stm_start, stm_64bit, stm_done};
49 /* indexes in Reserved array */
50 #define __CurrentMode 0
51 #define __CurrentSwitch 1
52 #define __NextSwitch 2
54 #define curr_mode (frame->Reserved[__CurrentMode])
55 #define curr_switch (frame->Reserved[__CurrentSwitch])
56 #define next_switch (frame->Reserved[__NextSwitch])
58 static BOOL x86_64_stack_walk(struct cpu_stack_walk* csw, LPSTACKFRAME64 frame)
61 if (curr_mode >= stm_done) return FALSE;
64 TRACE("Enter: PC=%s Frame=%s Return=%s Stack=%s Mode=%s\n",
65 wine_dbgstr_addr(&frame->AddrPC),
66 wine_dbgstr_addr(&frame->AddrFrame),
67 wine_dbgstr_addr(&frame->AddrReturn),
68 wine_dbgstr_addr(&frame->AddrStack),
69 curr_mode == stm_start ? "start" : "64bit");
71 if (curr_mode == stm_start)
73 if ((frame->AddrPC.Mode == AddrModeFlat) &&
74 (frame->AddrFrame.Mode != AddrModeFlat))
76 WARN("Bad AddrPC.Mode / AddrFrame.Mode combination\n");
81 curr_mode = stm_64bit;
83 frame->AddrReturn.Mode = frame->AddrStack.Mode = AddrModeFlat;
84 /* don't set up AddrStack on first call. Either the caller has set it up, or
85 * we will get it in the next frame
87 memset(&frame->AddrBStore, 0, sizeof(frame->AddrBStore));
91 if (frame->AddrReturn.Offset == 0) goto done_err;
92 frame->AddrPC = frame->AddrReturn;
95 if (!sw_read_mem(csw, frame->AddrStack.Offset,
96 &frame->AddrReturn.Offset, sizeof(DWORD64)))
98 WARN("Cannot read new frame offset %s\n",
99 wine_dbgstr_longlong(frame->AddrFrame.Offset + sizeof(DWORD64)));
102 /* FIXME: simplistic stuff... need to handle both dwarf & PE stack information */
103 frame->AddrStack.Offset += sizeof(DWORD64);
104 memset(&frame->Params, 0, sizeof(frame->Params));
107 frame->Virtual = TRUE;
108 if (frame->AddrPC.Offset && sw_module_base(csw, frame->AddrPC.Offset))
109 frame->FuncTableEntry = sw_table_access(csw, frame->AddrPC.Offset);
111 frame->FuncTableEntry = NULL;
113 TRACE("Leave: PC=%s Frame=%s Return=%s Stack=%s Mode=%s FuncTable=%p\n",
114 wine_dbgstr_addr(&frame->AddrPC),
115 wine_dbgstr_addr(&frame->AddrFrame),
116 wine_dbgstr_addr(&frame->AddrReturn),
117 wine_dbgstr_addr(&frame->AddrStack),
118 curr_mode == stm_start ? "start" : "64bit",
119 frame->FuncTableEntry);
123 curr_mode = stm_done;
127 struct cpu cpu_x86_64 = {
128 IMAGE_FILE_MACHINE_AMD64,