[libcxx-commits] [libcxx] [lldb] Make std::pair pretty-printer ABI-independent (PR #201768)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jun 5 00:35:44 PDT 2026
https://github.com/aokblast created https://github.com/llvm/llvm-project/pull/201768
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.
>From b6f30f72a8b7f67c8555e9b12c3f7cf13d7175b9 Mon Sep 17 00:00:00 2001
From: aokblast <aokblast at FreeBSD.org>
Date: Fri, 5 Jun 2026 15:26:41 +0800
Subject: [PATCH] [lldb] Make std::pair pretty-printer ABI-independent
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.
---
libcxx/utils/gdb/libcxx/printers.py | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
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,
More information about the libcxx-commits
mailing list