/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2012-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// DWARF record parser
-#ifndef FOLLY_EXPERIMENTAL_SYMBOLIZER_DWARF_H_
-#define FOLLY_EXPERIMENTAL_SYMBOLIZER_DWARF_H_
+#pragma once
#include <boost/variant.hpp>
-#include <folly/experimental/symbolizer/Elf.h>
#include <folly/Range.h>
+#include <folly/experimental/symbolizer/Elf.h>
namespace folly {
namespace symbolizer {
*/
class Path {
public:
- Path() { }
+ Path() {}
- Path(folly::StringPiece baseDir, folly::StringPiece subDir,
- folly::StringPiece file);
+ Path(
+ folly::StringPiece baseDir,
+ folly::StringPiece subDir,
+ folly::StringPiece file);
- folly::StringPiece baseDir() const { return baseDir_; };
- folly::StringPiece subDir() const { return subDir_; }
- folly::StringPiece file() const { return file_; }
+ folly::StringPiece baseDir() const {
+ return baseDir_;
+ }
+ folly::StringPiece subDir() const {
+ return subDir_;
+ }
+ folly::StringPiece file() const {
+ return file_;
+ }
size_t size() const;
folly::StringPiece file_;
};
- struct LocationInfo {
- LocationInfo() : hasMainFile(false), hasFileAndLine(false), line(0) { }
+ enum class LocationInfoMode {
+ // Don't resolve location info.
+ DISABLED,
+ // Perform CU lookup using .debug_aranges (might be incomplete).
+ FAST,
+ // Scan all CU in .debug_info (slow!) on .debug_aranges lookup failure.
+ FULL,
+ };
- bool hasMainFile;
+ struct LocationInfo {
+ bool hasMainFile = false;
Path mainFile;
- bool hasFileAndLine;
+ bool hasFileAndLine = false;
Path file;
- uint64_t line;
+ uint64_t line = 0;
};
- /** Find the file and line number information corresponding to address */
- bool findAddress(uintptr_t address, LocationInfo& info) const;
+ /**
+ * Find the file and line number information corresponding to address.
+ */
+ bool findAddress(uintptr_t address, LocationInfo& info, LocationInfoMode mode)
+ const;
private:
+ static bool
+ findDebugInfoOffset(uintptr_t address, StringPiece aranges, uint64_t& offset);
+
void init();
- static bool findDebugInfoOffset(uintptr_t address,
- StringPiece aranges,
- uint64_t& offset);
- bool findLocation(uintptr_t address,
- StringPiece& infoEntry,
- LocationInfo& info) const;
+ bool findLocation(
+ uintptr_t address,
+ StringPiece& infoEntry,
+ LocationInfo& info) const;
const ElfFile* elf_;
// (yes, DWARF-32 and DWARF-64 sections may coexist in the same file)
class Section {
public:
- Section() : is64Bit_(false) { }
+ Section() : is64Bit_(false) {}
explicit Section(folly::StringPiece d);
bool next(folly::StringPiece& chunk);
// Is the current chunk 64 bit?
- bool is64Bit() const { return is64Bit_; }
+ bool is64Bit() const {
+ return is64Bit_;
+ }
private:
// Yes, 32- and 64- bit sections may coexist. Yikes!
// Interpreter for the line number bytecode VM
class LineNumberVM {
public:
- LineNumberVM(folly::StringPiece data,
- folly::StringPiece compilationDirectory);
+ LineNumberVM(
+ folly::StringPiece data,
+ folly::StringPiece compilationDirectory);
bool findAddress(uintptr_t address, Path& file, uint64_t& line);
// Execute until we commit one new row to the line number matrix
bool next(folly::StringPiece& program);
enum StepResult {
- CONTINUE, // Continue feeding opcodes
- COMMIT, // Commit new <address, file, line> tuple
- END, // End of sequence
+ CONTINUE, // Continue feeding opcodes
+ COMMIT, // Commit new <address, file, line> tuple
+ END, // End of sequence
};
// Execute one opcode
StepResult step(folly::StringPiece& program);
// Read one attribute value, advance sp
typedef boost::variant<uint64_t, folly::StringPiece> AttributeValue;
- AttributeValue readAttributeValue(
- folly::StringPiece& sp,
- uint64_t form,
- bool is64Bit) const;
+ AttributeValue
+ readAttributeValue(folly::StringPiece& sp, uint64_t form, bool is64Bit) const;
// Get an ELF section by name, return true if found
bool getSection(const char* name, folly::StringPiece* section) const;
// Get a string from the .debug_str section
folly::StringPiece getStringFromStringSection(uint64_t offset) const;
- folly::StringPiece info_; // .debug_info
- folly::StringPiece abbrev_; // .debug_abbrev
- folly::StringPiece aranges_; // .debug_aranges
- folly::StringPiece line_; // .debug_line
- folly::StringPiece strings_; // .debug_str
+ folly::StringPiece info_; // .debug_info
+ folly::StringPiece abbrev_; // .debug_abbrev
+ folly::StringPiece aranges_; // .debug_aranges
+ folly::StringPiece line_; // .debug_line
+ folly::StringPiece strings_; // .debug_str
};
inline std::ostream& operator<<(std::ostream& out, const Dwarf::Path& path) {
return out << path.toString();
}
-} // namespace symbolizer
-} // namespace folly
-
-#endif /* FOLLY_EXPERIMENTAL_SYMBOLIZER_DWARF_H_ */
+} // namespace symbolizer
+} // namespace folly