Skip to content

Commit

Permalink
exchndl: Dump the module versions at the end of the report.
Browse files Browse the repository at this point in the history
So it doesn't clutter the stack back trace.
  • Loading branch information
jrfonseca committed Jun 16, 2015
1 parent 236befe commit a36b428
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
53 changes: 38 additions & 15 deletions src/common/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <psapi.h>
#include <dbghelp.h>
#include <ntstatus.h>
#include <tlhelp32.h>

#include <ctype.h>
#include <stdio.h>
Expand Down Expand Up @@ -81,8 +82,6 @@ int lprintf(const char * format, ...)
static BOOL
dumpSourceCode(LPCTSTR lpFileName, DWORD dwLineNumber);

static BOOL
getModuleVersionInfo(LPCTSTR szModule, DWORD *dwVInfo);

#define MAX_SYM_NAME_SIZE 512

Expand Down Expand Up @@ -289,19 +288,7 @@ dumpStack(HANDLE hProcess, HANDLE hThread,
if (hModule &&
GetModuleFileNameEx(hProcess, hModule, szModule, MAX_PATH)) {

DWORD dwVInfo[4];
if (getModuleVersionInfo(szModule, dwVInfo)) {
lprintf(
_T(" %s [%lu.%lu.%lu.%lu]"),
getBaseName(szModule),
dwVInfo[0],
dwVInfo[1],
dwVInfo[2],
dwVInfo[3]
);
} else {
lprintf( _T(" %s"), getBaseName(szModule));
}
lprintf( _T(" %s"), getBaseName(szModule));

bSymbol = GetSymFromAddr(hProcess, AddrPC + nudge, szSymName, MAX_SYM_NAME_SIZE);
if (bSymbol) {
Expand Down Expand Up @@ -558,6 +545,7 @@ dumpSourceCode(LPCTSTR lpFileName, DWORD dwLineNumber)
return TRUE;
}


static BOOL
getModuleVersionInfo(LPCTSTR szModule, DWORD *dwVInfo)
{
Expand All @@ -582,3 +570,38 @@ getModuleVersionInfo(LPCTSTR szModule, DWORD *dwVInfo)
}
return success;
}


void
dumpModules(HANDLE hProcess)
{

HANDLE hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetProcessId(hProcess));
if (hModuleSnap == INVALID_HANDLE_VALUE) {
return;
}

MODULEENTRY32 me32;
me32.dwSize = sizeof me32;
if (Module32First(hModuleSnap, &me32)) {
do {
const char *szBaseName = getBaseName(me32.szExePath);
DWORD dwVInfo[4];
if (getModuleVersionInfo(me32.szExePath, dwVInfo)) {
lprintf(
_T("%-12s\t%lu.%lu.%lu.%lu\n"),
szBaseName,
dwVInfo[0],
dwVInfo[1],
dwVInfo[2],
dwVInfo[3]
);
} else {
lprintf( _T("%s\n"), szBaseName);
}
} while (Module32Next(hModuleSnap, &me32));
lprintf("\n");
}

CloseHandle(hModuleSnap);
}
3 changes: 3 additions & 0 deletions src/common/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ dumpException(HANDLE hProcess, PEXCEPTION_RECORD pExceptionRecord);
EXTERN_C void
dumpStack(HANDLE hProcess, HANDLE hThread,
const CONTEXT *pContext);

EXTERN_C void
dumpModules(HANDLE hProcess);
2 changes: 2 additions & 0 deletions src/exchndl/exchndl.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ void GenerateExceptionReport(PEXCEPTION_POINTERS pExceptionInfo)
}
}

dumpModules(hProcess);

// TODO: Use GetFileVersionInfo on kernel32.dll as recommended on
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724429.aspx
// for Windows 10 detection?
Expand Down

0 comments on commit a36b428

Please sign in to comment.