Eric Pouech : dbghelp: Hacked a StackWalk implementation for x86_64.

Alexandre Julliard julliard at winehq.org
Wed Dec 23 10:04:10 CST 2009


Module: wine
Branch: master
Commit: 54766cdac0fc27ed8e33225b88a2d3a0bc174f25
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=54766cdac0fc27ed8e33225b88a2d3a0bc174f25

Author: Eric Pouech <eric.pouech at orange.fr>
Date:   Tue Dec 22 14:21:31 2009 +0100

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(-)

diff --git a/dlls/dbghelp/Makefile.in b/dlls/dbghelp/Makefile.in
index 57b9c57..d3a72a2 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 0000000..5678678
--- /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 <assert.h>
+
+#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 47691b9..860d267 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




More information about the wine-cvs mailing list