From 00f5c3d08e0d5abc04f7d382f42dda778c95fe09 Mon Sep 17 00:00:00 2001 From: Asher Baker Date: Fri, 1 Jul 2016 22:43:09 +0100 Subject: [PATCH] Added code for testing Breakpad minidump creation --- AMBuildScript | 1 + test/AMBuilder | 54 ++++++++++++++++++++++++++++ test/test.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 test/AMBuilder create mode 100644 test/test.cpp diff --git a/AMBuildScript b/AMBuildScript index b5cd120..b824de1 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -231,6 +231,7 @@ AMBuild.Include(os.path.join('buildbot', 'Versioning'), globals) FileList = [ ['extension', 'AMBuilder'], + ['test', 'AMBuilder'], ['buildbot', 'PackageScript'], ['buildbot', 'BreakpadSymbols'] ] diff --git a/test/AMBuilder b/test/AMBuilder new file mode 100644 index 0000000..3d45319 --- /dev/null +++ b/test/AMBuilder @@ -0,0 +1,54 @@ +# vim: set ts=2 sw=2 tw=99 noet ft=python: +import os +import ambuild.osutil as osutil +from ambuild.command import SymlinkCommand +from ambuild.command import ShellCommand +from ambuild.command import DirectCommand + +def BuildEverything(): + if AMBuild.target['platform'] not in ['linux']: + return + + compiler = SM.DefaultCompiler() + + compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'breakpad', 'src', 'src')) + + if AMBuild.target['platform'] in ['linux']: + compiler['POSTLINKFLAGS'].append('-lstdc++') + compiler['POSTLINKFLAGS'].append('-pthread') + + name = 'test' + extension = AMBuild.AddJob(name) + binary = Cpp.ExecutableBuilder(name, AMBuild, extension, compiler) + + binary.AddSourceFiles('test', [ + 'test.cpp', + ]) + + if AMBuild.target['platform'] in ['linux']: + link = os.path.join(AMBuild.outputFolder, extension.workFolder, 'libbreakpad_client.a') + target = os.path.join(AMBuild.outputFolder, 'breakpad', 'src', 'client', 'linux', 'libbreakpad_client.a') + try: + os.lstat(link) + except: + extension.AddCommand(SymlinkCommand(link, target)) + binary.AddObjectFiles(['libbreakpad_client.a']) + + 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') + 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() + +BuildEverything() diff --git a/test/test.cpp b/test/test.cpp new file mode 100644 index 0000000..dc5a430 --- /dev/null +++ b/test/test.cpp @@ -0,0 +1,98 @@ +/* + * ============================================================================= + * Accelerator Extension + * Copyright (C) 2011 Asher Baker (asherkin). All rights reserved. + * ============================================================================= + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, version 3.0, as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#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 +#include +#include +#elif defined _WINDOWS +#define _STDINT // ~.~ +#include "client/windows/handler/exception_handler.h" +#else +#error Bad platform. +#endif + +char dumpStoragePath[512] = "."; + +google_breakpad::ExceptionHandler *handler = NULL; + +#if defined _LINUX +static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded) +{ + if (succeeded) { + sys_write(STDOUT_FILENO, "Wrote minidump to: ", 19); + } else { + sys_write(STDOUT_FILENO, "Failed to write minidump to: ", 29); + } + + sys_write(STDOUT_FILENO, descriptor.path(), my_strlen(descriptor.path())); + sys_write(STDOUT_FILENO, "\n", 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("Failed to write minidump to: %ls\\%ls.dmp\n", dump_path, minidump_id); + return succeeded; + } + + printf("Wrote minidump to: %ls\\%ls.dmp\n", dump_path, minidump_id); + + return succeeded; +} +#else +#error Bad platform. +#endif + +int main(int argc, char *argv[]) +{ +#if defined _LINUX + google_breakpad::MinidumpDescriptor descriptor(dumpStoragePath); + handler = new google_breakpad::ExceptionHandler(descriptor, NULL, dumpCallback, NULL, true, -1); +#elif defined _WINDOWS + wchar_t *buf = new wchar_t[sizeof(dumpStoragePath)]; + size_t num_chars = mbstowcs(buf, dumpStoragePath, sizeof(dumpStoragePath)); + + handler = new google_breakpad::ExceptionHandler(std::wstring(buf, num_chars), NULL, dumpCallback, NULL, google_breakpad::ExceptionHandler::HANDLER_ALL); + + delete buf; +#else +#error Bad platform. +#endif + + // Test shit here. + + int a = *(int *)0x0; + + delete handler; + + return 0; +} +