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");
85 socklen_t len =
sizeof(error);
88 const int result = getsockopt(sockId, SOL_SOCKET, SO_ERROR, &error, &len);
89 return result == 0 && error == 0 && recv(sockId, &buff, 1, MSG_PEEK | MSG_DONTWAIT) != 0;
94 std::array<char, FILENAME_MAX> pathBuffer{
'\0'};
95 auto bytes = readlink(
"/proc/self/exe", pathBuffer.data(),
sizeof(pathBuffer));
97 auto path = std::string(pathBuffer.data(), bytes == -1 ? 0 :
static_cast<size_t>(bytes));
98 auto lastDelimPos = path.find_last_of(
'/');
99 return (lastDelimPos == std::string::npos) ?
"" : path.substr(0, lastDelimPos);
134 std::ofstream ofile(filePath);
135 if (!ofile.is_open())
137 throw std::invalid_argument(
"Can't open file: " + filePath);
141 std::ifstream maps(
"/proc/self/maps");
144 while (std::getline(maps, line))
148 std::istringstream iss(line);
154 std::string pathname;
155 iss >> address >> perms >> offset >> dev >> inode >> pathname;
158 if (pathname.find(
".so") != std::string::npos && perms.find(
"r-x") != std::string::npos)
161 const std::string start = address.substr(0, address.find(
'-'));
164 const unsigned long addr = std::stoul(start,
nullptr, 16);
166 ofile << pathname <<
" " << addr <<
'\n';
171Tracer::Tracer(std::shared_ptr<std::atomic_flag> checkFlag, std::string serverPath, std::string serverProxy,
172 const std::string &crashpadHandlerPath,
const std::string &reportPath,
173 std::vector<base::FilePath> attachments)
174 : _checkFlag(std::move(checkFlag)), _serverPath(std::move(serverPath)), _serverProxy(std::move(serverProxy)),
175 _attachments(std::move(attachments))
179 _handlerPath = crashpadHandlerPath.empty() ? selfDir +
"/crashpad_handler" : crashpadHandlerPath;
180 _reportPath = reportPath.empty() ? selfDir : reportPath;
184 {{
"name", PROJECT_NAME},
185 {
"version", PROJECT_FULL_REVISION},
186 {
"build_info", PROJECT_BUILD_DATE + std::string(
" ") + PROJECT_BUILD_TIME + std::string(
" ") + BUILD_TYPE},
187 {
"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={})