src/hotspot/os/windows/windbghelp.cpp
author coleenp
Wed, 13 Nov 2019 08:23:23 -0500
changeset 59056 15936b142f86
parent 47666 19219ec3f176
permissions -rw-r--r--
8233913: Remove implicit conversion from Method* to methodHandle Summary: Fix call sites to use existing THREAD local or pass down THREAD local for shallower callsites. Make linkResolver methods return Method* for caller to handleize if needed. Reviewed-by: iklam, thartmann, hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
     1
/*
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
     4
 *
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
     8
 *
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    13
 * accompanied this code).
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    14
 *
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    18
 *
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    21
 * questions.
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    22
 *
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    23
 */
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    24
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    25
#include "precompiled.hpp"
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    26
#include "utilities/ostream.hpp"
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    27
#include "windbghelp.hpp"
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    28
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    29
#include <windows.h>
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    30
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    31
typedef DWORD (WINAPI *pfn_SymSetOptions)(DWORD);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    32
typedef DWORD (WINAPI *pfn_SymGetOptions)(void);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    33
typedef BOOL  (WINAPI *pfn_SymInitialize)(HANDLE, PCTSTR, BOOL);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    34
typedef BOOL  (WINAPI *pfn_SymGetSymFromAddr64)(HANDLE, DWORD64, PDWORD64, PIMAGEHLP_SYMBOL64);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    35
typedef DWORD (WINAPI *pfn_UnDecorateSymbolName)(const char*, char*, DWORD, DWORD);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    36
typedef BOOL  (WINAPI *pfn_SymSetSearchPath)(HANDLE, PCTSTR);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    37
typedef BOOL  (WINAPI *pfn_SymGetSearchPath)(HANDLE, PTSTR, int);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    38
typedef BOOL  (WINAPI *pfn_StackWalk64)(DWORD MachineType,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    39
                                        HANDLE hProcess,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    40
                                        HANDLE hThread,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    41
                                        LPSTACKFRAME64 StackFrame,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    42
                                        PVOID ContextRecord,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    43
                                        PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    44
                                        PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    45
                                        PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    46
                                        PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    47
typedef PVOID (WINAPI *pfn_SymFunctionTableAccess64)(HANDLE hProcess, DWORD64 AddrBase);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    48
typedef DWORD64 (WINAPI *pfn_SymGetModuleBase64)(HANDLE hProcess, DWORD64 dwAddr);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    49
typedef BOOL (WINAPI *pfn_MiniDumpWriteDump) (HANDLE hProcess, DWORD ProcessId, HANDLE hFile,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    50
                                              MINIDUMP_TYPE DumpType, PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    51
                                              PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    52
                                              PMINIDUMP_CALLBACK_INFORMATION    CallbackParam);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    53
typedef BOOL (WINAPI *pfn_SymGetLineFromAddr64) (HANDLE hProcess, DWORD64 dwAddr,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    54
                                                 PDWORD pdwDisplacement, PIMAGEHLP_LINE64 Line);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    55
typedef LPAPI_VERSION (WINAPI *pfn_ImagehlpApiVersion)(void);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    56
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    57
// Add functions as needed.
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    58
#define FOR_ALL_FUNCTIONS(DO) \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    59
 DO(ImagehlpApiVersion) \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    60
 DO(SymGetOptions) \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    61
 DO(SymSetOptions) \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    62
 DO(SymInitialize) \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    63
 DO(SymGetSymFromAddr64) \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    64
 DO(UnDecorateSymbolName) \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    65
 DO(SymSetSearchPath) \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    66
 DO(SymGetSearchPath) \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    67
 DO(StackWalk64) \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    68
 DO(SymFunctionTableAccess64) \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    69
 DO(SymGetModuleBase64) \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    70
 DO(MiniDumpWriteDump) \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    71
 DO(SymGetLineFromAddr64)
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    72
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    73
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    74
#define DECLARE_FUNCTION_POINTER(functionname) \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    75
static pfn_##functionname g_pfn_##functionname;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    76
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    77
FOR_ALL_FUNCTIONS(DECLARE_FUNCTION_POINTER)
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    78
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    79
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    80
static HMODULE g_dll_handle = NULL;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    81
static DWORD g_dll_load_error = 0;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    82
static API_VERSION g_version = { 0, 0, 0, 0 };
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    83
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    84
static enum {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    85
  state_uninitialized = 0,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    86
  state_ready = 1,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    87
  state_error = 2
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    88
} g_state = state_uninitialized;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    89
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    90
static void initialize() {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    91
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    92
  assert(g_state == state_uninitialized, "wrong sequence");
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    93
  g_state = state_error;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    94
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    95
  g_dll_handle = ::LoadLibrary("DBGHELP.DLL");
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    96
  if (g_dll_handle == NULL) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    97
    g_dll_load_error = ::GetLastError();
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    98
  } else {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
    99
    // Note: We loaded the DLL successfully. From here on we count
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   100
    // initialization as success. We still may fail to load all of the
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   101
    // desired function pointers successfully, but DLL may still be usable
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   102
    // enough for our purposes.
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   103
    g_state = state_ready;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   104
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   105
#define DO_RESOLVE(functionname) \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   106
      g_pfn_##functionname = (pfn_##functionname) ::GetProcAddress(g_dll_handle, #functionname);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   107
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   108
    FOR_ALL_FUNCTIONS(DO_RESOLVE)
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   109
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   110
    // Retrieve version information.
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   111
    if (g_pfn_ImagehlpApiVersion) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   112
      const API_VERSION* p = g_pfn_ImagehlpApiVersion();
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   113
      memcpy(&g_version, p, sizeof(API_VERSION));
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   114
    }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   115
  }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   116
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   117
}
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   118
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   119
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   120
///////////////////// External functions //////////////////////////
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   121
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   122
// All outside facing functions are synchronized. Also, we run
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   123
// initialization on first touch.
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   124
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   125
static CRITICAL_SECTION g_cs;
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   126
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   127
namespace { // Do not export.
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   128
  class WindowsDbgHelpEntry {
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   129
   public:
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   130
    WindowsDbgHelpEntry() {
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   131
      ::EnterCriticalSection(&g_cs);
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   132
      if (g_state == state_uninitialized) {
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   133
        initialize();
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   134
      }
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   135
    }
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   136
    ~WindowsDbgHelpEntry() {
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   137
      ::LeaveCriticalSection(&g_cs);
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   138
    }
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   139
  };
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   140
}
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   141
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   142
// Called at DLL_PROCESS_ATTACH.
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   143
void WindowsDbgHelp::pre_initialize() {
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   144
  ::InitializeCriticalSection(&g_cs);
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   145
}
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   146
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   147
DWORD WindowsDbgHelp::symSetOptions(DWORD arg) {
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   148
  WindowsDbgHelpEntry entry_guard;
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   149
  if (g_pfn_SymSetOptions != NULL) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   150
    return g_pfn_SymSetOptions(arg);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   151
  }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   152
  return 0;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   153
}
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   154
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   155
DWORD WindowsDbgHelp::symGetOptions(void) {
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   156
  WindowsDbgHelpEntry entry_guard;
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   157
  if (g_pfn_SymGetOptions != NULL) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   158
    return g_pfn_SymGetOptions();
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   159
  }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   160
  return 0;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   161
}
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   162
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   163
BOOL WindowsDbgHelp::symInitialize(HANDLE hProcess, PCTSTR UserSearchPath, BOOL fInvadeProcess) {
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   164
  WindowsDbgHelpEntry entry_guard;
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   165
  if (g_pfn_SymInitialize != NULL) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   166
    return g_pfn_SymInitialize(hProcess, UserSearchPath, fInvadeProcess);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   167
  }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   168
  return FALSE;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   169
}
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   170
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   171
BOOL WindowsDbgHelp::symGetSymFromAddr64(HANDLE hProcess, DWORD64 the_address,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   172
                                         PDWORD64 Displacement, PIMAGEHLP_SYMBOL64 Symbol) {
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   173
  WindowsDbgHelpEntry entry_guard;
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   174
  if (g_pfn_SymGetSymFromAddr64 != NULL) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   175
    return g_pfn_SymGetSymFromAddr64(hProcess, the_address, Displacement, Symbol);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   176
  }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   177
  return FALSE;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   178
}
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   179
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   180
DWORD WindowsDbgHelp::unDecorateSymbolName(const char* DecoratedName, char* UnDecoratedName,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   181
                                           DWORD UndecoratedLength, DWORD Flags) {
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   182
  WindowsDbgHelpEntry entry_guard;
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   183
  if (g_pfn_UnDecorateSymbolName != NULL) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   184
    return g_pfn_UnDecorateSymbolName(DecoratedName, UnDecoratedName, UndecoratedLength, Flags);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   185
  }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   186
  if (UnDecoratedName != NULL && UndecoratedLength > 0) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   187
    UnDecoratedName[0] = '\0';
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   188
  }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   189
  return 0;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   190
}
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   191
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   192
BOOL WindowsDbgHelp::symSetSearchPath(HANDLE hProcess, PCTSTR SearchPath) {
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   193
  WindowsDbgHelpEntry entry_guard;
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   194
  if (g_pfn_SymSetSearchPath != NULL) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   195
    return g_pfn_SymSetSearchPath(hProcess, SearchPath);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   196
  }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   197
  return FALSE;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   198
}
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   199
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   200
BOOL WindowsDbgHelp::symGetSearchPath(HANDLE hProcess, PTSTR SearchPath, int SearchPathLength) {
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   201
  WindowsDbgHelpEntry entry_guard;
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   202
  if (g_pfn_SymGetSearchPath != NULL) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   203
    return g_pfn_SymGetSearchPath(hProcess, SearchPath, SearchPathLength);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   204
  }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   205
  return FALSE;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   206
}
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   207
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   208
BOOL WindowsDbgHelp::stackWalk64(DWORD MachineType,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   209
                                 HANDLE hProcess,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   210
                                 HANDLE hThread,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   211
                                 LPSTACKFRAME64 StackFrame,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   212
                                 PVOID ContextRecord) {
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   213
  WindowsDbgHelpEntry entry_guard;
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   214
  if (g_pfn_StackWalk64 != NULL) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   215
    return g_pfn_StackWalk64(MachineType, hProcess, hThread, StackFrame,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   216
                             ContextRecord,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   217
                             NULL, // ReadMemoryRoutine
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   218
                             g_pfn_SymFunctionTableAccess64, // FunctionTableAccessRoutine,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   219
                             g_pfn_SymGetModuleBase64, // GetModuleBaseRoutine
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   220
                             NULL // TranslateAddressRoutine
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   221
                             );
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   222
  }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   223
  return FALSE;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   224
}
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   225
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   226
PVOID WindowsDbgHelp::symFunctionTableAccess64(HANDLE hProcess, DWORD64 AddrBase) {
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   227
  WindowsDbgHelpEntry entry_guard;
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   228
  if (g_pfn_SymFunctionTableAccess64 != NULL) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   229
    return g_pfn_SymFunctionTableAccess64(hProcess, AddrBase);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   230
  }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   231
  return NULL;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   232
}
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   233
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   234
DWORD64 WindowsDbgHelp::symGetModuleBase64(HANDLE hProcess, DWORD64 dwAddr) {
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   235
  WindowsDbgHelpEntry entry_guard;
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   236
  if (g_pfn_SymGetModuleBase64 != NULL) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   237
    return g_pfn_SymGetModuleBase64(hProcess, dwAddr);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   238
  }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   239
  return 0;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   240
}
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   241
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   242
BOOL WindowsDbgHelp::miniDumpWriteDump(HANDLE hProcess, DWORD ProcessId, HANDLE hFile,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   243
                                       MINIDUMP_TYPE DumpType, PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   244
                                       PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   245
                                       PMINIDUMP_CALLBACK_INFORMATION CallbackParam) {
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   246
  WindowsDbgHelpEntry entry_guard;
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   247
  if (g_pfn_MiniDumpWriteDump != NULL) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   248
    return g_pfn_MiniDumpWriteDump(hProcess, ProcessId, hFile, DumpType,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   249
                                   ExceptionParam, UserStreamParam, CallbackParam);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   250
  }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   251
  return FALSE;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   252
}
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   253
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   254
BOOL WindowsDbgHelp::symGetLineFromAddr64(HANDLE hProcess, DWORD64 dwAddr,
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   255
                          PDWORD pdwDisplacement, PIMAGEHLP_LINE64 Line) {
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   256
  WindowsDbgHelpEntry entry_guard;
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   257
  if (g_pfn_SymGetLineFromAddr64 != NULL) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   258
    return g_pfn_SymGetLineFromAddr64(hProcess, dwAddr, pdwDisplacement, Line);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   259
  }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   260
  return FALSE;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   261
}
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   262
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   263
// Print one liner describing state (if library loaded, which functions are
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   264
// missing - if any, and the dbhelp API version)
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   265
void WindowsDbgHelp::print_state_on(outputStream* st) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   266
  // Note: We should not lock while printing, but this should be
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   267
  // safe to do without lock anyway.
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   268
  st->print("dbghelp: ");
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   269
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   270
  if (g_state == state_uninitialized) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   271
    st->print("uninitialized.");
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   272
  } else if (g_state == state_error) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   273
    st->print("loading error: %u", g_dll_load_error);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   274
  } else {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   275
    st->print("loaded successfully ");
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   276
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   277
    // We may want to print dll file name here - which may be interesting for
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   278
    // cases where more than one version exists on the system, e.g. with a
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   279
    // debugging sdk separately installed. But we get the file name in the DLL
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   280
    // section of the hs-err file too, so this may be redundant.
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   281
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   282
    // Print version.
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   283
    st->print("- version: %u.%u.%u",
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   284
              g_version.MajorVersion, g_version.MinorVersion, g_version.Revision);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   285
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   286
    // Print any functions which failed to load.
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   287
    int num_missing = 0;
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   288
    st->print(" - missing functions: ");
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   289
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   290
    #define CHECK_AND_PRINT_IF_NULL(functionname) \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   291
    if (g_pfn_##functionname == NULL) { \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   292
      st->print("%s" #functionname, ((num_missing > 0) ? ", " : "")); \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   293
      num_missing ++; \
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   294
    }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   295
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   296
    FOR_ALL_FUNCTIONS(CHECK_AND_PRINT_IF_NULL)
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   297
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   298
    if (num_missing == 0) {
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   299
      st->print("none");
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   300
    }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   301
  }
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   302
  st->cr();
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   303
}
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
diff changeset
   304