Here’s an example of binary built without -gsimple-template-names
which could also benefit from this change:
main.cpp
namespace N1 {
struct S;
}
template<typename T>
struct Foo {};
Foo<N1::S> foo;
int main() {
}
namespace.cpp
namespace N1 {
struct S {};
}
N1::S s;
Compile with clang++ -g main.cpp namespace.cpp
and test with lldb a.out -o "log enable dwarf comp" -o "b main" -o "r" -o "p foo" -o "p s"
Current lldb logging:
(lldb) p foo
lldb (x86_64) /tmp/a.out: DWARFASTParserClang::ParseTypeFromDWARF (die = 0x0000000000000040, decl_ctx = 0x000055F3D2C378A0 (die 0x000000000000000c)) DW_TAG_subprogram name = 'main')
lldb (x86_64) /tmp/a.out: DWARFASTParserClang::ParseTypeFromDWARF (die = 0x000000000000004f, decl_ctx = 0x000055F3D2C378A0 (die 0x000000000000000c)) DW_TAG_base_type name = 'int')
lldb (x86_64) /tmp/a.out: DWARFASTParserClang::ParseTypeFromDWARF (die = 0x000000000000002e, decl_ctx = 0x000055F3D2C378A0 (die 0x000000000000000c)) DW_TAG_structure_type name = 'Foo<N1::S>')
lldb (x86_64) /tmp/a.out: DWARFASTParserClang::ParseTypeFromDWARF (die = 0x000000000000003d, decl_ctx = 0x000055F3D2C381E8 (die 0x000000000000003b)) DW_TAG_structure_type name = 'S')
lldb (x86_64) /tmp/a.out: SymbolFileDWARF(0x000055F3D2C215E0) - 0x000000000000003d: DW_TAG_structure_type type "S" is a forward declaration, trying to find complete type
lldb (x86_64) /tmp/a.out: SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=DW_TAG_structure_type, name='S')
lldb (x86_64) /tmp/a.out: SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=DW_TAG_structure_type, name='S') trying die=0x000000000000007f (N1::S)
lldb (x86_64) /tmp/a.out: DWARFASTParserClang::ParseTypeFromDWARF (die = 0x000000000000007f, decl_ctx = 0x000055F3D2C381E8 (die 0x000000000000007d)) DW_TAG_structure_type name = 'S')
lldb (x86_64) /tmp/a.out: SymbolFileDWARF(0x000055F3D2C215E0) - 0x000000000000003d: DW_TAG_structure_type type "S" is a forward declaration, complete type is 0x0000007f
lldb (x86_64) /tmp/a.out: 0x0000002e: DW_TAG_structure_type 'Foo<N1::S>' resolving forward declaration...
(Foo<N1::S>) {}
(lldb) p s
(N1::S) {}
Notice that it’s trying to find definition DIE for N1::S
and create type from it when printing foo
whose type is Foo<N1::S>
. But it’s not actually being used at this moment. This is extra unnecessary work.
Snippet of the debug info:
0x0000007d: DW_TAG_namespace
DW_AT_name ("N1")
0x0000007f: DW_TAG_structure_type
DW_AT_calling_convention (DW_CC_pass_by_value)
DW_AT_name ("S")
DW_AT_byte_size (0x01)
DW_AT_decl_file ("/tmp/namespace.cpp")
DW_AT_decl_line (2)
With this change, lldb only search for definition DIE when p s
and that’s the time when we want to complete the type N1::S
and searching for its definition DIE:
(lldb) p foo
lldb (x86_64) /tmp/a.out: DWARFASTParserClang::ParseTypeFromDWARF (die = 0x0000000000000040, decl_ctx = 0x000055632AA21570 (die 0x000000000000000c)) DW_TAG_subprogram name = 'main')
lldb (x86_64) /tmp/a.out: DWARFASTParserClang::ParseTypeFromDWARF (die = 0x000000000000004f, decl_ctx = 0x000055632AA21570 (die 0x000000000000000c)) DW_TAG_base_type name = 'int')
lldb (x86_64) /tmp/a.out: DWARFASTParserClang::ParseTypeFromDWARF (die = 0x000000000000002e, decl_ctx = 0x000055632AA21570 (die 0x000000000000000c)) DW_TAG_structure_type name = 'Foo<N1::S>')
lldb (x86_64) /tmp/a.out: DWARFASTParserClang::ParseTypeFromDWARF (die = 0x000000000000003d, decl_ctx = 0x000055632AA21EB8 (die 0x000000000000003b)) DW_TAG_structure_type name = 'S')
lldb (x86_64) /tmp/a.out: 0x0000002e: DW_TAG_structure_type 'Foo<N1::S>' resolving forward declaration...
(Foo<N1::S>) {}
(lldb) p s
lldb (x86_64) /tmp/a.out: DWARFASTParserClang::ParseTypeFromDWARF (die = 0x000000000000007f, decl_ctx = 0x000055632AA21EB8 (die 0x000000000000007d)) DW_TAG_structure_type name = 'S')
lldb (x86_64) /tmp/a.out: 0x0000007f: DW_TAG_structure_type 'S' resolving forward declaration...
(N1::S) {}