473,668 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PDB does not allow jumping to first statement?

Hi all,

I have a simple script:

---
#!/usr/bin/env python

a = 1
b = 2

c = a + b

print c
---

I launch said script with pdb:

python -m pdb simple.py

I noticed that I absolutely cannot jump back to the first statement
(line 3, "a = 1") using the jump command. I can jump to any other line
BUT the first statement's using the "jump <line number>" command. I
experience the same behavior with Winpdb and rpdb2. Why is this?

Stumped,
Chris

Mar 26 '07 #1
7 1759
"Chris Lasher" <ch**********@g mail.comwrote:
I noticed that I absolutely cannot jump back to the first statement
(line 3, "a = 1") using the jump command. I can jump to any other line
BUT the first statement's using the "jump <line number>" command. I
experience the same behavior with Winpdb and rpdb2. Why is this?
Which version of Python, and what happens when you try it?

It works fine for me with Python 2.5 on Windows:

C:\Temp>\python 25\python -m pdb t.py
c:\temp\t.py(3) <module>()
-a = 1
(Pdb) s
c:\temp\t.py(4) <module>()
-b = 2
(Pdb) j 3
c:\temp\t.py(3) <module>()
-a = 1
(Pdb)
Mar 27 '07 #2
Duncan Booth wrote:
"Chris Lasher" <ch**********@g mail.comwrote:
>I noticed that I absolutely cannot jump back to the first statement
(line 3, "a = 1") using the jump command. I can jump to any other line
BUT the first statement's using the "jump <line number>" command. I
experience the same behavior with Winpdb and rpdb2. Why is this?

Which version of Python, and what happens when you try it?

It works fine for me with Python 2.5 on Windows:

C:\Temp>\python 25\python -m pdb t.py
>c:\temp\t.py(3 )<module>()
-a = 1
(Pdb) s
>c:\temp\t.py(4 )<module>()
-b = 2
(Pdb) j 3
>c:\temp\t.py(3 )<module>()
-a = 1
(Pdb)
It looks like you successfully jumped to the first line, but it will be
skipped if you try to execute it:

$ cat tmp.py
print "aaa"
print "bbb"
print "ccc"
print "ddd"
$ python2.5 -m pdb tmp.py
/home/nn/tmp.py(1)<modul e>()
-print "aaa"
(Pdb) s
aaa
/home/nn/tmp.py(2)<modul e>()
-print "bbb"
(Pdb) j 1
/home/nn/tmp.py(1)<modul e>()
-print "aaa"
(Pdb) s
bbb <-- wrong
/home/nn/tmp.py(3)<modul e>()
-print "ccc"
(Pdb) s
ccc
/home/nn/tmp.py(4)<modul e>()
-print "ddd"
(Pdb) j 2
/home/nn/tmp.py(2)<modul e>()
-print "bbb"
(Pdb) s
bbb <-- correct
/home/nn/tmp.py(3)<modul e>()
-print "ccc"

Peter
Mar 27 '07 #3
Peter Otten <__*******@web. dewrote:
>Which version of Python, and what happens when you try it?

It works fine for me with Python 2.5 on Windows:

C:\Temp>\pytho n25\python -m pdb t.py
>>c:\temp\t.py( 3)<module>()
-a = 1
(Pdb) s
>>c:\temp\t.py( 4)<module>()
-b = 2
(Pdb) j 3
>>c:\temp\t.py( 3)<module>()
-a = 1
(Pdb)

It looks like you successfully jumped to the first line, but it will
be
skipped if you try to execute it:
That's why I asked what actually happened. Yes, you and the OP seem to
be correct, jumping to the first executable line in a module appears not
to execute the line.

I verified (with a print statement in pdb) that assigning to
self.curframe.f _lineno sets self.curframe.f _lineno and
sel.curframe.f_ lasti incorrectly:

C:\Temp>\python 25\python -m pdb t.py
c:\temp\t.py(3) <module>()
-a = 1
(Pdb) s
c:\temp\t.py(4) <module>()
-b = 2
(Pdb) s
c:\temp\t.py(5) <module>()
-a = 3
(Pdb) l
1 #!/usr/bin/env python
2
3 a = 1
4 b = 2
5 -a = 3
6 c = a + b
7 import dis, sys
8 dis.dis(sys._ge tframe().f_code )
9 print c
[EOF]
(Pdb) j 4
f_lineno 4 f_lasti 6
c:\temp\t.py(4) <module>()
-b = 2
(Pdb) j 3
f_lineno 4 f_lasti 6
c:\temp\t.py(3) <module>()
-a = 1
(Pdb) j 5
f_lineno 5 f_lasti 12
c:\temp\t.py(5) <module>()
-a = 3
(Pdb) j 3
f_lineno 4 f_lasti 6
c:\temp\t.py(3) <module>()
-a = 1
(Pdb)

The problem looks to be in frameobject.c:

addr = 0;
line = f->f_code->co_firstlineno ;
new_lasti = -1;
for (offset = 0; offset < lnotab_len; offset += 2) {
addr += lnotab[offset];
line += lnotab[offset+1];
if (line >= new_lineno) {
new_lasti = addr;
new_lineno = line;
break;
}
}

The first bytes in lnotab are the length and line increment for line 3
(i.e. 6, 1). If line==f->f_code->co_firstline no it should set new_lasti=
0, new_lineno=line but the loop still executes once which increments
new_lasti and new_lineno to the next line (6, 4).
Mar 27 '07 #4
On Mar 26, 6:06 pm, "Chris Lasher" <chris.las...@g mail.comwrote:
Hi all,

I have a simple script:

---
#!/usr/bin/envpython

a = 1
b = 2

c = a + b

print c
---

I launch said script withpdb:

python-mpdbsimple.py

I noticed that I absolutely cannot jump back to the first statement
(line 3, "a = 1") using the jump command. I can jump to any other line
BUT the first statement's using the "jump <line number>" command. I
experience the same behavior with Winpdb and rpdb2. Why is this?

Stumped,
Chris
I tried on GNU/Linux and Python versions 2.4 and 2.5 and get the same
behavior. Best as I can tell, it looks like a bug in Python. pdb,
pydb, rpdb2 all handle the "jump" command by changing the frame
f_lineno value. When the corresponding code pointer has offset 0 (or
equivalently and more simlply as you put it, is the first statement)
this doesn't seem to work properly. But this also implies that all you
need to do is add something as the first statement. A docstring
comment, e.g.
"this is what my program does..."
comes to mind :-)

Lastly, I'll mention that I what most folks want to do is not jump to
the beginning of the program but rather *restart* it. The difference
here as applied to your example is seen in the way variables (e.g. a,
b, and c) are handled. In a "restart", those names would go back to
being undefined and referring to them before assigning to them would
cause a NameError exception. With "jump", they retain their existing
values.

In pydb (http://bashdb.sf.net/pydb) there are two variations of
restarting a program, one which preserves debugger state ("run") and
one which doesn't ("restart") as it is just a re-exec of the program.
In the presence of multiple threads the exec restart the only reliable
way I know of to force a restart.

Recently in Python's SVN the patch I submitted over a year ago was
applied, so if you prefer pdb and want the "run"-like restart, you can
use that.

Mar 27 '07 #5
On Mar 27, 5:59 am, "rocky.bernst.. .@gmail.com"
<rocky.bernst.. .@gmail.comwrot e:
I tried on GNU/Linux and Python versions 2.4 and 2.5 and get the same
behavior. Best as I can tell, it looks like a bug in Python. pdb,
pydb, rpdb2 all handle the "jump" command by changing the frame
f_lineno value. When the corresponding code pointer has offset 0 (or
equivalently and more simlply as you put it, is the first statement)
this doesn't seem to work properly. But this also implies that all you
need to do is add something as the first statement. A docstring
comment, e.g.
"this is what my program does..."
comes to mind :-)
I started implementing this, but it's a hack. Looks like it's time for
me to file a bug report!
Lastly, I'll mention that I what most folks want to do is not jump to
the beginning of the program but rather *restart* it. The difference
here as applied to your example is seen in the way variables (e.g. a,
b, and c) are handled. In a "restart", those names would go back to
being undefined and referring to them before assigning to them would
cause a NameError exception. With "jump", they retain their existing
values.
In the case I was working with, I really did want to "jump" and retain
the values, rather than restart and clear those values.

Just as an aside, Rocky, I really like your ShowMeDo on pydb. Thanks
for making that. (For those who haven't seen it, check out the
"Introducin g the pydb Debugger" at <http://showmedo.com/videos/Python>)

Mar 27 '07 #6
I have submitted this as a bug via SourceForge:
<https://sourceforge.net/tracker/?
func=detail&ati d=105470&aid=16 89458&group_id= 5470>
or if munged
<http://tinyurl.com/2nwxsf>

The Python folks would like a test case and/or a patch. This is well
beyond my ken as a humble Python user. Could anybody more
knowledgeable please contribute one or both? Duncan or Rocky, would
you be able to spare time and effort?

Chris

Mar 28 '07 #7
On Mar 28, 6:05 pm, "Chris Lasher" <chris.las...@g mail.comwrote:
I have submitted this as a bug via SourceForge:
<https://sourceforge.net/tracker/?
func=detail&ati d=105470&aid=16 89458&group_id= 5470>
or if munged
<http://tinyurl.com/2nwxsf>

ThePythonfolks would like a test case and/or a patch. This is well
beyond my ken as a humblePythonuse r. Could anybody more
knowledgeable please contribute one or both? Duncan or Rocky, would
you be able to spare time and effort?

Chris
First and foremost, thanks for submitting the bug report!

Alas, I don't use Python much anymore in day-to-day activities. Ruby
rules! However some weekend (when I'm not doing work) I'll try to find
time to conjure up an example.

But here's a sketch of how I think a small test case would work. One
would use sys.settrace() to set up the mechanism to get the current
frame after each statement gets run. In the function, say bugcheck(),
which used as the hook given to sys.settrace(), if the caller's
f_lineno is not the first statement, one would set it to the first
statement noting that the reassignment has happened so we don't loop
indefinitely. Then one would return from the function which will let
the program do a step and check what value of f_lineno appears in the
subsequent calls of bugcheck().

Alternatively one could write a .pdbrc which basically issues the
"step" and "jump" commands and prints out the line number. (In pydb or
gdb the command to print the current line would be "info line"; in
pdb I'm not sure what the best command is - "list"?, "bt?

Mar 29 '07 #8

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

Similar topics

20
10138
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
8
2535
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined in global space, therefore it is not a global variable, yes? Even if it was global, how would it get from one function to another? In PHP variables are copied by value. Are they copied by reference in Javascript? <SCRIPT LANGUAGE="JavaScript">
2
2469
by: greatbooksclassics | last post by:
Open Source DRM? What does everyone think about it? Will Open Source DRM ever catch up to MS DRM? Will DRM ever be integrated into common LAMP applications? (LAMP=Linux/Apache/MYSQL/PHP/Perl/Python/Ruby) Here's Sun's latest initiative in Open Source DRM: DReaM: Royalty-Free, Open Source DRM
3
1745
by: jalkadir | last post by:
By jump I mean ending unexpectedly. The program below, like the jumping beens, has an unusual behaviour. When the noted lines are not present the program terminates disregarding the rest of the lines. I have seen this type of behaviour before, but I can't find to recall the source, the needy greedy source, of the problem. I, however, was able to remember that the problem was resolved, temporarily, by using 'std::cin.get()', but I am...
38
3320
by: Martin Marcher | last post by:
Hi, I've read several questions and often the answer was 'C knows nothing about .' So if C knows that little as some people say, what are the benefits, I mean do other languages know more or is it a benefit that C knows nearly nothing (what I can think about is that C is the largest common divisor defined on most available platforms)?
9
2166
by: Andy B | last post by:
If I bought one of these boxes/OS combos as a postgresql database server, would postgresql be able to make the best use of it with a huge (e.g. 40GB) database? Box: HP ProLiant DL585, with 4 AMD64 CPUs and 64GB of RAM. (other vendor options also exist) OS: SUSE enterprise 8 linux for AMD (links to product info at bottom)
18
2118
by: sunny | last post by:
Hi Why does C allows declaration of variable inside switch block. ex: foll prg does not gives "undeclared "b" error msg. but also does not initialize b to 20 int a=1; switch(a) { int b=20; case 1: printf("b is %d\n",b);
19
2419
by: active | last post by:
The ColorPalette class has no constructor so how does one use it? I define a variable by: Dim cp as ColorPalette but don't know how assign an object to the variable. Thanks in advance
1
1630
by: prathna | last post by:
Hi I have this following code <script> function displayFields() { document.getElementById('Label12').style.display = 'none'; document.getElementById('Label13').style.display = 'none'; document.getElementById('Label22').style.display = 'none'; document.getElementById('Label23').style.display = 'none'; } function dispHideFileds() { alert(""); if (document.forms.number.value == 'One') { ...
0
8462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8382
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2028
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1787
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.