u_debug_symbol: Allow re-init of DbgHelp to work around already-initialized issues
authorJesse Natalie <jenatali@microsoft.com>
Tue, 26 Apr 2022 19:47:50 +0000 (12:47 -0700)
committerMarge Bot <emma+marge@anholt.net>
Mon, 2 May 2022 16:58:20 +0000 (16:58 +0000)
Reviewed-by: Sil Vilerino <sivileri@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16182>

src/util/u_debug_symbol.c

index 891b954..a006910 100644 (file)
@@ -142,6 +142,8 @@ DBGHELP_DISPATCH(SymGetLineFromAddr64,
                  (HANDLE hProcess, DWORD64 dwAddr, PDWORD pdwDisplacement, PIMAGEHLP_LINE64 Line),
                  (hProcess, dwAddr, pdwDisplacement, Line))
 
+DBGHELP_DISPATCH(SymCleanup, BOOL, FALSE, (HANDLE hProcess), (hProcess))
+
 
 #undef DBGHELP_DISPATCH
 
@@ -167,6 +169,14 @@ debug_symbol_name_dbghelp(const void *addr, char* buf, unsigned size)
    pSymbol->MaxNameLen = sizeof buffer - offsetof(SYMBOL_INFO, Name);
 
    if (!g_bSymInitialized) {
+      /* Some components (e.g. Java) will init dbghelp before we're loaded, causing the "invade process"
+       * option to be invalid when attempting to re-init. But without it, we'd have to manually
+       * load symbols for all modules in the stack. For simplicity, we can just uninit and then
+       * re-"invade".
+       */
+      if (debug_get_bool_option("GALLIUM_SYMBOL_FORCE_REINIT", false))
+         j_SymCleanup(hProcess);
+
       j_SymSetOptions(/* SYMOPT_UNDNAME | */ SYMOPT_LOAD_LINES);
       if (j_SymInitialize(hProcess, NULL, TRUE)) {
          g_bSymInitialized = TRUE;