sm-ext-accelerator-2023/test/test.cpp
2016-07-01 23:32:55 +01:00

100 lines
2.9 KiB
C++

/*
* =============================================================================
* 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 <http://www.gnu.org/licenses/>.
*/
#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>
#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.
volatile int *a = nullptr;
*a = 0xDEADBEEF;
delete handler;
return 0;
}