On Wed, 26 Feb 2020 at 17:01, Jonathan Wakely <jwakely....@gmail.com> wrote: > > On Wed, 26 Feb 2020 at 14:32, Paul Smith <p...@mad-scientist.net> wrote: > > > > Hi all. I was seeing a strange error in GDB (8.2.1) debugging some C++ > > code while trying to print a value. The pretty printer was throwing Python > > exceptions. > > > > Debugging it I discovered the problem, which is here (from GCC 9.2): > > > > libstdc++-v3/python/libstdcxx/v6/printers.py: > > # Starting with the type ORIG, search for the member type NAME. This > > # handles searching upward through superclasses. This is needed to > > # work around http://sourceware.org/bugzilla/show_bug.cgi?id=13615. > > def find_type(orig, name): > > typ = orig.strip_typedefs() > > while True: > > # Strip cv-qualifiers. PR 67440. > > --> search = '%s::%s' % (typ.unqualified(), name) > > try: > > return gdb.lookup_type(search) > > except RuntimeError: > > pass > > # The type was not found, so try the superclass. We only need > > # to check the first superclass, so we don't bother with > > # anything fancier here. > > field = typ.fields()[0] > > > > (First that GDB bug was fixed in 2012 so I'm not sure if we still need this > > method, but anyway...) > > > > The issue is on the marked line above. Here we are using the __str__() > > method on a gdb.Type to obtain the string name of the type. However, I've > > discovered that (at least on my system) the __str__() representation of a > > gdb.Type prepends the keyword "class " or "struct " (as appropriate) to the > > output. So the above will result in a string like: > > > > search = 'class std::unordered_map...::...' > > I don't think I've seen that problem before. Are you sure that's the > cause, and not something like > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91997 ?
I compiled this program: #include <unordered_map> int main() { std::unordered_map<int, int> m; m[3] = 5; return m[1]; } And with Fedora 31's GDB 8.3.50 I get this behaviour: (gdb) py m = gdb.parse_and_eval('m') (gdb) py print(m.type) std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<int const, int> > > (gdb) py print(str(m.type)) std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<int const, int> > > There's no 'class' being added. But I also tried changing the printers.py script to use .name and all our tests still pass, so I'm not opposed to that change.