[PATCH 1/3] dbghelp: Reimplement SymGetLineFromAddrW64

Alistair Leslie-Hughes leslie_alistair at hotmail.com
Mon Jun 3 01:00:00 CDT 2019


Signed-off-by: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
---
 dlls/dbghelp/symbol.c | 75 +++++++++++++++++++++++++++++++------------
 1 file changed, 54 insertions(+), 21 deletions(-)

diff --git a/dlls/dbghelp/symbol.c b/dlls/dbghelp/symbol.c
index f59e322fef..177c66480d 100644
--- a/dlls/dbghelp/symbol.c
+++ b/dlls/dbghelp/symbol.c
@@ -1485,6 +1485,47 @@ BOOL symt_fill_func_line_info(const struct module* module, const struct symt_fun
     return FALSE;
 }
 
+/******************************************************************
+ *		sym_fill_func_line_info64W
+ *
+ * fills information about a file
+ */
+static BOOL symt_fill_func_line_info64W(const struct module* module, const struct symt_function* func,
+                              DWORD64 addr, IMAGEHLP_LINEW64* line)
+{
+    struct line_info*   dli = NULL;
+    BOOL                found = FALSE;
+    int                 i;
+
+    assert(func->symt.tag == SymTagFunction);
+
+    for (i=vector_length(&func->vlines)-1; i>=0; i--)
+    {
+        dli = vector_at(&func->vlines, i);
+        if (!dli->is_source_file)
+        {
+            if (found || dli->u.pc_offset > addr) continue;
+            line->LineNumber = dli->line_number;
+            line->Address    = dli->u.pc_offset;
+            line->Key        = dli;
+            found = TRUE;
+            continue;
+        }
+        if (found)
+        {
+            char *filename = (char*)source_get(module, dli->u.source_file);
+            int len = lstrlenA(filename)+1;
+
+            line->FileName = fetch_buffer(module->process, len * sizeof(WCHAR));
+
+            MultiByteToWideChar(CP_ACP, 0, filename, -1, line->FileName, len);
+
+            return TRUE;
+        }
+    }
+    return FALSE;
+}
+
 /***********************************************************************
  *		SymGetSymNext64 (DBGHELP.@)
  */
@@ -1544,22 +1585,6 @@ static void copy_line_64_from_32(IMAGEHLP_LINE64* l64, const IMAGEHLP_LINE* l32)
     l64->Address = l32->Address;
 }
 
-/******************************************************************
- *		copy_line_W64_from_32 (internal)
- *
- */
-static void copy_line_W64_from_64(struct process* pcs, IMAGEHLP_LINEW64* l64w, const IMAGEHLP_LINE64* l64)
-{
-    unsigned len;
-
-    l64w->Key = l64->Key;
-    l64w->LineNumber = l64->LineNumber;
-    len = MultiByteToWideChar(CP_ACP, 0, l64->FileName, -1, NULL, 0);
-    if ((l64w->FileName = fetch_buffer(pcs, len * sizeof(WCHAR))))
-        MultiByteToWideChar(CP_ACP, 0, l64->FileName, -1, l64w->FileName, len);
-    l64w->Address = l64->Address;
-}
-
 /******************************************************************
  *		copy_line_32_from_64 (internal)
  *
@@ -1623,12 +1648,20 @@ BOOL WINAPI SymGetLineFromAddr64(HANDLE hProcess, DWORD64 dwAddr,
 BOOL WINAPI SymGetLineFromAddrW64(HANDLE hProcess, DWORD64 dwAddr, 
                                   PDWORD pdwDisplacement, PIMAGEHLP_LINEW64 Line)
 {
-    IMAGEHLP_LINE64     il64;
+    struct module_pair  pair;
+    struct symt_ht*     symt;
+
+    pair.pcs = process_find_by_handle(hProcess);
+    if (!pair.pcs) return FALSE;
+    pair.requested = module_find_by_addr(pair.pcs, dwAddr, DMT_UNKNOWN);
+    if (!module_get_debug(&pair)) return FALSE;
+    if ((symt = symt_find_nearest(pair.effective, dwAddr)) == NULL) return FALSE;
+
+    if (symt->symt.tag != SymTagFunction) return FALSE;
+    if (!symt_fill_func_line_info64W(pair.effective, (struct symt_function*)symt,
+                                  dwAddr, Line)) return FALSE;
+    *pdwDisplacement = dwAddr - Line->Address;
 
-    il64.SizeOfStruct = sizeof(il64);
-    if (!SymGetLineFromAddr64(hProcess, dwAddr, pdwDisplacement, &il64))
-        return FALSE;
-    copy_line_W64_from_64(process_find_by_handle(hProcess), Line, &il64);
     return TRUE;
 }
 
-- 
2.17.1



More information about the wine-devel mailing list