[Lldb-commits] [lldb] b66da73 - [lldb] Don't assume name of libc++ inline namespace in LibCxxUnorderedMap

Dave Lee via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 11 11:59:48 PST 2022


Author: Dave Lee
Date: 2022-11-11T11:59:36-08:00
New Revision: b66da73a05abe88bbe34bf7ffbe09f6e3d7f1fe0

URL: https://github.com/llvm/llvm-project/commit/b66da73a05abe88bbe34bf7ffbe09f6e3d7f1fe0
DIFF: https://github.com/llvm/llvm-project/commit/b66da73a05abe88bbe34bf7ffbe09f6e3d7f1fe0.diff

LOG: [lldb] Don't assume name of libc++ inline namespace in LibCxxUnorderedMap

Follow up to D117383, fixing the assumption that libc++ always uses `__1` as
its inline namespace name.

Reviewed By: rupprecht

Differential Revision: https://reviews.llvm.org/D133259

Added: 
    

Modified: 
    lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
index 90e6e124090e9..cba1078d05d7b 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
@@ -67,11 +67,23 @@ size_t lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::
   return m_num_elements;
 }
 
+static void consumeInlineNamespace(llvm::StringRef &name) {
+  // Delete past an inline namespace, if any: __[a-zA-Z0-9_]+::
+  auto scratch = name;
+  if (scratch.consume_front("__") && std::isalnum(scratch[0])) {
+    scratch = scratch.drop_while([](char c) { return std::isalnum(c); });
+    if (scratch.consume_front("::")) {
+      // Successfully consumed a namespace.
+      name = scratch;
+    }
+  }
+}
+
 static bool isStdTemplate(ConstString type_name, llvm::StringRef type) {
   llvm::StringRef name = type_name.GetStringRef();
-  // The type name may or may not be prefixed with `std::` or `std::__1::`.
+  // The type name may be prefixed with `std::__<inline-namespace>::`.
   if (name.consume_front("std::"))
-    name.consume_front("__1::");
+    consumeInlineNamespace(name);
   return name.consume_front(type) && name.startswith("<");
 }
 


        


More information about the lldb-commits mailing list