Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot start dbg on my python C extension

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

like image 825
wyDra Avatar asked Jan 07 '18 20:01

wyDra


People also ask

How do I debug a Python extension?

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.

How do I import GDB into Python?

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 ) ...

Is GDB written in Python?

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.


Video Answer


1 Answers

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

like image 60
krassowski Avatar answered Oct 22 '22 21:10

krassowski