From 696c813e5e1036df6985587451adccb05ffe763f Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Tue, 9 Dec 2025 15:02:05 +0000 Subject: [PATCH 01/10] support break function with file prefix --- Lib/pdb.py | 17 +++++++++++------ Lib/test/test_pdb.py | 12 ++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 1506e3d4709817..15e36824820fb7 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1337,7 +1337,7 @@ def do_commands(self, arg): complete_commands = _complete_bpnumber def do_break(self, arg, temporary=False): - """b(reak) [ ([filename:]lineno | function) [, condition] ] + """b(reak) [ [filename:](lineno | function) [, condition] ] Without argument, list all breaks. @@ -1347,9 +1347,9 @@ def do_break(self, arg, temporary=False): present, it is a string specifying an expression which must evaluate to true before the breakpoint is honored. - The line number may be prefixed with a filename and a colon, - to specify a breakpoint in another file (probably one that - hasn't been loaded yet). The file is searched for on + The line number and function may be prefixed with a filename and + a colon, to specify a breakpoint in another file (probably one + that hasn't been loaded yet). The file is searched for on sys.path; the .py suffix may be omitted. """ if not arg: @@ -1388,8 +1388,13 @@ def do_break(self, arg, temporary=False): try: lineno = int(arg) except ValueError: - self.error('Bad lineno: %s' % arg) - return + func = arg + ok, filename, ln = find_function(func, self.canonic(filename)) + if not ok: + self.error('Bad lineno or function name: %s' % arg) + return + funcname = ok + lineno = int(ln) else: # no colon; can be lineno or function try: diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index c097808e7fdc7c..05cf19dd302391 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -4622,6 +4622,18 @@ def foo(self): stdout, stderr = self.run_pdb_script(script, commands) self.assertIn("The specified object 'C.foo' is not a function", stdout) + def test_break_function_with_file(self): + script = """ + def foo(): + pass + """ + commands = """ + break main:foo + quit + """ + stdout, stderr = self.run_pdb_script(script, commands) + self.assertRegex(stdout, r"Breakpoint 1 at .*main\.py:3") + class ChecklineTests(unittest.TestCase): def setUp(self): From c7c55bc159d1335d1884f13b9f61fcad4174de70 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 9 Dec 2025 15:18:44 +0000 Subject: [PATCH 02/10] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2025-12-09-15-18-43.gh-issue-142468.V64wcC.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2025-12-09-15-18-43.gh-issue-142468.V64wcC.rst diff --git a/Misc/NEWS.d/next/Library/2025-12-09-15-18-43.gh-issue-142468.V64wcC.rst b/Misc/NEWS.d/next/Library/2025-12-09-15-18-43.gh-issue-142468.V64wcC.rst new file mode 100644 index 00000000000000..21b1a869c77629 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-12-09-15-18-43.gh-issue-142468.V64wcC.rst @@ -0,0 +1 @@ +:mod:`pdb` now supports setting breakpoints using the ``filename:function`` syntax From 2d6916437204c71d136160bb45964965116f1f6f Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Tue, 9 Dec 2025 23:45:10 +0800 Subject: [PATCH 03/10] Update Misc/NEWS.d/next/Library/2025-12-09-15-18-43.gh-issue-142468.V64wcC.rst Co-authored-by: AN Long --- .../next/Library/2025-12-09-15-18-43.gh-issue-142468.V64wcC.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-12-09-15-18-43.gh-issue-142468.V64wcC.rst b/Misc/NEWS.d/next/Library/2025-12-09-15-18-43.gh-issue-142468.V64wcC.rst index 21b1a869c77629..e8c28a4f3c4aa5 100644 --- a/Misc/NEWS.d/next/Library/2025-12-09-15-18-43.gh-issue-142468.V64wcC.rst +++ b/Misc/NEWS.d/next/Library/2025-12-09-15-18-43.gh-issue-142468.V64wcC.rst @@ -1 +1 @@ -:mod:`pdb` now supports setting breakpoints using the ``filename:function`` syntax +:mod:`pdb` now supports setting breakpoints using the ``filename:function`` syntax. From 10fb95444baee2f678ae24a463ad97fada64d423 Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Tue, 9 Dec 2025 15:48:26 +0000 Subject: [PATCH 04/10] deal with find_function res --- Lib/pdb.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 15e36824820fb7..98c6340dfa146a 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1389,7 +1389,8 @@ def do_break(self, arg, temporary=False): lineno = int(arg) except ValueError: func = arg - ok, filename, ln = find_function(func, self.canonic(filename)) + find_res = find_function(func, self.canonic(filename)) + ok, filename, ln = find_res or (None, None, None) if not ok: self.error('Bad lineno or function name: %s' % arg) return From f67d32133084f4a849042f8870a46b7df4099ce1 Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Tue, 9 Dec 2025 23:52:42 +0800 Subject: [PATCH 05/10] Update Lib/pdb.py Co-authored-by: AN Long --- Lib/pdb.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 98c6340dfa146a..546468c690aa44 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1390,11 +1390,10 @@ def do_break(self, arg, temporary=False): except ValueError: func = arg find_res = find_function(func, self.canonic(filename)) - ok, filename, ln = find_res or (None, None, None) - if not ok: + if not find_res: self.error('Bad lineno or function name: %s' % arg) return - funcname = ok + funcname, filename, ln = find_res lineno = int(ln) else: # no colon; can be lineno or function From 679b2aaed4b48b00dbcca7239971f4c67b2c2c7b Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Wed, 10 Dec 2025 00:01:32 +0800 Subject: [PATCH 06/10] Update Lib/pdb.py Co-authored-by: AN Long --- Lib/pdb.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 546468c690aa44..13c7c82f94c0cf 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1393,8 +1393,7 @@ def do_break(self, arg, temporary=False): if not find_res: self.error('Bad lineno or function name: %s' % arg) return - funcname, filename, ln = find_res - lineno = int(ln) + funcname, filename, lineno = find_res else: # no colon; can be lineno or function try: From 4d818c1c3b83653f2941ed3b5618d5d785eee56e Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Thu, 11 Dec 2025 14:00:31 +0000 Subject: [PATCH 07/10] support clear filename:function --- Lib/pdb.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 13c7c82f94c0cf..5cf090c751f253 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1675,13 +1675,24 @@ def do_clear(self, arg): if ':' in arg: # Make sure it works for "clear C:\foo\bar.py:12" i = arg.rfind(':') - filename = arg[:i] - arg = arg[i+1:] + filename = arg[:i].rstrip() + arg = arg[i+1:].lstrip() + err = None try: lineno = int(arg) except ValueError: - err = "Invalid line number (%s)" % arg - else: + f = self.lookupmodule(filename) + if not f: + err = '%r not found from sys.path' % filename + else: + filename = f + func = arg + find_res = find_function(func, self.canonic(filename)) + if find_res: + _, filename, lineno = find_res + else: + err = "Invalid line number or function name:(%r)" % arg + if not err: bplist = self.get_breaks(filename, lineno)[:] err = self.clear_break(filename, lineno) if err: From a0008516a0de534c4eff9a6fc913dfed83ec540d Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Thu, 11 Dec 2025 14:08:15 +0000 Subject: [PATCH 08/10] support clear filename:function --- Lib/pdb.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 5cf090c751f253..d04b91d3418ede 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1654,12 +1654,13 @@ def _prompt_for_confirmation(self, prompt, default): return reply.strip().lower() def do_clear(self, arg): - """cl(ear) [filename:lineno | bpnumber ...] + """cl(ear) [filename:(lineno | function) | bpnumber ...] With a space separated list of breakpoint numbers, clear those breakpoints. Without argument, clear all breaks (but first ask confirmation). With a filename:lineno argument, - clear all breaks at that line in that file. + clear all breakpoints at that line. With a filename:function + argument, clear all breakpoints at that function. """ if not arg: reply = self._prompt_for_confirmation( From cc96f92d8056877ada9dd6f15e33927eaf2f67f3 Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Thu, 11 Dec 2025 14:15:46 +0000 Subject: [PATCH 09/10] support clear filename:function --- Lib/pdb.py | 2 +- Lib/test/test_pdb.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index d04b91d3418ede..76bb5edc232b05 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1692,7 +1692,7 @@ def do_clear(self, arg): if find_res: _, filename, lineno = find_res else: - err = "Invalid line number or function name:(%r)" % arg + err = "Invalid line number or function name:(%s)" % arg if not err: bplist = self.get_breaks(filename, lineno)[:] err = self.clear_break(filename, lineno) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 05cf19dd302391..b7568e739db56d 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -4629,10 +4629,12 @@ def foo(): """ commands = """ break main:foo + clear main:foo quit """ stdout, stderr = self.run_pdb_script(script, commands) self.assertRegex(stdout, r"Breakpoint 1 at .*main\.py:3") + self.assertRegex(stdout, r"Deleted breakpoint 1 at .*main\.py:3") class ChecklineTests(unittest.TestCase): From ca4e403137f8d91efacc7dd22a7084c056cd7b31 Mon Sep 17 00:00:00 2001 From: LloydZ <35182391+cocolato@users.noreply.github.com> Date: Thu, 11 Dec 2025 22:19:12 +0800 Subject: [PATCH 10/10] Update pdb breakpoint syntax description --- .../next/Library/2025-12-09-15-18-43.gh-issue-142468.V64wcC.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-12-09-15-18-43.gh-issue-142468.V64wcC.rst b/Misc/NEWS.d/next/Library/2025-12-09-15-18-43.gh-issue-142468.V64wcC.rst index e8c28a4f3c4aa5..2ab64b377841dc 100644 --- a/Misc/NEWS.d/next/Library/2025-12-09-15-18-43.gh-issue-142468.V64wcC.rst +++ b/Misc/NEWS.d/next/Library/2025-12-09-15-18-43.gh-issue-142468.V64wcC.rst @@ -1 +1 @@ -:mod:`pdb` now supports setting breakpoints using the ``filename:function`` syntax. +:mod:`pdb` now supports setting or clearing breakpoints with the ``filename:function`` syntax.