Skip to content

Commit 5f86b49

Browse files
committed
Revert "[lldb][DWARFASTParserClang] Fetch constant value from variable defintion if available (#71004)"
This reverts commit ef3feba. This caused an LLDB test failure on Linux for `lang/cpp/symbols/TestSymbols.test_dwo`: ``` make: Leaving directory '/home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/lang/cpp/symbols/TestSymbols.test_dwo' runCmd: expression -- D::i PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. HandleCommand(command = "expression -- D::i") 1. <user expression 0>:1:4: current parser token 'i' 2. <lldb wrapper prefix>:44:1: parsing function body '$__lldb_expr' 3. <lldb wrapper prefix>:44:1: in compound statement ('{}') Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it): 0 _lldb.cpython-39-x86_64-linux-gnu.so 0x00007fbcfcb08b87 1 _lldb.cpython-39-x86_64-linux-gnu.so 0x00007fbcfcb067ae 2 _lldb.cpython-39-x86_64-linux-gnu.so 0x00007fbcfcb0923f 3 libpthread.so.0 0x00007fbd07ab7140 ``` And a failure in `TestCallStdStringFunction.py` on Linux aarch64: ``` -- Exit Code: -11 Command Output (stdout): -- lldb version 18.0.0git (https://github.com/llvm/llvm-project.git revision ef3feba) clang revision ef3feba llvm revision ef3feba -- Command Output (stderr): -- PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. HandleCommand(command = "expression str") 1. <lldb wrapper prefix>:45:34: current parser token ';' 2. <lldb wrapper prefix>:44:1: parsing function body '$__lldb_expr' 3. <lldb wrapper prefix>:44:1: in compound statement ('{}') #0 0x0000ffffb72a149c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_[lldb.cpython-38-aarch64-linux-gnu.so](http://lldb.cpython-38-aarch64-linux-gnu.so/)+0x58c749c) #1 0x0000ffffb729f458 llvm::sys::RunSignalHandlers() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_[lldb.cpython-38-aarch64-linux-gnu.so](http://lldb.cpython-38-aarch64-linux-gnu.so/)+0x58c5458) #2 0x0000ffffb72a1bd0 SignalHandler(int) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_[lldb.cpython-38-aarch64-linux-gnu.so](http://lldb.cpython-38-aarch64-linux-gnu.so/)+0x58c7bd0) #3 0x0000ffffbdd9e7dc (linux-vdso.so.1+0x7dc) #4 0x0000ffffb71799d8 lldb_private::plugin::dwarf::SymbolFileDWARF::FindGlobalVariables(lldb_private::ConstString, lldb_private::CompilerDeclContext const&, unsigned int, lldb_private::VariableList&) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_[lldb.cpython-38-aarch64-linux-gnu.so](http://lldb.cpython-38-aarch64-linux-gnu.so/)+0x579f9d8) #5 0x0000ffffb7197508 DWARFASTParserClang::FindConstantOnVariableDefinition(lldb_private::plugin::dwarf::DWARFDIE) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_[lldb.cpython-38-aarch64-linux-gnu.so](http://lldb.cpython-38-aarch64-linux-gnu.so/)+0x57bd508) ```
1 parent 947a32a commit 5f86b49

File tree

5 files changed

+6
-119
lines changed

5 files changed

+6
-119
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "lldb/Symbol/SymbolFile.h"
3232
#include "lldb/Symbol/TypeList.h"
3333
#include "lldb/Symbol/TypeMap.h"
34-
#include "lldb/Symbol/VariableList.h"
3534
#include "lldb/Target/Language.h"
3635
#include "lldb/Utility/LLDBAssert.h"
3736
#include "lldb/Utility/Log.h"
@@ -134,54 +133,6 @@ static lldb::ModuleSP GetContainingClangModule(const DWARFDIE &die) {
134133
return lldb::ModuleSP();
135134
}
136135

137-
std::optional<DWARFFormValue>
138-
DWARFASTParserClang::FindConstantOnVariableDefinition(DWARFDIE die) {
139-
assert(die.Tag() == llvm::dwarf::DW_TAG_member);
140-
141-
auto *dwarf = die.GetDWARF();
142-
if (!dwarf)
143-
return {};
144-
145-
ConstString name{die.GetName()};
146-
if (!name)
147-
return {};
148-
149-
auto *CU = die.GetCU();
150-
if (!CU)
151-
return {};
152-
153-
DWARFASTParser *dwarf_ast = dwarf->GetDWARFParser(*CU);
154-
auto parent_decl_ctx = dwarf_ast->GetDeclContextContainingUIDFromDWARF(die);
155-
156-
// Make sure we populate the GetDieToVariable cache.
157-
VariableList variables;
158-
dwarf->FindGlobalVariables(name, parent_decl_ctx, UINT_MAX, variables);
159-
160-
// The cache contains the variable definition whose DW_AT_specification
161-
// points to our declaration DIE. Look up that definition using our
162-
// declaration.
163-
auto const &die_to_var = dwarf->GetDIEToVariable();
164-
auto it = die_to_var.find(die.GetDIE());
165-
if (it == die_to_var.end())
166-
return {};
167-
168-
auto var_sp = it->getSecond();
169-
assert(var_sp != nullptr);
170-
171-
if (!var_sp->GetLocationIsConstantValueData())
172-
return {};
173-
174-
auto def = dwarf->GetDIE(var_sp->GetID());
175-
auto def_attrs = def.GetAttributes();
176-
DWARFFormValue form_value;
177-
if (!def_attrs.ExtractFormValueAtIndex(
178-
def_attrs.FindAttributeIndex(llvm::dwarf::DW_AT_const_value),
179-
form_value))
180-
return {};
181-
182-
return form_value;
183-
}
184-
185136
TypeSP DWARFASTParserClang::ParseTypeFromClangModule(const SymbolContext &sc,
186137
const DWARFDIE &die,
187138
Log *log) {
@@ -2955,21 +2906,9 @@ void DWARFASTParserClang::ParseSingleMember(
29552906

29562907
bool unused;
29572908
// TODO: Support float/double static members as well.
2958-
if (!ct.IsIntegerOrEnumerationType(unused))
2909+
if (!attrs.const_value_form || !ct.IsIntegerOrEnumerationType(unused))
29592910
return;
29602911

2961-
// Newer versions of Clang don't emit the DW_AT_const_value
2962-
// on the declaration of an inline static data member. Instead
2963-
// it's attached to the definition DIE. If that's the case,
2964-
// try and fetch it.
2965-
if (!attrs.const_value_form) {
2966-
auto maybe_form_value = FindConstantOnVariableDefinition(die);
2967-
if (!maybe_form_value)
2968-
return;
2969-
2970-
attrs.const_value_form = *maybe_form_value;
2971-
}
2972-
29732912
llvm::Expected<llvm::APInt> const_value_or_err =
29742913
ExtractIntFromFormValue(ct, *attrs.const_value_form);
29752914
if (!const_value_or_err) {

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -373,17 +373,6 @@ class DWARFASTParserClang : public lldb_private::plugin::dwarf::DWARFASTParser {
373373
lldb_private::CompilerType &class_clang_type,
374374
const lldb::AccessType default_accesibility,
375375
lldb_private::ClangASTImporter::LayoutInfo &layout_info);
376-
377-
/// Tries to find the definition DW_TAG_variable DIE of the the specified
378-
/// DW_TAG_member 'die'. If such definition exists, returns the
379-
/// DW_AT_const_value of that definition if available. Returns std::nullopt
380-
/// otherwise.
381-
///
382-
/// In newer versions of clang, DW_AT_const_value attributes are not attached
383-
/// to the declaration of a inline static data-member anymore, but rather on
384-
/// its definition. This function is used to locate said constant.
385-
std::optional<lldb_private::plugin::dwarf::DWARFFormValue>
386-
FindConstantOnVariableDefinition(lldb_private::plugin::dwarf::DWARFDIE die);
387376
};
388377

389378
/// Parsed form of all attributes that are relevant for type reconstruction.

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,6 @@ class SymbolFileDWARF : public SymbolFileCommon {
343343
return m_forward_decl_compiler_type_to_die;
344344
}
345345

346-
typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP>
347-
DIEToVariableSP;
348-
349-
virtual DIEToVariableSP &GetDIEToVariable() { return m_die_to_variable_sp; }
350-
351346
virtual UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap();
352347

353348
bool ClassOrStructIsVirtual(const DWARFDIE &die);
@@ -367,6 +362,9 @@ class SymbolFileDWARF : public SymbolFileCommon {
367362
Type *ResolveTypeUID(const DIERef &die_ref);
368363

369364
protected:
365+
typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP>
366+
DIEToVariableSP;
367+
370368
SymbolFileDWARF(const SymbolFileDWARF &) = delete;
371369
const SymbolFileDWARF &operator=(const SymbolFileDWARF &) = delete;
372370

@@ -490,6 +488,8 @@ class SymbolFileDWARF : public SymbolFileCommon {
490488

491489
void UpdateExternalModuleListIfNeeded();
492490

491+
virtual DIEToVariableSP &GetDIEToVariable() { return m_die_to_variable_sp; }
492+
493493
void BuildCuTranslationTable();
494494
std::optional<uint32_t> GetDWARFUnitIndex(uint32_t cu_idx);
495495

lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -139,24 +139,3 @@ def test_class_with_only_constexpr_static(self):
139139
self.expect_expr(
140140
"ClassWithEnumAlias::enum_alias_alias", result_value="scoped_enum_case1"
141141
)
142-
143-
def test_shadowed_static_inline_members(self):
144-
"""Tests that the expression evaluator and SBAPI can both
145-
correctly determine the requested inline static variable
146-
in the presence of multiple variables of the same name."""
147-
148-
self.build()
149-
lldbutil.run_to_name_breakpoint(self, "bar")
150-
151-
self.check_global_var("ns::Foo::mem", "const int", "10")
152-
153-
self.expect_expr("mem", result_value="10")
154-
self.expect_expr("Foo::mem", result_value="10")
155-
self.expect_expr("ns::Foo::mem", result_value="10")
156-
self.expect_expr("::Foo::mem", result_value="-29")
157-
158-
@expectedFailureAll(bugnumber="target var doesn't honour global namespace")
159-
def test_shadowed_static_inline_members_xfail(self):
160-
self.build()
161-
lldbutil.run_to_name_breakpoint(self, "bar")
162-
self.check_global_var("::Foo::mem", "const int", "-29")

lldb/test/API/lang/cpp/const_static_integral_member/main.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,25 +89,6 @@ struct ClassWithEnumAlias {
8989
ScopedEnum::scoped_enum_case1;
9090
};
9191

92-
namespace ns {
93-
struct Foo {
94-
constexpr static int mem = 10;
95-
96-
void bar() { return; }
97-
};
98-
} // namespace ns
99-
100-
struct Foo {
101-
constexpr static int mem = -29;
102-
};
103-
104-
int func() {
105-
Foo f1;
106-
ns::Foo f2;
107-
f2.bar();
108-
return ns::Foo::mem + Foo::mem;
109-
}
110-
11192
int main() {
11293
A a;
11394

@@ -143,7 +124,6 @@ int main() {
143124

144125
auto enum_alias_val = ClassWithEnumAlias::enum_alias;
145126
auto enum_alias_alias_val = ClassWithEnumAlias::enum_alias_alias;
146-
auto ret = func();
147127

148128
return 0; // break here
149129
}

0 commit comments

Comments
 (0)