3

i start to learn debugging python code using gdb. But when i add breakpoint, gdb give error:"No source file named test.py."

this is my source code test.py:

a = "foo"
b = "bar"

c = a + b
print c

this is my gdb debug information:

panzhengyu@ubuntu:~$ gdb python
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.3) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from python...Reading symbols from /usr/lib/debug//usr/bin/python2.7...done.
done.
(gdb) b pan.py:2
No source file named pan.py.
Make breakpoint pending on future shared library load? (y or [n]) 
PZY
  • 131
  • 1
  • 16
  • i have used the command " gdb --args python pan.py", but when i add breakpoint, it still not work, give the same error. – PZY Oct 11 '17 at 09:09
  • Why you use gdb for debugging a python script ? just if you want to debug the python binary it make sense – invictus1306 Oct 11 '17 at 09:16
  • in any case try to look at this https://wiki.python.org/moin/DebuggingWithGdb – invictus1306 Oct 11 '17 at 09:18
  • @invictus1306,recently, i need to debug python code extended by c language code, pdb can just debug python code, but i need to debug the c code part. so i write python snippets using gdb debugging. – PZY Oct 11 '17 at 09:25
  • Understand now :) look at this https://stackoverflow.com/questions/7412708/debugging-stepping-through-python-script-using-gdb – invictus1306 Oct 11 '17 at 09:36
  • @invictus1306, i have read that, but i still don't know how to step debug the code. – PZY Oct 11 '17 at 10:15
  • 1
    You can run `gdb --args python -mpdb pan.py`, then `run` the python interpreter and use pdb to debug at the python level. After your compiled C code is loaded, type Ctrl-C to get back to gdb and set breakpoints etc. – Mark Plotnick Oct 11 '17 at 22:38
  • @MarkPlotnick,right,thank you very much. – PZY Oct 12 '17 at 01:55

0 Answers0