[Lldb-commits] [lldb] [lldb] Format `atomic<shared_ptr>` on MSVC STL (PR #237631)

Charles Zablit via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 2 10:53:51 PST 2026


================
@@ -29,20 +31,39 @@ class MsvcStlAtomicSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
   llvm::Expected<size_t> GetIndexOfChildWithName(llvm::StringRef name) override;
 
 private:
-  ValueObject *m_storage = nullptr;
-  CompilerType m_element_type;
+  ValueObjectSP m_storage;
+  bool m_is_smart_ptr = false;
 };
 
 } // namespace formatters
 } // namespace lldb_private
 
-lldb_private::formatters::MsvcStlAtomicSyntheticFrontEnd::
-    MsvcStlAtomicSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
-    : SyntheticChildrenFrontEnd(*valobj_sp), m_element_type() {
-  if (valobj_sp)
-    Update();
+static ValueObjectSP ValueOfAtomic(ValueObject &valobj) {
+  ValueObjectSP storage_sp = valobj.GetChildMemberWithName("_Storage");
+  if (!storage_sp)
+    return nullptr;
+
+  CompilerType backend_type = valobj.GetCompilerType();
+  if (!backend_type)
+    return nullptr;
+
+  CompilerType element_type = backend_type.GetTypeTemplateArgument(0);
+  if (!element_type) {
+    // PDB doesn't have info about templates, so use value_type which equals T.
+    element_type = backend_type.GetDirectNestedTypeWithName("value_type");
+
+    if (!element_type)
+      return nullptr;
+  }
+
+  return valobj.Cast(element_type);
----------------
charles-zablit wrote:

```suggestion
  return storage_sp->Cast(element_type);
```

`storage_sp` is only checked for nullptr, and the whole atomic is cast instead of `_Storage`, which only works while `_Storage` is at offset 0. The old code did `return m_storage->Cast(m_element_type)->Clone("Value");`

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


More information about the lldb-commits mailing list