Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cfd3884

Browse files
author
Michael W. Hudson
committed
This is Richie Hindle's patch
[ 643835 ] Set Next Statement for Python debuggers with a few tweaks by me: adding an unsigned or two, mentioning that not all jumps are allowed in the doc for pdb, adding a NEWS item and a note to whatsnew, and AuCTeX doing something cosmetic to libpdb.tex.
1 parent f680cc4 commit cfd3884

7 files changed

Lines changed: 607 additions & 13 deletions

File tree

Doc/lib/libpdb.tex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,16 @@ \section{Debugger Commands \label{debugger-commands}}
255255

256256
Continue execution, only stop when a breakpoint is encountered.
257257

258+
\item[j(ump) \var{lineno}]
259+
260+
Set the next line that will be executed. Only available in the
261+
bottom-most frame. This lets you jump back and execute code
262+
again, or jump forward to skip code that you don't want to run.
263+
264+
It should be noted that not all jumps are allowed -- for instance it
265+
it not possible to jump into the middle of a for loop or out of a
266+
finally clause.
267+
258268
\item[l(ist) \optional{\var{first\optional{, last}}}]
259269

260270
List source code for the current file. Without arguments, list 11
@@ -303,7 +313,7 @@ \section{Debugger Commands \label{debugger-commands}}
303313
#Print instance variables in self
304314
alias ps pi self
305315
\end{verbatim}
306-
316+
307317
\item[unalias \var{name}]
308318

309319
Deletes the specified alias.

Doc/ref/ref3.tex

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -812,16 +812,14 @@ \section{The standard type hierarchy\label{types}}
812812
variables; \member{f_globals} is used for global variables;
813813
\member{f_builtins} is used for built-in (intrinsic) names;
814814
\member{f_restricted} is a flag indicating whether the function is
815-
executing in restricted execution mode;
816-
\member{f_lineno} gives the line number and \member{f_lasti} gives the
815+
executing in restricted execution mode; \member{f_lasti} gives the
817816
precise instruction (this is an index into the bytecode string of
818817
the code object).
819818
\withsubitem{(frame attribute)}{
820819
\ttindex{f_back}
821820
\ttindex{f_code}
822821
\ttindex{f_globals}
823822
\ttindex{f_locals}
824-
\ttindex{f_lineno}
825823
\ttindex{f_lasti}
826824
\ttindex{f_builtins}
827825
\ttindex{f_restricted}}
@@ -830,12 +828,16 @@ \section{The standard type hierarchy\label{types}}
830828
function called at the start of each source code line (this is used by
831829
the debugger); \member{f_exc_type}, \member{f_exc_value},
832830
\member{f_exc_traceback} represent the most recent exception caught in
833-
this frame.
831+
this frame; \member{f_lineno} is the current line number of the frame
832+
--- writing to this from within a trace function jumps to the given line
833+
(only for the bottom-most frame). A debugger can implement a Jump
834+
command (aka Set Next Statement) by writing to f_lineno.
834835
\withsubitem{(frame attribute)}{
835836
\ttindex{f_trace}
836837
\ttindex{f_exc_type}
837838
\ttindex{f_exc_value}
838-
\ttindex{f_exc_traceback}}
839+
\ttindex{f_exc_traceback}
840+
\ttindex{f_lineno}}
839841

840842
\item[Traceback objects] \label{traceback}
841843
Traceback objects represent a stack trace of an exception. A

Doc/whatsnew/whatsnew23.tex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
% MacOS framework-related changes (section of its own, probably)
1414

15+
% the new set-next-statement functionality of pdb (SF #643835)
16+
1517
%\section{Introduction \label{intro}}
1618

1719
{\large This article is a draft, and is currently up to date for some
@@ -1201,13 +1203,13 @@ \section{New and Improved Modules}
12011203

12021204
\begin{verbatim}
12031205
>>> days = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'St', 'Sn']
1204-
>>> random.sample(days, 3) # Choose 3 elements
1206+
>>> random.sample(days, 3) # Choose 3 elements
12051207
['St', 'Sn', 'Th']
1206-
>>> random.sample(days, 7) # Choose 7 elements
1208+
>>> random.sample(days, 7) # Choose 7 elements
12071209
['Tu', 'Th', 'Mo', 'We', 'St', 'Fr', 'Sn']
1208-
>>> random.sample(days, 7) # Choose 7 again
1210+
>>> random.sample(days, 7) # Choose 7 again
12091211
['We', 'Mo', 'Sn', 'Fr', 'Tu', 'St', 'Th']
1210-
>>> random.sample(days, 8) # Can't choose eight
1212+
>>> random.sample(days, 8) # Can't choose eight
12111213
Traceback (most recent call last):
12121214
File "<stdin>", line 1, in ?
12131215
File "random.py", line 414, in sample

Lib/pdb.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,25 @@ def do_continue(self, arg):
506506
return 1
507507
do_c = do_cont = do_continue
508508

509+
def do_jump(self, arg):
510+
if self.curindex + 1 != len(self.stack):
511+
print "*** You can only jump within the bottom frame"
512+
return
513+
try:
514+
arg = int(arg)
515+
except ValueError:
516+
print "*** The 'jump' command requires a line number."
517+
else:
518+
try:
519+
# Do the jump, fix up our copy of the stack, and display the
520+
# new position
521+
self.curframe.f_lineno = arg
522+
self.stack[self.curindex] = self.stack[self.curindex][0], arg
523+
self.print_stack_entry(self.stack[self.curindex])
524+
except ValueError, e:
525+
print '*** Jump failed:', e
526+
do_j = do_jump
527+
509528
def do_quit(self, arg):
510529
self.set_quit()
511530
return 1
@@ -805,6 +824,13 @@ def help_c(self):
805824
print """c(ont(inue))
806825
Continue execution, only stop when a breakpoint is encountered."""
807826

827+
def help_jump(self):
828+
self.help_j()
829+
830+
def help_j(self):
831+
print """j(ump) lineno
832+
Set the next line that will be executed."""
833+
808834
def help_list(self):
809835
self.help_l()
810836

0 commit comments

Comments
 (0)