[PATCH 07/11] dbghelp: implement the SymSetScope* functions

Eric Pouech eric.pouech at gmail.com
Wed Oct 20 11:36:26 CDT 2021


Signed-off-by: Eric Pouech <eric.pouech at gmail.com>

---
 dlls/dbghelp/dbghelp.c |   75 ++++++++++++++++++++++++++++++++----------------
 dlls/dbghelp/module.c  |   10 ++++++
 2 files changed, 59 insertions(+), 26 deletions(-)

diff --git a/dlls/dbghelp/dbghelp.c b/dlls/dbghelp/dbghelp.c
index 64ceb447ee9..6c63d6eddcd 100644
--- a/dlls/dbghelp/dbghelp.c
+++ b/dlls/dbghelp/dbghelp.c
@@ -607,34 +607,27 @@ BOOL WINAPI SymSetContext(HANDLE hProcess, PIMAGEHLP_STACK_FRAME StackFrame,
                           PIMAGEHLP_CONTEXT Context)
 {
     struct process* pcs;
-    struct module_pair pair;
-    struct symt_ht* sym;
+    BOOL same;
 
-    pair.pcs = pcs = process_find_by_handle(hProcess);
-    if (!pcs) return FALSE;
+    if (!(pcs = process_find_by_handle(hProcess))) return FALSE;
+    same = pcs->ctx_frame.ReturnOffset == StackFrame->ReturnOffset &&
+        pcs->ctx_frame.FrameOffset  == StackFrame->FrameOffset  &&
+        pcs->ctx_frame.StackOffset  == StackFrame->StackOffset;
 
-    pair.requested = module_find_by_addr(pair.pcs, StackFrame->InstructionOffset, DMT_UNKNOWN);
-    if (!module_get_debug(&pair)) return FALSE;
+    if (!SymSetScopeFromAddr(hProcess, StackFrame->InstructionOffset))
         return FALSE;
-    if ((sym = symt_find_nearest(pair.effective, StackFrame->InstructionOffset)) == NULL) return FALSE;
-    if (sym->symt.tag != SymTagFunction) return FALSE;
-    pcs->localscope_pc = StackFrame->InstructionOffset;
-    pcs->localscope_symt = &sym->symt;
 
-    if (pcs->ctx_frame.ReturnOffset == StackFrame->ReturnOffset &&
-        pcs->ctx_frame.FrameOffset  == StackFrame->FrameOffset  &&
-        pcs->ctx_frame.StackOffset  == StackFrame->StackOffset)
+    pcs->ctx_frame = *StackFrame;
+    if (same)
     {
         TRACE("Setting same frame {rtn=%I64x frm=%I64x stk=%I64x}\n",
               pcs->ctx_frame.ReturnOffset,
               pcs->ctx_frame.FrameOffset,
               pcs->ctx_frame.StackOffset);
-        pcs->ctx_frame.InstructionOffset = StackFrame->InstructionOffset;
         SetLastError(ERROR_SUCCESS);
         return FALSE;
     }
 
-    pcs->ctx_frame = *StackFrame;
     /* Context is not (no longer?) used */
     return TRUE;
 }
@@ -644,11 +637,17 @@ BOOL WINAPI SymSetContext(HANDLE hProcess, PIMAGEHLP_STACK_FRAME StackFrame,
  */
 BOOL WINAPI SymSetScopeFromAddr(HANDLE hProcess, ULONG64 addr)
 {
-    struct process*     pcs;
+    struct module_pair pair;
+    struct symt_ht* sym;
 
-    FIXME("(%p %#I64x): stub\n", hProcess, addr);
+    TRACE("(%p %#I64x): stub\n", hProcess, addr);
 
-    if (!(pcs = process_find_by_handle(hProcess))) return FALSE;
+    if (!module_init_pair(&pair, hProcess, addr)) return FALSE;
+    if ((sym = symt_find_nearest(pair.effective, addr)) == NULL) return FALSE;
+    if (sym->symt.tag != SymTagFunction) return FALSE;
+
+    pair.pcs->localscope_pc = addr;
+    pair.pcs->localscope_symt = &sym->symt;
     return TRUE;
 }
 
@@ -657,11 +656,18 @@ BOOL WINAPI SymSetScopeFromAddr(HANDLE hProcess, ULONG64 addr)
  */
 BOOL WINAPI SymSetScopeFromIndex(HANDLE hProcess, ULONG64 addr, DWORD index)
 {
-    struct process*     pcs;
+    struct module_pair pair;
+    struct symt* sym;
 
-    FIXME("(%p %#I64x %u): stub\n", hProcess, addr, index);
+    TRACE("(%p %#I64x %u): stub\n", hProcess, addr, index);
+
+    if (!module_init_pair(&pair, hProcess, addr)) return FALSE;
+    sym = symt_index2ptr(pair.effective, index);
+    if (!symt_check_tag(sym, SymTagFunction)) return FALSE;
+
+    pair.pcs->localscope_pc = ((struct symt_function*)sym)->address; /* FIXME of FuncDebugStart when it exists? */
+    pair.pcs->localscope_symt = sym;
 
-    if (!(pcs = process_find_by_handle(hProcess))) return FALSE;
     return TRUE;
 }
 
@@ -670,12 +676,31 @@ BOOL WINAPI SymSetScopeFromIndex(HANDLE hProcess, ULONG64 addr, DWORD index)
  */
 BOOL WINAPI SymSetScopeFromInlineContext(HANDLE hProcess, ULONG64 addr, DWORD inlinectx)
 {
-    struct process*     pcs;
+    TRACE("(%p %I64x %x)\n", hProcess, addr, inlinectx);
 
-    FIXME("(%p %#I64x %u): stub\n", hProcess, addr, inlinectx);
+    switch (IFC_MODE(inlinectx))
+    {
+    case IFC_MODE_IGNORE:
+    case IFC_MODE_REGULAR: return SymSetScopeFromAddr(hProcess, addr);
+    case IFC_MODE_INLINE:
+        {
+            struct module_pair pair;
+            struct symt_inlinesite* inlined;
 
-    if (!(pcs = process_find_by_handle(hProcess))) return FALSE;
-    return TRUE;
+            if (!module_init_pair(&pair, hProcess, addr)) return FALSE;
+            inlined = symt_find_inlined_site(pair.effective, addr, inlinectx);
+            if (inlined)
+            {
+                pair.pcs->localscope_pc = addr;
+                pair.pcs->localscope_symt = &inlined->func.symt;
+                return TRUE;
+            }
+        }
+        return FALSE;
+    default:
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
 }
 
 /******************************************************************
diff --git a/dlls/dbghelp/module.c b/dlls/dbghelp/module.c
index f0fd2a55016..8168e727c52 100644
--- a/dlls/dbghelp/module.c
+++ b/dlls/dbghelp/module.c
@@ -1048,7 +1048,15 @@ BOOL WINAPI SymUnloadModule64(HANDLE hProcess, DWORD64 BaseOfDll)
     if (!pcs) return FALSE;
     module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
     if (!module) return FALSE;
-    return module_remove(pcs, module);
+    if (!module_remove(pcs, module)) return FALSE;
+    /* remove local scope if defined inside this module */
+    if (pcs->localscope_pc >= module->module.BaseOfImage &&
+        pcs->localscope_pc < module->module.BaseOfImage + module->module.ImageSize)
+    {
+        pcs->localscope_pc = 0;
+        pcs->localscope_symt = NULL;
+    }
+    return TRUE;
 }
 
 /******************************************************************




More information about the wine-devel mailing list