GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
libstdc++

libstdc++: Fix num_children for map/set pretty-printers

Corrects the `num_children` method in GDB pretty-printers for std::map and std::unordered_map to accurately reflect GDB's child count.

This commit fixes a discrepancy in GDB’s pretty-printers for std::map and std::unordered_map in libstdc++. The num_children methods were incorrectly reporting half the number of children that GDB’s children() function provided. This caused issues for debuggers and clients (like KDevelop) that rely on these methods, leading to an inaccurate display of map and unordered map contents. The fix ensures num_children returns twice the number of elements, matching the children() output.

In Details

Fixes libstdc++'s GDB pretty-printers for StdMapPrinter and Tr1UnorderedMapPrinter. The num_children methods were returning the count of map elements, while the children() method (and GDB's interpretation of the map display hint) yields two children per element (key and value). This commit corrects num_children to return double the element count, resolving mismatches with GDB's child counting mechanism and ensuring proper display in debuggers and DAP clients.

For Context
libstdc++
The standard C++ library implementation used by GCC.
pretty-printer
A mechanism in debuggers (like GDB) that formats complex data structures (e.g., C++ std::map) into a more human-readable representation.
num_children
A method within a debugger's pretty-printer that reports the number of child elements for a given data structure.
std::map
A C++ standard library container that stores key-value pairs, sorted by key. Each key must be unique.
std::unordered_map
A C++ standard library container that stores key-value pairs using a hash table. It provides average constant-time complexity for lookups, insertions, and deletions.
DAP
The Debug Adapter Protocol, a standardized communication protocol used between development tools and debuggers.
Filed Under: libstdc++gdbpretty-printerdebugcontainer