return true;
}
+ElfCache* defaultElfCache() {
+ static constexpr size_t defaultCapacity = 500;
+ static ElfCache cache(defaultCapacity);
+ return &cache;
+}
+
} // namespace
+Symbolizer::Symbolizer(ElfCacheBase* cache)
+ : cache_(cache ?: defaultElfCache()) {
+}
+
void Symbolizer::symbolize(const uintptr_t* addresses,
SymbolizedFrame* frames,
size_t addressCount) {
}
bool first = true;
- ElfFile* elfFile = nullptr;
+ std::shared_ptr<ElfFile> elfFile;
// See if any addresses are here
for (size_t i = 0; i < addressCount; ++i) {
// Open the file on first use
if (first) {
first = false;
- if (fileCount_ < kMaxFiles &&
- !fileName.empty() &&
- fileName.size() < sizeof(fileNameBuf)) {
- memcpy(fileNameBuf, fileName.data(), fileName.size());
- fileNameBuf[fileName.size()] = '\0';
- auto& f = files_[fileCount_++];
- if (f.openNoThrow(fileNameBuf) != -1) {
- elfFile = &f;
- }
- }
+ elfFile = cache_->getFile(fileName);
}
if (!elfFile) {
frame.name = name;
}
- Dwarf(elfFile).findAddress(fileAddress, frame.location);
+ Dwarf(elfFile.get()).findAddress(fileAddress, frame.location);
}
}
const SymbolizePrinter::Color kFileColor = SymbolizePrinter::Color::DEFAULT;
} // namespace
+constexpr char AddressFormatter::bufTemplate[];
+
+AddressFormatter::AddressFormatter() {
+ memcpy(buf_, bufTemplate, sizeof(buf_));
+}
+
+folly::StringPiece AddressFormatter::format(uintptr_t address) {
+ // Can't use sprintf, not async-signal-safe
+ static_assert(sizeof(uintptr_t) <= 8, "huge uintptr_t?");
+ char* end = buf_ + sizeof(buf_) - 1 - (16 - 2 * sizeof(uintptr_t));
+ char* p = end;
+ *p-- = '\0';
+ while (address != 0) {
+ *p-- = kHexChars[address & 0xf];
+ address >>= 4;
+ }
+
+ return folly::StringPiece(buf_, end);
+}
+
void SymbolizePrinter::print(uintptr_t address, const SymbolizedFrame& frame) {
if (options_ & TERSE) {
printTerse(address, frame);
SCOPE_EXIT { color(Color::DEFAULT); };
color(kAddressColor);
- // Can't use sprintf, not async-signal-safe
- static_assert(sizeof(uintptr_t) <= 8, "huge uintptr_t?");
- char buf[] = " @ 0000000000000000";
- char* end = buf + sizeof(buf) - 1 - (16 - 2 * sizeof(uintptr_t));
+
+ AddressFormatter formatter;
+ doPrint(formatter.format(address));
+
const char padBuf[] = " ";
folly::StringPiece pad(padBuf,
sizeof(padBuf) - 1 - (16 - 2 * sizeof(uintptr_t)));
- char* p = end;
- *p-- = '\0';
- while (address != 0) {
- *p-- = kHexChars[address & 0xf];
- address >>= 4;
- }
- doPrint(folly::StringPiece(buf, end));
color(kFunctionColor);
char mangledBuf[1024];