André Hentschel : dbghelp: Implement rudimentary stack walk for ARM.

Alexandre Julliard julliard at winehq.org
Thu Apr 28 12:18:54 CDT 2011


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

Author: André Hentschel <nerv at dawncrow.de>
Date:   Wed Apr 27 21:08:49 2011 +0200

dbghelp: Implement rudimentary stack walk for ARM.

---

 dlls/dbghelp/cpu_arm.c |  111 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 108 insertions(+), 3 deletions(-)

diff --git a/dlls/dbghelp/cpu_arm.c b/dlls/dbghelp/cpu_arm.c
index 4f54ef4..5bec525 100644
--- a/dlls/dbghelp/cpu_arm.c
+++ b/dlls/dbghelp/cpu_arm.c
@@ -1,8 +1,8 @@
 /*
  * File cpu_arm.c
  *
- * Copyright (C) 2009-2009, Eric Pouech
- * Copyright (C) 2010, André Hentschel
+ * Copyright (C) 2009 Eric Pouech
+ * Copyright (C) 2010, 2011 André Hentschel
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -46,11 +46,116 @@ static unsigned arm_get_addr(HANDLE hThread, const CONTEXT* ctx,
     }
 }
 
+#ifdef __arm__
+enum st_mode {stm_start, stm_arm, stm_done};
+
+/* indexes in Reserved array */
+#define __CurrentModeCount      0
+
+#define curr_mode   (frame->Reserved[__CurrentModeCount] & 0x0F)
+#define curr_count  (frame->Reserved[__CurrentModeCount] >> 4)
+
+#define set_curr_mode(m) {frame->Reserved[__CurrentModeCount] &= ~0x0F; frame->Reserved[__CurrentModeCount] |= (m & 0x0F);}
+#define inc_curr_count() (frame->Reserved[__CurrentModeCount] += 0x10)
+
+/* fetch_next_frame()
+ *
+ * modify (at least) context.Pc using unwind information
+ * either out of debug info (dwarf), or simple Lr trace
+ */
+static BOOL fetch_next_frame(struct cpu_stack_walk* csw,
+                               CONTEXT* context, DWORD_PTR curr_pc)
+{
+    DWORD_PTR               xframe;
+    DWORD                   oldReturn = context->Lr;
+
+    if (dwarf2_virtual_unwind(csw, curr_pc, context, &xframe))
+    {
+        context->Sp = xframe;
+        context->Pc = oldReturn;
+        return TRUE;
+    }
+
+    if (context->Pc == context->Lr) return FALSE;
+    context->Pc = oldReturn;
+
+    return TRUE;
+}
+
+static BOOL arm_stack_walk(struct cpu_stack_walk* csw, LPSTACKFRAME64 frame, CONTEXT* context)
+{
+    unsigned    deltapc = curr_count <= 1 ? 0 : 4;
+
+    /* sanity check */
+    if (curr_mode >= stm_done) return FALSE;
+
+    TRACE("Enter: PC=%s Frame=%s Return=%s Stack=%s Mode=%s Count=%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" : "ARM",
+          wine_dbgstr_longlong(curr_count));
+
+    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 */
+        set_curr_mode(stm_arm);
+        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 (context->Sp != frame->AddrStack.Offset) FIXME("inconsistent Stack Pointer\n");
+        if (context->Pc != frame->AddrPC.Offset) FIXME("inconsistent Program Counter\n");
+
+        if (frame->AddrReturn.Offset == 0) goto done_err;
+        if (!fetch_next_frame(csw, context, frame->AddrPC.Offset - deltapc))
+            goto done_err;
+    }
+
+    memset(&frame->Params, 0, sizeof(frame->Params));
+
+    /* set frame information */
+    frame->AddrStack.Offset = context->Sp;
+    frame->AddrReturn.Offset = context->Lr;
+    frame->AddrFrame.Offset = context->Fp;
+    frame->AddrPC.Offset = context->Pc;
+
+    frame->Far = TRUE;
+    frame->Virtual = TRUE;
+    inc_curr_count();
+
+    TRACE("Leave: PC=%s Frame=%s Return=%s Stack=%s Mode=%s Count=%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" : "ARM",
+          wine_dbgstr_longlong(curr_count),
+          frame->FuncTableEntry);
+
+    return TRUE;
+done_err:
+    set_curr_mode(stm_done);
+    return FALSE;
+}
+#else
 static BOOL arm_stack_walk(struct cpu_stack_walk* csw, LPSTACKFRAME64 frame, CONTEXT* context)
 {
-    FIXME("not done for ARM\n");
     return FALSE;
 }
+#endif
 
 static unsigned arm_map_dwarf_register(unsigned regno)
 {




More information about the wine-cvs mailing list