https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109064

            Bug ID: 109064
           Summary: Maximum recursion depth exceeded in std::shared_ptr
                    xmethod
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ks1322 at gmail dot com
  Target Milestone: ---

Based on
https://stackoverflow.com/questions/75652764/gdb-fails-with-python-exception-class-recursionerror-maximum-recursion-dep

Seems that trying to print unique() and use_count() in GDB for std::shared_ptr
causes infinite recursion in Python xmethods.

For this code:
```
#include <iostream>
#include <memory>

int main() {
    auto ptr = std::make_shared<int>(0);
    std::cout << ptr.use_count() << "\n";
    return 0;
}
```

Buid with:
```
g++ -g main.cc
```

Results in "maximum recursion depth exceeded" error
```
$ gdb -batch -ex "b 7" -ex r -ex "p ptr.use_count()" -ex "p ptr.unique()" a.out
Breakpoint 1 at 0x40122f: file /tmp/main.cc, line 7.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
1

Breakpoint 1, main () at /tmp/main.cc:7
7           return 0;
Python Exception <class 'RecursionError'>: maximum recursion depth exceeded
Error while looking for matching xmethod workers defined in Python.
Python Exception <class 'RecursionError'>: maximum recursion depth exceeded
Error while looking for matching xmethod workers defined in Python.
```

As a workaround xmethods can be disabled with
```
(gdb) disable xmethod
```

Reply via email to