Skip to content

Commit

Permalink
[LLDB][NativePDB] Add support for inlined functions
Browse files Browse the repository at this point in the history
This adds inline function support to NativePDB by parsing S_INLINESITE records
to retrieve inlinee line info and add them into line table at `ParseLineTable`.

Differential Revision: https://reviews.llvm.org/D116845
  • Loading branch information
ZequanWu committed Jan 12, 2022
1 parent 7acb68b commit 945aa52
Show file tree
Hide file tree
Showing 7 changed files with 1,178 additions and 95 deletions.
2 changes: 1 addition & 1 deletion lldb/include/lldb/Symbol/LineTable.h
Expand Up @@ -206,7 +206,6 @@ class LineTable {

LineTable *LinkLineTable(const FileRangeMap &file_range_map);

protected:
struct Entry {
Entry()
: line(0), is_start_of_statement(false), is_start_of_basic_block(false),
Expand Down Expand Up @@ -303,6 +302,7 @@ class LineTable {
uint16_t file_idx = 0;
};

protected:
struct EntrySearchInfo {
LineTable *line_table;
lldb_private::Section *a_section;
Expand Down
19 changes: 19 additions & 0 deletions lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
Expand Up @@ -106,6 +106,24 @@ static void ParseExtendedInfo(PdbIndex &index, CompilandIndexItem &item) {
}
}

static void ParseInlineeLineTableForCompileUnit(CompilandIndexItem &item) {
for (const auto &ss : item.m_debug_stream.getSubsectionsArray()) {
if (ss.kind() != DebugSubsectionKind::InlineeLines)
continue;

DebugInlineeLinesSubsectionRef inlinee_lines;
llvm::BinaryStreamReader reader(ss.getRecordData());
if (llvm::Error error = inlinee_lines.initialize(reader)) {
consumeError(std::move(error));
continue;
}

for (const InlineeSourceLine &Line : inlinee_lines) {
item.m_inline_map[Line.Header->Inlinee] = Line;
}
}
}

CompilandIndexItem::CompilandIndexItem(
PdbCompilandId id, llvm::pdb::ModuleDebugStreamRef debug_stream,
llvm::pdb::DbiModuleDescriptor descriptor)
Expand Down Expand Up @@ -142,6 +160,7 @@ CompilandIndexItem &CompileUnitIndex::GetOrCreateCompiland(uint16_t modi) {
cci = std::make_unique<CompilandIndexItem>(
PdbCompilandId{modi}, std::move(debug_stream), std::move(descriptor));
ParseExtendedInfo(m_index, *cci);
ParseInlineeLineTableForCompileUnit(*cci);

cci->m_strings.initialize(debug_stream.getSubsectionsArray());
PDBStringTable &strings = cantFail(m_index.pdb().getStringTable());
Expand Down
13 changes: 13 additions & 0 deletions lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h
Expand Up @@ -9,10 +9,12 @@
#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_COMPILEUNITINDEX_H
#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_COMPILEUNITINDEX_H

#include "lldb/Utility/RangeMap.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/IntervalMap.h"
#include "llvm/ADT/Optional.h"
#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
Expand Down Expand Up @@ -69,6 +71,17 @@ struct CompilandIndexItem {
// command line, etc. This usually contains exactly 5 items which
// are references to other strings.
llvm::SmallVector<llvm::codeview::TypeIndex, 5> m_build_info;

// Inlinee lines table in this compile unit.
std::map<llvm::codeview::TypeIndex, llvm::codeview::InlineeSourceLine>
m_inline_map;

// It's the line table parsed from DEBUG_S_LINES sections, mapping the file
// address range to file index and source line number.
using GlobalLineTable =
lldb_private::RangeDataVector<lldb::addr_t, uint32_t,
std::pair<uint32_t, uint32_t>>;
GlobalLineTable m_global_line_table;
};

/// Indexes information about all compile units. This is really just a map of
Expand Down

0 comments on commit 945aa52

Please sign in to comment.