[Lldb-commits] [PATCH] D141828: [WIP][lldb] Add support for DW_AT_default_value in template params

Michael Buch via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Jan 16 01:30:42 PST 2023


Michael137 created this revision.
Michael137 added a reviewer: dblaikie.
Herald added a reviewer: shafik.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

**Summary**

This patch makes LLDB understand the `DW_AT_default_value` on
template argument DIEs. As a result, type summaries will no
longer contain the defaulted template arguments, reducing
noise substantially. E.g.,

Before:

  (lldb) v nested
  (std::vector<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::allocator<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator <char> > > > > >) nested = size=0 {}

After:

  (lldb) v nested
  (std::vector<std::vector<std::basic_string<char> > >) nested = size=0 {}

See discussion in https://reviews.llvm.org/D140423

**TODO**

- TODO: need to adjust API tests


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141828

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


Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2026,6 +2026,7 @@
     CompilerType clang_type;
     uint64_t uval64 = 0;
     bool uval64_valid = false;
+    bool is_default_template_arg = false;
     if (num_attributes > 0) {
       DWARFFormValue form_value;
       for (size_t i = 0; i < num_attributes; ++i) {
@@ -2056,6 +2057,11 @@
             uval64 = form_value.Unsigned();
           }
           break;
+        case DW_AT_default_value:
+          if (attributes.ExtractFormValueAtIndex(i, form_value)) {
+            is_default_template_arg = form_value.Boolean();
+          }
+          break;
         default:
           break;
         }
@@ -2078,19 +2084,21 @@
           if (!size)
             return false;
           llvm::APInt apint(*size, uval64, is_signed);
-          template_param_infos.InsertArg(
-              name,
+          auto TA =
               clang::TemplateArgument(ast, llvm::APSInt(apint, !is_signed),
-                                      ClangUtil::GetQualType(clang_type)));
+                                      ClangUtil::GetQualType(clang_type));
+          TA.setIsDefaulted(is_default_template_arg);
+          template_param_infos.InsertArg(name, std::move(TA));
         } else {
-          template_param_infos.InsertArg(
-              name,
-              clang::TemplateArgument(ClangUtil::GetQualType(clang_type)));
+          auto TA = clang::TemplateArgument(ClangUtil::GetQualType(clang_type));
+          TA.setIsDefaulted(is_default_template_arg);
+          template_param_infos.InsertArg(name, std::move(TA));
         }
       } else {
         auto *tplt_type = m_ast.CreateTemplateTemplateParmDecl(template_name);
-        template_param_infos.InsertArg(
-            name, clang::TemplateArgument(clang::TemplateName(tplt_type)));
+        auto TA = clang::TemplateArgument(clang::TemplateName(tplt_type));
+        TA.setIsDefaulted(is_default_template_arg);
+        template_param_infos.InsertArg(name, std::move(TA));
       }
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141828.489459.patch
Type: text/x-patch
Size: 2238 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230116/866e5eea/attachment.bin>


More information about the lldb-commits mailing list