niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » python
How to use pdb?
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
tron.thomas@verizon.net
*nix forums beginner


Joined: 13 Sep 2005
Posts: 5

PostPosted: Fri Jul 21, 2006 4:46 am    Post subject: How to use pdb? Reply with quote

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:

Quote:
import pdb
import MyProgram
pdb.run('MyProgram.mainFunction')
string>(1)?()
(Pdb) b MyProgram.MyClass.method

Breakpoint 1 at MyProgram.py:8
(Pdb) cont
Quote:


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.
Back to top
peter.mosley@talk21.com
*nix forums beginner


Joined: 25 Nov 2005
Posts: 17

PostPosted: Fri Jul 21, 2006 7:44 am    Post subject: Re: How to use pdb? Reply with quote

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
Back to top
R. Bernstein
*nix forums beginner


Joined: 28 Apr 2005
Posts: 45

PostPosted: Fri Jul 21, 2006 7:46 am    Post subject: Re: How to use pdb? Reply with quote

tron.thomas@verizon.net writes:

Quote:
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. ;-)


Quote:
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.

Quote:
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
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Sun Nov 23, 2008 2:21 pm | All times are GMT
navigation Forum index » Programming » python
Jump to:  


Watch Gossip Girl Online | Credit Cards | Mortgage Calculator | Property in Spain | Loans
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0964s ][ Queries: 11 (0.0178s) ][ GZIP on - Debug on ]