Skip to content

Commit

Permalink
Issue #66 Fix (vsextension only): dbghelp.dll is attempted to load fr…
Browse files Browse the repository at this point in the history
…om the list of libraries

- vsextension now includes dbghelp.dll from MS SDK (to support symbols reading on Windows 7 and on some Windows 10 machines).
  • Loading branch information
tyoma committed Mar 1, 2021
1 parent 38ced6c commit a2e7c7f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ The steps are much like the ones above.

# Revision History

## v1.8.631

* Symbols produced by Visual Studio 2019 are now correctly read by using redistributable dbghelp.dll.

## v1.8.629

* Major UI rework: statistic lists are now entirely custom, performance (although not measured precisely) significantly improved (meaning, less CPU is busy displaying stats - more available to the profiled app);
Expand Down
9 changes: 9 additions & 0 deletions build-vsix.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ popd
pushd "%~dp0_build.android.arm\_bin"
call sha256 hashandroidarm libmicro-profiler_arm.so
popd
pushd "%~dp0redist\dbghelp"
call sha256 hashkernel32downlevelapix64 windows7+\x64\api-ms-win-downlevel-kernel32-l2-1-0.dll
call sha256 hashdbghelpx64 windows7+\x64\dbghelp.dll
call sha256 hashkernel32downlevelapix86 windows7+\x86\api-ms-win-downlevel-kernel32-l2-1-0.dll
call sha256 hashdbghelpx86 windows7+\x86\dbghelp.dll
popd

pushd "%~dp0legacy"
call mkzip micro-profiler.initializer.cpp "%OUTPUT%"
Expand Down Expand Up @@ -72,6 +78,9 @@ popd
pushd "%~dp0_build.android.arm\_bin"
call mkzip libmicro-profiler_arm.so "%OUTPUT%"
popd
pushd "%~dp0redist\dbghelp"
call mkzip * "%OUTPUT%"
popd

pushd "%~dp0_setup"
call replace.cmd "%~dp0deployment\vsix\catalog.json" > catalog.json
Expand Down
38 changes: 23 additions & 15 deletions common/src/image_info_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <stdexcept>
#include <common/unordered_map.h>

#define GET_PROC_ADDRESS(hmodule, symbol) reinterpret_cast<decltype(::symbol) *>(::GetProcAddress(hmodule, #symbol))

using namespace std;
using namespace std::placeholders;

Expand All @@ -42,10 +44,15 @@ namespace micro_profiler
namespace
{
#ifdef _M_IX86
const string c_own_dbghelp_filename = "dbghelp_x86.dll";
const string c_bitness_directory = "x86";
#elif _M_X64
const string c_own_dbghelp_filename = "dbghelp_x64.dll";
const string c_bitness_directory = "x64";
#endif
const string c_dbghelps[] = {
~get_module_info(&c_bitness_directory).path & "windows7+" & c_bitness_directory & "dbghelp.dll",
~get_module_info(&c_bitness_directory).path & "windowsxp+" & c_bitness_directory & "dbghelp.dll",
"dbghelp.dll",
};

class dbghelp : noncopyable
{
Expand Down Expand Up @@ -90,23 +97,24 @@ namespace micro_profiler

dbghelp::dbghelp()
{
const auto local_directory = ~get_module_info(&c_own_dbghelp_filename).path;
auto path_env = _wgetenv(L"PATH");

_module.reset(::LoadLibraryW(unicode(local_directory & c_own_dbghelp_filename).c_str()), &FreeLibrary);
if (!_module)
_module.reset(::LoadLibraryW(L"dbghelp.dll"), &FreeLibrary);
path_env = path_env ? path_env : L"";
for (auto i = begin(c_dbghelps); !_module && i != end(c_dbghelps); ++i)
{
::SetEnvironmentVariableW(L"PATH", (wstring(path_env) + L";" + unicode(~*i)).c_str());
_module.reset(::LoadLibraryW(unicode(*i).c_str()), &FreeLibrary);
}
::SetEnvironmentVariableW(L"PATH", path_env);
const auto hmodule = static_cast<HMODULE>(_module.get());
SymEnumSymbols = reinterpret_cast<decltype(::SymEnumSymbols) *>(::GetProcAddress(hmodule, "SymEnumSymbols"));
SymGetLineFromAddr64 = reinterpret_cast<decltype(::SymGetLineFromAddr64) *>(::GetProcAddress(hmodule,
"SymGetLineFromAddr64"));
_SymInitialize = reinterpret_cast<decltype(::SymInitialize) *>(::GetProcAddress(hmodule, "SymInitialize"));
_SymCleanup = reinterpret_cast<decltype(::SymCleanup) *>(::GetProcAddress(hmodule, "SymCleanup"));
_SymLoadModuleExW = reinterpret_cast<decltype(::SymLoadModuleExW) *>(::GetProcAddress(hmodule,
"SymLoadModuleExW"));
_SymLoadModule64 = reinterpret_cast<decltype(::SymLoadModule64) *>(::GetProcAddress(hmodule,
"SymLoadModule64"));
SymEnumSymbols = GET_PROC_ADDRESS(hmodule, SymEnumSymbols);
SymGetLineFromAddr64 = GET_PROC_ADDRESS(hmodule, SymGetLineFromAddr64);
_SymInitialize = GET_PROC_ADDRESS(hmodule, SymInitialize);
_SymCleanup = GET_PROC_ADDRESS(hmodule, SymCleanup);
_SymLoadModuleExW = GET_PROC_ADDRESS(hmodule, SymLoadModuleExW);
_SymLoadModule64 = GET_PROC_ADDRESS(hmodule, SymLoadModule64);
if (!_SymInitialize(this, NULL, FALSE))
throw 0;
Expand Down
7 changes: 6 additions & 1 deletion deployment/vsix/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
{"fileName":"/logo.ico","sha256":"!hashappicon!"},
{"fileName":"/libmicro-profiler_x86.so","sha256":"!hashlinuxmpx86!"},
{"fileName":"/libmicro-profiler_x64.so","sha256":"!hashlinuxmpx64!"},
{"fileName":"/libmicro-profiler_arm.so","sha256":"!hashandroidarm!"}
{"fileName":"/libmicro-profiler_arm.so","sha256":"!hashandroidarm!"},

{"fileName":"/windows7+/x64/api-ms-win-downlevel-kernel32-l2-1-0.dll","sha256":"!hashkernel32downlevelapix64!"},
{"fileName":"/windows7+/x64/dbghelp.dll","sha256":"!hashdbghelpx64!"},
{"fileName":"/windows7+/x86/api-ms-win-downlevel-kernel32-l2-1-0.dll","sha256":"!hashkernel32downlevelapix86!"},
{"fileName":"/windows7+/x86/dbghelp.dll","sha256":"!hashdbghelpx86!"}
],
"dependencies":{"Microsoft.VisualStudio.Component.CoreEditor":"[11.0,17.0)"}
}

0 comments on commit a2e7c7f

Please sign in to comment.