Issue 230206.1: Add DW_AT_imported_declaration entries to name index

Author: Michael Buch
Champion: David Blaikie
Date submitted: 2023-02-06
Date revised: 2023-10-30
Date closed:
Type: Improvement
Status: Open
DWARF Version: 6

Section 6.1.1.1, pg 137

Add DW_AT_imported_declaration entries to name index for accelerated lookup.

Background

C++ supports the ability to create aliases for namespaces.

Example — C++ namespace alias

namespace A {                 
  namespace B {                 
    namespace C {                 
      int a = 1;                    
    }                              
  }  // namespace B

  namespace C = B::C;           
}  // namespace A

int main() { return A::C::a; }

<1> DW_TAG_namespace            
         DW_AT_name "A"

<2>   DW_TAG_namespace          
           DW_AT_name "B"

<3>     DW_TAG_namespace        
              DW_AT_name "C"

<4>       DW_TAG_variable       
                DW_AT_name "a"


<5>  DW_TAG_imported_declaration
          DW_AT_import <3>         
          DW_AT_name "C"

In DWARF, the namespace alias “C” declared in namespace “A” is represented using a DW_TAG_imported_declaration whose name is that of the alias in the source program. However, compliant DWARF producers skip emitting DW_TAG_imported_declaration for the namespace alias into the name index. This is problematic for consumers that need to perform lookup by name on the namespace alias (for example during LLDB’s expression evaluation) because there is nothing linking the import declaration and the namespace DIEs to each other, forcing the consumer to perform expensive scans through the DWARF tree or complicated bookkeeping.

This proposal extends the list of tags that may be put into the name index further to include DW_TAG_imported_declaration to simplify the work consumers have to do to find namespace alias DIEs by name.

Document changes

6.1.1.1 Contents of the Name Index

[ORIGINAL TEXT]

The name index must contain an entry for each debugging information entry that defines a named subprogram, label, variable, type, or namespace, subject to the following rules:

[NEW TEXT]

The name index must contain an entry for each debugging information entry that defines a named subprogram, label, variable, type, namespace, or import declaration subject to the following rules:


2023-10-30: Fixed indentation issues and typos.
Accepted in principle, but need to investigate additional cases. Will revisit at next meeting.