Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,36 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <minidump/minidump_user_extension_stream_data_source.h>
#include <vector>
namespace Lumberyard
{
class BufferedDataStream : public crashpad::MinidumpUserExtensionStreamDataSource
{
public:
BufferedDataStream(uint32_t stream_type, const void* data, size_t data_size);
size_t StreamDataSize() override;
bool ReadStreamData(Delegate* delegate) override;
private:
std::vector<uint8_t> data_;
BufferedDataStream(const BufferedDataStream& rhs) = delete;
BufferedDataStream& operator=(const BufferedDataStream& rhs) = delete;
};
}
@@ -0,0 +1,75 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <client/crash_report_database.h>
#include <util/net/http_multipart_builder.h>
#include <util/net/http_transport.h>
#include <handler/user_stream_data_source.h>
#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif
#include <base/logging.h>
#include <string>
namespace Lumberyard
{
bool CheckConfirmation(const crashpad::CrashReportDatabase::Report& report);
void InstallCrashUploader(int& argc, char* argv[]);
bool AddAttachments(crashpad::HTTPMultipartBuilder& builder);
bool UpdateHttpTransport(std::unique_ptr<crashpad::HTTPTransport>& httpTransport, const std::string& baseURL);
class CrashUploader
{
public:
CrashUploader(int& argc, char** argv);
virtual ~CrashUploader();
static void SetCrashUploader(std::shared_ptr<CrashUploader> uploader);
static std::shared_ptr<CrashUploader> GetCrashUploader();
virtual bool CheckConfirmation(const crashpad::CrashReportDatabase::Report& report);
virtual void InstallLogHandler() const;
virtual bool AddAttachments(crashpad::HTTPMultipartBuilder& builder);
virtual bool UpdateHttpTransport(std::unique_ptr<crashpad::HTTPTransport>& httpTransport, const std::string& baseURL);
static const char* GetLogFileName() { return "CrashUploaderLog.txt"; }
// base/logging.h::LogMessageHandlerFunction
static bool DoLogging(logging::LogSeverity severity,
const char* file_poath,
int line,
size_t message_start,
const std::string& string);
// We parse out our arguments from the list and let the rest pass through to crashpad
virtual void ParseArguments(int& argc, char** argv);
virtual crashpad::UserStreamDataSources* GetUserStreamSources();
protected:
// Skip confirmation dialog by argument
bool m_noConfirmation{ false };
// Log paths to uploadas user streams with the minidump
std::vector<base::FilePath> m_uploadPaths;
crashpad::UserStreamDataSources m_userStreams;
static std::shared_ptr<CrashUploader> s_uploader;
std::string m_submissionToken;
std::string m_executableName;
};
}
@@ -0,0 +1,34 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <handler/user_stream_data_source.h>
#include "base/files/file_path.h"
namespace Lumberyard
{
class FileStreamDataSource : public crashpad::UserStreamDataSource
{
public:
FileStreamDataSource(const base::FilePath& filePath);
std::unique_ptr<crashpad::MinidumpUserExtensionStreamDataSource> ProduceStreamData(crashpad::ProcessSnapshot* process_snapshot) override;
private:
FileStreamDataSource(const FileStreamDataSource& rhs) = delete;
FileStreamDataSource& operator=(const FileStreamDataSource& rhs) = delete;
base::FilePath m_filePath;
};
}
@@ -0,0 +1,38 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <BufferedDataStream.h>
namespace Lumberyard
{
BufferedDataStream::BufferedDataStream(uint32_t stream_type, const void* data, size_t data_size)
: crashpad::MinidumpUserExtensionStreamDataSource(stream_type)
{
data_.resize(data_size);
if (data_size)
{
memcpy(data_.data(), data, data_size);
}
}
size_t BufferedDataStream::StreamDataSize()
{
return data_.size();
}
bool BufferedDataStream::ReadStreamData(Delegate* delegate)
{
return delegate->ExtensionStreamDataSourceRead(data_.size() ? data_.data() : nullptr, data_.size());
}
}
@@ -0,0 +1,249 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <CrashUploader.h>
#include <CrashSupport.h>
#include <AzCore/PlatformDef.h>
#include <getopt.h>
#include <util/file/file_reader.h>
#include <util/string/split_string.h>
#include <tools/tool_support.h>
#include <base/strings/utf_string_conversions.h>
#include <fstream>
#include <memory>
namespace Lumberyard
{
using namespace crashpad;
std::shared_ptr<CrashUploader> CrashUploader::s_uploader = nullptr;
bool CheckConfirmation(const crashpad::CrashReportDatabase::Report& report)
{
return CrashUploader::GetCrashUploader()->CheckConfirmation(report);
}
bool AddAttachments(HTTPMultipartBuilder& builder)
{
return CrashUploader::GetCrashUploader()->AddAttachments(builder);
}
bool UpdateHttpTransport(std::unique_ptr<crashpad::HTTPTransport>& httpTransport, const std::string& baseURL)
{
return CrashUploader::GetCrashUploader()->UpdateHttpTransport(httpTransport, baseURL);
}
CrashUploader::CrashUploader(int& argc, char** argv)
{
ParseArguments(argc, argv);
}
CrashUploader::~CrashUploader()
{
}
bool CrashUploader::DoLogging([[maybe_unused]] logging::LogSeverity severity,
[[maybe_unused]] const char* file_path,
[[maybe_unused]] int line,
[[maybe_unused]] size_t message_start,
const std::string& string)
{
const char* crashLog = GetLogFileName();
std::ofstream outFile(crashLog, std::ofstream::out | std::ofstream::app);
outFile << "[" << CrashHandler::GetTimeString() << "] " << string;
outFile.close();
return true;
}
void CrashUploader::InstallLogHandler() const
{
logging::SetLogMessageHandler(&CrashUploader::DoLogging);
}
void CrashUploader::SetCrashUploader(std::shared_ptr<CrashUploader> uploader)
{
s_uploader = uploader;
if (uploader)
{
uploader->InstallLogHandler();
}
else
{
logging::SetLogMessageHandler(nullptr);
}
}
std::shared_ptr<CrashUploader> CrashUploader::GetCrashUploader()
{
if (!s_uploader)
{
int noArgCount{ 0 };
s_uploader = std::make_shared<CrashUploader>(noArgCount, nullptr);
}
return s_uploader;
}
crashpad::UserStreamDataSources* CrashUploader::GetUserStreamSources()
{
return &m_userStreams;
}
bool CrashUploader::CheckConfirmation([[maybe_unused]] const crashpad::CrashReportDatabase::Report& report)
{
return !m_noConfirmation;
}
bool CrashUploader::UpdateHttpTransport(std::unique_ptr<crashpad::HTTPTransport>& httpTransport, const std::string& baseURL)
{
std::string newURL{ baseURL };
// Are there already query parameters
auto findPos = baseURL.find('?');
if (findPos == std::string::npos)
{
newURL += "?";
}
else
{
newURL += "&";
}
newURL += "token=" + m_submissionToken;
httpTransport->SetURL(newURL);
return true;
}
bool CrashUploader::AddAttachments(crashpad::HTTPMultipartBuilder& builder)
{
int attachmentCount = 0;
for(auto thisFile : m_uploadPaths)
{
static std::vector<std::unique_ptr<crashpad::FileReader>> logFileReaders;
logFileReaders.push_back(std::make_unique<crashpad::FileReader>());
crashpad::FileReader* logFileReader = logFileReaders.back().get();
if (!logFileReader->Open(thisFile))
{
#if defined(AZ_PLATFORM_WINDOWS)
LOG(ERROR) << "Failed to open " << base::UTF16ToUTF8(thisFile.BaseName().value());
#else
LOG(ERROR) << "Failed to open " << thisFile.BaseName().value();
#endif
continue;
}
FileOffset start_offset = logFileReader->SeekGet();
if (start_offset < 0)
{
#if defined(AZ_PLATFORM_WINDOWS)
LOG(ERROR) << "Failed to get offset for " << base::UTF16ToUTF8(thisFile.BaseName().value());
#else
LOG(ERROR) << "Failed to get offset for " << thisFile.BaseName().value();
#endif
continue;
}
++attachmentCount;
std::string attachmentKey{ "attachment_" };
attachmentKey += std::to_string(attachmentCount);
std::string fileNameKey{ "attachment_" };
#if defined(AZ_PLATFORM_WINDOWS)
fileNameKey += base::UTF16ToUTF8(thisFile.BaseName().value());
#else
fileNameKey += thisFile.BaseName().value();
#endif
attachmentKey = fileNameKey;
builder.SetFileAttachment(
attachmentKey,
fileNameKey,
logFileReader,
"");
}
return true;
}
void CrashUploader::ParseArguments(int& argc, char** argv)
{
if (!argc)
{
return;
}
enum ParsedFlags
{
NoConfirmation,
UploadPath,
UserStream,
SubmissionToken,
ExecutableName,
EndFlags
};
static constexpr option options_list[] = {
{"noconfirmation", no_argument, nullptr, NoConfirmation},
{"uploadpath", required_argument, nullptr, UploadPath},
{"userstream", required_argument, nullptr, UserStream },
{"submission-token", required_argument, nullptr, SubmissionToken },
{"executable-name", required_argument, nullptr, ExecutableName },
{nullptr, no_argument, nullptr, EndFlags}
};
int opt{ 0 };
while ((opt = getopt_long(argc, argv, "", options_list, nullptr)) != -1)
{
switch (opt)
{
case NoConfirmation:
{
m_noConfirmation = true;
argv[--optind] = argv[--argc];
break;
}
case UploadPath:
{
m_uploadPaths.push_back(base::FilePath(crashpad::ToolSupport::CommandLineArgumentToFilePathStringType(optarg)));
argv[--optind] = argv[--argc];
break;
}
case UserStream:
{
argv[--optind] = argv[--argc];
break;
}
case SubmissionToken:
{
m_submissionToken = optarg;
argv[--optind] = argv[--argc];
break;
}
case ExecutableName:
{
m_executableName = optarg;
argv[--optind] = argv[--argc];
break;
}
default:
{
// Likely an argument for crashpad - passthrough
}
}
}
// Reset so we can loop again inside crashpad
optind = 0;
}
}
@@ -0,0 +1,33 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <FileStreamDataSource.h>
#include <BufferedDataStream.h>
#include <memory>
namespace Lumberyard
{
FileStreamDataSource::FileStreamDataSource(const base::FilePath& filePath) :
m_filePath{ filePath }
{
}
std::unique_ptr<crashpad::MinidumpUserExtensionStreamDataSource> FileStreamDataSource::ProduceStreamData(crashpad::ProcessSnapshot* process_snapshot)
{
static constexpr char testBuffer[] = "Test Data From buffer.";
return std::make_unique<BufferedDataStream>( 0xCAFEBABE, testBuffer, sizeof(testBuffer));
}
}