| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 221cbcd commit 5c271de
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -887,7 +887,7 @@ def do_break(self, arg, temporary = 0): | |||
| 887 | 887 | #use co_name to identify the bkpt (function names | |
| 888 | 888 | #could be aliased, but co_name is invariant) | |
| 889 | 889 | funcname = code.co_name | |
| 890 | - lineno = code.co_firstlineno | ||
| 890 | + lineno = self._find_first_executable_line(code) | ||
| 891 | 891 | filename = code.co_filename | |
| 892 | 892 | except: | |
| 893 | 893 | # last thing to try | |
@@ -990,6 +990,23 @@ def checkline(self, filename, lineno): | |||
| 990 | 990 | return 0 | |
| 991 | 991 | return lineno | |
| 992 | 992 | ||
| 993 | + def _find_first_executable_line(self, code): | ||
| 994 | + """ Try to find the first executable line of the code object. | ||
| 995 | + | ||
| 996 | + Equivalently, find the line number of the instruction that's | ||
| 997 | + after RESUME | ||
| 998 | + | ||
| 999 | + Return code.co_firstlineno if no executable line is found. | ||
| 1000 | + """ | ||
| 1001 | + prev = None | ||
| 1002 | + for instr in dis.get_instructions(code): | ||
| 1003 | + if prev is not None and prev.opname == 'RESUME': | ||
| 1004 | + if instr.positions.lineno is not None: | ||
| 1005 | + return instr.positions.lineno | ||
| 1006 | + return code.co_firstlineno | ||
| 1007 | + prev = instr | ||
| 1008 | + return code.co_firstlineno | ||
| 1009 | + | ||
| 993 | 1010 | def do_enable(self, arg): | |
| 994 | 1011 | """enable bpnumber [bpnumber ...] | |
| 995 | 1012 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1516,7 +1516,7 @@ def test_next_until_return_at_return_event(): | |||
| 1516 | 1516 | > <doctest test.test_pdb.test_next_until_return_at_return_event[1]>(3)test_function() | |
| 1517 | 1517 | -> test_function_2() | |
| 1518 | 1518 | (Pdb) break test_function_2 | |
| 1519 | - Breakpoint 1 at <doctest test.test_pdb.test_next_until_return_at_return_event[0]>:1 | ||
| 1519 | + Breakpoint 1 at <doctest test.test_pdb.test_next_until_return_at_return_event[0]>:2 | ||
| 1520 | 1520 | (Pdb) continue | |
| 1521 | 1521 | > <doctest test.test_pdb.test_next_until_return_at_return_event[0]>(2)test_function_2() | |
| 1522 | 1522 | -> x = 1 | |
@@ -1938,7 +1938,7 @@ def test_pdb_next_command_in_generator_for_loop(): | |||
| 1938 | 1938 | > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[1]>(3)test_function() | |
| 1939 | 1939 | -> for i in test_gen(): | |
| 1940 | 1940 | (Pdb) break test_gen | |
| 1941 | - Breakpoint 1 at <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>:1 | ||
| 1941 | + Breakpoint 1 at <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>:2 | ||
| 1942 | 1942 | (Pdb) continue | |
| 1943 | 1943 | > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>(2)test_gen() | |
| 1944 | 1944 | -> yield 0 | |
@@ -2350,6 +2350,48 @@ def test_pdb_ambiguous_statements(): | |||
| 2350 | 2350 | (Pdb) continue | |
| 2351 | 2351 | """ | |
| 2352 | 2352 | ||
| 2353 | + def test_pdb_function_break(): | ||
| 2354 | + """Testing the line number of break on function | ||
| 2355 | + | ||
| 2356 | + >>> def foo(): pass | ||
| 2357 | + | ||
| 2358 | + >>> def bar(): | ||
| 2359 | + ... | ||
| 2360 | + ... pass | ||
| 2361 | + | ||
| 2362 | + >>> def boo(): | ||
| 2363 | + ... # comments | ||
| 2364 | + ... global x | ||
| 2365 | + ... x = 1 | ||
| 2366 | + | ||
| 2367 | + >>> def gen(): | ||
| 2368 | + ... yield 42 | ||
| 2369 | + | ||
| 2370 | + >>> def test_function(): | ||
| 2371 | + ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() | ||
| 2372 | + ... pass | ||
| 2373 | + | ||
| 2374 | + >>> with PdbTestInput([ # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE | ||
| 2375 | + ... 'break foo', | ||
| 2376 | + ... 'break bar', | ||
| 2377 | + ... 'break boo', | ||
| 2378 | + ... 'break gen', | ||
| 2379 | + ... 'continue' | ||
| 2380 | + ... ]): | ||
| 2381 | + ... test_function() | ||
| 2382 | + > <doctest test.test_pdb.test_pdb_function_break[4]>(3)test_function() | ||
| 2383 | + -> pass | ||
| 2384 | + (Pdb) break foo | ||
| 2385 | + Breakpoint ... at <doctest test.test_pdb.test_pdb_function_break[0]>:1 | ||
| 2386 | + (Pdb) break bar | ||
| 2387 | + Breakpoint ... at <doctest test.test_pdb.test_pdb_function_break[1]>:3 | ||
| 2388 | + (Pdb) break boo | ||
| 2389 | + Breakpoint ... at <doctest test.test_pdb.test_pdb_function_break[2]>:4 | ||
| 2390 | + (Pdb) break gen | ||
| 2391 | + Breakpoint ... at <doctest test.test_pdb.test_pdb_function_break[3]>:2 | ||
| 2392 | + (Pdb) continue | ||
| 2393 | + """ | ||
| 2394 | + | ||
| 2353 | 2395 | def test_pdb_issue_gh_65052(): | |
| 2354 | 2396 | """See GH-65052 | |
| 2355 | 2397 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Make line number of function breakpoint more precise in :mod:`pdb` | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments