Add Windows support to test tool
This commit is contained in:
+13
-9
@@ -6,7 +6,7 @@ from ambuild.command import ShellCommand
|
||||
from ambuild.command import DirectCommand
|
||||
|
||||
def BuildEverything():
|
||||
if AMBuild.target['platform'] not in ['linux']:
|
||||
if AMBuild.target['platform'] not in ['linux', 'windows']:
|
||||
return
|
||||
|
||||
compiler = SM.DefaultCompiler()
|
||||
@@ -16,6 +16,9 @@ def BuildEverything():
|
||||
if AMBuild.target['platform'] in ['linux']:
|
||||
compiler['POSTLINKFLAGS'].append('-lstdc++')
|
||||
compiler['POSTLINKFLAGS'].append('-pthread')
|
||||
elif compiler.cc.name == 'msvc':
|
||||
compiler['POSTLINKFLAGS'].remove('/SUBSYSTEM:WINDOWS')
|
||||
compiler['POSTLINKFLAGS'].append('/SUBSYSTEM:CONSOLE')
|
||||
|
||||
name = 'test-crash-dump-generation'
|
||||
extension = AMBuild.AddJob(name)
|
||||
@@ -42,18 +45,19 @@ def BuildEverything():
|
||||
binary.AddObjectFiles([lib])
|
||||
|
||||
elif AMBuild.target['platform'] in ['windows']:
|
||||
libs = ['exception_handler', 'common']
|
||||
for lib in libs:
|
||||
path = os.path.join(AMBuild.sourceFolder, 'breakpad', 'src', 'src', 'client', 'windows', 'handler', 'Release', 'lib', lib + '.lib')
|
||||
libs = [
|
||||
os.path.join(AMBuild.sourceFolder, 'breakpad', 'src', 'src', 'client', 'windows', 'handler', 'Release', 'lib', 'common.lib'),
|
||||
os.path.join(AMBuild.sourceFolder, 'breakpad', 'src', 'src', 'client', 'windows', 'handler', 'Release', 'lib', 'exception_handler.lib'),
|
||||
os.path.join(AMBuild.sourceFolder, 'breakpad', 'src', 'src', 'client', 'windows', 'crash_generation', 'Release', 'lib', 'crash_generation_client.lib'),
|
||||
os.path.join(AMBuild.sourceFolder, 'breakpad', 'src', 'src', 'processor', 'Release', 'lib', 'libdisasm.lib'),
|
||||
os.path.join(AMBuild.sourceFolder, 'breakpad', 'src', 'src', 'processor', 'Release', 'lib', 'processor.lib'),
|
||||
]
|
||||
|
||||
for path in libs:
|
||||
if os.path.isfile(path):
|
||||
binary.RelinkIfNewer(path)
|
||||
binary['POSTLINKFLAGS'].extend([path])
|
||||
|
||||
path = os.path.join(AMBuild.sourceFolder, 'breakpad', 'src', 'src', 'client', 'windows', 'crash_generation', 'Release', 'lib', 'crash_generation_client.lib')
|
||||
if os.path.isfile(path):
|
||||
binary.RelinkIfNewer(path)
|
||||
binary['POSTLINKFLAGS'].extend([path])
|
||||
|
||||
SM.ExtractDebugInfo(extension, binary)
|
||||
|
||||
binary.SendToJob()
|
||||
|
||||
+58
-28
@@ -1,7 +1,30 @@
|
||||
#if defined _LINUX
|
||||
#include "client/linux/handler/exception_handler.h"
|
||||
#include "common/linux/linux_libc_support.h"
|
||||
#include "third_party/lss/linux_syscall_support.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define my_jmp_buf sigjmp_buf
|
||||
#define my_setjmp(x) sigsetjmp(x, 0)
|
||||
#define my_longjmp siglongjmp
|
||||
|
||||
using google_breakpad::MinidumpDescriptor;
|
||||
|
||||
#elif defined _WINDOWS
|
||||
#define _STDINT // ~.~
|
||||
#include "client/windows/handler/exception_handler.h"
|
||||
|
||||
#define my_jmp_buf jmp_buf
|
||||
#define my_setjmp(x) setjmp(x)
|
||||
#define my_longjmp longjmp
|
||||
|
||||
#else
|
||||
#error Bad platform.
|
||||
#endif
|
||||
|
||||
#include <google_breakpad/processor/minidump.h>
|
||||
#include <google_breakpad/processor/minidump_processor.h>
|
||||
#include <google_breakpad/processor/process_state.h>
|
||||
@@ -9,14 +32,10 @@
|
||||
#include <google_breakpad/processor/stack_frame.h>
|
||||
#include <processor/pathname_stripper.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <streambuf>
|
||||
|
||||
using google_breakpad::MinidumpDescriptor;
|
||||
#include <setjmp.h>
|
||||
|
||||
using google_breakpad::ExceptionHandler;
|
||||
|
||||
using google_breakpad::Minidump;
|
||||
@@ -28,9 +47,10 @@ using google_breakpad::StackFrame;
|
||||
using google_breakpad::PathnameStripper;
|
||||
using google_breakpad::CodeModule;
|
||||
|
||||
sigjmp_buf envbuf;
|
||||
my_jmp_buf envbuf;
|
||||
char path[1024];
|
||||
|
||||
#if defined _LINUX
|
||||
static bool dumpCallback(const MinidumpDescriptor &descriptor, void *context, bool succeeded)
|
||||
{
|
||||
if (succeeded) {
|
||||
@@ -43,10 +63,28 @@ static bool dumpCallback(const MinidumpDescriptor &descriptor, void *context, bo
|
||||
sys_write(STDOUT_FILENO, "\n", 1);
|
||||
|
||||
my_strlcpy(path, descriptor.path(), sizeof(path));
|
||||
siglongjmp(envbuf, 1);
|
||||
my_longjmp(envbuf, 1);
|
||||
|
||||
return succeeded;
|
||||
}
|
||||
#elif defined _WINDOWS
|
||||
static bool dumpCallback(const wchar_t *dump_path, const wchar_t *minidump_id, void *context, EXCEPTION_POINTERS *exinfo, MDRawAssertionInfo *assertion, bool succeeded)
|
||||
{
|
||||
if (succeeded) {
|
||||
printf("Wrote minidump to: %ls\\%ls.dmp\n", dump_path, minidump_id);
|
||||
} else {
|
||||
printf("Failed to write minidump to: %ls\\%ls.dmp\n", dump_path, minidump_id);
|
||||
}
|
||||
|
||||
// TODO: setjmp/longjmp doesn't play nicely with SEH on Windows, so we never get back.
|
||||
// But the exception handler is called and writes the dump, so the user can just invoke us again.
|
||||
|
||||
// snprintf(path, sizeof(path), "%ls\\%ls.dmp", dump_path, minidump_id);
|
||||
// my_longjmp(envbuf, 1);
|
||||
|
||||
return succeeded;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@@ -54,12 +92,16 @@ int main(int argc, char *argv[])
|
||||
if (argc <= 1) {
|
||||
generateCrash = true;
|
||||
|
||||
if (sigsetjmp(envbuf, 0) == 0) {
|
||||
if (my_setjmp(envbuf) == 0) {
|
||||
#if defined _LINUX
|
||||
MinidumpDescriptor descriptor(".");
|
||||
ExceptionHandler *handler = new ExceptionHandler(descriptor, NULL, dumpCallback, NULL, true, -1);
|
||||
#elif defined _WINDOWS
|
||||
ExceptionHandler *handler = new ExceptionHandler(L".", NULL, dumpCallback, NULL, ExceptionHandler::HANDLER_ALL);
|
||||
#endif
|
||||
|
||||
// Test shit here.
|
||||
__builtin_trap();
|
||||
volatile int *ptr = (volatile int *)(0xdeadbeef);
|
||||
*ptr = 0;
|
||||
|
||||
delete handler;
|
||||
return 0;
|
||||
@@ -70,19 +112,9 @@ int main(int argc, char *argv[])
|
||||
argc = 2;
|
||||
}
|
||||
|
||||
#define ONELINE
|
||||
|
||||
#ifdef ONELINE
|
||||
# define CRPRE "|"
|
||||
# define CRPOST ""
|
||||
#else
|
||||
# define CRPRE ""
|
||||
# define CRPOST "\n"
|
||||
#endif
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (!generateCrash) {
|
||||
my_strlcpy(path, argv[i], sizeof(path));
|
||||
strncpy(path, argv[i], sizeof(path));
|
||||
}
|
||||
|
||||
MinidumpProcessor minidumpProcessor(nullptr, nullptr);
|
||||
@@ -115,7 +147,7 @@ int main(int argc, char *argv[])
|
||||
frameCount = 10;
|
||||
}
|
||||
|
||||
printf("1|%d|%s|%x|%d" CRPOST, processState.crashed(), processState.crash_reason().c_str(), (intptr_t)processState.crash_address(), requestingThread);
|
||||
printf("1|%d|%s|%x|%d", processState.crashed(), processState.crash_reason().c_str(), (intptr_t)processState.crash_address(), requestingThread);
|
||||
|
||||
std::map<const CodeModule *, unsigned int> moduleMap;
|
||||
|
||||
@@ -126,7 +158,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
auto debugFile = PathnameStripper::File(module->debug_file());
|
||||
auto debugIdentifier = module->debug_identifier();
|
||||
printf(CRPRE "M|%s|%s" CRPOST, debugFile.c_str(), debugIdentifier.c_str());
|
||||
printf("|M|%s|%s", debugFile.c_str(), debugIdentifier.c_str());
|
||||
}
|
||||
|
||||
for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) {
|
||||
@@ -135,15 +167,13 @@ int main(int argc, char *argv[])
|
||||
auto moduleIndex = moduleMap[frame->module];
|
||||
auto moduleOffset = frame->ReturnAddress() - frame->module->base_address();
|
||||
|
||||
printf(CRPRE "F|%d|%x" CRPOST, moduleIndex, (intptr_t)moduleOffset);
|
||||
printf("|F|%d|%x", moduleIndex, (intptr_t)moduleOffset);
|
||||
} else {
|
||||
printf(CRPRE "F|%d|%x" CRPOST, -1, (intptr_t)frame->ReturnAddress());
|
||||
printf("|F|%d|%x", -1, (intptr_t)frame->ReturnAddress());
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ONELINE
|
||||
printf("\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (generateCrash) {
|
||||
|
||||
Reference in New Issue
Block a user