From 54766cdac0fc27ed8e33225b88a2d3a0bc174f25 Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Tue, 22 Dec 2009 14:21:31 +0100 Subject: [PATCH] dbghelp: Hacked a StackWalk implementation for x86_64. --- dlls/dbghelp/Makefile.in | 1 + dlls/dbghelp/cpu_x86_64.c | 115 ++++++++++++++++++++++++++++++++++++++ dlls/dbghelp/dbghelp.c | 6 +- 3 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 dlls/dbghelp/cpu_x86_64.c diff --git a/dlls/dbghelp/Makefile.in b/dlls/dbghelp/Makefile.in index 57b9c57ba6c..d3a72a2073b 100644 --- a/dlls/dbghelp/Makefile.in +++ b/dlls/dbghelp/Makefile.in @@ -11,6 +11,7 @@ DELAYIMPORTS = version C_SRCS = \ coff.c \ cpu_i386.c \ + cpu_x86_64.c \ crc32.c \ dbghelp.c \ dwarf.c \ diff --git a/dlls/dbghelp/cpu_x86_64.c b/dlls/dbghelp/cpu_x86_64.c new file mode 100644 index 00000000000..56786786b9c --- /dev/null +++ b/dlls/dbghelp/cpu_x86_64.c @@ -0,0 +1,115 @@ +/* + * File cpu_x86_64.c + * + * Copyright (C) 2009-2009, Eric Pouech. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include + +#include "ntstatus.h" +#define WIN32_NO_STATUS +#include "dbghelp_private.h" +#include "wine/winbase16.h" +#include "winternl.h" +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(dbghelp); + +enum st_mode {stm_start, stm_64bit, stm_done}; + +/* indexes in Reserved array */ +#define __CurrentMode 0 +#define __CurrentSwitch 1 +#define __NextSwitch 2 + +#define curr_mode (frame->Reserved[__CurrentMode]) +#define curr_switch (frame->Reserved[__CurrentSwitch]) +#define next_switch (frame->Reserved[__NextSwitch]) + +static BOOL x86_64_stack_walk(struct cpu_stack_walk* csw, LPSTACKFRAME64 frame) +{ + /* sanity check */ + if (curr_mode >= stm_done) return FALSE; + assert(!csw->is32); + + TRACE("Enter: PC=%s Frame=%s Return=%s Stack=%s Mode=%s\n", + wine_dbgstr_addr(&frame->AddrPC), + wine_dbgstr_addr(&frame->AddrFrame), + wine_dbgstr_addr(&frame->AddrReturn), + wine_dbgstr_addr(&frame->AddrStack), + curr_mode == stm_start ? "start" : "64bit"); + + if (curr_mode == stm_start) + { + if ((frame->AddrPC.Mode == AddrModeFlat) && + (frame->AddrFrame.Mode != AddrModeFlat)) + { + WARN("Bad AddrPC.Mode / AddrFrame.Mode combination\n"); + goto done_err; + } + + /* Init done */ + curr_mode = stm_64bit; + curr_switch = 0; + frame->AddrReturn.Mode = frame->AddrStack.Mode = AddrModeFlat; + /* don't set up AddrStack on first call. Either the caller has set it up, or + * we will get it in the next frame + */ + memset(&frame->AddrBStore, 0, sizeof(frame->AddrBStore)); + } + else + { + if (frame->AddrReturn.Offset == 0) goto done_err; + frame->AddrPC = frame->AddrReturn; + } + + if (!sw_read_mem(csw, frame->AddrStack.Offset, + &frame->AddrReturn.Offset, sizeof(DWORD64))) + { + WARN("Cannot read new frame offset %s\n", + wine_dbgstr_longlong(frame->AddrFrame.Offset + sizeof(DWORD64))); + goto done_err; + } + /* FIXME: simplistic stuff... need to handle both dwarf & PE stack information */ + frame->AddrStack.Offset += sizeof(DWORD64); + memset(&frame->Params, 0, sizeof(frame->Params)); + + frame->Far = TRUE; + frame->Virtual = TRUE; + if (frame->AddrPC.Offset && sw_module_base(csw, frame->AddrPC.Offset)) + frame->FuncTableEntry = sw_table_access(csw, frame->AddrPC.Offset); + else + frame->FuncTableEntry = NULL; + + TRACE("Leave: PC=%s Frame=%s Return=%s Stack=%s Mode=%s FuncTable=%p\n", + wine_dbgstr_addr(&frame->AddrPC), + wine_dbgstr_addr(&frame->AddrFrame), + wine_dbgstr_addr(&frame->AddrReturn), + wine_dbgstr_addr(&frame->AddrStack), + curr_mode == stm_start ? "start" : "64bit", + frame->FuncTableEntry); + + return TRUE; +done_err: + curr_mode = stm_done; + return FALSE; +} + +struct cpu cpu_x86_64 = { + IMAGE_FILE_MACHINE_AMD64, + x86_64_stack_walk, +}; diff --git a/dlls/dbghelp/dbghelp.c b/dlls/dbghelp/dbghelp.c index 47691b90b1c..860d267c19e 100644 --- a/dlls/dbghelp/dbghelp.c +++ b/dlls/dbghelp/dbghelp.c @@ -151,12 +151,14 @@ const char* wine_dbgstr_addr(const ADDRESS64* addr) } } -extern struct cpu cpu_i386; +extern struct cpu cpu_i386, cpu_x86_64; -static struct cpu* dbghelp_cpus[] = {&cpu_i386, NULL}; +static struct cpu* dbghelp_cpus[] = {&cpu_i386, &cpu_x86_64, NULL}; struct cpu* dbghelp_current_cpu = #if defined(__i386__) &cpu_i386 +#elif defined(__x86_64__) + &cpu_x86_64 #else #error define support for you CPU #endif