-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
258 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
#include "breakpad.hpp" | ||
|
||
auto main(int argc, char *argv[]) -> int | ||
void crash() | ||
{ | ||
Breakpad breakpad("./"); | ||
int *p = nullptr; | ||
*p = 1; | ||
} | ||
|
||
auto main(int argc, char *argv[]) -> int | ||
{ | ||
Breakpad breakpad("./"); | ||
|
||
crash(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#pragma once | ||
|
||
#include <object.hpp> | ||
#include <utils/object.hpp> | ||
|
||
#include <atomic> | ||
#include <cassert> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
add_executable(Crashpad crashpad.cc crashpad.hpp main.cc) | ||
target_link_libraries(Crashpad PRIVATE crashpad::crashpad) | ||
|
||
string(REPLACE "share" "tools" crash_handler_path ${crashpad_DIR}) | ||
message(STATUS "crashpad tools directory: ${crash_handler_path}") | ||
|
||
add_custom_command( | ||
TARGET Crashpad | ||
POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E make_directory | ||
"$<TARGET_FILE_DIR:Crashpad>/crashpad/" | ||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${crash_handler_path}/ | ||
"$<TARGET_FILE_DIR:Crashpad>/crashpad") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "crashpad.hpp" | ||
|
||
#include <crashpad/client/crash_report_database.h> | ||
#include <crashpad/client/crashpad_client.h> | ||
#include <crashpad/client/settings.h> | ||
|
||
#ifdef _WIN32 | ||
auto convertStringToWideString(const std::string &str) -> std::wstring | ||
{ | ||
if (str.empty()) { | ||
return {}; | ||
} | ||
|
||
// 首先,获取转换后的字符串长度(不包括空终止符) | ||
int len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0); | ||
|
||
// 如果转换失败,返回空字符串 | ||
if (len == 0) { | ||
return {}; | ||
} | ||
|
||
// 分配足够的空间来存储转换后的字符串 | ||
std::wstring wstr(len, 0); | ||
|
||
// 执行转换 | ||
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &wstr[0], len); | ||
|
||
// 去除末尾的空字符 | ||
wstr.resize(len - 1); | ||
return wstr; | ||
} | ||
#endif | ||
|
||
Crashpad::Crashpad(const std::string &dumpPath, | ||
const std::string &libexecPath, | ||
const std::string &reportUrl, | ||
bool crashReportingEnabled) | ||
{ | ||
auto handlerPath = libexecPath + "/crashpad_handler"; | ||
#ifdef _WIN32 | ||
handlerPath += ".exe"; | ||
base::FilePath database(convertStringToWideString(dumpPath)); | ||
base::FilePath handler(convertStringToWideString(handlerPath)); | ||
#else | ||
base::FilePath database(dumpPath); | ||
base::FilePath handler(handlerPath); | ||
#endif | ||
|
||
auto dbPtr = crashpad::CrashReportDatabase::Initialize(database); | ||
if (dbPtr && (dbPtr->GetSettings() != nullptr)) { | ||
dbPtr->GetSettings()->SetUploadsEnabled(crashReportingEnabled); | ||
} | ||
|
||
m_crashpadClientPtr = std::make_unique<crashpad::CrashpadClient>(); | ||
m_crashpadClientPtr | ||
->StartHandler(handler, database, database, reportUrl, {}, {"--no-rate-limit"}, true, true); | ||
} | ||
|
||
Crashpad::~Crashpad() = default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include <utils/object.hpp> | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
namespace crashpad { | ||
class CrashpadClient; | ||
} // namespace crashpad | ||
|
||
class Crashpad : noncopyable | ||
{ | ||
public: | ||
explicit Crashpad(const std::string &dumpPath, | ||
const std::string &libexecPath, | ||
const std::string &reportUrl, | ||
bool crashReportingEnabled); | ||
~Crashpad(); | ||
|
||
private: | ||
std::unique_ptr<crashpad::CrashpadClient> m_crashpadClientPtr; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "crashpad.hpp" | ||
|
||
#include <filesystem> | ||
|
||
void crash() | ||
{ | ||
int *p = nullptr; | ||
*p = 1; | ||
} | ||
|
||
auto main() -> int | ||
{ | ||
auto dumpPath = std::filesystem::current_path() / "crashpad"; | ||
if (!std::filesystem::exists(dumpPath)) { | ||
std::filesystem::create_directory(dumpPath); | ||
} | ||
|
||
Crashpad crashpad(dumpPath.string(), dumpPath.string(), "http://127.0.0.1:8080", true); | ||
|
||
crash(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#pragma once | ||
|
||
#include <object.hpp> | ||
#include <utils/object.hpp> | ||
|
||
#include <curl/curl.h> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#pragma once | ||
|
||
#include <object.hpp> | ||
#include <utils/object.hpp> | ||
|
||
#include <curl/curl.h> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#pragma once | ||
|
||
#include <object.hpp> | ||
#include <utils/object.hpp> | ||
|
||
#include <netinet/in.h> | ||
#include <string> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#pragma once | ||
|
||
#include <object.hpp> | ||
#include <utils/object.hpp> | ||
|
||
#include <atomic> | ||
#include <cassert> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.