[gcc r16-9433] libstdc++: Fix num_children of the map pretty-printers
Jonathan Wakely via Gcc-cvs <[email protected]> Wed, 29 Jul 2026 14:15:28 +0000 (GMT)
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <20260729141528.085684BB58D8__8683.98910840682$1785334538$gmane$org@sourceware.org> |
https://gcc.gnu.org/g:562f758458047c4db65fc72a02c2eb199e2d912a commit r16-9433-g562f758458047c4db65fc72a02c2eb199e2d912a Author: David Faure <[email protected]> Date: Mon Jul 27 20:02:29 2026 +0200 libstdc++: Fix num_children of the map pretty-printers StdMapPrinter and Tr1UnorderedMapPrinter yield a separate child for the key and for the value of every element, as their 'map' display hint requires, but their num_children methods return the number of elements, i.e. half of what children() produces. GDB counts the children itself where it does not use num_children, so the two disagree about the same map. For a std::map with 2 elements: (gdb) interpreter-exec mi "-enable-pretty-printing" (gdb) interpreter-exec mi "-var-create v * m" (gdb) interpreter-exec mi "-var-list-children v" ^done,numchild="4",displayhint="map",children=[...] while num_children() returns 2. The DAP code in gdb treats the two as interchangeable: gdb/python/lib/gdb/dap/varref.py calls num_children() when the printer has one, and falls back to len(list(children())) when it does not, so a DAP client sees half the children of a std::map, std::multimap or std::unordered_map. StdSetPrinter and the sequence container printers yield one child per element, so they are correct as they are. libstdc++-v3/ChangeLog * python/libstdcxx/v6/printers.py (StdMapPrinter.num_children): Count two children per element. (Tr1UnorderedMapPrinter.num_children): Likewise. Signed-off-by: David Faure <[email protected]> Reviewed-by: Tom Tromey <[email protected]> (cherry picked from commit b80a4347fc63b1a6ed6e2b3ea26c5948f08ba3cd) Diff: --- libstdc++-v3/python/libstdcxx/v6/printers.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index eff4b72c1d8a..1bba377513ca 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -909,7 +909,8 @@ class StdMapPrinter(printer_base): return self._iter(RbtreeIterator(self._val), node) def num_children(self): - return len(RbtreeIterator(self._val)) + # Each element produces two children, the key and the value. + return 2 * len(RbtreeIterator(self._val)) def display_hint(self): return 'map' @@ -1301,7 +1302,8 @@ class Tr1UnorderedMapPrinter(printer_base): return izip(counter, data) def num_children(self): - return int(self._hashtable()['_M_element_count']) + # Each element produces two children, the key and the value. + return 2 * int(self._hashtable()['_M_element_count']) def display_hint(self): return 'map'