32 auto database = crashpad::CrashReportDatabase::Initialize(reportsDir);
33 if (database ==
nullptr)
35 throw std::ios_base::failure(
"Can't initialize crash report database");
39 auto *settings = database->GetSettings();
40 if (settings ==
nullptr)
42 throw std::ios_base::failure(
"Can't get crash report database settings");
44 settings->SetUploadsEnabled(
true);
50 throw std::ios_base::failure(
"Can't start crash handler");
87 socklen_t len =
sizeof(error);
90 const int result = getsockopt(sockId, SOL_SOCKET, SO_ERROR, &error, &len);
91 return result == 0 && error == 0 && recv(sockId, &buff, 1, MSG_PEEK | MSG_DONTWAIT) != 0;
96 std::array<char, FILENAME_MAX> pathBuffer{
'\0'};
97 auto bytes = readlink(
"/proc/self/exe", pathBuffer.data(),
sizeof(pathBuffer));
99 auto path = std::string(pathBuffer.data(), bytes == -1 ? 0 :
static_cast<size_t>(bytes));
100 auto lastDelimPos = path.find_last_of(
'/');
101 return (lastDelimPos == std::string::npos) ?
"" : path.substr(0, lastDelimPos);
136 std::ofstream ofile(filePath);
137 if (!ofile.is_open())
139 throw std::invalid_argument(
"Can't open file: " + filePath);
143 std::ifstream maps(
"/proc/self/maps");
146 while (std::getline(maps, line))
150 std::istringstream iss(line);
156 std::string pathname;
157 iss >> address >> perms >> offset >> dev >> inode >> pathname;
160 if (pathname.find(
".so") != std::string::npos && perms.find(
"r-x") != std::string::npos)
163 const std::string start = address.substr(0, address.find(
'-'));
166 const unsigned long addr = std::stoul(start,
nullptr, 16);
168 ofile << pathname <<
" " << addr <<
'\n';
173Tracer::Tracer(std::shared_ptr<std::atomic_flag> checkFlag, std::string serverPath, std::string serverProxy,
174 const std::string &crashpadHandlerPath,
const std::string &reportPath,
175 std::vector<base::FilePath> attachments)
176 : _checkFlag(std::move(checkFlag)), _serverPath(std::move(serverPath)), _serverProxy(std::move(serverProxy)),
177 _attachments(std::move(attachments))
181 _handlerPath = crashpadHandlerPath.empty() ? selfDir +
"/crashpad_handler" : crashpadHandlerPath;
182 _reportPath = reportPath.empty() ? selfDir : reportPath;
186 {{
"name", PROJECT_NAME},
187 {
"version", PROJECT_FULL_REVISION},
188 {
"build_info", PROJECT_BUILD_DATE + std::string(
" ") + PROJECT_BUILD_TIME + std::string(
" ") + BUILD_TYPE},
189 {
"compiler_info", COMPILER_NAME + std::string(
" ") + COMPILER_VERSION}});
Tracer(std::shared_ptr< std::atomic_flag > checkFlag, std::string serverPath="", std::string serverProxy="", const std::string &crashpadHandlerPath="", const std::string &reportPath="", std::vector< base::FilePath > attachments={})