[all-commits] [llvm/llvm-project] 7c3707: Reland "clang][DebugInfo] Emit global variable def...

Michael Buch via All-commits all-commits at lists.llvm.org
Mon Nov 6 20:54:51 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7c3707aea8a6f1fc245ad2862982b8a51b6c0fea
      https://github.com/llvm/llvm-project/commit/7c3707aea8a6f1fc245ad2862982b8a51b6c0fea
  Author: Michael Buch <michaelbuch12 at gmail.com>
  Date:   2023-11-07 (Tue, 07 Nov 2023)

  Changed paths:
    M clang/lib/CodeGen/CGDebugInfo.cpp
    M clang/lib/CodeGen/CGDebugInfo.h
    M clang/test/CodeGenCXX/debug-info-class.cpp
    A clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
    M clang/test/CodeGenCXX/debug-info-static-member.cpp
    M lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
    M lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py

  Log Message:
  -----------
  Reland "clang][DebugInfo] Emit global variable definitions for static data members with constant initializers (#70639)"

When an LLDB user asks for the value of a static data member, LLDB
starts by searching the Names accelerator table for the corresponding
variable definition DIE. For static data members with out-of-class
definitions that works fine, because those get represented as global
variables with a location and making them eligible to be added to the
Names table. However, in-class definitions won’t get indexed because
we usually don't emit global variables for them. So in DWARF we end
up with a single `DW_TAG_member` that usually holds the constant
initializer.  But we don't get a corresponding CU-level
`DW_TAG_variable` like we do for out-of-class definitions.

To make it more convenient for debuggers to get to the value of
inline static data members, this patch makes sure we emit definitions
for static variables with constant initializers the same way we do
for other static variables. This also aligns Clang closer to GCC,
which produces CU-level definitions for inline statics and also
emits these into `.debug_pubnames`.

The implementation keeps track of newly created static data members.
Then in `CGDebugInfo::finalize`, we emit a global `DW_TAG_variable`
with a `DW_AT_const_value` for any of those declarations that didn't
end up with a definition in the `DeclCache`.

The newly emitted `DW_TAG_variable` will look as follows:
```
0x0000007b:   DW_TAG_structure_type
                DW_AT_calling_convention        (DW_CC_pass_by_value)
                DW_AT_name      ("Foo")
                ...

0x0000008d:     DW_TAG_member
                  DW_AT_name    ("i")
                  DW_AT_type    (0x00000062 "const int")
                  DW_AT_external        (true)
                  DW_AT_declaration     (true)
                  DW_AT_const_value     (4)

Newly added
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

0x0000009a:   DW_TAG_variable
                DW_AT_specification     (0x0000008d "i")
                DW_AT_const_value       (4)
                DW_AT_linkage_name      ("_ZN2t2IiE1iIfEE")
```

This patch also drops the `DW_AT_const_value` off of the declaration
since we now always have it on the definition. This ensures that the
`DWARFParallelLinker` can type-merge class with static members where
we couldn't attach the constant on the declaration in some CUs.


  Commit: 470de2bbec7f5fdd199775aa99c68ac76f4d5c74
      https://github.com/llvm/llvm-project/commit/470de2bbec7f5fdd199775aa99c68ac76f4d5c74
  Author: Michael Buch <michaelbuch12 at gmail.com>
  Date:   2023-11-07 (Tue, 07 Nov 2023)

  Changed paths:
    M lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
    M lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
    M lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
    M lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
    M lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
    M lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
    M lldb/test/API/lang/cpp/const_static_integral_member/main.cpp

  Log Message:
  -----------
  Reland "[lldb][DWARFASTParserClang] Fetch constant value from variable defintion if available (#71004)"

 https://github.com/llvm/llvm-project/pull/70639 proposes moving the
 `DW_AT_const_value` on inline static members from the declaration DIE to
 the definition DIE. This patch makes sure the LLDB's expression
 evaluator can continue to support static initialisers even if the
 declaration doesn't have a `DW_AT_const_value` anymore.

 Previously the expression evaluator would find the constant for a
 VarDecl from its declaration `DW_TAG_member` DIE. In cases where the
 initialiser was specified out-of-class, LLDB could find it during symbol
 resolution.

 However, neither of those will work for constants, since we don't have a
 constant attribute on the declaration anymore and we don't have
 constants in the symbol table.

 **Testing**

 * If https://github.com/llvm/llvm-project/pull/70639 were to land
 without this patch then most of the `TestConstStaticIntegralMember.py`
 would start failing


  Commit: 15fc809404d4715822e5349b76dcca50eb100eec
      https://github.com/llvm/llvm-project/commit/15fc809404d4715822e5349b76dcca50eb100eec
  Author: Michael Buch <michaelbuch12 at gmail.com>
  Date:   2023-11-07 (Tue, 07 Nov 2023)

  Changed paths:
    M lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py

  Log Message:
  -----------
  Reland "[lldb][test] Add FindGlobalVariables tests for C++ inline static data members (#70641)"

Tests that LLDB can find inline static data members.

Relies on the debug-info change in:
https://github.com/llvm/llvm-project/pull/70639


Compare: https://github.com/llvm/llvm-project/compare/3c11ac51180f...15fc809404d4


More information about the All-commits mailing list