[libcxx-commits] [libcxx] [libcxx] Make std::pair pretty-printer ABI-independent (PR #201768)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jun 5 00:36:26 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: aokblast

<details>
<summary>Changes</summary>

std::pair is printed explicitly instead of relying on GDB's default struct formatting to keep output stable across ABI configurations.

With _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR (default on some platforms, e.g. FreeBSD), std::pair gains an empty __non_trivially_copyable_base base class. GDB would otherwise render this as <...__non_trivially_copyable_base<...>> = {<No data fields>}, which makes output ABI-dependent.

Only first and second are meaningful, so print them directly.

---
Full diff: https://github.com/llvm/llvm-project/pull/201768.diff


1 Files Affected:

- (modified) libcxx/utils/gdb/libcxx/printers.py (+20) 


``````````diff
diff --git a/libcxx/utils/gdb/libcxx/printers.py b/libcxx/utils/gdb/libcxx/printers.py
index ccaa6e9a019e8..9c9ecb245271a 100644
--- a/libcxx/utils/gdb/libcxx/printers.py
+++ b/libcxx/utils/gdb/libcxx/printers.py
@@ -182,6 +182,25 @@ def children(self):
             return iter(())
         return self._Children(self.val)
 
+class StdPairPrinter(object):
+    """Print a std::pair.
+
+    Print std::pair explicitly instead of relying on GDB's default struct
+    formatting. Some ABI configurations (e.g.
+    _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR, enabled by default on
+    FreeBSD) add an empty __non_trivially_copyable_base base class to
+    std::pair. GDB renders this implementation detail as
+    '<...__non_trivially_copyable_base<...>> = {<No data fields>}', which makes
+    the output ABI-dependent. Only 'first' and 'second' are meaningful, so
+    print just those members.
+    """
+
+    def __init__(self, val):
+        self.val = val
+
+    def children(self):
+        return iter([("first", self.val["first"]), ("second", self.val["second"])])
+
 class StdStringPrinter(object):
     """Print a std::string."""
 
@@ -901,6 +920,7 @@ def __init__(self, name):
             "basic_string": StdStringPrinter,
             "string": StdStringPrinter,
             "string_view": StdStringViewPrinter,
+            "pair": StdPairPrinter,
             "tuple": StdTuplePrinter,
             "unique_ptr": StdUniquePtrPrinter,
             "shared_ptr": StdSharedPointerPrinter,

``````````

</details>


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


More information about the libcxx-commits mailing list