I am trying to use gdb on a program in python, but it doesn't seem to work the same way it does with programs in c. I tried looking at a few links here: https://sourceware.org/gdb/onlinedocs/gdb/Breakpoints-In-Python.html https://wiki.python.org/moin/DebuggingWithGdb https://stackoverflow.com/questions/7412708/debugging-stepping-through-python-script-using-gdb

but I still don't really understand how to set breakpoints although I think I know now how to get gdb started with for example

$ gdb python

and run it with

$ (gdb) run mario.py

both seem to work, but I still haven't been able to figure out how to set breakpoints at a specific line or breakpoints in general. Also are other commands the same like p for print and info locals?

When I try using debug50 I get this error:

debug50 mario.py readelf: Error: Not an ELF file - it has the wrong magic bytes at the start Can't debug this program! Are you sure you compiled it with -ggdb?

What am I doing wrong?

  • Maybe try pdb instead. – DinoCoderSaurus Jun 24 '17 at 15:20
  • @DinoCoderSaurus Yeah it seems that there a few tutorials on pdb just like gdb, thanks a lot – dumbitdownjr Jun 24 '17 at 19:06

I haven't been using gdb but another solution I would offer (for all debugging in general regardless of the language you use) is just simple print statements. It will help you understand where you are in the code and what is happening (executing) and what it NOT.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .