Commit 55a91da8 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

Wrap _r_debug per platform

Summary: [Folly] Wrap `_r_debug` per platform, since the way to get it varies by platform.

Reviewed By: ot, luciang

Differential Revision: D22004737

fbshipit-source-id: 6f6a6163c9709da0a5042b807cdd88fcdf2e57eb
parent f75211c0
...@@ -41,13 +41,20 @@ ...@@ -41,13 +41,20 @@
#include <folly/portability/SysMman.h> #include <folly/portability/SysMman.h>
#include <folly/portability/Unistd.h> #include <folly/portability/Unistd.h>
/* #if defined(__linux__)
* This is declared in `link.h' on Linux platforms, but apparently not on the static struct r_debug* get_r_debug() {
* Mac version of the file. It's harmless to declare again, in any case. return &_r_debug;
* }
* Note that declaring it with `extern "C"` results in linkage conflicts. #elif defined(__APPLE__)
*/ extern struct r_debug _r_debug;
FOLLY_ATTR_WEAK extern struct r_debug _r_debug; static struct r_debug* get_r_debug() {
return &_r_debug;
}
#else
static struct r_debug* get_r_debug() {
return nullptr;
}
#endif
namespace folly { namespace folly {
namespace symbolizer { namespace symbolizer {
...@@ -84,7 +91,7 @@ void setSymbolizedFrame( ...@@ -84,7 +91,7 @@ void setSymbolizedFrame(
} // namespace } // namespace
bool Symbolizer::isAvailable() { bool Symbolizer::isAvailable() {
return &_r_debug != nullptr; return get_r_debug();
} }
Symbolizer::Symbolizer( Symbolizer::Symbolizer(
...@@ -105,10 +112,11 @@ size_t Symbolizer::symbolize( ...@@ -105,10 +112,11 @@ size_t Symbolizer::symbolize(
FOLLY_SAFE_CHECK(addrCount <= frameCount, "Not enough frames."); FOLLY_SAFE_CHECK(addrCount <= frameCount, "Not enough frames.");
size_t remaining = addrCount; size_t remaining = addrCount;
if (&_r_debug == nullptr) { auto const dbg = get_r_debug();
if (dbg == nullptr) {
return 0; return 0;
} }
if (_r_debug.r_version != 1) { if (dbg->r_version != 1) {
return 0; return 0;
} }
...@@ -133,7 +141,7 @@ size_t Symbolizer::symbolize( ...@@ -133,7 +141,7 @@ size_t Symbolizer::symbolize(
})); }));
}; };
for (auto lmap = _r_debug.r_map; lmap != nullptr && remaining != 0; for (auto lmap = dbg->r_map; lmap != nullptr && remaining != 0;
lmap = lmap->l_next) { lmap = lmap->l_next) {
// The empty string is used in place of the filename for the link_map // The empty string is used in place of the filename for the link_map
// corresponding to the running executable. Additionally, the `l_addr' is // corresponding to the running executable. Additionally, the `l_addr' is
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment