-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
python-gdb error: Python Exception <class 'RuntimeError'> Type does not have a target #79313
Comments
Python version: 3.6.6-debug Expected: py-list and py-bt to print the current python frame and traceback when attaching to a hung python process with gdb, a debug build of python, and cpython/Tools/gdb/libpython.py loaded. Actual: py-list and py-bt fail with:
Invoking 'set python print-stack full' in gdb produces the more useful: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "~/git/cpython/Tools/gdb/libpython.py", line 916, in filename
File "~/git/cpython/Tools/gdb/libpython.py", line 1158, in proxyval
RuntimeError: Type does not have a target. so it is failing at: fields = gdb.lookup_type('PyUnicodeObject').target().fields() in libpython.py [1]. Reproduce: I haven't been able to create a simple standalone program that triggers the failure. I am working on a PR for Keras to try and fix the multiprocessing support in some of their utility classes. Currently the tests are sporadically hanging and my intention was to use python's gdb integration to identify exactly where and why the hangs are occuring... but I can't get that information at the moment because of the error above when invoking py-list and py-bt. So, unfortunately, the shortest path to reproduce is to checkout the PR branch, run the offending tests, connect with gdb, and invoke py-list/py-bt:
I am happy to poke around in libpython.py and try to fix/submit a PR myself, but I'm not at all familiar with the python internals so I would need some guidance. And obviously let me know if this isn't actually a bug but rather environment related/user error. Thank you! [1] https://github.com/python/cpython/blob/v3.6.6/Tools/gdb/libpython.py#L1158 |
I experienced this bug as well and have tried to dig into it a little. I experimented with a service I have that uses shared libraries. If I compile with high level of optimizations for the C++ code (-O3) I don't experience the issue, but compiling without any optimizations I do. I also tried with a script that does not use any shared libraries and I do not see the issue. Digging into it a little, when running with the optimized version I found: gdb.lookup_type('PyUnicodeObject') returns a gdb.TYPE_CODE_TYPEDEF, which is the correct type. Running with the non-optimized version instead returns a gdb.TYPE_CODE_STRUCT. The struct type errors because it has no target(), but I actually think target() might be superfluous here. Both versions if I only call |
Hum, Dylan: what is your gdb version? On Fedora 29 with gdb 8.2-6.fc29, it seems like .target() is useless: $ gdb ./python
GNU gdb (GDB) Fedora 8.2-6.fc29
...
(gdb) python print([field.name for field in gdb.lookup_type('PyUnicodeObject').target().fields()])
['_base', 'data'] (gdb) python print([field.name for field in gdb.lookup_type('PyUnicodeObject').fields()]) I tested on a Python compiled manually from source, I ran my test in the directory of Python source code. I also tested on /usr/bin/python3 (system Python), same behavior. |
Python 3.6 no longer accept bugfixes, only security fixes: You can try faulthandler has a workaround. For example, install faulthandler signal handler using faulthandler.register(signal.SIGUSR1) and then send a SIGUSR1 signal to the blocked process. You might want to write the output into a file if you don't have access the program stdout: use the 'file' parameter of faulthandler.register(). See also faulthandler.dump_traceback_later() to use a timeout. |
$ gdb --version
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
I can confirm removing the .target() call in libpython.py resolved the issue for me with no ill effects
I'll give this a try, thank you |
Thanks Dylan Cali for the bug report. Lisa Roach fixed the bug in 3.7 and master branches. Until a new release is published, you can copy manually the file from: |
Thank you! And thank you Lisa Roach for the investigation and fix. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: