1
#include "source/server/backtrace.h"
2

            
3
#include <fstream>
4

            
5
#include "absl/strings/str_split.h"
6

            
7
namespace Envoy {
8

            
9
bool BackwardsTrace::log_to_stderr_ = false;
10

            
11
50
absl::string_view BackwardsTrace::addrMapping(bool setup) {
12
50
  static absl::string_view value = [setup]() -> absl::string_view {
13
13
    if (!setup) {
14
1
      return "";
15
1
    }
16
12
#ifndef WIN32
17
12
    std::ifstream maps("/proc/self/maps");
18
12
    if (maps.fail()) {
19
      return "";
20
    }
21
12
    std::string line;
22
    // Search for the first executable memory mapped block.
23
24
    while (std::getline(maps, line)) {
24
24
      std::vector<absl::string_view> parts = absl::StrSplit(line, ' ');
25
24
      if (parts[1] == "r-xp") {
26
12
        static std::string result = absl::StrCat(parts[0], " ", parts.back());
27
12
        return result;
28
12
      }
29
24
    }
30
#endif
31
    return "";
32
12
  }();
33
50
  return value;
34
50
}
35

            
36
1664
void BackwardsTrace::setLogToStderr(bool log_to_stderr) { log_to_stderr_ = log_to_stderr; }
37

            
38
} // namespace Envoy