Skip to content

Instantly share code, notes, and snippets.

@urasandesu
Last active April 1, 2017 02:26
Show Gist options
  • Save urasandesu/e08b338d60af57d2918819010b85b628 to your computer and use it in GitHub Desktop.
Save urasandesu/e08b338d60af57d2918819010b85b628 to your computer and use it in GitHub Desktop.
Debug Help Library hangs up - About SymGetSymFromAddr of Debug Help Library, we found it hangs up in the application that is built by Visual Studio 2017. It was no problem in Visual Studio 2013. I attached the solution files of 2013, 2017 and the mini dump that is in hanging up.
// DbgHelp2013.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <Dbghelp.h>
#include <iostream>
#include <string>
int _tmain(int argc, _TCHAR* argv[])
{
using namespace std;
auto hProcess = ::GetCurrentProcess();
auto hThread = ::GetCurrentThread();
string absoluteSearchPath("C:\\Users\\urasa\\Documents\\Visual Studio 2013\\Projects\\DbgHelp2013\\x64\\Debug");
auto userSearchPath = const_cast<PSTR>(absoluteSearchPath.c_str());
auto options = ::SymGetOptions();
options |= SYMOPT_LOAD_LINES;
options &= ~SYMOPT_UNDNAME;
::SymSetOptions(options);
::SymInitialize(hProcess, userSearchPath, TRUE);
STACKFRAME sf;
::ZeroMemory(&sf, sizeof(STACKFRAME));
DWORD MachineType = IMAGE_FILE_MACHINE_AMD64;
CONTEXT context;
::ZeroMemory(&context, sizeof(CONTEXT));
context.ContextFlags = CONTEXT_CONTROL;
::RtlCaptureContext(&context);
sf.AddrPC.Offset = context.Rip;
sf.AddrPC.Mode = AddrModeFlat;
sf.AddrStack.Offset = context.Rsp;
sf.AddrStack.Mode = AddrModeFlat;
sf.AddrFrame.Offset = context.Rsp;
sf.AddrFrame.Mode = AddrModeFlat;
while (::StackWalk(MachineType, hProcess, hThread, &sf, &context, nullptr, ::SymFunctionTableAccess, ::SymGetModuleBase, nullptr) == TRUE)
{
if (sf.AddrFrame.Offset == 0)
break;
if (sf.AddrPC.Offset == 0)
continue;
if (sf.AddrPC.Offset == sf.AddrReturn.Offset)
continue;
DWORD_PTR pSymDisp;
BYTE pBuf[MAX_SYM_NAME + sizeof(IMAGEHLP_SYMBOL)];
PIMAGEHLP_SYMBOL pSym = reinterpret_cast<PIMAGEHLP_SYMBOL>(pBuf);
::ZeroMemory(pSym, sizeof(pBuf));
pSym->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL);
pSym->MaxNameLength = MAX_SYM_NAME;
string symName(::SymGetSymFromAddr(hProcess, sf.AddrPC.Offset, &pSymDisp, pSym) == TRUE ? pSym->Name : "<Unknown Symbol>");
cout << symName << endl;
}
return 0;
}
@urasandesu
Copy link
Author

Attached files are here: DbgHelp2017.dmp, DbgHelp2013.zip, DbgHelp2017.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment