Search code examples
gdb

GDB fails with "Python Exception <class 'RecursionError'>: maximum recursion depth exceeded" error


I'm running g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 and GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1.

All I am doing is to try to run use_count() method of std::shared_ptr, which fails with the error

(gdb) p ptr.use_count()
Python Exception <class 'RecursionError'>: maximum recursion depth exceeded
Error while looking for matching xmethod workers defined in Python.

The following bash script reproduces the issue.

cat << EOF > main.cc
#include <iostream>
#include <memory>

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

g++ -std=c++17 -g main.cc
./a.out
gdb -q a.out -ex "set confirm off" -ex "b 7" -ex "r" -ex "p ptr.use_count()" -ex "q"

By the way, LLDB executes the function without an issue. Is this a GDB bug or am I missing something?

--Edit 1--

As Mark suggested, I added set python print-stack full in gdb. The following is the output

(gdb) set python print-stack full
(gdb) p ptr.use_count()
Traceback (most recent call last):
  File "/lib/x86_64-linux-gnu/../../share/gcc/python/libstdcxx/v6/xmethods.py", line 777, in match
    worker = method.worker_class(class_type.template_argument(0))
  File "/lib/x86_64-linux-gnu/../../share/gcc/python/libstdcxx/v6/xmethods.py", line 733, in __init__
    SharedPtrUseCountWorker.__init__(self, elem_type)
  File "/lib/x86_64-linux-gnu/../../share/gcc/python/libstdcxx/v6/xmethods.py", line 733, in __init__
    SharedPtrUseCountWorker.__init__(self, elem_type)
  File "/lib/x86_64-linux-gnu/../../share/gcc/python/libstdcxx/v6/xmethods.py", line 733, in __init__
    SharedPtrUseCountWorker.__init__(self, elem_type)
  [Previous line repeated 995 more times]
RecursionError: maximum recursion depth exceeded
Error while looking for matching xmethod workers defined in Python.

-- Edit 2 --

As ks1322 suggested, a temporary work around is to disable xmethod

(gdb) disable xmethod
(gdb) p ptr.use_count()
$1 = 1

Solution

  • Is this a GDB bug or am I missing something?

    It is either GDB bug or libstdc++ xmethods bug. As a workaround you can disable all xmethods with disable xmethod.