Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/bloaty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ struct DataSourceDefinition {

constexpr DataSourceDefinition data_sources[] = {
{DataSource::kArchiveMembers, "armembers", "the .o files in a .a file"},
{DataSource::kArchs, "archs", "architecture slices in universal binaries"},
{DataSource::kCompileUnits, "compileunits",
"source file for the .o file (translation unit). requires debug info."},
{DataSource::kInputFiles, "inputfiles",
Expand Down Expand Up @@ -2157,7 +2158,7 @@ void Bloaty::DisassembleFunction(string_view function, const Options& options,
for (const auto& file_info : input_files_) {
auto file = GetObjectFile(file_info.filename_);
if (file->GetDisassemblyInfo(function, EffectiveSymbolSource(options),
&info)) {
options, &info)) {
output->SetDisassembly(::bloaty::DisassembleFunction(info));
return;
}
Expand Down
34 changes: 22 additions & 12 deletions src/bloaty.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ enum class DataSource {
kRawRanges,
kSections,
kSegments,
kArchs,

// We always set this to one of the concrete symbol types below before
// setting it on a sink.
Expand Down Expand Up @@ -261,38 +262,46 @@ class NameMunger {
std::vector<std::pair<std::unique_ptr<ReImpl>, std::string>> regexes_;
};

struct SymbolInfo {
uint64_t address;
uint64_t size;
uint16_t n_desc;

SymbolInfo(uint64_t addr, uint64_t sz, uint16_t desc = 0)
: address(addr), size(sz), n_desc(desc) {}
};

/// SymbolTable holds the symbol table for an object file.
/// It maps symbol names to their address and size.
/// It maps symbol names to their address, size, and other metadata.
///
/// This structure is used in src/elf.cc to accumulate symbols from the ELF
/// symbol table, which are then used to look up symbols during disassembly.
/// This structure is used in src/elf.cc and src/macho.cc to accumulate symbols
/// from symbol tables, which are then used to look up symbols during
/// disassembly.
class SymbolTable {
public:
/// Inserts a symbol into the table.
/// The name must be guaranteed to outlive the SymbolTable (e.g. it points
/// into the memory-mapped file).
/// @return The string_view of the inserted name.
std::string_view insert(std::string_view name,
std::pair<uint64_t, uint64_t> val) {
table.insert(std::make_pair(name, val));
std::string_view insert(std::string_view name, const SymbolInfo& info) {
table.insert(std::make_pair(name, info));
return name;
}

/// Inserts a symbol into the table.
/// The name is moved into the SymbolTable and owned by it.
/// @return The string_view of the inserted name (which points to the owned
/// string).
std::string_view insert(std::string&& name,
std::pair<uint64_t, uint64_t> val) {
std::string_view insert(std::string&& name, const SymbolInfo& info) {
owned_strings.push_back(std::move(name));
std::string_view sv = owned_strings.back();
table.insert(std::make_pair(sv, val));
table.insert(std::make_pair(sv, info));
return sv;
}

/// Inserts a symbol into the table.
/// The name must be guaranteed to outlive the SymbolTable.
void insert(std::pair<std::string_view, std::pair<uint64_t, uint64_t>> val) {
void insert(std::pair<std::string_view, SymbolInfo> val) {
table.insert(val);
}

Expand All @@ -304,8 +313,8 @@ class SymbolTable {
auto end() { return table.end(); }

private:
/// Map of symbol name to (address, size) pair.
std::map<std::string_view, std::pair<uint64_t, uint64_t>> table;
/// Map of symbol name to SymbolInfo.
std::map<std::string_view, SymbolInfo> table;

/// Strings that are owned by this SymbolTable.
/// This is used for synthetic symbols that don't exist in the file (e.g.
Expand All @@ -330,6 +339,7 @@ class ObjectFile {

virtual bool GetDisassemblyInfo(std::string_view symbol,
DataSource symbol_source,
const Options& options,
DisassemblyInfo* info) const = 0;

const InputFile& file_data() const { return *file_data_; }
Expand Down
17 changes: 10 additions & 7 deletions src/elf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -936,10 +936,10 @@ static void ReadELFSymbols(const InputFile& file, RangeSink* sink,
}
if (table) {
if (name_storage.empty()) {
table->insert(name, std::make_pair(full_addr, sym.st_size));
table->insert(name, SymbolInfo(full_addr, sym.st_size));
} else {
name = table->insert(std::move(name_storage),
std::make_pair(full_addr, sym.st_size));
SymbolInfo(full_addr, sym.st_size));
}
}

Expand Down Expand Up @@ -1401,6 +1401,8 @@ class ElfObjectFile : public ObjectFile {
DoReadELFSections(sink, kReportByEscapedSectionName);
break;
}
case DataSource::kArchs:
THROW("ELF files do not support 'archs' data source");
default:
THROW("unknown data source");
}
Expand All @@ -1421,14 +1423,15 @@ class ElfObjectFile : public ObjectFile {
}

bool GetDisassemblyInfo(const std::string_view symbol,
DataSource symbol_source,
DataSource symbol_source, const Options& options,
DisassemblyInfo* info) const override {
return DoGetDisassemblyInfo(&symbol, symbol_source, info);
return DoGetDisassemblyInfo(&symbol, symbol_source, options, info);
}

bool DoGetDisassemblyInfo(const std::string_view* symbol,
DataSource symbol_source,
DataSource symbol_source, const Options& options,
DisassemblyInfo* info) const {
(void)options;
// Find the corresponding file range. This also could be optimized not to
// build the entire map.
DualMap base_map;
Expand All @@ -1455,8 +1458,8 @@ class ElfObjectFile : public ObjectFile {
return false;
}
}
uint64_t vmaddr = entry->second.first;
uint64_t size = entry->second.second;
uint64_t vmaddr = entry->second.address;
uint64_t size = entry->second.size;

// TODO(haberman); Add PLT entries to symbol map, so call <plt stub> gets
// symbolized.
Expand Down
Loading