forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbacktrace.cc
More file actions
38 lines (31 loc) · 935 Bytes
/
backtrace.cc
File metadata and controls
38 lines (31 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "source/server/backtrace.h"
#include <fstream>
#include "absl/strings/str_split.h"
namespace Envoy {
bool BackwardsTrace::log_to_stderr_ = false;
absl::string_view BackwardsTrace::addrMapping(bool setup) {
static absl::string_view value = [setup]() -> absl::string_view {
if (!setup) {
return "";
}
#ifndef WIN32
std::ifstream maps("/proc/self/maps");
if (maps.fail()) {
return "";
}
std::string line;
// Search for the first executable memory mapped block.
while (std::getline(maps, line)) {
std::vector<absl::string_view> parts = absl::StrSplit(line, ' ');
if (parts[1] == "r-xp") {
static std::string result = absl::StrCat(parts[0], " ", parts.back());
return result;
}
}
#endif
return "";
}();
return value;
}
void BackwardsTrace::setLogToStderr(bool log_to_stderr) { log_to_stderr_ = log_to_stderr; }
} // namespace Envoy