* Makefile.in (minidumper.exe): Link directly with dbghelp.

* minidumper.cc (minidump): Ditto.
This commit is contained in:
Jon TURNEY 2014-05-13 10:24:16 +00:00
parent c57ccec649
commit 8f8e7757cf
3 changed files with 16 additions and 37 deletions

View File

@ -1,3 +1,8 @@
2014-04-21 Jon TURNEY <jon.turney@dronecode.org.uk>
* Makefile.in (minidumper.exe): Link directly with dbghelp.
* minidumper.cc (minidump): Ditto.
2014-04-21 Jon TURNEY <jon.turney@dronecode.org.uk> 2014-04-21 Jon TURNEY <jon.turney@dronecode.org.uk>
* minidumper.cc (minidump): Fix copy and paste error in checking * minidumper.cc (minidump): Fix copy and paste error in checking

View File

@ -96,6 +96,7 @@ strace.exe: MINGW_LDFLAGS += -lntdll
ldd.exe:CYGWIN_LDFLAGS += -lpsapi ldd.exe:CYGWIN_LDFLAGS += -lpsapi
pldd.exe: CYGWIN_LDFLAGS += -lpsapi pldd.exe: CYGWIN_LDFLAGS += -lpsapi
minidumper.exe: CYGWIN_LDFLAGS += -ldbghelp
ldh.exe: MINGW_LDFLAGS += -nostdlib -lkernel32 ldh.exe: MINGW_LDFLAGS += -nostdlib -lkernel32

View File

@ -26,42 +26,16 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <windows.h> #include <windows.h>
#include <dbghelp.h>
BOOL verbose = FALSE; BOOL verbose = FALSE;
BOOL nokill = FALSE; BOOL nokill = FALSE;
typedef DWORD MINIDUMP_TYPE;
typedef BOOL (WINAPI *MiniDumpWriteDump_type)(
HANDLE hProcess,
DWORD dwPid,
HANDLE hFile,
MINIDUMP_TYPE DumpType,
CONST void *ExceptionParam,
CONST void *UserStreamParam,
CONST void *allbackParam);
static void static void
minidump(DWORD pid, MINIDUMP_TYPE dump_type, const char *minidump_file) minidump(DWORD pid, MINIDUMP_TYPE dump_type, const char *minidump_file)
{ {
HANDLE dump_file; HANDLE dump_file;
HANDLE process; HANDLE process;
MiniDumpWriteDump_type MiniDumpWriteDump_fp;
HMODULE module;
module = LoadLibrary("dbghelp.dll");
if (!module)
{
fprintf (stderr, "error loading DbgHelp\n");
return;
}
MiniDumpWriteDump_fp = (MiniDumpWriteDump_type)GetProcAddress(module, "MiniDumpWriteDump");
if (!MiniDumpWriteDump_fp)
{
fprintf (stderr, "error getting the address of MiniDumpWriteDump\n");
return;
}
dump_file = CreateFile(minidump_file, dump_file = CreateFile(minidump_file,
GENERIC_READ | GENERIC_WRITE, GENERIC_READ | GENERIC_WRITE,
@ -85,13 +59,13 @@ minidump(DWORD pid, MINIDUMP_TYPE dump_type, const char *minidump_file)
return; return;
} }
BOOL success = (*MiniDumpWriteDump_fp)(process, BOOL success = MiniDumpWriteDump(process,
pid, pid,
dump_file, dump_file,
dump_type, dump_type,
NULL, NULL,
NULL, NULL,
NULL); NULL);
if (success) if (success)
{ {
if (verbose) if (verbose)
@ -112,7 +86,6 @@ minidump(DWORD pid, MINIDUMP_TYPE dump_type, const char *minidump_file)
CloseHandle(process); CloseHandle(process);
CloseHandle(dump_file); CloseHandle(dump_file);
FreeLibrary(module);
} }
static void static void
@ -164,7 +137,7 @@ main (int argc, char **argv)
int opt; int opt;
const char *p = ""; const char *p = "";
DWORD pid; DWORD pid;
MINIDUMP_TYPE dump_type = 0; // MINIDUMP_NORMAL MINIDUMP_TYPE dump_type = MiniDumpNormal;
while ((opt = getopt_long (argc, argv, opts, longopts, NULL) ) != EOF) while ((opt = getopt_long (argc, argv, opts, longopts, NULL) ) != EOF)
switch (opt) switch (opt)
@ -172,7 +145,7 @@ main (int argc, char **argv)
case 't': case 't':
{ {
char *endptr; char *endptr;
dump_type = strtoul(optarg, &endptr, 0); dump_type = (MINIDUMP_TYPE)strtoul(optarg, &endptr, 0);
if (*endptr != '\0') if (*endptr != '\0')
{ {
fprintf (stderr, "syntax error in minidump type \"%s\" near character #%d.\n", optarg, (int) (endptr - optarg)); fprintf (stderr, "syntax error in minidump type \"%s\" near character #%d.\n", optarg, (int) (endptr - optarg));