Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,24 @@ def do_down(self, arg):
self._select_frame(newframe)
do_d = do_down

def do_frame(self, arg):
"""f(rame) [frame index]

Move the current frame levels to the new stack frame
according to the argument (from bt command).
"""
try:
new_frame_idx = int(arg)
except ValueError:
self.error("The 'frame' command requires a frame index (from bt command)")

if new_frame_idx >= len(self.stack) or new_frame_idx < 0:
self.error('Wrong frame index, it should be in range [0, {}]'.format(len(self.stack) - 1))
return

self._select_frame(new_frame_idx)
do_f = do_frame

def do_until(self, arg):
"""unt(il) [lineno]

Expand Down Expand Up @@ -2122,17 +2140,26 @@ def print_stack_trace(self, count=None):
else:
stack_to_print = self.stack[-count:]
try:
for frame_lineno in stack_to_print:
self.print_stack_entry(frame_lineno)
if count is None:
# only print frame idx when we print whole frame
for frame_idx, frame_lineno in enumerate(stack_to_print, start = 0):
self.print_stack_entry(frame_lineno, frame_idx)
return
else:
for frame_lineno in stack_to_print:
self.print_stack_entry(frame_lineno)
except KeyboardInterrupt:
pass

def print_stack_entry(self, frame_lineno, prompt_prefix=line_prefix):
def print_stack_entry(self, frame_lineno, frame_idx = -1, prompt_prefix=line_prefix):
frame, lineno = frame_lineno
prefix = ""
if frame_idx != -1:
prefix += '#' + str(frame_idx) + ' '
if frame is self.curframe:
prefix = '> '
prefix += '> '
else:
prefix = ' '
prefix += ' '
self.message(prefix +
self.format_stack_entry(frame_lineno, prompt_prefix))

Expand Down
42 changes: 21 additions & 21 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ def test_pdb_basic_commands():
[EOF]
(Pdb) bt
...
<doctest test.test_pdb.test_pdb_basic_commands[4]>(26)<module>()
... <doctest test.test_pdb.test_pdb_basic_commands[4]>(26)<module>()
-> test_function()
<doctest test.test_pdb.test_pdb_basic_commands[3]>(3)test_function()
... <doctest test.test_pdb.test_pdb_basic_commands[3]>(3)test_function()
-> ret = test_function_2('baz')
> <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
... > <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
-> def test_function_2(foo, bar='default'):
(Pdb) up
> <doctest test.test_pdb.test_pdb_basic_commands[3]>(3)test_function()
Expand Down Expand Up @@ -960,23 +960,23 @@ def test_pdb_where_command():
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
(Pdb) w
...
<doctest test.test_pdb.test_pdb_where_command[3]>(13)<module>()
... <doctest test.test_pdb.test_pdb_where_command[3]>(13)<module>()
-> test_function()
<doctest test.test_pdb.test_pdb_where_command[2]>(2)test_function()
... <doctest test.test_pdb.test_pdb_where_command[2]>(2)test_function()
-> f()
<doctest test.test_pdb.test_pdb_where_command[1]>(2)f()
... <doctest test.test_pdb.test_pdb_where_command[1]>(2)f()
-> g()
> <doctest test.test_pdb.test_pdb_where_command[0]>(2)g()
... > <doctest test.test_pdb.test_pdb_where_command[0]>(2)g()
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
(Pdb) where
...
<doctest test.test_pdb.test_pdb_where_command[3]>(13)<module>()
... <doctest test.test_pdb.test_pdb_where_command[3]>(13)<module>()
-> test_function()
<doctest test.test_pdb.test_pdb_where_command[2]>(2)test_function()
... <doctest test.test_pdb.test_pdb_where_command[2]>(2)test_function()
-> f()
<doctest test.test_pdb.test_pdb_where_command[1]>(2)f()
... <doctest test.test_pdb.test_pdb_where_command[1]>(2)f()
-> g()
> <doctest test.test_pdb.test_pdb_where_command[0]>(2)g()
... > <doctest test.test_pdb.test_pdb_where_command[0]>(2)g()
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
(Pdb) w 1
> <doctest test.test_pdb.test_pdb_where_command[0]>(2)g()
Expand All @@ -988,13 +988,13 @@ def test_pdb_where_command():
-> g()
(Pdb) w
...
<doctest test.test_pdb.test_pdb_where_command[3]>(13)<module>()
... <doctest test.test_pdb.test_pdb_where_command[3]>(13)<module>()
-> test_function()
<doctest test.test_pdb.test_pdb_where_command[2]>(2)test_function()
... <doctest test.test_pdb.test_pdb_where_command[2]>(2)test_function()
-> f()
> <doctest test.test_pdb.test_pdb_where_command[1]>(2)f()
... > <doctest test.test_pdb.test_pdb_where_command[1]>(2)f()
-> g()
<doctest test.test_pdb.test_pdb_where_command[0]>(2)g()
... <doctest test.test_pdb.test_pdb_where_command[0]>(2)g()
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
(Pdb) w 0
> <doctest test.test_pdb.test_pdb_where_command[1]>(2)f()
Expand Down Expand Up @@ -1648,11 +1648,11 @@ def test_post_mortem():
-> test_function_2()
(Pdb) bt
...
<doctest test.test_pdb.test_post_mortem[2]>(11)<module>()
... <doctest test.test_pdb.test_post_mortem[2]>(11)<module>()
-> test_function()
> <doctest test.test_pdb.test_post_mortem[1]>(3)test_function()
... > <doctest test.test_pdb.test_post_mortem[1]>(3)test_function()
-> test_function_2()
<doctest test.test_pdb.test_post_mortem[0]>(3)test_function_2()
... <doctest test.test_pdb.test_post_mortem[0]>(3)test_function_2()
-> 1/0
(Pdb) list
1 def test_function():
Expand Down Expand Up @@ -3746,10 +3746,10 @@ def test_file_modified_after_execution(self):
# the time.sleep is needed for low-resolution filesystems like HFS+
commands = """
filename = $_frame.f_code.co_filename
f = open(filename, "w")
f.write("print('goodbye')")
file = open(filename, "w")
file.write("print('goodbye')")
import time; time.sleep(1)
f.close()
file.close()
ll
"""

Expand Down
Loading