[Lldb-commits] [lldb] Reland "[lldb][DWARFASTParserClang] Fetch constant value from variable defintion if available" (PR #71800)

via lldb-commits lldb-commits at lists.llvm.org
Sun Nov 12 22:11:54 PST 2023


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff d4912e80500706a9912725d45d822675cf9153d8 feba840daf34d0a8c0756d3cef34ec4585849c92 -- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 570cd5d469..63f0561b4e 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -141,53 +141,53 @@ static bool ShouldIgnoreArtificialField(llvm::StringRef FieldName) {
          // gdb emit vtable pointer as "_vptr.classname"
          || FieldName.starts_with("_vptr.");
 
-std::optional<DWARFFormValue>
-DWARFASTParserClang::FindConstantOnVariableDefinition(DWARFDIE die) {
-  assert(die.Tag() == llvm::dwarf::DW_TAG_member);
+  std::optional<DWARFFormValue>
+  DWARFASTParserClang::FindConstantOnVariableDefinition(DWARFDIE die) {
+    assert(die.Tag() == llvm::dwarf::DW_TAG_member);
 
-  auto *dwarf = die.GetDWARF();
-  if (!dwarf)
-    return {};
+    auto *dwarf = die.GetDWARF();
+    if (!dwarf)
+      return {};
 
-  ConstString name{die.GetName()};
-  if (!name)
-    return {};
+    ConstString name{die.GetName()};
+    if (!name)
+      return {};
 
-  auto *CU = die.GetCU();
-  if (!CU)
-    return {};
+    auto *CU = die.GetCU();
+    if (!CU)
+      return {};
 
-  DWARFASTParser *dwarf_ast = dwarf->GetDWARFParser(*CU);
-  auto parent_decl_ctx = dwarf_ast->GetDeclContextContainingUIDFromDWARF(die);
+    DWARFASTParser *dwarf_ast = dwarf->GetDWARFParser(*CU);
+    auto parent_decl_ctx = dwarf_ast->GetDeclContextContainingUIDFromDWARF(die);
 
-  // Make sure we populate the GetDieToVariable cache.
-  VariableList variables;
-  dwarf->FindGlobalVariables(name, parent_decl_ctx, UINT_MAX, variables);
+    // Make sure we populate the GetDieToVariable cache.
+    VariableList variables;
+    dwarf->FindGlobalVariables(name, parent_decl_ctx, UINT_MAX, variables);
 
-  // The cache contains the variable definition whose DW_AT_specification
-  // points to our declaration DIE. Look up that definition using our
-  // declaration.
-  auto const &die_to_var = dwarf->GetDIEToVariable();
-  auto it = die_to_var.find(die.GetDIE());
-  if (it == die_to_var.end())
-    return {};
+    // The cache contains the variable definition whose DW_AT_specification
+    // points to our declaration DIE. Look up that definition using our
+    // declaration.
+    auto const &die_to_var = dwarf->GetDIEToVariable();
+    auto it = die_to_var.find(die.GetDIE());
+    if (it == die_to_var.end())
+      return {};
 
-  auto var_sp = it->getSecond();
-  assert(var_sp != nullptr);
+    auto var_sp = it->getSecond();
+    assert(var_sp != nullptr);
 
-  if (!var_sp->GetLocationIsConstantValueData())
-    return {};
+    if (!var_sp->GetLocationIsConstantValueData())
+      return {};
 
-  auto def = dwarf->GetDIE(var_sp->GetID());
-  auto def_attrs = def.GetAttributes();
-  DWARFFormValue form_value;
-  if (!def_attrs.ExtractFormValueAtIndex(
-          def_attrs.FindAttributeIndex(llvm::dwarf::DW_AT_const_value),
-          form_value))
-    return {};
+    auto def = dwarf->GetDIE(var_sp->GetID());
+    auto def_attrs = def.GetAttributes();
+    DWARFFormValue form_value;
+    if (!def_attrs.ExtractFormValueAtIndex(
+            def_attrs.FindAttributeIndex(llvm::dwarf::DW_AT_const_value),
+            form_value))
+      return {};
 
-  return form_value;
-}
+    return form_value;
+  }
 
 TypeSP DWARFASTParserClang::ParseTypeFromClangModule(const SymbolContext &sc,
                                                      const DWARFDIE &die,

``````````

</details>


https://github.com/llvm/llvm-project/pull/71800


More information about the lldb-commits mailing list