Commit 9d50a6a7 by Jonathan Wakely Committed by Jonathan Wakely

libstdc++:: improve how pretty printers find node types (PR 91997)

This fixes two related problems.

The iterators for node-based containers use nested typedefs such as
std::list<T>::iterator::_Node to denote their node types. As reported in
https://bugzilla.redhat.com/show_bug.cgi?id=1053438 those typedefs are
not always present in the debug info. That means the pretty printers
cannot find them using gdb.lookup_type (via the find_type helper).
Instead of looking up the nested typedefs this patch makes the printers
look up the actual class templates directly.

A related problem (and the original topic of PR 91997) is that GDB fails
to find types via gdb.lookup_type when printing a backtrace from a
non-C++ functiion: https://sourceware.org/bugzilla/show_bug.cgi?id=25234
That is also solved by not looking up the nested typedef.

	PR libstdc++/91997
	* python/libstdcxx/v6/printers.py (find_type): Fail more gracefully
	if we run out of base classes to look at.
	(llokup_templ_spec, lookup_node_type): New utilities to find node
	types for node-based containers.
	(StdListPrinter.children, NodeIteratorPrinter.__init__)
	(NodeIteratorPrinter.to_string, StdSlistPrinter.children)
	(StdSlistIteratorPrinter.to_string, StdRbtreeIteratorPrinter.__init__)
	(StdMapPrinter.children, StdSetPrinter.children)
	(StdForwardListPrinter.children): Use lookup_node_type instead of
	find_type.
	(StdListIteratorPrinter.__init__, StdFwdListIteratorPrinter.__init__):
	Pass name of node type to NodeIteratorPrinter constructor.
	(Tr1HashtableIterator.__init__): Rename argument.
	(StdHashtableIterator.__init__): Likewise. Use lookup_templ_spec
	instead of find_type.
	* testsuite/libstdc++-prettyprinters/59161.cc: Remove workaround for
	_Node typedef not being present in debuginfo.
	* testsuite/libstdc++-prettyprinters/91997.cc: New test.

From-SVN: r278846
parent 9909a059
2019-11-29 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/91997
* python/libstdcxx/v6/printers.py (find_type): Fail more gracefully
if we run out of base classes to look at.
(llokup_templ_spec, lookup_node_type): New utilities to find node
types for node-based containers.
(StdListPrinter.children, NodeIteratorPrinter.__init__)
(NodeIteratorPrinter.to_string, StdSlistPrinter.children)
(StdSlistIteratorPrinter.to_string, StdRbtreeIteratorPrinter.__init__)
(StdMapPrinter.children, StdSetPrinter.children)
(StdForwardListPrinter.children): Use lookup_node_type instead of
find_type.
(StdListIteratorPrinter.__init__, StdFwdListIteratorPrinter.__init__):
Pass name of node type to NodeIteratorPrinter constructor.
(Tr1HashtableIterator.__init__): Rename argument.
(StdHashtableIterator.__init__): Likewise. Use lookup_templ_spec
instead of find_type.
* testsuite/libstdc++-prettyprinters/59161.cc: Remove workaround for
_Node typedef not being present in debuginfo.
* testsuite/libstdc++-prettyprinters/91997.cc: New test.
2019-11-26 François Dumont <fdumont@gcc.gnu.org> 2019-11-26 François Dumont <fdumont@gcc.gnu.org>
* include/debug/helper_functions.h (__valid_range_aux): Use C++98 * include/debug/helper_functions.h (__valid_range_aux): Use C++98
......
...@@ -45,8 +45,6 @@ int main() ...@@ -45,8 +45,6 @@ int main()
std::list<C> l; std::list<C> l;
l.push_back(c); l.push_back(c);
std::list<C>::iterator liter = l.begin(); std::list<C>::iterator liter = l.begin();
// Need to ensure the list<C>::iterator::_Node typedef is in the debuginfo:
int tmp __attribute__((unused)) = (*liter).ref;
// { dg-final { regexp-test liter {ref = @0x.*} } } // { dg-final { regexp-test liter {ref = @0x.*} } }
__gnu_cxx::slist<C> sl; __gnu_cxx::slist<C> sl;
......
// { dg-options "-std=gnu++17 -g -O0 -Wno-unused" }
// { dg-do run { target c++17 } }
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <forward_list>
#include <list>
#include <set>
#include <map>
#include <string>
#include <any>
#include <iostream>
int main()
{
std::list<std::string> list{"a"};
std::list<std::string>::iterator lit = list.begin();
// { dg-final { note-test lit {"a"} } }
std::forward_list<std::string> flist{"b"};
std::forward_list<std::string>::iterator flit = flist.begin();
// { dg-final { note-test flit {"b"} } }
std::map<int, int> m{ {1, 2} };
auto mit = m.begin();
// { dg-final { note-test mit {{first = 1, second = 2}} } }
std::any a = m;
// { dg-final { note-test a {std::any containing std::map with 1 element = {[1] = 2}} } }
std::set<int> s{1, 2};
auto sit = s.begin();
// { dg-final { note-test sit {1} } }
std::cout << "\n";
return 0; // Mark SPOT
}
// { dg-final { gdb-test SPOT } }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment