473,322 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to use pdb?

I am trying to figure out how to use the pdb module to debug Python
programs, and I'm having difficulties. I am pretty familiar with GDB
which seems to be similar, however I cannot even get the Python
debugger to break into a program so I can step through it. I wrote a
simple program and below is an example of the steps I tried, as well as
the results I got:
>>import pdb
import MyProgram
pdb.run('MyProgram.mainFunction')
<string>(1)?()
(Pdb) b MyProgram.MyClass.method
Breakpoint 1 at MyProgram.py:8
(Pdb) cont
>>>
The program should have printed a message to the screen when execution
was continued, and it should have hit the breakpoint during that
execution. Instead the debugger exitted to the main prompt.

What is the reason the dubugger behaves like this?
What is the correct way to accomplish what I am trying to do?

I have tried this process on Python 2.3.5 and 2.4.3 with the same
results on each version.

Jul 21 '06 #1
5 2317
I haven't tried to use pdb myself, but this looks fairly helpful ...

http://www.ferg.org/papers/debugging_in_python.html

good luck

Peter

Jul 21 '06 #2
tr*********@verizon.net writes:
I am trying to figure out how to use the pdb module to debug Python
programs, and I'm having difficulties. I am pretty familiar with GDB
which seems to be similar,
If you are pretty familiar with gdb, try
http://bashdb.sourceforge.net/pydb. It is a great deal more similar. ;-)

however I cannot even get the Python
debugger to break into a program so I can step through it. I wrote a
simple program and below is an example of the steps I tried, as well as
the results I got:
>import pdb
import MyProgram
pdb.run('MyProgram.mainFunction')
<string>(1)?()
(Pdb) b MyProgram.MyClass.method
Breakpoint 1 at MyProgram.py:8
(Pdb) cont
>>

The program should have printed a message to the screen when execution
was continued, and it should have hit the breakpoint during that
execution. Instead the debugger exitted to the main prompt.

What is the reason the dubugger behaves like this?
I think you misunderstand what pdb.run is supposed to do. It's not at
all like gdb's "run" command. In fact pdb doesn't even have a
debugger *command* called "run", although it does have top-level
function called "run".

pdb.run is evaluating MyProgram.mainfunction the same as if you were
to type it at Python's >>prompt.

Except it will call the debugger control WHEN IT ENCOUNTERS THE FIRST
STATEMENT. I think if you were issu MyProgram.mainFunction at the
python prompt you'd get back something like: <function mainFunction at
0xb7f5c304>.

It wouldn't *call* the routine. To call it, you'd type something like
Myprogram.mainFunction()

But before you try to issue pdb.run('Myprogram.mainFunction()'), read
on. The way to use pdb.run is to insert it somewhere in your program
like MyProgram and have the debugger kick in, not something you issue
from a Python prompt.
What is the correct way to accomplish what I am trying to do?

I have tried this process on Python 2.3.5 and 2.4.3 with the same
results on each version.
Perhaps what you are looking for is:
python /usr/lib/python2.4/pdb.py Myprogram.py

(Subtitute the correct path name for pdb.py.)

If you have pydb installed it adds a symbolic link to pydb.py. So here
you should be able to issue:

pydb Myprogram.py

Jul 21 '06 #3

peter wrote:
I haven't tried to use pdb myself, but this looks fairly helpful ...

http://www.ferg.org/papers/debugging_in_python.html

good luck

Peter
That link was indeed helpful. I was finally able to debug the program

Jul 22 '06 #4

R. Bernstein wrote:
Perhaps what you are looking for is:
python /usr/lib/python2.4/pdb.py Myprogram.py
I tried this and it did not work. pdb did not load the file so it
could be debugged.

Jul 22 '06 #5
tr*********@verizon.net writes:
R. Bernstein wrote:
Perhaps what you are looking for is:
python /usr/lib/python2.4/pdb.py Myprogram.py

I tried this and it did not work. pdb did not load the file so it
could be debugged.
lol. Yes, if you are not in the same directory as Myprogram.py you may
have to add be more explicit about where Myprogram.py is.

Reminds me of the story of the guy who was so lazy that when he got an
award for "laziest person alive" he said, "roll me over and put it in
my back pocket." :-)

Glad you were able to solve your problem though.

For other similarly confused folks I have updated pydb's
documentation (in CVS):

In contrast to running a program from a shell (or gdb), no path
searching is performed on the python-script. Therefore python-script
should be explicit enough (include relative or absolute file paths)
so that the debugger can read it as a file name. Similarly, the
location of the Python interpeter used for the script will not
necessarily be the one specified in the magic field (the first line
of the file), but will be the Python interpreter that the debugger
specifies. (In most cases they'll be the same and/or it won't
matter.)

Jul 22 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.