llvm-capstone/lldb
Michael Buch 638a839361
Reland "[clang][DebugInfo] Emit global variable definitions for static data members with constant initializers" (#71780)
This patch relands https://github.com/llvm/llvm-project/pull/70639

It was reverted because under certain conditions we triggered an
assertion
in `DIBuilder`. Specifically, in the original patch we called
`EmitGlobalVariable`
at the end of `CGDebugInfo::finalize`, after all the temporary `DIType`s
have
been uniqued. With limited debug-info such temporary nodes would be
created
more frequently, leaving us with non-uniqued nodes by the time we got to
`DIBuilder::finalize`; this violated its pre-condition and caused
assertions to trigger.

To fix this, the latest iteration of the patch moves
`EmitGlobalVariable` to the
beginning of `CGDebugInfo::finalize`. Now, when we create a temporary
`DIType` node as a result of emitting a variable definition, it will get
uniqued
in time. A test-case was added for this scenario.

We also now don't emit a linkage name for non-locationed constants since
LLDB doesn't make use of it anyway.

Original commit message:
"""
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.
"""

Dependent changes:
* https://github.com/llvm/llvm-project/pull/71800
2023-11-13 06:04:27 +00:00
..
bindings Add the ability to get a C++ vtable ValueObject from another ValueObj… (#67599) 2023-10-30 17:46:18 -07:00
cmake [lldb][windows] Allow exporting plugin symbols in LLDB_EXPORT_ALL_SYMBOLS (#71087) 2023-11-02 15:06:16 -07:00
docs [lldb][docs] Update Discord invite link 2023-11-10 11:18:30 +00:00
examples [lldb/test] Fix failures following ec456ba9ca 2023-10-26 21:21:54 -07:00
include Centralize the code that figures out which memory ranges to save into core files (#71772) 2023-11-11 11:21:32 -08:00
packages/Python/lldbsuite [lldb][test] Implement getting thread ID on OpenBSD (#71129) 2023-11-12 14:38:09 -05:00
resources [lldb][NFC] Remove copy of debugserver entitlements plist 2023-01-31 12:58:37 -08:00
scripts [lldb] Replace the usage of module imp with module importlib (#70443) 2023-10-31 17:08:55 -03:00
source Centralize the code that figures out which memory ranges to save into core files (#71772) 2023-11-11 11:21:32 -08:00
test Reland "[clang][DebugInfo] Emit global variable definitions for static data members with constant initializers" (#71780) 2023-11-13 06:04:27 +00:00
third_party/Python/module [lldb] Remove use of __future__ in python 2023-08-14 14:14:48 -07:00
tools Improve VSCode DAP logpoint value summary (#71723) 2023-11-08 16:48:55 -08:00
unittests [lldb] Change interface of StructuredData::Array::GetItemAtIndexAsDictionary (#71961) 2023-11-10 12:47:43 -08:00
utils [llvm][tblgen] Add Source Filename for emitSourceFileHeader (#65744) 2023-09-26 13:40:56 +08:00
.clang-format
.clang-tidy
.gitignore
CMakeLists.txt Reland "[CMake] Bumps minimum version to 3.20.0. 2023-05-27 12:51:21 +02:00
CodeOwners.rst [lldb] Remove more references to lldb-vscode (#69696) 2023-10-20 15:08:37 +01:00
LICENSE.TXT
use_lldb_suite_root.py [lldb] Format more Python files with black (#65979) 2023-09-12 08:46:34 +01:00