annotate Lib/test/test_gdb.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 3d170d1e2fa3
children 1b1ead5cecae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1 # Verify that gdb can pretty-print the various PyObject* types
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
2 #
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
3 # The code for testing gdb was adapted from similar work in Unladen Swallow's
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
4 # Lib/test/test_jit_gdb.py
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
5
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
6 import os
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
7 import re
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
8 import subprocess
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
9 import sys
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
10 import unittest
62863
c7305ba84619 Merged revisions 82647 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 61770
diff changeset
11 import sysconfig
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
12
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
13 from test.test_support import run_unittest, findfile
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
14
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
15 try:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
16 gdb_version, _ = subprocess.Popen(["gdb", "--version"],
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
17 stdout=subprocess.PIPE).communicate()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
18 except OSError:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
19 # This is what "no gdb" looks like. There may, however, be other
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
20 # errors that manifest this way too.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
21 raise unittest.SkipTest("Couldn't find gdb on the path")
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
22 gdb_version_number = re.search(r"^GNU gdb [^\d]*(\d+)\.", gdb_version)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
23 if int(gdb_version_number.group(1)) < 7:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
24 raise unittest.SkipTest("gdb versions before 7.0 didn't support python embedding"
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
25 " Saw:\n" + gdb_version)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
26
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
27 # Verify that "gdb" was built with the embedded python support enabled:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
28 cmd = "--eval-command=python import sys; print sys.version_info"
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
29 p = subprocess.Popen(["gdb", "--batch", cmd],
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
30 stdout=subprocess.PIPE)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
31 gdbpy_version, _ = p.communicate()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
32 if gdbpy_version == '':
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
33 raise unittest.SkipTest("gdb not built with embedded python support")
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
34
77488
ac2f5067c220 Issue #15043: skip test_gdb if the custom hooks can't be loaded (backport from 3.x)
Nick Coghlan <ncoghlan@gmail.com>
parents: 75123
diff changeset
35 # Verify that "gdb" can load our custom hooks
ac2f5067c220 Issue #15043: skip test_gdb if the custom hooks can't be loaded (backport from 3.x)
Nick Coghlan <ncoghlan@gmail.com>
parents: 75123
diff changeset
36 p = subprocess.Popen(["gdb", "--batch", cmd,
ac2f5067c220 Issue #15043: skip test_gdb if the custom hooks can't be loaded (backport from 3.x)
Nick Coghlan <ncoghlan@gmail.com>
parents: 75123
diff changeset
37 "--args", sys.executable],
ac2f5067c220 Issue #15043: skip test_gdb if the custom hooks can't be loaded (backport from 3.x)
Nick Coghlan <ncoghlan@gmail.com>
parents: 75123
diff changeset
38 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
ac2f5067c220 Issue #15043: skip test_gdb if the custom hooks can't be loaded (backport from 3.x)
Nick Coghlan <ncoghlan@gmail.com>
parents: 75123
diff changeset
39 __, gdbpy_errors = p.communicate()
ac2f5067c220 Issue #15043: skip test_gdb if the custom hooks can't be loaded (backport from 3.x)
Nick Coghlan <ncoghlan@gmail.com>
parents: 75123
diff changeset
40 if b"auto-loading has been declined" in gdbpy_errors:
ac2f5067c220 Issue #15043: skip test_gdb if the custom hooks can't be loaded (backport from 3.x)
Nick Coghlan <ncoghlan@gmail.com>
parents: 75123
diff changeset
41 msg = "gdb security settings prevent use of custom hooks: %s"
ac2f5067c220 Issue #15043: skip test_gdb if the custom hooks can't be loaded (backport from 3.x)
Nick Coghlan <ncoghlan@gmail.com>
parents: 75123
diff changeset
42 raise unittest.SkipTest(msg % gdbpy_errors)
ac2f5067c220 Issue #15043: skip test_gdb if the custom hooks can't be loaded (backport from 3.x)
Nick Coghlan <ncoghlan@gmail.com>
parents: 75123
diff changeset
43
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
44 def python_is_optimized():
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
45 cflags = sysconfig.get_config_vars()['PY_CFLAGS']
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
46 final_opt = ""
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
47 for opt in cflags.split():
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
48 if opt.startswith('-O'):
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
49 final_opt = opt
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
50 return (final_opt and final_opt != '-O0')
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
51
60791
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
52 def gdb_has_frame_select():
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
53 # Does this build of gdb have gdb.Frame.select ?
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
54 cmd = "--eval-command=python print(dir(gdb.Frame))"
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
55 p = subprocess.Popen(["gdb", "--batch", cmd],
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
56 stdout=subprocess.PIPE)
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
57 stdout, _ = p.communicate()
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
58 m = re.match(r'.*\[(.*)\].*', stdout)
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
59 if not m:
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
60 raise unittest.SkipTest("Unable to parse output from gdb.Frame.select test")
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
61 gdb_frame_dir = m.group(1).split(', ')
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
62 return "'select'" in gdb_frame_dir
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
63
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
64 HAS_PYUP_PYDOWN = gdb_has_frame_select()
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
65
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
66 class DebuggerTests(unittest.TestCase):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
67
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
68 """Test that the debugger can debug Python."""
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
69
75104
a0b663935b45 fix test_gdb under hash randomization
Benjamin Peterson <benjamin@python.org>
parents: 74078
diff changeset
70 def run_gdb(self, *args, **env_vars):
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
71 """Runs gdb with the command line given by *args.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
72
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
73 Returns its stdout, stderr
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
74 """
75104
a0b663935b45 fix test_gdb under hash randomization
Benjamin Peterson <benjamin@python.org>
parents: 74078
diff changeset
75 if env_vars:
a0b663935b45 fix test_gdb under hash randomization
Benjamin Peterson <benjamin@python.org>
parents: 74078
diff changeset
76 env = os.environ.copy()
a0b663935b45 fix test_gdb under hash randomization
Benjamin Peterson <benjamin@python.org>
parents: 74078
diff changeset
77 env.update(env_vars)
a0b663935b45 fix test_gdb under hash randomization
Benjamin Peterson <benjamin@python.org>
parents: 74078
diff changeset
78 else:
a0b663935b45 fix test_gdb under hash randomization
Benjamin Peterson <benjamin@python.org>
parents: 74078
diff changeset
79 env = None
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
80 out, err = subprocess.Popen(
75104
a0b663935b45 fix test_gdb under hash randomization
Benjamin Peterson <benjamin@python.org>
parents: 74078
diff changeset
81 args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
82 ).communicate()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
83 return out, err
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
84
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
85 def get_stack_trace(self, source=None, script=None,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
86 breakpoint='PyObject_Print',
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
87 cmds_after_breakpoint=None,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
88 import_site=False):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
89 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
90 Run 'python -c SOURCE' under gdb with a breakpoint.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
91
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
92 Support injecting commands after the breakpoint is reached
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
93
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
94 Returns the stdout from gdb
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
95
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
96 cmds_after_breakpoint: if provided, a list of strings: gdb commands
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
97 '''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
98 # We use "set breakpoint pending yes" to avoid blocking with a:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
99 # Function "foo" not defined.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
100 # Make breakpoint pending on future shared library load? (y or [n])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
101 # error, which typically happens python is dynamically linked (the
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
102 # breakpoints of interest are to be found in the shared library)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
103 # When this happens, we still get:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
104 # Function "PyObject_Print" not defined.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
105 # emitted to stderr each time, alas.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
106
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
107 # Initially I had "--eval-command=continue" here, but removed it to
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
108 # avoid repeated print breakpoints when traversing hierarchical data
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
109 # structures
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
110
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
111 # Generate a list of commands in gdb's language:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
112 commands = ['set breakpoint pending yes',
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
113 'break %s' % breakpoint,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
114 'run']
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
115 if cmds_after_breakpoint:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
116 commands += cmds_after_breakpoint
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
117 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
118 commands += ['backtrace']
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
119
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
120 # print commands
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
121
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
122 # Use "commands" to generate the arguments with which to invoke "gdb":
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
123 args = ["gdb", "--batch"]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
124 args += ['--eval-command=%s' % cmd for cmd in commands]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
125 args += ["--args",
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
126 sys.executable]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
127
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
128 if not import_site:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
129 # -S suppresses the default 'import site'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
130 args += ["-S"]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
131
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
132 if source:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
133 args += ["-c", source]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
134 elif script:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
135 args += [script]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
136
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
137 # print args
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
138 # print ' '.join(args)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
139
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
140 # Use "args" to invoke gdb, capturing stdout, stderr:
75104
a0b663935b45 fix test_gdb under hash randomization
Benjamin Peterson <benjamin@python.org>
parents: 74078
diff changeset
141 out, err = self.run_gdb(*args, PYTHONHASHSEED='0')
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
142
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
143 # Ignore some noise on stderr due to the pending breakpoint:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
144 err = err.replace('Function "%s" not defined.\n' % breakpoint, '')
61256
33ac109de0cc Issue #8600: fix test_gdb failures when gdb issues some spurious warnings.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60791
diff changeset
145 # Ignore some other noise on stderr (http://bugs.python.org/issue8600)
33ac109de0cc Issue #8600: fix test_gdb failures when gdb issues some spurious warnings.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60791
diff changeset
146 err = err.replace("warning: Unable to find libthread_db matching"
33ac109de0cc Issue #8600: fix test_gdb failures when gdb issues some spurious warnings.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60791
diff changeset
147 " inferior's thread library, thread debugging will"
33ac109de0cc Issue #8600: fix test_gdb failures when gdb issues some spurious warnings.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60791
diff changeset
148 " not be available.\n",
33ac109de0cc Issue #8600: fix test_gdb failures when gdb issues some spurious warnings.
Antoine Pitrou <solipsis@pitrou.net>
parents: 60791
diff changeset
149 '')
68577
93053ce76075 Close issue #8600: test_gdb failures because innocuous warnings
Jesus Cea <jcea@jcea.es>
parents: 66348
diff changeset
150 err = err.replace("warning: Cannot initialize thread debugging"
93053ce76075 Close issue #8600: test_gdb failures because innocuous warnings
Jesus Cea <jcea@jcea.es>
parents: 66348
diff changeset
151 " library: Debugger service failed\n",
93053ce76075 Close issue #8600: test_gdb failures because innocuous warnings
Jesus Cea <jcea@jcea.es>
parents: 66348
diff changeset
152 '')
79079
3d170d1e2fa3 remove gdb noise about linux-vdso
Benjamin Peterson <benjamin@python.org>
parents: 77488
diff changeset
153 err = err.replace('warning: Could not load shared library symbols for '
3d170d1e2fa3 remove gdb noise about linux-vdso
Benjamin Peterson <benjamin@python.org>
parents: 77488
diff changeset
154 'linux-vdso.so.1.\n'
3d170d1e2fa3 remove gdb noise about linux-vdso
Benjamin Peterson <benjamin@python.org>
parents: 77488
diff changeset
155 'Do you need "set solib-search-path" or '
3d170d1e2fa3 remove gdb noise about linux-vdso
Benjamin Peterson <benjamin@python.org>
parents: 77488
diff changeset
156 '"set sysroot"?\n',
3d170d1e2fa3 remove gdb noise about linux-vdso
Benjamin Peterson <benjamin@python.org>
parents: 77488
diff changeset
157 '')
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
158
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
159 # Ensure no unexpected error messages:
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
160 self.assertEqual(err, '')
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
161
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
162 return out
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
163
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
164 def get_gdb_repr(self, source,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
165 cmds_after_breakpoint=None,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
166 import_site=False):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
167 # Given an input python source representation of data,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
168 # run "python -c'print DATA'" under gdb with a breakpoint on
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
169 # PyObject_Print and scrape out gdb's representation of the "op"
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
170 # parameter, and verify that the gdb displays the same string
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
171 #
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
172 # For a nested structure, the first time we hit the breakpoint will
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
173 # give us the top-level structure
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
174 gdb_output = self.get_stack_trace(source, breakpoint='PyObject_Print',
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
175 cmds_after_breakpoint=cmds_after_breakpoint,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
176 import_site=import_site)
60363
7f2d7bfb0567 Issue 8316: make test_gdb robust in the face of differing terminal
R. David Murray <rdmurray@bitdance.com>
parents: 60125
diff changeset
177 # gdb can insert additional '\n' and space characters in various places
7f2d7bfb0567 Issue 8316: make test_gdb robust in the face of differing terminal
R. David Murray <rdmurray@bitdance.com>
parents: 60125
diff changeset
178 # in its output, depending on the width of the terminal it's connected
7f2d7bfb0567 Issue 8316: make test_gdb robust in the face of differing terminal
R. David Murray <rdmurray@bitdance.com>
parents: 60125
diff changeset
179 # to (using its "wrap_here" function)
7f2d7bfb0567 Issue 8316: make test_gdb robust in the face of differing terminal
R. David Murray <rdmurray@bitdance.com>
parents: 60125
diff changeset
180 m = re.match('.*#0\s+PyObject_Print\s+\(\s*op\=\s*(.*?),\s+fp=.*\).*',
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
181 gdb_output, re.DOTALL)
60363
7f2d7bfb0567 Issue 8316: make test_gdb robust in the face of differing terminal
R. David Murray <rdmurray@bitdance.com>
parents: 60125
diff changeset
182 if not m:
7f2d7bfb0567 Issue 8316: make test_gdb robust in the face of differing terminal
R. David Murray <rdmurray@bitdance.com>
parents: 60125
diff changeset
183 self.fail('Unexpected gdb output: %r\n%s' % (gdb_output, gdb_output))
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
184 return m.group(1), gdb_output
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
185
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
186 def assertEndsWith(self, actual, exp_end):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
187 '''Ensure that the given "actual" string ends with "exp_end"'''
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
188 self.assertTrue(actual.endswith(exp_end),
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
189 msg='%r did not end with %r' % (actual, exp_end))
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
190
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
191 def assertMultilineMatches(self, actual, pattern):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
192 m = re.match(pattern, actual, re.DOTALL)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
193 self.assertTrue(m, msg='%r did not match %r' % (actual, pattern))
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
194
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
195 def get_sample_script(self):
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
196 return findfile('gdb_sample.py')
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
197
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
198 class PrettyPrintTests(DebuggerTests):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
199 def test_getting_backtrace(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
200 gdb_output = self.get_stack_trace('print 42')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
201 self.assertTrue('PyObject_Print' in gdb_output)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
202
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
203 def assertGdbRepr(self, val, cmds_after_breakpoint=None):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
204 # Ensure that gdb's rendering of the value in a debugged process
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
205 # matches repr(value) in this process:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
206 gdb_repr, gdb_output = self.get_gdb_repr('print ' + repr(val),
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
207 cmds_after_breakpoint)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
208 self.assertEqual(gdb_repr, repr(val), gdb_output)
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
209
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
210 def test_int(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
211 'Verify the pretty-printing of various "int" values'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
212 self.assertGdbRepr(42)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
213 self.assertGdbRepr(0)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
214 self.assertGdbRepr(-7)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
215 self.assertGdbRepr(sys.maxint)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
216 self.assertGdbRepr(-sys.maxint)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
217
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
218 def test_long(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
219 'Verify the pretty-printing of various "long" values'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
220 self.assertGdbRepr(0L)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
221 self.assertGdbRepr(1000000000000L)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
222 self.assertGdbRepr(-1L)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
223 self.assertGdbRepr(-1000000000000000L)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
224
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
225 def test_singletons(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
226 'Verify the pretty-printing of True, False and None'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
227 self.assertGdbRepr(True)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
228 self.assertGdbRepr(False)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
229 self.assertGdbRepr(None)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
230
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
231 def test_dicts(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
232 'Verify the pretty-printing of dictionaries'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
233 self.assertGdbRepr({})
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
234 self.assertGdbRepr({'foo': 'bar'})
75104
a0b663935b45 fix test_gdb under hash randomization
Benjamin Peterson <benjamin@python.org>
parents: 74078
diff changeset
235 self.assertGdbRepr("{'foo': 'bar', 'douglas':42}")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
236
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
237 def test_lists(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
238 'Verify the pretty-printing of lists'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
239 self.assertGdbRepr([])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
240 self.assertGdbRepr(range(5))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
241
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
242 def test_strings(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
243 'Verify the pretty-printing of strings'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
244 self.assertGdbRepr('')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
245 self.assertGdbRepr('And now for something hopefully the same')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
246 self.assertGdbRepr('string with embedded NUL here \0 and then some more text')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
247 self.assertGdbRepr('this is byte 255:\xff and byte 128:\x80')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
248
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
249 def test_tuples(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
250 'Verify the pretty-printing of tuples'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
251 self.assertGdbRepr(tuple())
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
252 self.assertGdbRepr((1,))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
253 self.assertGdbRepr(('foo', 'bar', 'baz'))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
254
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
255 def test_unicode(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
256 'Verify the pretty-printing of unicode values'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
257 # Test the empty unicode string:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
258 self.assertGdbRepr(u'')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
259
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
260 self.assertGdbRepr(u'hello world')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
261
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
262 # Test printing a single character:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
263 # U+2620 SKULL AND CROSSBONES
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
264 self.assertGdbRepr(u'\u2620')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
265
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
266 # Test printing a Japanese unicode string
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
267 # (I believe this reads "mojibake", using 3 characters from the CJK
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
268 # Unified Ideographs area, followed by U+3051 HIRAGANA LETTER KE)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
269 self.assertGdbRepr(u'\u6587\u5b57\u5316\u3051')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
270
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
271 # Test a character outside the BMP:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
272 # U+1D121 MUSICAL SYMBOL C CLEF
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
273 # This is:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
274 # UTF-8: 0xF0 0x9D 0x84 0xA1
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
275 # UTF-16: 0xD834 0xDD21
61770
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61256
diff changeset
276 # This will only work on wide-unicode builds:
5d6b76890f17 libpython.py: fix support of non-BMP unicode characters
Victor Stinner <victor.stinner@haypocalc.com>
parents: 61256
diff changeset
277 self.assertGdbRepr(u"\U0001D121")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
278
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
279 def test_sets(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
280 'Verify the pretty-printing of sets'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
281 self.assertGdbRepr(set())
75123
51c417a7e8f8 carefully don't depend on any dict order
Benjamin Peterson <benjamin@python.org>
parents: 75104
diff changeset
282 rep = self.get_gdb_repr("print set(['a', 'b'])")[0]
51c417a7e8f8 carefully don't depend on any dict order
Benjamin Peterson <benjamin@python.org>
parents: 75104
diff changeset
283 self.assertTrue(rep.startswith("set(["))
51c417a7e8f8 carefully don't depend on any dict order
Benjamin Peterson <benjamin@python.org>
parents: 75104
diff changeset
284 self.assertTrue(rep.endswith("])"))
51c417a7e8f8 carefully don't depend on any dict order
Benjamin Peterson <benjamin@python.org>
parents: 75104
diff changeset
285 self.assertEqual(eval(rep), {'a', 'b'})
51c417a7e8f8 carefully don't depend on any dict order
Benjamin Peterson <benjamin@python.org>
parents: 75104
diff changeset
286 rep = self.get_gdb_repr("print set([4, 5])")[0]
51c417a7e8f8 carefully don't depend on any dict order
Benjamin Peterson <benjamin@python.org>
parents: 75104
diff changeset
287 self.assertTrue(rep.startswith("set(["))
51c417a7e8f8 carefully don't depend on any dict order
Benjamin Peterson <benjamin@python.org>
parents: 75104
diff changeset
288 self.assertTrue(rep.endswith("])"))
51c417a7e8f8 carefully don't depend on any dict order
Benjamin Peterson <benjamin@python.org>
parents: 75104
diff changeset
289 self.assertEqual(eval(rep), {4, 5})
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
290
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
291 # Ensure that we handled sets containing the "dummy" key value,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
292 # which happens on deletion:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
293 gdb_repr, gdb_output = self.get_gdb_repr('''s = set(['a','b'])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
294 s.pop()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
295 print s''')
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
296 self.assertEqual(gdb_repr, "set(['b'])")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
297
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
298 def test_frozensets(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
299 'Verify the pretty-printing of frozensets'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
300 self.assertGdbRepr(frozenset())
75123
51c417a7e8f8 carefully don't depend on any dict order
Benjamin Peterson <benjamin@python.org>
parents: 75104
diff changeset
301 rep = self.get_gdb_repr("print frozenset(['a', 'b'])")[0]
51c417a7e8f8 carefully don't depend on any dict order
Benjamin Peterson <benjamin@python.org>
parents: 75104
diff changeset
302 self.assertTrue(rep.startswith("frozenset(["))
51c417a7e8f8 carefully don't depend on any dict order
Benjamin Peterson <benjamin@python.org>
parents: 75104
diff changeset
303 self.assertTrue(rep.endswith("])"))
51c417a7e8f8 carefully don't depend on any dict order
Benjamin Peterson <benjamin@python.org>
parents: 75104
diff changeset
304 self.assertEqual(eval(rep), {'a', 'b'})
51c417a7e8f8 carefully don't depend on any dict order
Benjamin Peterson <benjamin@python.org>
parents: 75104
diff changeset
305 rep = self.get_gdb_repr("print frozenset([4, 5])")[0]
51c417a7e8f8 carefully don't depend on any dict order
Benjamin Peterson <benjamin@python.org>
parents: 75104
diff changeset
306 self.assertTrue(rep.startswith("frozenset(["))
51c417a7e8f8 carefully don't depend on any dict order
Benjamin Peterson <benjamin@python.org>
parents: 75104
diff changeset
307 self.assertTrue(rep.endswith("])"))
51c417a7e8f8 carefully don't depend on any dict order
Benjamin Peterson <benjamin@python.org>
parents: 75104
diff changeset
308 self.assertEqual(eval(rep), {4, 5})
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
309
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
310 def test_exceptions(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
311 # Test a RuntimeError
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
312 gdb_repr, gdb_output = self.get_gdb_repr('''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
313 try:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
314 raise RuntimeError("I am an error")
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
315 except RuntimeError, e:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
316 print e
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
317 ''')
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
318 self.assertEqual(gdb_repr,
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
319 "exceptions.RuntimeError('I am an error',)")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
320
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
321
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
322 # Test division by zero:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
323 gdb_repr, gdb_output = self.get_gdb_repr('''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
324 try:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
325 a = 1 / 0
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
326 except ZeroDivisionError, e:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
327 print e
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
328 ''')
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
329 self.assertEqual(gdb_repr,
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
330 "exceptions.ZeroDivisionError('integer division or modulo by zero',)")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
331
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
332 def test_classic_class(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
333 'Verify the pretty-printing of classic class instances'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
334 gdb_repr, gdb_output = self.get_gdb_repr('''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
335 class Foo:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
336 pass
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
337 foo = Foo()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
338 foo.an_int = 42
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
339 print foo''')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
340 m = re.match(r'<Foo\(an_int=42\) at remote 0x[0-9a-f]+>', gdb_repr)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
341 self.assertTrue(m,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
342 msg='Unexpected classic-class rendering %r' % gdb_repr)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
343
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
344 def test_modern_class(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
345 'Verify the pretty-printing of new-style class instances'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
346 gdb_repr, gdb_output = self.get_gdb_repr('''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
347 class Foo(object):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
348 pass
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
349 foo = Foo()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
350 foo.an_int = 42
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
351 print foo''')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
352 m = re.match(r'<Foo\(an_int=42\) at remote 0x[0-9a-f]+>', gdb_repr)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
353 self.assertTrue(m,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
354 msg='Unexpected new-style class rendering %r' % gdb_repr)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
355
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
356 def test_subclassing_list(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
357 'Verify the pretty-printing of an instance of a list subclass'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
358 gdb_repr, gdb_output = self.get_gdb_repr('''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
359 class Foo(list):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
360 pass
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
361 foo = Foo()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
362 foo += [1, 2, 3]
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
363 foo.an_int = 42
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
364 print foo''')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
365 m = re.match(r'<Foo\(an_int=42\) at remote 0x[0-9a-f]+>', gdb_repr)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
366 self.assertTrue(m,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
367 msg='Unexpected new-style class rendering %r' % gdb_repr)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
368
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
369 def test_subclassing_tuple(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
370 'Verify the pretty-printing of an instance of a tuple subclass'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
371 # This should exercise the negative tp_dictoffset code in the
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
372 # new-style class support
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
373 gdb_repr, gdb_output = self.get_gdb_repr('''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
374 class Foo(tuple):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
375 pass
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
376 foo = Foo((1, 2, 3))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
377 foo.an_int = 42
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
378 print foo''')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
379 m = re.match(r'<Foo\(an_int=42\) at remote 0x[0-9a-f]+>', gdb_repr)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
380 self.assertTrue(m,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
381 msg='Unexpected new-style class rendering %r' % gdb_repr)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
382
60534
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
383 def assertSane(self, source, corruption, expvalue=None, exptype=None):
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
384 '''Run Python under gdb, corrupting variables in the inferior process
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
385 immediately before taking a backtrace.
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
386
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
387 Verify that the variable's representation is the expected failsafe
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
388 representation'''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
389 if corruption:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
390 cmds_after_breakpoint=[corruption, 'backtrace']
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
391 else:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
392 cmds_after_breakpoint=['backtrace']
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
393
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
394 gdb_repr, gdb_output = \
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
395 self.get_gdb_repr(source,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
396 cmds_after_breakpoint=cmds_after_breakpoint)
60534
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
397
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
398 if expvalue:
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
399 if gdb_repr == repr(expvalue):
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
400 # gdb managed to print the value in spite of the corruption;
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
401 # this is good (see http://bugs.python.org/issue8330)
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
402 return
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
403
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
404 if exptype:
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
405 pattern = '<' + exptype + ' at remote 0x[0-9a-f]+>'
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
406 else:
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
407 # Match anything for the type name; 0xDEADBEEF could point to
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
408 # something arbitrary (see http://bugs.python.org/issue8330)
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
409 pattern = '<.* at remote 0x[0-9a-f]+>'
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
410
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
411 m = re.match(pattern, gdb_repr)
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
412 if not m:
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
413 self.fail('Unexpected gdb representation: %r\n%s' % \
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
414 (gdb_repr, gdb_output))
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
415
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
416 def test_NULL_ptr(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
417 'Ensure that a NULL PyObject* is handled gracefully'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
418 gdb_repr, gdb_output = (
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
419 self.get_gdb_repr('print 42',
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
420 cmds_after_breakpoint=['set variable op=0',
60363
7f2d7bfb0567 Issue 8316: make test_gdb robust in the face of differing terminal
R. David Murray <rdmurray@bitdance.com>
parents: 60125
diff changeset
421 'backtrace'])
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
422 )
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
423
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
424 self.assertEqual(gdb_repr, '0x0')
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
425
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
426 def test_NULL_ob_type(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
427 'Ensure that a PyObject* with NULL ob_type is handled gracefully'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
428 self.assertSane('print 42',
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
429 'set op->ob_type=0')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
430
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
431 def test_corrupt_ob_type(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
432 'Ensure that a PyObject* with a corrupt ob_type is handled gracefully'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
433 self.assertSane('print 42',
60534
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
434 'set op->ob_type=0xDEADBEEF',
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
435 expvalue=42)
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
436
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
437 def test_corrupt_tp_flags(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
438 'Ensure that a PyObject* with a type with corrupt tp_flags is handled'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
439 self.assertSane('print 42',
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
440 'set op->ob_type->tp_flags=0x0',
60534
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
441 expvalue=42)
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
442
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
443 def test_corrupt_tp_name(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
444 'Ensure that a PyObject* with a type with corrupt tp_name is handled'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
445 self.assertSane('print 42',
60534
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
446 'set op->ob_type->tp_name=0xDEADBEEF',
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
447 expvalue=42)
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
448
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
449 def test_NULL_instance_dict(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
450 'Ensure that a PyInstanceObject with with a NULL in_dict is handled'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
451 self.assertSane('''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
452 class Foo:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
453 pass
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
454 foo = Foo()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
455 foo.an_int = 42
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
456 print foo''',
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
457 'set ((PyInstanceObject*)op)->in_dict = 0',
60534
e475b771dd4c Issue #8330: Fix expected output in test_gdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 60450
diff changeset
458 exptype='Foo')
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
459
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
460 def test_builtins_help(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
461 'Ensure that the new-style class _Helper in site.py can be handled'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
462 # (this was the issue causing tracebacks in
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
463 # http://bugs.python.org/issue8032#msg100537 )
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
464
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
465 gdb_repr, gdb_output = self.get_gdb_repr('print __builtins__.help', import_site=True)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
466 m = re.match(r'<_Helper at remote 0x[0-9a-f]+>', gdb_repr)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
467 self.assertTrue(m,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
468 msg='Unexpected rendering %r' % gdb_repr)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
469
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
470 def test_selfreferential_list(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
471 '''Ensure that a reference loop involving a list doesn't lead proxyval
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
472 into an infinite loop:'''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
473 gdb_repr, gdb_output = \
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
474 self.get_gdb_repr("a = [3, 4, 5] ; a.append(a) ; print a")
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
475
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
476 self.assertEqual(gdb_repr, '[3, 4, 5, [...]]')
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
477
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
478 gdb_repr, gdb_output = \
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
479 self.get_gdb_repr("a = [3, 4, 5] ; b = [a] ; a.append(b) ; print a")
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
480
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
481 self.assertEqual(gdb_repr, '[3, 4, 5, [[...]]]')
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
482
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
483 def test_selfreferential_dict(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
484 '''Ensure that a reference loop involving a dict doesn't lead proxyval
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
485 into an infinite loop:'''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
486 gdb_repr, gdb_output = \
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
487 self.get_gdb_repr("a = {} ; b = {'bar':a} ; a['foo'] = b ; print a")
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
488
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
489 self.assertEqual(gdb_repr, "{'foo': {'bar': {...}}}")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
490
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
491 def test_selfreferential_old_style_instance(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
492 gdb_repr, gdb_output = \
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
493 self.get_gdb_repr('''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
494 class Foo:
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
495 pass
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
496 foo = Foo()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
497 foo.an_attr = foo
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
498 print foo''')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
499 self.assertTrue(re.match('<Foo\(an_attr=<\.\.\.>\) at remote 0x[0-9a-f]+>',
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
500 gdb_repr),
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
501 'Unexpected gdb representation: %r\n%s' % \
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
502 (gdb_repr, gdb_output))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
503
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
504 def test_selfreferential_new_style_instance(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
505 gdb_repr, gdb_output = \
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
506 self.get_gdb_repr('''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
507 class Foo(object):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
508 pass
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
509 foo = Foo()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
510 foo.an_attr = foo
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
511 print foo''')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
512 self.assertTrue(re.match('<Foo\(an_attr=<\.\.\.>\) at remote 0x[0-9a-f]+>',
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
513 gdb_repr),
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
514 'Unexpected gdb representation: %r\n%s' % \
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
515 (gdb_repr, gdb_output))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
516
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
517 gdb_repr, gdb_output = \
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
518 self.get_gdb_repr('''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
519 class Foo(object):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
520 pass
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
521 a = Foo()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
522 b = Foo()
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
523 a.an_attr = b
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
524 b.an_attr = a
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
525 print a''')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
526 self.assertTrue(re.match('<Foo\(an_attr=<Foo\(an_attr=<\.\.\.>\) at remote 0x[0-9a-f]+>\) at remote 0x[0-9a-f]+>',
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
527 gdb_repr),
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
528 'Unexpected gdb representation: %r\n%s' % \
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
529 (gdb_repr, gdb_output))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
530
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
531 def test_truncation(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
532 'Verify that very long output is truncated'
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
533 gdb_repr, gdb_output = self.get_gdb_repr('print range(1000)')
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
534 self.assertEqual(gdb_repr,
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
535 "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
536 "14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
537 "27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
538 "40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
539 "53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
540 "66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
541 "79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
542 "92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
543 "104, 105, 106, 107, 108, 109, 110, 111, 112, 113, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
544 "114, 115, 116, 117, 118, 119, 120, 121, 122, 123, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
545 "124, 125, 126, 127, 128, 129, 130, 131, 132, 133, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
546 "134, 135, 136, 137, 138, 139, 140, 141, 142, 143, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
547 "144, 145, 146, 147, 148, 149, 150, 151, 152, 153, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
548 "154, 155, 156, 157, 158, 159, 160, 161, 162, 163, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
549 "164, 165, 166, 167, 168, 169, 170, 171, 172, 173, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
550 "174, 175, 176, 177, 178, 179, 180, 181, 182, 183, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
551 "184, 185, 186, 187, 188, 189, 190, 191, 192, 193, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
552 "194, 195, 196, 197, 198, 199, 200, 201, 202, 203, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
553 "204, 205, 206, 207, 208, 209, 210, 211, 212, 213, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
554 "214, 215, 216, 217, 218, 219, 220, 221, 222, 223, "
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
555 "224, 225, 226...(truncated)")
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
556 self.assertEqual(len(gdb_repr),
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
557 1024 + len('...(truncated)'))
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
558
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
559 def test_builtin_function(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
560 gdb_repr, gdb_output = self.get_gdb_repr('print len')
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 62863
diff changeset
561 self.assertEqual(gdb_repr, '<built-in function len>')
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
562
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
563 def test_builtin_method(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
564 gdb_repr, gdb_output = self.get_gdb_repr('import sys; print sys.stdout.readlines')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
565 self.assertTrue(re.match('<built-in method readlines of file object at remote 0x[0-9a-f]+>',
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
566 gdb_repr),
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
567 'Unexpected gdb representation: %r\n%s' % \
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
568 (gdb_repr, gdb_output))
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
569
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
570 def test_frames(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
571 gdb_output = self.get_stack_trace('''
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
572 def foo(a, b, c):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
573 pass
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
574
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
575 foo(3, 4, 5)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
576 print foo.__code__''',
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
577 breakpoint='PyObject_Print',
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
578 cmds_after_breakpoint=['print (PyFrameObject*)(((PyCodeObject*)op)->co_zombieframe)']
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
579 )
60363
7f2d7bfb0567 Issue 8316: make test_gdb robust in the face of differing terminal
R. David Murray <rdmurray@bitdance.com>
parents: 60125
diff changeset
580 self.assertTrue(re.match(r'.*\s+\$1 =\s+Frame 0x[0-9a-f]+, for file <string>, line 3, in foo \(\)\s+.*',
7f2d7bfb0567 Issue 8316: make test_gdb robust in the face of differing terminal
R. David Murray <rdmurray@bitdance.com>
parents: 60125
diff changeset
581 gdb_output,
7f2d7bfb0567 Issue 8316: make test_gdb robust in the face of differing terminal
R. David Murray <rdmurray@bitdance.com>
parents: 60125
diff changeset
582 re.DOTALL),
7f2d7bfb0567 Issue 8316: make test_gdb robust in the face of differing terminal
R. David Murray <rdmurray@bitdance.com>
parents: 60125
diff changeset
583 'Unexpected gdb representation: %r\n%s' % (gdb_output, gdb_output))
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
584
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
585 @unittest.skipIf(python_is_optimized(),
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
586 "Python was compiled with optimizations")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
587 class PyListTests(DebuggerTests):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
588 def assertListing(self, expected, actual):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
589 self.assertEndsWith(actual, expected)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
590
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
591 def test_basic_command(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
592 'Verify that the "py-list" command works'
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
593 bt = self.get_stack_trace(script=self.get_sample_script(),
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
594 cmds_after_breakpoint=['py-list'])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
595
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
596 self.assertListing(' 5 \n'
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
597 ' 6 def bar(a, b, c):\n'
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
598 ' 7 baz(a, b, c)\n'
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
599 ' 8 \n'
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
600 ' 9 def baz(*args):\n'
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
601 ' >10 print(42)\n'
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
602 ' 11 \n'
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
603 ' 12 foo(1, 2, 3)\n',
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
604 bt)
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
605
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
606 def test_one_abs_arg(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
607 'Verify the "py-list" command with one absolute argument'
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
608 bt = self.get_stack_trace(script=self.get_sample_script(),
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
609 cmds_after_breakpoint=['py-list 9'])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
610
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
611 self.assertListing(' 9 def baz(*args):\n'
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
612 ' >10 print(42)\n'
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
613 ' 11 \n'
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
614 ' 12 foo(1, 2, 3)\n',
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
615 bt)
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
616
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
617 def test_two_abs_args(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
618 'Verify the "py-list" command with two absolute arguments'
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
619 bt = self.get_stack_trace(script=self.get_sample_script(),
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
620 cmds_after_breakpoint=['py-list 1,3'])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
621
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
622 self.assertListing(' 1 # Sample script for use by test_gdb.py\n'
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
623 ' 2 \n'
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
624 ' 3 def foo(a, b, c):\n',
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
625 bt)
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
626
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
627 class StackNavigationTests(DebuggerTests):
60791
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
628 @unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
629 @unittest.skipIf(python_is_optimized(),
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
630 "Python was compiled with optimizations")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
631 def test_pyup_command(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
632 'Verify that the "py-up" command works'
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
633 bt = self.get_stack_trace(script=self.get_sample_script(),
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
634 cmds_after_breakpoint=['py-up'])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
635 self.assertMultilineMatches(bt,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
636 r'''^.*
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
637 #[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\)
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
638 baz\(a, b, c\)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
639 $''')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
640
60791
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
641 @unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
642 def test_down_at_bottom(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
643 'Verify handling of "py-down" at the bottom of the stack'
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
644 bt = self.get_stack_trace(script=self.get_sample_script(),
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
645 cmds_after_breakpoint=['py-down'])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
646 self.assertEndsWith(bt,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
647 'Unable to find a newer python frame\n')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
648
60791
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
649 @unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
650 def test_up_at_top(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
651 'Verify handling of "py-up" at the top of the stack'
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
652 bt = self.get_stack_trace(script=self.get_sample_script(),
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
653 cmds_after_breakpoint=['py-up'] * 4)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
654 self.assertEndsWith(bt,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
655 'Unable to find an older python frame\n')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
656
60791
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
657 @unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
658 @unittest.skipIf(python_is_optimized(),
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
659 "Python was compiled with optimizations")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
660 def test_up_then_down(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
661 'Verify "py-up" followed by "py-down"'
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
662 bt = self.get_stack_trace(script=self.get_sample_script(),
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
663 cmds_after_breakpoint=['py-up', 'py-down'])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
664 self.assertMultilineMatches(bt,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
665 r'''^.*
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
666 #[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\)
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
667 baz\(a, b, c\)
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
668 #[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 10, in baz \(args=\(1, 2, 3\)\)
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
669 print\(42\)
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
670 $''')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
671
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
672 class PyBtTests(DebuggerTests):
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
673 @unittest.skipIf(python_is_optimized(),
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
674 "Python was compiled with optimizations")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
675 def test_basic_command(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
676 'Verify that the "py-bt" command works'
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
677 bt = self.get_stack_trace(script=self.get_sample_script(),
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
678 cmds_after_breakpoint=['py-bt'])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
679 self.assertMultilineMatches(bt,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
680 r'''^.*
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
681 #[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\)
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
682 baz\(a, b, c\)
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
683 #[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 4, in foo \(a=1, b=2, c=3\)
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
684 bar\(a, b, c\)
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
685 #[0-9]+ Frame 0x[0-9a-f]+, for file .*gdb_sample.py, line 12, in <module> \(\)
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
686 foo\(1, 2, 3\)
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
687 ''')
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
688
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
689 class PyPrintTests(DebuggerTests):
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
690 @unittest.skipIf(python_is_optimized(),
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
691 "Python was compiled with optimizations")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
692 def test_basic_command(self):
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
693 'Verify that the "py-print" command works'
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
694 bt = self.get_stack_trace(script=self.get_sample_script(),
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
695 cmds_after_breakpoint=['py-print args'])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
696 self.assertMultilineMatches(bt,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
697 r".*\nlocal 'args' = \(1, 2, 3\)\n.*")
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
698
60791
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
699 @unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
700 @unittest.skipIf(python_is_optimized(),
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
701 "Python was compiled with optimizations")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
702 def test_print_after_up(self):
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
703 bt = self.get_stack_trace(script=self.get_sample_script(),
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
704 cmds_after_breakpoint=['py-up', 'py-print c', 'py-print b', 'py-print a'])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
705 self.assertMultilineMatches(bt,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
706 r".*\nlocal 'c' = 3\nlocal 'b' = 2\nlocal 'a' = 1\n.*")
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
707
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
708 @unittest.skipIf(python_is_optimized(),
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
709 "Python was compiled with optimizations")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
710 def test_printing_global(self):
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
711 bt = self.get_stack_trace(script=self.get_sample_script(),
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
712 cmds_after_breakpoint=['py-print __name__'])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
713 self.assertMultilineMatches(bt,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
714 r".*\nglobal '__name__' = '__main__'\n.*")
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
715
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
716 @unittest.skipIf(python_is_optimized(),
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
717 "Python was compiled with optimizations")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
718 def test_printing_builtin(self):
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
719 bt = self.get_stack_trace(script=self.get_sample_script(),
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
720 cmds_after_breakpoint=['py-print len'])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
721 self.assertMultilineMatches(bt,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
722 r".*\nbuiltin 'len' = <built-in function len>\n.*")
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
723
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
724 class PyLocalsTests(DebuggerTests):
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
725 @unittest.skipIf(python_is_optimized(),
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
726 "Python was compiled with optimizations")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
727 def test_basic_command(self):
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
728 bt = self.get_stack_trace(script=self.get_sample_script(),
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
729 cmds_after_breakpoint=['py-locals'])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
730 self.assertMultilineMatches(bt,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
731 r".*\nargs = \(1, 2, 3\)\n.*")
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
732
60791
86d08cb6ba5c Issue #8437: Fix test_gdb failures, patch written by Dave Malcolm
Victor Stinner <victor.stinner@haypocalc.com>
parents: 60664
diff changeset
733 @unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
74078
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
734 @unittest.skipIf(python_is_optimized(),
1cc8e9565339 Issue #13628: python-gdb.py is now able to retrieve more frames in the Python
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68577
diff changeset
735 "Python was compiled with optimizations")
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
736 def test_locals_after_up(self):
60664
d7d5c76545fb Issue #8279: Fix test_gdb failures.
Martin v. Löwis <martin@v.loewis.de>
parents: 60535
diff changeset
737 bt = self.get_stack_trace(script=self.get_sample_script(),
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
738 cmds_after_breakpoint=['py-up', 'py-locals'])
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
739 self.assertMultilineMatches(bt,
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
740 r".*\na = 1\nb = 2\nc = 3\n.*")
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
741
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
742 def test_main():
60535
2ae5f60e27c9 Re-enable all tests, to see which ones fail on the buildbots.
Martin v. Löwis <martin@v.loewis.de>
parents: 60534
diff changeset
743 run_unittest(PrettyPrintTests,
2ae5f60e27c9 Re-enable all tests, to see which ones fail on the buildbots.
Martin v. Löwis <martin@v.loewis.de>
parents: 60534
diff changeset
744 PyListTests,
2ae5f60e27c9 Re-enable all tests, to see which ones fail on the buildbots.
Martin v. Löwis <martin@v.loewis.de>
parents: 60534
diff changeset
745 StackNavigationTests,
2ae5f60e27c9 Re-enable all tests, to see which ones fail on the buildbots.
Martin v. Löwis <martin@v.loewis.de>
parents: 60534
diff changeset
746 PyBtTests,
2ae5f60e27c9 Re-enable all tests, to see which ones fail on the buildbots.
Martin v. Löwis <martin@v.loewis.de>
parents: 60534
diff changeset
747 PyPrintTests,
2ae5f60e27c9 Re-enable all tests, to see which ones fail on the buildbots.
Martin v. Löwis <martin@v.loewis.de>
parents: 60534
diff changeset
748 PyLocalsTests
60125
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
749 )
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
750
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
751 if __name__ == "__main__":
6de3de3ab71f Issue #8032: For gdb7, a python-gdb.py file is added to the build,
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
752 test_main()