makefiles: Generate the config.status dependency as part of the makefile dependencies.
[wine/multimedia.git] / dlls / dbghelp / cpu_x86_64.c
blobd7fb138eb2446b34c661cbfaf37111eb296bc119
1 /*
2 * File cpu_x86_64.c
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
21 #include <assert.h>
23 #include "ntstatus.h"
24 #define WIN32_NO_STATUS
25 #include "dbghelp_private.h"
26 #include "wine/winbase16.h"
27 #include "winternl.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;
36 switch (ca)
38 #ifdef __x86_64__
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;
42 #endif
43 default: addr->Mode = -1;
44 return FALSE;
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)
61 /* sanity check */
62 if (curr_mode >= stm_done) return FALSE;
63 assert(!csw->is32);
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");
78 goto done_err;
81 /* Init done */
82 curr_mode = stm_64bit;
83 curr_switch = 0;
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));
90 else
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)));
101 goto done_err;
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));
107 frame->Far = TRUE;
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);
111 else
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);
122 return TRUE;
123 done_err:
124 curr_mode = stm_done;
125 return FALSE;
128 struct cpu cpu_x86_64 = {
129 IMAGE_FILE_MACHINE_AMD64,
131 x86_64_get_addr,
132 x86_64_stack_walk,