teemperor created this revision.
teemperor added reviewers: shafik, jingham.
Herald added subscribers: lldb-commits, JDevlieghere, christof.
Herald added a project: LLDB.

Currently when printing data types we include implicit scopes such as inline 
namespaces or anonymous namespaces.
This leads to command output like this (for `std::set<int>`):

  (lldb) print my_set
  (std::__1::set<int, std::__1::less<int>, std::__1::allocator<int> >) $0 = 
size=0 {}

This patch removes all the implicit scopes when printing type names in 
TypeSystemClang::GetDisplayTypeName
so that our output now looks like this:

  (lldb) print my_set
  (std::set<int, std::less<int>, std::allocator<int> >) $0 = size=0 {}

As previously GetDisplayTypeName and GetTypeName had the same output we 
actually often used the
two as if they are the same method (they were in fact using the same 
implementation), so this patch also
fixes the places where we actually want the display type name and not the 
actual type name.

Note that this doesn't touch the `GetTypeName` class that for example the data 
formatters use, so this patch
is only changes the way we display types to the user.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D74478

Files:
  lldb/packages/Python/lldbsuite/test/lldbtest.py
  lldb/source/DataFormatters/FormatManager.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
  
lldb/test/API/commands/expression/import-std-module/basic/TestImportStdModule.py
  
lldb/test/API/commands/expression/import-std-module/conflicts/TestStdModuleWithConflicts.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/forward_list/TestDataFormatterLibcxxForwardList.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/TestDataFormatterLibccIterator.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/multimap/TestDataFormatterLibccMultiMap.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/TestDataFormatterLibcxxMultiSet.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/main.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/queue/TestDataFormatterLibcxxQueue.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/set/TestDataFormatterLibcxxSet.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/set/main.cpp
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/TestDataFormatterLibcxxTuple.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered/TestDataFormatterUnordered.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
  lldb/test/Shell/SymbolFile/NativePDB/ast-types.cpp

Index: lldb/test/Shell/SymbolFile/NativePDB/ast-types.cpp
===================================================================
--- lldb/test/Shell/SymbolFile/NativePDB/ast-types.cpp
+++ lldb/test/Shell/SymbolFile/NativePDB/ast-types.cpp
@@ -102,9 +102,9 @@
 // CHECK: (A::C<-1>::D) ACNeg1D = (ACDMember = 0, CPtr = 0x{{0+}})
 // CHECK: (A::D) AD = {}
 // CHECK: (A::D::E) ADE = (ADDMember = 0)
-// CHECK: ((anonymous namespace)::Anonymous<int>) AnonInt = (AnonymousMember = 0)
-// CHECK: ((anonymous namespace)::Anonymous<A::B::C<void>>) AnonABCVoid = (AnonymousMember = 0)
-// CHECK: ((anonymous namespace)::Anonymous<A::B::C<void>>::D) AnonABCVoidD = (AnonymousDMember = 0)
+// CHECK: (Anonymous<int>) AnonInt = (AnonymousMember = 0)
+// CHECK: (Anonymous<A::B::C<void>>) AnonABCVoid = (AnonymousMember = 0)
+// CHECK: (Anonymous<A::B::C<void>>::D) AnonABCVoidD = (AnonymousDMember = 0)
 // CHECK: Dumping clang ast for 1 modules.
 // CHECK: TranslationUnitDecl {{.*}}
 // CHECK: |-CXXRecordDecl {{.*}} class TrivialC definition
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
@@ -51,7 +51,7 @@
                                '}'])
 
         self.expect("frame variable v_v1",
-                substrs=['v_v1 =  Active Type = std::__1::variant<int, double, char>  {',
+                substrs=['v_v1 =  Active Type = std::variant<int, double, char>  {',
                                  'Value =  Active Type = int  {',
                                    'Value = 12',
                                  '}',
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered/TestDataFormatterUnordered.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered/TestDataFormatterUnordered.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unordered/TestDataFormatterUnordered.py
@@ -16,8 +16,7 @@
 
     def setUp(self):
         TestBase.setUp(self)
-        ns = 'ndk' if lldbplatformutil.target_is_android() else ''
-        self.namespace = 'std::__' + ns + '1'
+        self.namespace = 'std'
 
     @add_test_categories(["libc++"])
     def test_with_run_command(self):
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/TestDataFormatterLibcxxTuple.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/TestDataFormatterLibcxxTuple.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/tuple/TestDataFormatterLibcxxTuple.py
@@ -17,8 +17,7 @@
     def setUp(self):
         TestBase.setUp(self)
         self.line = line_number('main.cpp', '// break here')
-        ns = 'ndk' if lldbplatformutil.target_is_android() else ''
-        self.namespace = 'std::__' + ns + '1'
+        self.namespace = 'std'
 
     @add_test_categories(["libc++"])
     def test(self):
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
@@ -20,8 +20,7 @@
         TestBase.setUp(self)
         # Find the line number to break at.
         self.line = line_number('main.cpp', '// Set break point at this line.')
-        ns = 'ndk' if lldbplatformutil.target_is_android() else ''
-        self.namespace = 'std::__' + ns + '1'
+        self.namespace = 'std'
 
     @add_test_categories(["libc++"])
     @expectedFailureAll(bugnumber="llvm.org/pr36109", debug_info="gmodules", triple=".*-android")
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/set/main.cpp
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/set/main.cpp
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/set/main.cpp
@@ -1,9 +1,6 @@
 #include <string>
 #include <set>
 
-typedef std::set<int> intset;
-typedef std::set<std::string> stringset;
-
 int g_the_foo = 0;
 
 int thefoo_rw(int arg = 1)
@@ -16,7 +13,7 @@
 	return g_the_foo;
 }
 
-void by_ref_and_ptr(intset &ref, intset *ptr)
+void by_ref_and_ptr(std::set<int> &ref, std::set<int> *ptr)
 {
     // Stop here to check by ref and ptr
     return;
@@ -24,7 +21,7 @@
 
 int main()
 {
-    intset ii;
+    std::set<int> ii;
     thefoo_rw(1);  // Set break point at this line.
 	
 	ii.insert(0);
@@ -43,7 +40,7 @@
 	ii.clear();
 	thefoo_rw(1);  // Set break point at this line.
 
-	stringset ss;
+	std::set<std::string> ss;
 	thefoo_rw(1);  // Set break point at this line.
 
 	ss.insert("a");
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/set/TestDataFormatterLibcxxSet.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/set/TestDataFormatterLibcxxSet.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/set/TestDataFormatterLibcxxSet.py
@@ -16,13 +16,12 @@
 
     def setUp(self):
         TestBase.setUp(self)
-        ns = 'ndk' if lldbplatformutil.target_is_android() else ''
-        self.namespace = 'std::__' + ns + '1'
+        self.namespace = 'std'
 
     def getVariableType(self, name):
         var = self.frame().FindVariable(name)
         self.assertTrue(var.IsValid())
-        return var.GetType().GetCanonicalType().GetName()
+        return var.GetType().GetDisplayTypeName()
 
     def check_ii(self, var_name):
         """ This checks the value of the bitset stored in ii at the call to by_ref_and_ptr.
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/queue/TestDataFormatterLibcxxQueue.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/queue/TestDataFormatterLibcxxQueue.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/queue/TestDataFormatterLibcxxQueue.py
@@ -16,15 +16,14 @@
 
     def setUp(self):
         TestBase.setUp(self)
-        ns = 'ndk' if lldbplatformutil.target_is_android() else ''
-        self.namespace = 'std::__' + ns + '1'
+        self.namespace = 'std'
 
     def check_variable(self, name):
         var = self.frame().FindVariable(name)
         self.assertTrue(var.IsValid())
 
         queue = self.namespace + '::queue'
-        self.assertTrue(queue in var.GetTypeName())
+        self.assertTrue(queue in var.GetDisplayTypeName())
         self.assertEqual(var.GetNumChildren(), 5)
         for i in range(5):
             ch = var.GetChildAtIndex(i)
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/main.cpp
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/main.cpp
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/main.cpp
@@ -1,9 +1,6 @@
 #include <string>
 #include <set>
 
-typedef std::multiset<int> intset;
-typedef std::multiset<std::string> stringset;
-
 int g_the_foo = 0;
 
 int thefoo_rw(int arg = 1)
@@ -16,7 +13,7 @@
 	return g_the_foo;
 }
 
-void by_ref_and_ptr(intset &ref, intset *ptr)
+void by_ref_and_ptr(std::multiset<int> &ref, std::multiset<int> *ptr)
 {
     // Stop here to check by ref and ptr
     return;
@@ -24,7 +21,7 @@
 
 int main()
 {
-    intset ii;
+    std::multiset<int> ii;
     thefoo_rw(1);  // Set break point at this line.
 	
 	ii.insert(0);
@@ -43,7 +40,7 @@
 	ii.clear();
 	thefoo_rw(1);  // Set break point at this line.
 
-	stringset ss;
+	std::multiset<std::string> ss;
 	thefoo_rw(1);  // Set break point at this line.
 
 	ss.insert("a");
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/TestDataFormatterLibcxxMultiSet.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/TestDataFormatterLibcxxMultiSet.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/multiset/TestDataFormatterLibcxxMultiSet.py
@@ -16,13 +16,12 @@
 
     def setUp(self):
         TestBase.setUp(self)
-        ns = 'ndk' if lldbplatformutil.target_is_android() else ''
-        self.namespace = 'std::__' + ns + '1'
+        self.namespace = 'std'
 
     def getVariableType(self, name):
         var = self.frame().FindVariable(name)
         self.assertTrue(var.IsValid())
-        return var.GetType().GetCanonicalType().GetName()
+        return var.GetType().GetDisplayTypeName()
 
     def check_ii(self, var_name):
         """ This checks the value of the bitset stored in ii at the call to by_ref_and_ptr.
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/multimap/TestDataFormatterLibccMultiMap.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/multimap/TestDataFormatterLibccMultiMap.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/multimap/TestDataFormatterLibccMultiMap.py
@@ -17,8 +17,7 @@
 
     def setUp(self):
         TestBase.setUp(self)
-        ns = 'ndk' if lldbplatformutil.target_is_android() else ''
-        self.namespace = 'std::__' + ns + '1'
+        self.namespace = 'std'
 
     @add_test_categories(["libc++"])
     def test_with_run_command(self):
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
@@ -17,7 +17,7 @@
     def setUp(self):
         TestBase.setUp(self)
         ns = 'ndk' if lldbplatformutil.target_is_android() else ''
-        self.namespace = 'std::__' + ns + '1'
+        self.namespace = 'std'
 
     @add_test_categories(["libc++"])
     def test_with_run_command(self):
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/TestDataFormatterLibccIterator.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/TestDataFormatterLibccIterator.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/iterator/TestDataFormatterLibccIterator.py
@@ -19,8 +19,7 @@
         TestBase.setUp(self)
         # Find the line number to break at.
         self.line = line_number('main.cpp', '// Set break point at this line.')
-        ns = 'ndk' if lldbplatformutil.target_is_android() else ''
-        self.namespace = 'std::__' + ns + '1'
+        self.namespace = 'std'
 
     @add_test_categories(["libc++"])
     def test_with_run_command(self):
Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/forward_list/TestDataFormatterLibcxxForwardList.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/forward_list/TestDataFormatterLibcxxForwardList.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/forward_list/TestDataFormatterLibcxxForwardList.py
@@ -17,8 +17,7 @@
     def setUp(self):
         TestBase.setUp(self)
         self.line = line_number('main.cpp', '// break here')
-        ns = 'ndk' if lldbplatformutil.target_is_android() else ''
-        self.namespace = 'std::__' + ns + '1'
+        self.namespace = 'std'
 
     @add_test_categories(["libc++"])
     def test(self):
Index: lldb/test/API/commands/expression/import-std-module/conflicts/TestStdModuleWithConflicts.py
===================================================================
--- lldb/test/API/commands/expression/import-std-module/conflicts/TestStdModuleWithConflicts.py
+++ lldb/test/API/commands/expression/import-std-module/conflicts/TestStdModuleWithConflicts.py
@@ -27,6 +27,6 @@
         self.runCmd("settings set target.import-std-module true")
         self.expect_expr("std::abs(-42)", result_type="int", result_value="42")
         self.expect_expr("std::div(2, 1).quot", result_type="int", result_value="2")
-        self.expect_expr("(std::size_t)33U", result_type="size_t", result_value="33")
+        self.expect_expr("(std::size_t)33U", result_type="std::size_t", result_value="33")
         self.expect("expr char char_a = 'b'; char char_b = 'a'; std::swap(char_a, char_b); char_a",
                     substrs=["(char) $3 = 'a'"])
Index: lldb/test/API/commands/expression/import-std-module/basic/TestImportStdModule.py
===================================================================
--- lldb/test/API/commands/expression/import-std-module/basic/TestImportStdModule.py
+++ lldb/test/API/commands/expression/import-std-module/basic/TestImportStdModule.py
@@ -25,7 +25,7 @@
         self.expect_expr("std::abs(-42)", result_type="int", result_value="42")
         self.expect_expr("std::div(2, 1).quot", result_type="int", result_value="2")
         # Using types from std.
-        self.expect_expr("(std::size_t)33U", result_type="size_t", result_value="33")
+        self.expect_expr("(std::size_t)33U", result_type="std::size_t", result_value="33")
         # Calling templated functions that return non-template types.
         self.expect_expr("char char_a = 'b'; char char_b = 'a'; std::swap(char_a, char_b); char_a",
                     result_type="char", result_value="'a'")
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
===================================================================
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -586,9 +586,7 @@
 
   ConstString GetTypeName(lldb::opaque_compiler_type_t type) override;
 
-  ConstString GetDisplayTypeName(lldb::opaque_compiler_type_t type) override {
-    return GetTypeName(type);
-  }
+  ConstString GetDisplayTypeName(lldb::opaque_compiler_type_t type) override;
 
   uint32_t GetTypeInfo(lldb::opaque_compiler_type_t type,
                        CompilerType *pointee_or_element_compiler_type) override;
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===================================================================
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -3511,6 +3511,19 @@
   return ConstString(qual_type.getAsString(printing_policy));
 }
 
+ConstString
+TypeSystemClang::GetDisplayTypeName(lldb::opaque_compiler_type_t type) {
+  if (!type)
+    return ConstString();
+
+  clang::QualType qual_type(GetQualType(type));
+  clang::PrintingPolicy printing_policy(getASTContext().getPrintingPolicy());
+  printing_policy.SuppressTagKeyword = true;
+  printing_policy.SuppressScope = false;
+  printing_policy.SuppressUnwrittenScope = true;
+  return ConstString(qual_type.getAsString(printing_policy));
+}
+
 uint32_t
 TypeSystemClang::GetTypeInfo(lldb::opaque_compiler_type_t type,
                              CompilerType *pointee_or_element_clang_type) {
Index: lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp
===================================================================
--- lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp
+++ lldb/source/Plugins/Language/CPlusPlus/LibCxxVariant.cpp
@@ -159,7 +159,7 @@
   if (!template_type)
     return false;
 
-  stream.Printf(" Active Type = %s ", template_type.GetTypeName().GetCString());
+  stream << " Active Type = " << template_type.GetDisplayTypeName() << " ";
 
   return true;
 }
Index: lldb/source/DataFormatters/FormatManager.cpp
===================================================================
--- lldb/source/DataFormatters/FormatManager.cpp
+++ lldb/source/DataFormatters/FormatManager.cpp
@@ -193,7 +193,7 @@
     entries.push_back(
         {type_name, reason, did_strip_ptr, did_strip_ref, did_strip_typedef});
 
-    ConstString display_type_name(compiler_type.GetDisplayTypeName());
+    ConstString display_type_name(compiler_type.GetTypeName());
     if (display_type_name != type_name)
       entries.push_back({display_type_name, reason, did_strip_ptr,
                          did_strip_ref, did_strip_typedef});
Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -2406,7 +2406,7 @@
                 "Unexpected failure with msg: " + eval_result.GetError().GetCString())
 
         if result_type:
-            self.assertEqual(result_type, eval_result.GetTypeName())
+            self.assertEqual(result_type, eval_result.GetDisplayTypeName())
 
         if result_value:
             self.assertEqual(result_value, eval_result.GetValue())
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to