Kaydet (Commit) 24f09fdb authored tarafından Martin v. Löwis's avatar Martin v. Löwis

Issue #8279: Fix test_gdb failures.

üst fb4812fb
...@@ -9,7 +9,7 @@ import subprocess ...@@ -9,7 +9,7 @@ import subprocess
import sys import sys
import unittest import unittest
from test.test_support import run_unittest from test.test_support import run_unittest, findfile
try: try:
gdb_version, _ = subprocess.Popen(["gdb", "--version"], gdb_version, _ = subprocess.Popen(["gdb", "--version"],
...@@ -144,6 +144,9 @@ class DebuggerTests(unittest.TestCase): ...@@ -144,6 +144,9 @@ class DebuggerTests(unittest.TestCase):
self.assert_(m, self.assert_(m,
msg='%r did not match %r' % (actual, pattern)) msg='%r did not match %r' % (actual, pattern))
def get_sample_script(self):
return findfile('gdb_sample.py')
class PrettyPrintTests(DebuggerTests): class PrettyPrintTests(DebuggerTests):
def test_getting_backtrace(self): def test_getting_backtrace(self):
gdb_output = self.get_stack_trace('print 42') gdb_output = self.get_stack_trace('print 42')
...@@ -531,133 +534,127 @@ class PyListTests(DebuggerTests): ...@@ -531,133 +534,127 @@ class PyListTests(DebuggerTests):
def test_basic_command(self): def test_basic_command(self):
'Verify that the "py-list" command works' 'Verify that the "py-list" command works'
bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-list']) cmds_after_breakpoint=['py-list'])
self.assertListing(''' self.assertListing(' 5 \n'
5 ' 6 def bar(a, b, c):\n'
6 def bar(a, b, c): ' 7 baz(a, b, c)\n'
7 baz(a, b, c) ' 8 \n'
8 ' 9 def baz(*args):\n'
9 def baz(*args): ' >10 print(42)\n'
>10 print(42) ' 11 \n'
11 ' 12 foo(1, 2, 3)\n',
12 foo(1, 2, 3)
''',
bt) bt)
def test_one_abs_arg(self): def test_one_abs_arg(self):
'Verify the "py-list" command with one absolute argument' 'Verify the "py-list" command with one absolute argument'
bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-list 9']) cmds_after_breakpoint=['py-list 9'])
self.assertListing(''' self.assertListing(' 9 def baz(*args):\n'
9 def baz(*args): ' >10 print(42)\n'
>10 print(42) ' 11 \n'
11 ' 12 foo(1, 2, 3)\n',
12 foo(1, 2, 3)
''',
bt) bt)
def test_two_abs_args(self): def test_two_abs_args(self):
'Verify the "py-list" command with two absolute arguments' 'Verify the "py-list" command with two absolute arguments'
bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-list 1,3']) cmds_after_breakpoint=['py-list 1,3'])
self.assertListing(''' self.assertListing(' 1 # Sample script for use by test_gdb.py\n'
1 # Sample script for use by test_gdb.py ' 2 \n'
2 ' 3 def foo(a, b, c):\n',
3 def foo(a, b, c):
''',
bt) bt)
class StackNavigationTests(DebuggerTests): class StackNavigationTests(DebuggerTests):
def test_pyup_command(self): def test_pyup_command(self):
'Verify that the "py-up" command works' 'Verify that the "py-up" command works'
bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-up']) cmds_after_breakpoint=['py-up'])
self.assertMultilineMatches(bt, self.assertMultilineMatches(bt,
r'''^.* r'''^.*
#[0-9]+ Frame 0x[0-9a-f]+, for file Lib/test/test_gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\) #[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\)
baz\(a, b, c\) baz\(a, b, c\)
$''') $''')
def test_down_at_bottom(self): def test_down_at_bottom(self):
'Verify handling of "py-down" at the bottom of the stack' 'Verify handling of "py-down" at the bottom of the stack'
bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-down']) cmds_after_breakpoint=['py-down'])
self.assertEndsWith(bt, self.assertEndsWith(bt,
'Unable to find a newer python frame\n') 'Unable to find a newer python frame\n')
def test_up_at_top(self): def test_up_at_top(self):
'Verify handling of "py-up" at the top of the stack' 'Verify handling of "py-up" at the top of the stack'
bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-up'] * 4) cmds_after_breakpoint=['py-up'] * 4)
self.assertEndsWith(bt, self.assertEndsWith(bt,
'Unable to find an older python frame\n') 'Unable to find an older python frame\n')
def test_up_then_down(self): def test_up_then_down(self):
'Verify "py-up" followed by "py-down"' 'Verify "py-up" followed by "py-down"'
bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-up', 'py-down']) cmds_after_breakpoint=['py-up', 'py-down'])
self.assertMultilineMatches(bt, self.assertMultilineMatches(bt,
r'''^.* r'''^.*
#[0-9]+ Frame 0x[0-9a-f]+, for file Lib/test/test_gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\) #[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\)
baz\(a, b, c\) baz\(a, b, c\)
#[0-9]+ Frame 0x[0-9a-f]+, for file Lib/test/test_gdb_sample.py, line 10, in baz \(args=\(1, 2, 3\)\) #[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 10, in baz \(args=\(1, 2, 3\)\)
print\(42\) print\(42\)
$''') $''')
class PyBtTests(DebuggerTests): class PyBtTests(DebuggerTests):
def test_basic_command(self): def test_basic_command(self):
'Verify that the "py-bt" command works' 'Verify that the "py-bt" command works'
bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-bt']) cmds_after_breakpoint=['py-bt'])
self.assertMultilineMatches(bt, self.assertMultilineMatches(bt,
r'''^.* r'''^.*
#[0-9]+ Frame 0x[0-9a-f]+, for file Lib/test/test_gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\) #[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\)
baz\(a, b, c\) baz\(a, b, c\)
#[0-9]+ Frame 0x[0-9a-f]+, for file Lib/test/test_gdb_sample.py, line 4, in foo \(a=1, b=2, c=3\) #[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 4, in foo \(a=1, b=2, c=3\)
bar\(a, b, c\) bar\(a, b, c\)
#[0-9]+ Frame 0x[0-9a-f]+, for file Lib/test/test_gdb_sample.py, line 12, in <module> \(\) #[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 12, in <module> \(\)
foo\(1, 2, 3\) foo\(1, 2, 3\)
''') ''')
class PyPrintTests(DebuggerTests): class PyPrintTests(DebuggerTests):
def test_basic_command(self): def test_basic_command(self):
'Verify that the "py-print" command works' 'Verify that the "py-print" command works'
bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-print args']) cmds_after_breakpoint=['py-print args'])
self.assertMultilineMatches(bt, self.assertMultilineMatches(bt,
r".*\nlocal 'args' = \(1, 2, 3\)\n.*") r".*\nlocal 'args' = \(1, 2, 3\)\n.*")
def test_print_after_up(self): def test_print_after_up(self):
bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-up', 'py-print c', 'py-print b', 'py-print a']) cmds_after_breakpoint=['py-up', 'py-print c', 'py-print b', 'py-print a'])
self.assertMultilineMatches(bt, self.assertMultilineMatches(bt,
r".*\nlocal 'c' = 3\nlocal 'b' = 2\nlocal 'a' = 1\n.*") r".*\nlocal 'c' = 3\nlocal 'b' = 2\nlocal 'a' = 1\n.*")
def test_printing_global(self): def test_printing_global(self):
bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-print __name__']) cmds_after_breakpoint=['py-print __name__'])
self.assertMultilineMatches(bt, self.assertMultilineMatches(bt,
r".*\nglobal '__name__' = '__main__'\n.*") r".*\nglobal '__name__' = '__main__'\n.*")
def test_printing_builtin(self): def test_printing_builtin(self):
bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-print len']) cmds_after_breakpoint=['py-print len'])
self.assertMultilineMatches(bt, self.assertMultilineMatches(bt,
r".*\nbuiltin 'len' = <built-in function len>\n.*") r".*\nbuiltin 'len' = <built-in function len>\n.*")
class PyLocalsTests(DebuggerTests): class PyLocalsTests(DebuggerTests):
def test_basic_command(self): def test_basic_command(self):
bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-locals']) cmds_after_breakpoint=['py-locals'])
self.assertMultilineMatches(bt, self.assertMultilineMatches(bt,
r".*\nargs = \(1, 2, 3\)\n.*") r".*\nargs = \(1, 2, 3\)\n.*")
def test_locals_after_up(self): def test_locals_after_up(self):
bt = self.get_stack_trace(script='Lib/test/test_gdb_sample.py', bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-up', 'py-locals']) cmds_after_breakpoint=['py-up', 'py-locals'])
self.assertMultilineMatches(bt, self.assertMultilineMatches(bt,
r".*\na = 1\nb = 2\nc = 3\n.*") r".*\na = 1\nb = 2\nc = 3\n.*")
......
...@@ -18,6 +18,8 @@ Core and Builtins ...@@ -18,6 +18,8 @@ Core and Builtins
Library Library
------- -------
- Issue #8279: Fix test_gdb failures.
- Issue #8322: Add a *ciphers* argument to SSL sockets, so as to change the - Issue #8322: Add a *ciphers* argument to SSL sockets, so as to change the
available cipher list. Helps fix test_ssl with OpenSSL 1.0.0. available cipher list. Helps fix test_ssl with OpenSSL 1.0.0.
......
...@@ -1097,6 +1097,11 @@ def register (obj): ...@@ -1097,6 +1097,11 @@ def register (obj):
register (gdb.current_objfile ()) register (gdb.current_objfile ())
# Unfortunately, the exact API exposed by the gdb module varies somewhat
# from build to build
# See http://bugs.python.org/issue8279?#msg102276
class Frame(object): class Frame(object):
''' '''
Wrapper for gdb.Frame, adding various methods Wrapper for gdb.Frame, adding various methods
...@@ -1119,7 +1124,16 @@ class Frame(object): ...@@ -1119,7 +1124,16 @@ class Frame(object):
return None return None
def select(self): def select(self):
'''If supported, select this frame and return True; return False if unsupported
Not all builds have a gdb.Frame.select method; seems to be present on Fedora 12
onwards, but absent on Ubuntu buildbot'''
if not hasattr(self._gdbframe, 'select'):
print ('Unable to select frame: '
'this build of gdb does not expose a gdb.Frame.select method')
return False
self._gdbframe.select() self._gdbframe.select()
return True
def get_index(self): def get_index(self):
'''Calculate index of frame, starting at 0 for the newest frame within '''Calculate index of frame, starting at 0 for the newest frame within
...@@ -1133,8 +1147,9 @@ class Frame(object): ...@@ -1133,8 +1147,9 @@ class Frame(object):
return index return index
def is_evalframeex(self): def is_evalframeex(self):
'''Is this a PyEval_EvalFrameEx frame?'''
if self._gdbframe.function(): if self._gdbframe.function():
if self._gdbframe.function().name == 'PyEval_EvalFrameEx': if self._gdbframe.name() == 'PyEval_EvalFrameEx':
''' '''
I believe we also need to filter on the inline I believe we also need to filter on the inline
struct frame_id.inline_depth, only regarding frames with struct frame_id.inline_depth, only regarding frames with
...@@ -1271,7 +1286,7 @@ def move_in_stack(move_up): ...@@ -1271,7 +1286,7 @@ def move_in_stack(move_up):
if iter_frame.is_evalframeex(): if iter_frame.is_evalframeex():
# Result: # Result:
iter_frame.select() if iter_frame.select():
iter_frame.print_summary() iter_frame.print_summary()
return return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment