Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -3633,8 +3633,7 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes(
static_cast<DWARFASTParserClang *>(
SymbolFileDWARF::GetDWARFParser(*dst_class_die.GetCU()));
auto link = [&](DWARFDIE src, DWARFDIE dst) {
SymbolFileDWARF::DIEToTypePtr &die_to_type =
dst_class_die.GetDWARF()->GetDIEToType();
auto &die_to_type = dst_class_die.GetDWARF()->GetDIEToType();
clang::DeclContext *dst_decl_ctx =
dst_dwarf_ast_parser->m_die_to_decl_ctx[dst.GetDIE()];
if (dst_decl_ctx)
Expand Down
9 changes: 9 additions & 0 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,13 @@ static ConstString GetDWARFMachOSegmentName() {
return g_dwarf_section_name;
}

llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> &
SymbolFileDWARF::GetDIEToType() {
if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile())
return debug_map_symfile->GetDIEToType();
return m_die_to_type;
}

llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> &
SymbolFileDWARF::GetForwardDeclCompilerTypeToDIE() {
if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile())
Expand Down Expand Up @@ -1594,6 +1601,8 @@ bool SymbolFileDWARF::CompleteType(CompilerType &compiler_type) {
if (!dwarf_ast)
return false;
Type *type = GetDIEToType().lookup(decl_die.GetDIE());
assert(type);

if (decl_die != def_die) {
GetDIEToType()[def_die.GetDIE()] = type;
DWARFASTParserClang *ast_parser =
Expand Down
6 changes: 2 additions & 4 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,7 @@ class SymbolFileDWARF : public SymbolFileCommon {
m_file_index = file_index;
}

typedef llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> DIEToTypePtr;

virtual DIEToTypePtr &GetDIEToType() { return m_die_to_type; }
virtual llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> &GetDIEToType();

virtual llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> &
GetForwardDeclCompilerTypeToDIE();
Expand Down Expand Up @@ -529,7 +527,7 @@ class SymbolFileDWARF : public SymbolFileCommon {
UniqueDWARFASTTypeMap m_unique_ast_type_map;
// A map from DIE to lldb_private::Type. For record type, the key might be
// either declaration DIE or definition DIE.
DIEToTypePtr m_die_to_type;
llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> m_die_to_type;
DIEToVariableSP m_die_to_variable_sp;
// A map from CompilerType to the struct/class/union/enum DIE (might be a
// declaration or a definition) that is used to construct it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ class SymbolFileDWARFDebugMap : public SymbolFileCommon {
return m_unique_ast_type_map;
}

llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> &GetDIEToType() {
return m_die_to_type;
}

// OSOEntry
class OSOEntry {
public:
Expand Down Expand Up @@ -329,6 +333,8 @@ class SymbolFileDWARFDebugMap : public SymbolFileCommon {
llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef>
m_forward_decl_compiler_type_to_die;
UniqueDWARFASTTypeMap m_unique_ast_type_map;
llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> m_die_to_type;

DebugMap m_debug_map;

// When an object file from the debug map gets parsed in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ bool SymbolFileDWARFDwo::ParseVendorDWARFOpcode(
return GetBaseSymbolFile().ParseVendorDWARFOpcode(op, opcodes, offset, stack);
}

SymbolFileDWARF::DIEToTypePtr &SymbolFileDWARFDwo::GetDIEToType() {
llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> &
SymbolFileDWARFDwo::GetDIEToType() {
return GetBaseSymbolFile().GetDIEToType();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class SymbolFileDWARFDwo : public SymbolFileDWARF {
SymbolFileDWARF *GetDIERefSymbolFile(const DIERef &die_ref) override;

protected:
DIEToTypePtr &GetDIEToType() override;
llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> &GetDIEToType() override;

DIEToVariableSP &GetDIEToVariable() override;

Expand Down
3 changes: 3 additions & 0 deletions lldb/test/API/lang/cpp/typedef-to-outer-fwd/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CXX_SOURCES := lib.cpp main.cpp

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class TestCaseTypedefToOuterFwd(TestBase):
"""
We a global variable whose type is forward declared. We then
try to get the Ref typedef (whose definition is in either main.o
or lib.o). Make sure we correctly resolve this typedef.
We test this for two cases, where the definition lives
in main.o or lib.o.
"""

def check_global_var(self, target, name: str):
var = target.FindFirstGlobalVariable(name)
self.assertSuccess(var.GetError(), f"Found {name}")

var_type = var.GetType()
self.assertTrue(var_type)

impl = var_type.GetPointeeType()
self.assertTrue(impl)

ref = impl.FindDirectNestedType("Ref")
self.assertTrue(ref)

self.assertEqual(ref.GetCanonicalType(), var_type)

def test_definition_in_main(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe merge these into one so we don't end up building the binary twice (for each debug info flavour)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, done

self.build()
target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
self.check_global_var(target, "gLibExternalDef")

def test_definition_in_lib(self):
self.build()
target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
self.check_global_var(target, "gMainExternalDef")
10 changes: 10 additions & 0 deletions lldb/test/API/lang/cpp/typedef-to-outer-fwd/lib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "lib.h"

template <typename T> struct FooImpl {
using Ref = FooImpl<T> *;

Ref Create() { return new FooImpl<T>(); }
};

FooImpl<char> gLibLocalDef;
BarImpl<char> *gLibExternalDef = nullptr;
7 changes: 7 additions & 0 deletions lldb/test/API/lang/cpp/typedef-to-outer-fwd/lib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef LIB_H_IN
#define LIB_H_IN

template <typename T> struct FooImpl;
template <typename T> struct BarImpl;

#endif // LIB_H_IN
12 changes: 12 additions & 0 deletions lldb/test/API/lang/cpp/typedef-to-outer-fwd/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "lib.h"

template <typename T> struct BarImpl {
using Ref = BarImpl<T> *;

Ref Create() { return new BarImpl<T>(); }
};

BarImpl<char> gMainLocalDef;
FooImpl<char> *gMainExternalDef = nullptr;

int main() { return 0; }
Loading