Im using python3.6.1 installed in pyenv. I have problem with running gdb on my code. When I run gdb --args python mycode.py
it ends with error "/home/vydra/.pyenv/shims/python": not in executable format: File format not recognized
In order to debug the C/C++ code of an extension, you need to use the native debugger, GDB or LLDB, and debug the interpreter process that loads your script and runs the application. For that, you can either attach to a running Python process or debug a properly configured Custom Build Application.
Explanation. GDB embeds the Python interpreter so it can use Python as an extension language. You can't just import gdb from /usr/bin/python like it's an ordinary Python library because GDB isn't structured as a library. What you can do is source MY-SCRIPT.py from within gdb (equivalent to running gdb -x MY-SCRIPT.py ) ...
Additionally, gdb commands and convenience functions which are written in Python and are located in the data-directory /python/gdb/command or data-directory /python/gdb/function directories are automatically imported when gdb starts.
As suggested by Jean-François Fabre, the python file installed by pyenv is actually a bash script. You can easily make gdb run this script with:
gdb -ex r --args bash python mycode.py
See this question for other approaches: Use GDB to debug a C++ program called from a shell script
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With