mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	[3.9] bpo-45838: Fix incorrect line numbers in Tools/gdb/libpython.py (GH-29628)
The line number calculation in libpython.py did not properly handle negative (signed) line table deltas.
This commit is contained in:
		
							parent
							
								
									4296396db0
								
							
						
					
					
						commit
						2a32dbf110
					
				
					 3 changed files with 30 additions and 1 deletions
				
			
		|  | @ -955,6 +955,31 @@ def __init__(self): | |||
|         self.assertRegex(gdb_output, | ||||
|                          r"<method-wrapper u?'__init__' of MyList object at ") | ||||
| 
 | ||||
|     @unittest.skipIf(python_is_optimized(), | ||||
|                      "Python was compiled with optimizations") | ||||
|     def test_try_finally_lineno(self): | ||||
|         cmd = textwrap.dedent(''' | ||||
|             def foo(x): | ||||
|                 try: | ||||
|                     raise RuntimeError("error") | ||||
|                     return x | ||||
|                 except: | ||||
|                     id("break point") | ||||
|                 finally: | ||||
|                     x += 2 | ||||
|                 return x | ||||
|             r = foo(3) | ||||
|         ''') | ||||
|         gdb_output = self.get_stack_trace(cmd, | ||||
|                                           cmds_after_breakpoint=["py-bt"]) | ||||
|         self.assertMultilineMatches(gdb_output, | ||||
|                                     r'''^.* | ||||
| Traceback \(most recent call first\): | ||||
|   <built-in method id of module object .*> | ||||
|   File "<string>", line 7, in foo | ||||
|   File "<string>", line 11, in <module> | ||||
| ''') | ||||
| 
 | ||||
| 
 | ||||
| class PyPrintTests(DebuggerTests): | ||||
|     @unittest.skipIf(python_is_optimized(), | ||||
|  |  | |||
|  | @ -0,0 +1 @@ | |||
| Fix line number calculation when debugging Python with GDB. | ||||
|  | @ -659,7 +659,10 @@ def addr2line(self, addrq): | |||
|             addr += ord(addr_incr) | ||||
|             if addr > addrq: | ||||
|                 return lineno | ||||
|             lineno += ord(line_incr) | ||||
|             line_delta = ord(line_incr) | ||||
|             if line_delta >= 128: | ||||
|                 line_delta -= 256 | ||||
|             lineno += line_delta | ||||
|         return lineno | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Sam Gross
						Sam Gross