Skip to content

Commit 696c813

Browse files
committed
support break function with file prefix
1 parent 4279785 commit 696c813

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

Lib/pdb.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ def do_commands(self, arg):
13371337
complete_commands = _complete_bpnumber
13381338

13391339
def do_break(self, arg, temporary=False):
1340-
"""b(reak) [ ([filename:]lineno | function) [, condition] ]
1340+
"""b(reak) [ [filename:](lineno | function) [, condition] ]
13411341
13421342
Without argument, list all breaks.
13431343
@@ -1347,9 +1347,9 @@ def do_break(self, arg, temporary=False):
13471347
present, it is a string specifying an expression which must
13481348
evaluate to true before the breakpoint is honored.
13491349
1350-
The line number may be prefixed with a filename and a colon,
1351-
to specify a breakpoint in another file (probably one that
1352-
hasn't been loaded yet). The file is searched for on
1350+
The line number and function may be prefixed with a filename and
1351+
a colon, to specify a breakpoint in another file (probably one
1352+
that hasn't been loaded yet). The file is searched for on
13531353
sys.path; the .py suffix may be omitted.
13541354
"""
13551355
if not arg:
@@ -1388,8 +1388,13 @@ def do_break(self, arg, temporary=False):
13881388
try:
13891389
lineno = int(arg)
13901390
except ValueError:
1391-
self.error('Bad lineno: %s' % arg)
1392-
return
1391+
func = arg
1392+
ok, filename, ln = find_function(func, self.canonic(filename))
1393+
if not ok:
1394+
self.error('Bad lineno or function name: %s' % arg)
1395+
return
1396+
funcname = ok
1397+
lineno = int(ln)
13931398
else:
13941399
# no colon; can be lineno or function
13951400
try:

Lib/test/test_pdb.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4622,6 +4622,18 @@ def foo(self):
46224622
stdout, stderr = self.run_pdb_script(script, commands)
46234623
self.assertIn("The specified object 'C.foo' is not a function", stdout)
46244624

4625+
def test_break_function_with_file(self):
4626+
script = """
4627+
def foo():
4628+
pass
4629+
"""
4630+
commands = """
4631+
break main:foo
4632+
quit
4633+
"""
4634+
stdout, stderr = self.run_pdb_script(script, commands)
4635+
self.assertRegex(stdout, r"Breakpoint 1 at .*main\.py:3")
4636+
46254637

46264638
class ChecklineTests(unittest.TestCase):
46274639
def setUp(self):

0 commit comments

Comments
 (0)