Merge pull request #8214 from janisozaur/more-backtrace-info

Add compressed sv6 to backtrace.io uploads
This commit is contained in:
Michał Janiszewski 2018-11-29 22:41:52 +01:00 committed by GitHub
commit eeaca6112e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 19 deletions

View File

@ -1341,6 +1341,18 @@ static int32_t cc_abort(
return 0;
}
static int32_t cc_dereference(
[[maybe_unused]] InteractiveConsole& console, [[maybe_unused]] const utf8** argv, [[maybe_unused]] int32_t argc)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnull-dereference"
// Dereference a nullptr to induce a crash to be caught by crash handler, on supported platforms
uint8_t* myptr = nullptr;
*myptr = 42;
return 0;
#pragma GCC diagnostic pop
}
static int32_t cc_terminate(
[[maybe_unused]] InteractiveConsole& console, [[maybe_unused]] const utf8** argv, [[maybe_unused]] int32_t argc)
{
@ -1413,6 +1425,7 @@ static constexpr const console_command console_command_table[] = {
{ "clear", cc_clear, "Clears the console.", "clear" },
{ "close", cc_close, "Closes the console.", "close" },
{ "date", cc_for_date, "Sets the date to a given date.", "Format <year>[ <month>[ <day>]]." },
{ "dereference", cc_dereference, "Dereferences a nullptr, for testing purposes only", "dereference" },
{ "echo", cc_echo, "Echoes the text to the console.", "echo <text>" },
{ "exit", cc_close, "Closes the console.", "exit" },
{ "get", cc_get, "Gets the value of the specified variable.", "get <variable>" },

View File

@ -48,12 +48,15 @@ const wchar_t* _wszArchitecture = WSZ(OPENRCT2_ARCHITECTURE);
// so just hope the file name with '.gz' suffix is enough.
// For docs on uplading to backtrace.io check
// https://documentation.backtrace.io/product_integration_minidump_breakpad/
static bool UploadMinidump(const wchar_t* dumpPath, int& error, std::wstring& response)
static bool UploadMinidump(const std::map<std::wstring, std::wstring>& files, int& error, std::wstring& response)
{
for (auto file : files)
{
wprintf(L"files[%s] = %s\n", file.first.c_str(), file.second.c_str());
}
std::wstring url(L"https://openrct2.sp.backtrace.io:6098/"
L"post?format=minidump&token=f9c5e640d498f15dbe902eab3e822e472af9270d5b0cbdc269cee65a926bf306");
std::map<std::wstring, std::wstring> parameters;
std::map<std::wstring, std::wstring> files;
parameters[L"product_name"] = L"openrct2";
// In case of releases this can be empty
if (wcslen(_wszCommitSha1Short) > 0)
@ -64,7 +67,6 @@ static bool UploadMinidump(const wchar_t* dumpPath, int& error, std::wstring& re
{
parameters[L"commit"] = String::ToUtf16(gVersionInfoFull);
}
files[L"upload_file_minidump"] = dumpPath;
int timeout = 10000;
bool success = google_breakpad::HTTPUpload::SendRequest(url, parameters, files, &timeout, &response, &error);
wprintf(L"Success = %d, error = %d, response = %s\n", success, error, response.c_str());
@ -88,12 +90,15 @@ static bool OnCrash(
return succeeded;
}
std::map<std::wstring, std::wstring> uploadFiles;
// Get filenames
wchar_t dumpFilePath[MAX_PATH];
wchar_t saveFilePath[MAX_PATH];
wchar_t saveFilePathGZIP[MAX_PATH];
swprintf_s(dumpFilePath, sizeof(dumpFilePath), L"%s\\%s.dmp", dumpPath, miniDumpId);
swprintf_s(saveFilePath, sizeof(saveFilePath), L"%s\\%s.sv6", dumpPath, miniDumpId);
const wchar_t* minidumpToUpload = dumpFilePath;
swprintf_s(saveFilePathGZIP, sizeof(saveFilePathGZIP), L"%s\\%s.sv6.gz", dumpPath, miniDumpId);
wchar_t dumpFilePathNew[MAX_PATH];
swprintf_s(
@ -103,28 +108,32 @@ static bool OnCrash(
wchar_t dumpFilePathGZIP[MAX_PATH];
swprintf_s(dumpFilePathGZIP, sizeof(dumpFilePathGZIP), L"%s.gz", dumpFilePathNew);
FILE* input = _wfopen(dumpFilePath, L"rb");
FILE* dest = _wfopen(dumpFilePathGZIP, L"wb");
if (util_gzip_compress(input, dest))
// Compress the dump
{
// TODO: enable upload of gzip-compressed dumps once supported on
// backtrace.io (uncomment the line below). For now leave compression
// on, as GitHub will accept .gz files, even though it does not
// advertise it officially.
FILE* input = _wfopen(dumpFilePath, L"rb");
FILE* dest = _wfopen(dumpFilePathGZIP, L"wb");
/*
minidumpToUpload = dumpFilePathGZIP;
*/
if (util_gzip_compress(input, dest))
{
// TODO: enable upload of gzip-compressed dumps once supported on
// backtrace.io (uncomment the line below). For now leave compression
// on, as GitHub will accept .gz files, even though it does not
// advertise it officially.
/*
uploadFiles[L"upload_file_minidump"] = dumpFilePathGZIP;
*/
}
fclose(input);
fclose(dest);
}
fclose(input);
fclose(dest);
// Try to rename the files
if (_wrename(dumpFilePath, dumpFilePathNew) == 0)
{
std::wcscpy(dumpFilePath, dumpFilePathNew);
}
uploadFiles[L"upload_file_minidump"] = dumpFilePath;
// Compress to gzip-compatible stream
@ -149,11 +158,29 @@ static bool OnCrash(
}
free(saveFilePathUTF8);
// Compress the save
if (savedGameDumped)
{
FILE* input = _wfopen(saveFilePath, L"rb");
FILE* dest = _wfopen(saveFilePathGZIP, L"wb");
if (util_gzip_compress(input, dest))
{
uploadFiles[L"attachment_park.sv6.gz"] = saveFilePathGZIP;
}
else
{
uploadFiles[L"attachment_park.sv6"] = saveFilePath;
}
fclose(input);
fclose(dest);
}
if (gOpenRCT2SilentBreakpad)
{
int error;
std::wstring response;
UploadMinidump(minidumpToUpload, error, response);
UploadMinidump(uploadFiles, error, response);
return succeeded;
}
@ -171,7 +198,7 @@ static bool OnCrash(
{
int error;
std::wstring response;
bool ok = UploadMinidump(minidumpToUpload, error, response);
bool ok = UploadMinidump(uploadFiles, error, response);
if (!ok)
{
const wchar_t* MessageFormat2 = L"There was a problem while uploading the dump. Please upload it manually to "