Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 1 | # Verify that gdb can pretty-print the various PyObject* types |
| 2 | # |
| 3 | # The code for testing gdb was adapted from similar work in Unladen Swallow's |
| 4 | # Lib/test/test_jit_gdb.py |
| 5 | |
| 6 | import os |
| 7 | import re |
Antoine Pitrou | d0f3e07 | 2013-09-21 23:56:17 +0200 | [diff] [blame] | 8 | import pprint |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 9 | import subprocess |
| 10 | import sys |
Vinay Sajip | f1b34ee | 2012-05-06 12:03:05 +0100 | [diff] [blame] | 11 | import sysconfig |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 12 | import unittest |
Victor Stinner | 150016f | 2010-05-19 23:04:56 +0000 | [diff] [blame] | 13 | import locale |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 14 | |
David Malcolm | 8d37ffa | 2012-06-27 14:15:34 -0400 | [diff] [blame] | 15 | # Is this Python configured to support threads? |
| 16 | try: |
| 17 | import _thread |
| 18 | except ImportError: |
| 19 | _thread = None |
| 20 | |
Antoine Pitrou | d0f3e07 | 2013-09-21 23:56:17 +0200 | [diff] [blame] | 21 | from test import support |
Benjamin Peterson | 65c66ab | 2010-10-29 21:31:35 +0000 | [diff] [blame] | 22 | from test.support import run_unittest, findfile, python_is_optimized |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 23 | |
| 24 | try: |
| 25 | gdb_version, _ = subprocess.Popen(["gdb", "--version"], |
| 26 | stdout=subprocess.PIPE).communicate() |
| 27 | except OSError: |
| 28 | # This is what "no gdb" looks like. There may, however, be other |
| 29 | # errors that manifest this way too. |
| 30 | raise unittest.SkipTest("Couldn't find gdb on the path") |
R David Murray | f933302 | 2012-10-27 13:22:41 -0400 | [diff] [blame] | 31 | gdb_version_number = re.search(b"^GNU gdb [^\d]*(\d+)\.(\d)", gdb_version) |
| 32 | gdb_major_version = int(gdb_version_number.group(1)) |
| 33 | gdb_minor_version = int(gdb_version_number.group(2)) |
| 34 | if gdb_major_version < 7: |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 35 | raise unittest.SkipTest("gdb versions before 7.0 didn't support python embedding" |
Antoine Pitrou | 6a45e9d | 2010-04-11 22:47:34 +0000 | [diff] [blame] | 36 | " Saw:\n" + gdb_version.decode('ascii', 'replace')) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 37 | |
Vinay Sajip | f1b34ee | 2012-05-06 12:03:05 +0100 | [diff] [blame] | 38 | if not sysconfig.is_python_build(): |
| 39 | raise unittest.SkipTest("test_gdb only works on source builds at the moment.") |
| 40 | |
R David Murray | f933302 | 2012-10-27 13:22:41 -0400 | [diff] [blame] | 41 | # Location of custom hooks file in a repository checkout. |
| 42 | checkout_hook_path = os.path.join(os.path.dirname(sys.executable), |
| 43 | 'python-gdb.py') |
| 44 | |
Victor Stinner | 5132493 | 2013-11-20 12:27:48 +0100 | [diff] [blame] | 45 | PYTHONHASHSEED = '123' |
| 46 | |
R David Murray | f933302 | 2012-10-27 13:22:41 -0400 | [diff] [blame] | 47 | def run_gdb(*args, **env_vars): |
| 48 | """Runs gdb in --batch mode with the additional arguments given by *args. |
| 49 | |
| 50 | Returns its (stdout, stderr) decoded from utf-8 using the replace handler. |
| 51 | """ |
| 52 | if env_vars: |
| 53 | env = os.environ.copy() |
| 54 | env.update(env_vars) |
| 55 | else: |
| 56 | env = None |
| 57 | base_cmd = ('gdb', '--batch') |
| 58 | if (gdb_major_version, gdb_minor_version) >= (7, 4): |
| 59 | base_cmd += ('-iex', 'add-auto-load-safe-path ' + checkout_hook_path) |
| 60 | out, err = subprocess.Popen(base_cmd + args, |
| 61 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, |
| 62 | ).communicate() |
| 63 | return out.decode('utf-8', 'replace'), err.decode('utf-8', 'replace') |
| 64 | |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 65 | # Verify that "gdb" was built with the embedded python support enabled: |
Antoine Pitrou | e50240c | 2013-11-23 17:40:36 +0100 | [diff] [blame] | 66 | gdbpy_version, _ = run_gdb("--eval-command=python import sys; print(sys.version_info)") |
R David Murray | f933302 | 2012-10-27 13:22:41 -0400 | [diff] [blame] | 67 | if not gdbpy_version: |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 68 | raise unittest.SkipTest("gdb not built with embedded python support") |
| 69 | |
Nick Coghlan | ce34687 | 2013-09-22 19:38:16 +1000 | [diff] [blame] | 70 | # Verify that "gdb" can load our custom hooks, as OS security settings may |
| 71 | # disallow this without a customised .gdbinit. |
R David Murray | f933302 | 2012-10-27 13:22:41 -0400 | [diff] [blame] | 72 | cmd = ['--args', sys.executable] |
| 73 | _, gdbpy_errors = run_gdb('--args', sys.executable) |
| 74 | if "auto-loading has been declined" in gdbpy_errors: |
| 75 | msg = "gdb security settings prevent use of custom hooks: " |
| 76 | raise unittest.SkipTest(msg + gdbpy_errors.rstrip()) |
Nick Coghlan | be4e4b5 | 2012-06-17 18:57:20 +1000 | [diff] [blame] | 77 | |
Victor Stinner | 50eb60e | 2010-04-20 22:32:07 +0000 | [diff] [blame] | 78 | def gdb_has_frame_select(): |
| 79 | # Does this build of gdb have gdb.Frame.select ? |
R David Murray | f933302 | 2012-10-27 13:22:41 -0400 | [diff] [blame] | 80 | stdout, _ = run_gdb("--eval-command=python print(dir(gdb.Frame))") |
| 81 | m = re.match(r'.*\[(.*)\].*', stdout) |
Victor Stinner | 50eb60e | 2010-04-20 22:32:07 +0000 | [diff] [blame] | 82 | if not m: |
| 83 | raise unittest.SkipTest("Unable to parse output from gdb.Frame.select test") |
R David Murray | f933302 | 2012-10-27 13:22:41 -0400 | [diff] [blame] | 84 | gdb_frame_dir = m.group(1).split(', ') |
| 85 | return "'select'" in gdb_frame_dir |
Victor Stinner | 50eb60e | 2010-04-20 22:32:07 +0000 | [diff] [blame] | 86 | |
| 87 | HAS_PYUP_PYDOWN = gdb_has_frame_select() |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 88 | |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 89 | BREAKPOINT_FN='builtin_id' |
| 90 | |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 91 | class DebuggerTests(unittest.TestCase): |
| 92 | |
| 93 | """Test that the debugger can debug Python.""" |
| 94 | |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 95 | def get_stack_trace(self, source=None, script=None, |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 96 | breakpoint=BREAKPOINT_FN, |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 97 | cmds_after_breakpoint=None, |
| 98 | import_site=False): |
| 99 | ''' |
| 100 | Run 'python -c SOURCE' under gdb with a breakpoint. |
| 101 | |
| 102 | Support injecting commands after the breakpoint is reached |
| 103 | |
| 104 | Returns the stdout from gdb |
| 105 | |
| 106 | cmds_after_breakpoint: if provided, a list of strings: gdb commands |
| 107 | ''' |
| 108 | # We use "set breakpoint pending yes" to avoid blocking with a: |
| 109 | # Function "foo" not defined. |
| 110 | # Make breakpoint pending on future shared library load? (y or [n]) |
| 111 | # error, which typically happens python is dynamically linked (the |
| 112 | # breakpoints of interest are to be found in the shared library) |
| 113 | # When this happens, we still get: |
Victor Stinner | 67df3a4 | 2010-04-21 13:53:05 +0000 | [diff] [blame] | 114 | # Function "textiowrapper_write" not defined. |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 115 | # emitted to stderr each time, alas. |
| 116 | |
| 117 | # Initially I had "--eval-command=continue" here, but removed it to |
| 118 | # avoid repeated print breakpoints when traversing hierarchical data |
| 119 | # structures |
| 120 | |
| 121 | # Generate a list of commands in gdb's language: |
| 122 | commands = ['set breakpoint pending yes', |
| 123 | 'break %s' % breakpoint, |
| 124 | 'run'] |
| 125 | if cmds_after_breakpoint: |
| 126 | commands += cmds_after_breakpoint |
| 127 | else: |
| 128 | commands += ['backtrace'] |
| 129 | |
| 130 | # print commands |
| 131 | |
| 132 | # Use "commands" to generate the arguments with which to invoke "gdb": |
| 133 | args = ["gdb", "--batch"] |
| 134 | args += ['--eval-command=%s' % cmd for cmd in commands] |
| 135 | args += ["--args", |
| 136 | sys.executable] |
| 137 | |
| 138 | if not import_site: |
| 139 | # -S suppresses the default 'import site' |
| 140 | args += ["-S"] |
| 141 | |
| 142 | if source: |
| 143 | args += ["-c", source] |
| 144 | elif script: |
| 145 | args += [script] |
| 146 | |
| 147 | # print args |
Antoine Pitrou | f6eb31f | 2013-11-24 14:58:17 +0100 | [diff] [blame] | 148 | # print (' '.join(args)) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 149 | |
| 150 | # Use "args" to invoke gdb, capturing stdout, stderr: |
Victor Stinner | 5132493 | 2013-11-20 12:27:48 +0100 | [diff] [blame] | 151 | out, err = run_gdb(*args, PYTHONHASHSEED=PYTHONHASHSEED) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 152 | |
Antoine Pitrou | 81641d6 | 2013-05-01 00:15:44 +0200 | [diff] [blame] | 153 | errlines = err.splitlines() |
| 154 | unexpected_errlines = [] |
| 155 | |
| 156 | # Ignore some benign messages on stderr. |
| 157 | ignore_patterns = ( |
| 158 | 'Function "%s" not defined.' % breakpoint, |
| 159 | "warning: no loadable sections found in added symbol-file" |
| 160 | " system-supplied DSO", |
| 161 | "warning: Unable to find libthread_db matching" |
| 162 | " inferior's thread library, thread debugging will" |
| 163 | " not be available.", |
| 164 | "warning: Cannot initialize thread debugging" |
| 165 | " library: Debugger service failed", |
| 166 | 'warning: Could not load shared library symbols for ' |
| 167 | 'linux-vdso.so', |
| 168 | 'warning: Could not load shared library symbols for ' |
| 169 | 'linux-gate.so', |
| 170 | 'Do you need "set solib-search-path" or ' |
| 171 | '"set sysroot"?', |
Victor Stinner | 5ac1b93 | 2013-06-25 21:54:32 +0200 | [diff] [blame] | 172 | 'warning: Source file is more recent than executable.', |
Victor Stinner | 23ed7e3 | 2013-11-25 10:43:59 +0100 | [diff] [blame] | 173 | # Issue #19753: missing symbols on System Z |
Victor Stinner | f4a4898 | 2013-11-24 18:55:25 +0100 | [diff] [blame] | 174 | 'Missing separate debuginfo for ', |
Victor Stinner | 23ed7e3 | 2013-11-25 10:43:59 +0100 | [diff] [blame] | 175 | 'Try: zypper install -C ', |
Antoine Pitrou | 81641d6 | 2013-05-01 00:15:44 +0200 | [diff] [blame] | 176 | ) |
| 177 | for line in errlines: |
| 178 | if not line.startswith(ignore_patterns): |
| 179 | unexpected_errlines.append(line) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 180 | |
| 181 | # Ensure no unexpected error messages: |
Antoine Pitrou | 81641d6 | 2013-05-01 00:15:44 +0200 | [diff] [blame] | 182 | self.assertEqual(unexpected_errlines, []) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 183 | return out |
| 184 | |
| 185 | def get_gdb_repr(self, source, |
| 186 | cmds_after_breakpoint=None, |
| 187 | import_site=False): |
| 188 | # Given an input python source representation of data, |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 189 | # run "python -c'id(DATA)'" under gdb with a breakpoint on |
| 190 | # builtin_id and scrape out gdb's representation of the "op" |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 191 | # parameter, and verify that the gdb displays the same string |
| 192 | # |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 193 | # Verify that the gdb displays the expected string |
| 194 | # |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 195 | # For a nested structure, the first time we hit the breakpoint will |
| 196 | # give us the top-level structure |
Antoine Pitrou | f6eb31f | 2013-11-24 14:58:17 +0100 | [diff] [blame] | 197 | |
| 198 | # NOTE: avoid decoding too much of the traceback as some |
| 199 | # undecodable characters may lurk there in optimized mode |
| 200 | # (issue #19743). |
| 201 | cmds_after_breakpoint = cmds_after_breakpoint or ["backtrace 1"] |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 202 | gdb_output = self.get_stack_trace(source, breakpoint=BREAKPOINT_FN, |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 203 | cmds_after_breakpoint=cmds_after_breakpoint, |
| 204 | import_site=import_site) |
| 205 | # gdb can insert additional '\n' and space characters in various places |
| 206 | # in its output, depending on the width of the terminal it's connected |
| 207 | # to (using its "wrap_here" function) |
David Malcolm | 8d37ffa | 2012-06-27 14:15:34 -0400 | [diff] [blame] | 208 | m = re.match('.*#0\s+builtin_id\s+\(self\=.*,\s+v=\s*(.*?)\)\s+at\s+\S*Python/bltinmodule.c.*', |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 209 | gdb_output, re.DOTALL) |
| 210 | if not m: |
| 211 | self.fail('Unexpected gdb output: %r\n%s' % (gdb_output, gdb_output)) |
| 212 | return m.group(1), gdb_output |
| 213 | |
| 214 | def assertEndsWith(self, actual, exp_end): |
| 215 | '''Ensure that the given "actual" string ends with "exp_end"''' |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 216 | self.assertTrue(actual.endswith(exp_end), |
| 217 | msg='%r did not end with %r' % (actual, exp_end)) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 218 | |
| 219 | def assertMultilineMatches(self, actual, pattern): |
| 220 | m = re.match(pattern, actual, re.DOTALL) |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 221 | if not m: |
| 222 | self.fail(msg='%r did not match %r' % (actual, pattern)) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 223 | |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 224 | def get_sample_script(self): |
| 225 | return findfile('gdb_sample.py') |
| 226 | |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 227 | class PrettyPrintTests(DebuggerTests): |
| 228 | def test_getting_backtrace(self): |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 229 | gdb_output = self.get_stack_trace('id(42)') |
| 230 | self.assertTrue(BREAKPOINT_FN in gdb_output) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 231 | |
Antoine Pitrou | f6eb31f | 2013-11-24 14:58:17 +0100 | [diff] [blame] | 232 | def assertGdbRepr(self, val, exp_repr=None): |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 233 | # Ensure that gdb's rendering of the value in a debugged process |
| 234 | # matches repr(value) in this process: |
Antoine Pitrou | f6eb31f | 2013-11-24 14:58:17 +0100 | [diff] [blame] | 235 | gdb_repr, gdb_output = self.get_gdb_repr('id(' + ascii(val) + ')') |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 236 | if not exp_repr: |
Victor Stinner | a282825 | 2013-11-21 10:25:09 +0100 | [diff] [blame] | 237 | exp_repr = repr(val) |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 238 | self.assertEqual(gdb_repr, exp_repr, |
| 239 | ('%r did not equal expected %r; full output was:\n%s' |
| 240 | % (gdb_repr, exp_repr, gdb_output))) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 241 | |
| 242 | def test_int(self): |
Serhiy Storchaka | 9594942 | 2013-08-27 19:40:23 +0300 | [diff] [blame] | 243 | 'Verify the pretty-printing of various int values' |
Victor Stinner | a282825 | 2013-11-21 10:25:09 +0100 | [diff] [blame] | 244 | self.assertGdbRepr(42) |
| 245 | self.assertGdbRepr(0) |
| 246 | self.assertGdbRepr(-7) |
| 247 | self.assertGdbRepr(1000000000000) |
| 248 | self.assertGdbRepr(-1000000000000000) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 249 | |
| 250 | def test_singletons(self): |
| 251 | 'Verify the pretty-printing of True, False and None' |
Victor Stinner | a282825 | 2013-11-21 10:25:09 +0100 | [diff] [blame] | 252 | self.assertGdbRepr(True) |
| 253 | self.assertGdbRepr(False) |
| 254 | self.assertGdbRepr(None) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 255 | |
| 256 | def test_dicts(self): |
| 257 | 'Verify the pretty-printing of dictionaries' |
Victor Stinner | a282825 | 2013-11-21 10:25:09 +0100 | [diff] [blame] | 258 | self.assertGdbRepr({}) |
| 259 | self.assertGdbRepr({'foo': 'bar'}, "{'foo': 'bar'}") |
| 260 | self.assertGdbRepr({'foo': 'bar', 'douglas': 42}, "{'douglas': 42, 'foo': 'bar'}") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 261 | |
| 262 | def test_lists(self): |
| 263 | 'Verify the pretty-printing of lists' |
Victor Stinner | a282825 | 2013-11-21 10:25:09 +0100 | [diff] [blame] | 264 | self.assertGdbRepr([]) |
| 265 | self.assertGdbRepr(list(range(5))) |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 266 | |
| 267 | def test_bytes(self): |
| 268 | 'Verify the pretty-printing of bytes' |
| 269 | self.assertGdbRepr(b'') |
| 270 | self.assertGdbRepr(b'And now for something hopefully the same') |
| 271 | self.assertGdbRepr(b'string with embedded NUL here \0 and then some more text') |
| 272 | self.assertGdbRepr(b'this is a tab:\t' |
| 273 | b' this is a slash-N:\n' |
| 274 | b' this is a slash-R:\r' |
| 275 | ) |
| 276 | |
| 277 | self.assertGdbRepr(b'this is byte 255:\xff and byte 128:\x80') |
| 278 | |
| 279 | self.assertGdbRepr(bytes([b for b in range(255)])) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 280 | |
| 281 | def test_strings(self): |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 282 | 'Verify the pretty-printing of unicode strings' |
Victor Stinner | 150016f | 2010-05-19 23:04:56 +0000 | [diff] [blame] | 283 | encoding = locale.getpreferredencoding() |
| 284 | def check_repr(text): |
| 285 | try: |
| 286 | text.encode(encoding) |
| 287 | printable = True |
| 288 | except UnicodeEncodeError: |
Antoine Pitrou | 4c7c421 | 2010-09-09 20:40:28 +0000 | [diff] [blame] | 289 | self.assertGdbRepr(text, ascii(text)) |
Victor Stinner | 150016f | 2010-05-19 23:04:56 +0000 | [diff] [blame] | 290 | else: |
| 291 | self.assertGdbRepr(text) |
| 292 | |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 293 | self.assertGdbRepr('') |
| 294 | self.assertGdbRepr('And now for something hopefully the same') |
| 295 | self.assertGdbRepr('string with embedded NUL here \0 and then some more text') |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 296 | |
| 297 | # Test printing a single character: |
| 298 | # U+2620 SKULL AND CROSSBONES |
Victor Stinner | 150016f | 2010-05-19 23:04:56 +0000 | [diff] [blame] | 299 | check_repr('\u2620') |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 300 | |
| 301 | # Test printing a Japanese unicode string |
| 302 | # (I believe this reads "mojibake", using 3 characters from the CJK |
| 303 | # Unified Ideographs area, followed by U+3051 HIRAGANA LETTER KE) |
Victor Stinner | 150016f | 2010-05-19 23:04:56 +0000 | [diff] [blame] | 304 | check_repr('\u6587\u5b57\u5316\u3051') |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 305 | |
| 306 | # Test a character outside the BMP: |
| 307 | # U+1D121 MUSICAL SYMBOL C CLEF |
| 308 | # This is: |
| 309 | # UTF-8: 0xF0 0x9D 0x84 0xA1 |
| 310 | # UTF-16: 0xD834 0xDD21 |
Victor Stinner | 150016f | 2010-05-19 23:04:56 +0000 | [diff] [blame] | 311 | check_repr(chr(0x1D121)) |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 312 | |
| 313 | def test_tuples(self): |
| 314 | 'Verify the pretty-printing of tuples' |
Victor Stinner | 5132493 | 2013-11-20 12:27:48 +0100 | [diff] [blame] | 315 | self.assertGdbRepr(tuple(), '()') |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 316 | self.assertGdbRepr((1,), '(1,)') |
| 317 | self.assertGdbRepr(('foo', 'bar', 'baz')) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 318 | |
| 319 | def test_sets(self): |
| 320 | 'Verify the pretty-printing of sets' |
Antoine Pitrou | a78cccb | 2013-09-22 00:14:27 +0200 | [diff] [blame] | 321 | if (gdb_major_version, gdb_minor_version) < (7, 3): |
| 322 | self.skipTest("pretty-printing of sets needs gdb 7.3 or later") |
Victor Stinner | a282825 | 2013-11-21 10:25:09 +0100 | [diff] [blame] | 323 | self.assertGdbRepr(set(), 'set()') |
| 324 | self.assertGdbRepr(set(['a', 'b']), "{'a', 'b'}") |
| 325 | self.assertGdbRepr(set([4, 5, 6]), "{4, 5, 6}") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 326 | |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 327 | # Ensure that we handle sets containing the "dummy" key value, |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 328 | # which happens on deletion: |
| 329 | gdb_repr, gdb_output = self.get_gdb_repr('''s = set(['a','b']) |
Victor Stinner | 5132493 | 2013-11-20 12:27:48 +0100 | [diff] [blame] | 330 | s.remove('a') |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 331 | id(s)''') |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 332 | self.assertEqual(gdb_repr, "{'b'}") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 333 | |
| 334 | def test_frozensets(self): |
| 335 | 'Verify the pretty-printing of frozensets' |
Antoine Pitrou | a78cccb | 2013-09-22 00:14:27 +0200 | [diff] [blame] | 336 | if (gdb_major_version, gdb_minor_version) < (7, 3): |
| 337 | self.skipTest("pretty-printing of frozensets needs gdb 7.3 or later") |
Victor Stinner | a282825 | 2013-11-21 10:25:09 +0100 | [diff] [blame] | 338 | self.assertGdbRepr(frozenset(), 'frozenset()') |
| 339 | self.assertGdbRepr(frozenset(['a', 'b']), "frozenset({'a', 'b'})") |
| 340 | self.assertGdbRepr(frozenset([4, 5, 6]), "frozenset({4, 5, 6})") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 341 | |
| 342 | def test_exceptions(self): |
| 343 | # Test a RuntimeError |
| 344 | gdb_repr, gdb_output = self.get_gdb_repr(''' |
| 345 | try: |
| 346 | raise RuntimeError("I am an error") |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 347 | except RuntimeError as e: |
| 348 | id(e) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 349 | ''') |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 350 | self.assertEqual(gdb_repr, |
| 351 | "RuntimeError('I am an error',)") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 352 | |
| 353 | |
| 354 | # Test division by zero: |
| 355 | gdb_repr, gdb_output = self.get_gdb_repr(''' |
| 356 | try: |
| 357 | a = 1 / 0 |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 358 | except ZeroDivisionError as e: |
| 359 | id(e) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 360 | ''') |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 361 | self.assertEqual(gdb_repr, |
| 362 | "ZeroDivisionError('division by zero',)") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 363 | |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 364 | def test_modern_class(self): |
| 365 | 'Verify the pretty-printing of new-style class instances' |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 366 | gdb_repr, gdb_output = self.get_gdb_repr(''' |
| 367 | class Foo: |
| 368 | pass |
| 369 | foo = Foo() |
| 370 | foo.an_int = 42 |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 371 | id(foo)''') |
Antoine Pitrou | 4d09873 | 2011-11-26 01:42:03 +0100 | [diff] [blame] | 372 | m = re.match(r'<Foo\(an_int=42\) at remote 0x-?[0-9a-f]+>', gdb_repr) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 373 | self.assertTrue(m, |
| 374 | msg='Unexpected new-style class rendering %r' % gdb_repr) |
| 375 | |
| 376 | def test_subclassing_list(self): |
| 377 | 'Verify the pretty-printing of an instance of a list subclass' |
| 378 | gdb_repr, gdb_output = self.get_gdb_repr(''' |
| 379 | class Foo(list): |
| 380 | pass |
| 381 | foo = Foo() |
| 382 | foo += [1, 2, 3] |
| 383 | foo.an_int = 42 |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 384 | id(foo)''') |
Antoine Pitrou | 4d09873 | 2011-11-26 01:42:03 +0100 | [diff] [blame] | 385 | m = re.match(r'<Foo\(an_int=42\) at remote 0x-?[0-9a-f]+>', gdb_repr) |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 386 | |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 387 | self.assertTrue(m, |
| 388 | msg='Unexpected new-style class rendering %r' % gdb_repr) |
| 389 | |
| 390 | def test_subclassing_tuple(self): |
| 391 | 'Verify the pretty-printing of an instance of a tuple subclass' |
| 392 | # This should exercise the negative tp_dictoffset code in the |
| 393 | # new-style class support |
| 394 | gdb_repr, gdb_output = self.get_gdb_repr(''' |
| 395 | class Foo(tuple): |
| 396 | pass |
| 397 | foo = Foo((1, 2, 3)) |
| 398 | foo.an_int = 42 |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 399 | id(foo)''') |
Antoine Pitrou | 4d09873 | 2011-11-26 01:42:03 +0100 | [diff] [blame] | 400 | m = re.match(r'<Foo\(an_int=42\) at remote 0x-?[0-9a-f]+>', gdb_repr) |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 401 | |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 402 | self.assertTrue(m, |
| 403 | msg='Unexpected new-style class rendering %r' % gdb_repr) |
| 404 | |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 405 | def assertSane(self, source, corruption, exprepr=None): |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 406 | '''Run Python under gdb, corrupting variables in the inferior process |
| 407 | immediately before taking a backtrace. |
| 408 | |
| 409 | Verify that the variable's representation is the expected failsafe |
| 410 | representation''' |
| 411 | if corruption: |
| 412 | cmds_after_breakpoint=[corruption, 'backtrace'] |
| 413 | else: |
| 414 | cmds_after_breakpoint=['backtrace'] |
| 415 | |
| 416 | gdb_repr, gdb_output = \ |
| 417 | self.get_gdb_repr(source, |
| 418 | cmds_after_breakpoint=cmds_after_breakpoint) |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 419 | if exprepr: |
| 420 | if gdb_repr == exprepr: |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 421 | # gdb managed to print the value in spite of the corruption; |
| 422 | # this is good (see http://bugs.python.org/issue8330) |
| 423 | return |
| 424 | |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 425 | # Match anything for the type name; 0xDEADBEEF could point to |
| 426 | # something arbitrary (see http://bugs.python.org/issue8330) |
Antoine Pitrou | 4d09873 | 2011-11-26 01:42:03 +0100 | [diff] [blame] | 427 | pattern = '<.* at remote 0x-?[0-9a-f]+>' |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 428 | |
| 429 | m = re.match(pattern, gdb_repr) |
| 430 | if not m: |
| 431 | self.fail('Unexpected gdb representation: %r\n%s' % \ |
| 432 | (gdb_repr, gdb_output)) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 433 | |
| 434 | def test_NULL_ptr(self): |
| 435 | 'Ensure that a NULL PyObject* is handled gracefully' |
| 436 | gdb_repr, gdb_output = ( |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 437 | self.get_gdb_repr('id(42)', |
| 438 | cmds_after_breakpoint=['set variable v=0', |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 439 | 'backtrace']) |
| 440 | ) |
| 441 | |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 442 | self.assertEqual(gdb_repr, '0x0') |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 443 | |
| 444 | def test_NULL_ob_type(self): |
| 445 | 'Ensure that a PyObject* with NULL ob_type is handled gracefully' |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 446 | self.assertSane('id(42)', |
| 447 | 'set v->ob_type=0') |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 448 | |
| 449 | def test_corrupt_ob_type(self): |
| 450 | 'Ensure that a PyObject* with a corrupt ob_type is handled gracefully' |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 451 | self.assertSane('id(42)', |
| 452 | 'set v->ob_type=0xDEADBEEF', |
| 453 | exprepr='42') |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 454 | |
| 455 | def test_corrupt_tp_flags(self): |
| 456 | 'Ensure that a PyObject* with a type with corrupt tp_flags is handled' |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 457 | self.assertSane('id(42)', |
| 458 | 'set v->ob_type->tp_flags=0x0', |
| 459 | exprepr='42') |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 460 | |
| 461 | def test_corrupt_tp_name(self): |
| 462 | 'Ensure that a PyObject* with a type with corrupt tp_name is handled' |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 463 | self.assertSane('id(42)', |
| 464 | 'set v->ob_type->tp_name=0xDEADBEEF', |
| 465 | exprepr='42') |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 466 | |
| 467 | def test_builtins_help(self): |
| 468 | 'Ensure that the new-style class _Helper in site.py can be handled' |
| 469 | # (this was the issue causing tracebacks in |
| 470 | # http://bugs.python.org/issue8032#msg100537 ) |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 471 | gdb_repr, gdb_output = self.get_gdb_repr('id(__builtins__.help)', import_site=True) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 472 | |
Antoine Pitrou | 4d09873 | 2011-11-26 01:42:03 +0100 | [diff] [blame] | 473 | m = re.match(r'<_Helper at remote 0x-?[0-9a-f]+>', gdb_repr) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 474 | self.assertTrue(m, |
| 475 | msg='Unexpected rendering %r' % gdb_repr) |
| 476 | |
| 477 | def test_selfreferential_list(self): |
| 478 | '''Ensure that a reference loop involving a list doesn't lead proxyval |
| 479 | into an infinite loop:''' |
| 480 | gdb_repr, gdb_output = \ |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 481 | self.get_gdb_repr("a = [3, 4, 5] ; a.append(a) ; id(a)") |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 482 | self.assertEqual(gdb_repr, '[3, 4, 5, [...]]') |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 483 | |
| 484 | gdb_repr, gdb_output = \ |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 485 | self.get_gdb_repr("a = [3, 4, 5] ; b = [a] ; a.append(b) ; id(a)") |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 486 | self.assertEqual(gdb_repr, '[3, 4, 5, [[...]]]') |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 487 | |
| 488 | def test_selfreferential_dict(self): |
| 489 | '''Ensure that a reference loop involving a dict doesn't lead proxyval |
| 490 | into an infinite loop:''' |
| 491 | gdb_repr, gdb_output = \ |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 492 | self.get_gdb_repr("a = {} ; b = {'bar':a} ; a['foo'] = b ; id(a)") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 493 | |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 494 | self.assertEqual(gdb_repr, "{'foo': {'bar': {...}}}") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 495 | |
| 496 | def test_selfreferential_old_style_instance(self): |
| 497 | gdb_repr, gdb_output = \ |
| 498 | self.get_gdb_repr(''' |
| 499 | class Foo: |
| 500 | pass |
| 501 | foo = Foo() |
| 502 | foo.an_attr = foo |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 503 | id(foo)''') |
Antoine Pitrou | 4d09873 | 2011-11-26 01:42:03 +0100 | [diff] [blame] | 504 | self.assertTrue(re.match('<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>', |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 505 | gdb_repr), |
| 506 | 'Unexpected gdb representation: %r\n%s' % \ |
| 507 | (gdb_repr, gdb_output)) |
| 508 | |
| 509 | def test_selfreferential_new_style_instance(self): |
| 510 | gdb_repr, gdb_output = \ |
| 511 | self.get_gdb_repr(''' |
| 512 | class Foo(object): |
| 513 | pass |
| 514 | foo = Foo() |
| 515 | foo.an_attr = foo |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 516 | id(foo)''') |
Antoine Pitrou | 4d09873 | 2011-11-26 01:42:03 +0100 | [diff] [blame] | 517 | self.assertTrue(re.match('<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>', |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 518 | gdb_repr), |
| 519 | 'Unexpected gdb representation: %r\n%s' % \ |
| 520 | (gdb_repr, gdb_output)) |
| 521 | |
| 522 | gdb_repr, gdb_output = \ |
| 523 | self.get_gdb_repr(''' |
| 524 | class Foo(object): |
| 525 | pass |
| 526 | a = Foo() |
| 527 | b = Foo() |
| 528 | a.an_attr = b |
| 529 | b.an_attr = a |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 530 | id(a)''') |
Antoine Pitrou | 4d09873 | 2011-11-26 01:42:03 +0100 | [diff] [blame] | 531 | self.assertTrue(re.match('<Foo\(an_attr=<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>\) at remote 0x-?[0-9a-f]+>', |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 532 | gdb_repr), |
| 533 | 'Unexpected gdb representation: %r\n%s' % \ |
| 534 | (gdb_repr, gdb_output)) |
| 535 | |
| 536 | def test_truncation(self): |
| 537 | 'Verify that very long output is truncated' |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 538 | gdb_repr, gdb_output = self.get_gdb_repr('id(list(range(1000)))') |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 539 | self.assertEqual(gdb_repr, |
| 540 | "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, " |
| 541 | "14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, " |
| 542 | "27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, " |
| 543 | "40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, " |
| 544 | "53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, " |
| 545 | "66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, " |
| 546 | "79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, " |
| 547 | "92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, " |
| 548 | "104, 105, 106, 107, 108, 109, 110, 111, 112, 113, " |
| 549 | "114, 115, 116, 117, 118, 119, 120, 121, 122, 123, " |
| 550 | "124, 125, 126, 127, 128, 129, 130, 131, 132, 133, " |
| 551 | "134, 135, 136, 137, 138, 139, 140, 141, 142, 143, " |
| 552 | "144, 145, 146, 147, 148, 149, 150, 151, 152, 153, " |
| 553 | "154, 155, 156, 157, 158, 159, 160, 161, 162, 163, " |
| 554 | "164, 165, 166, 167, 168, 169, 170, 171, 172, 173, " |
| 555 | "174, 175, 176, 177, 178, 179, 180, 181, 182, 183, " |
| 556 | "184, 185, 186, 187, 188, 189, 190, 191, 192, 193, " |
| 557 | "194, 195, 196, 197, 198, 199, 200, 201, 202, 203, " |
| 558 | "204, 205, 206, 207, 208, 209, 210, 211, 212, 213, " |
| 559 | "214, 215, 216, 217, 218, 219, 220, 221, 222, 223, " |
| 560 | "224, 225, 226...(truncated)") |
| 561 | self.assertEqual(len(gdb_repr), |
| 562 | 1024 + len('...(truncated)')) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 563 | |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 564 | def test_builtin_method(self): |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 565 | gdb_repr, gdb_output = self.get_gdb_repr('import sys; id(sys.stdout.readlines)') |
Antoine Pitrou | 4d09873 | 2011-11-26 01:42:03 +0100 | [diff] [blame] | 566 | self.assertTrue(re.match('<built-in method readlines of _io.TextIOWrapper object at remote 0x-?[0-9a-f]+>', |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 567 | gdb_repr), |
| 568 | 'Unexpected gdb representation: %r\n%s' % \ |
| 569 | (gdb_repr, gdb_output)) |
| 570 | |
| 571 | def test_frames(self): |
| 572 | gdb_output = self.get_stack_trace(''' |
| 573 | def foo(a, b, c): |
| 574 | pass |
| 575 | |
| 576 | foo(3, 4, 5) |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 577 | id(foo.__code__)''', |
| 578 | breakpoint='builtin_id', |
| 579 | cmds_after_breakpoint=['print (PyFrameObject*)(((PyCodeObject*)v)->co_zombieframe)'] |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 580 | ) |
Antoine Pitrou | 4d09873 | 2011-11-26 01:42:03 +0100 | [diff] [blame] | 581 | self.assertTrue(re.match('.*\s+\$1 =\s+Frame 0x-?[0-9a-f]+, for file <string>, line 3, in foo \(\)\s+.*', |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 582 | gdb_output, |
| 583 | re.DOTALL), |
| 584 | 'Unexpected gdb representation: %r\n%s' % (gdb_output, gdb_output)) |
| 585 | |
Victor Stinner | d208416 | 2011-12-19 13:42:24 +0100 | [diff] [blame] | 586 | @unittest.skipIf(python_is_optimized(), |
| 587 | "Python was compiled with optimizations") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 588 | class PyListTests(DebuggerTests): |
| 589 | def assertListing(self, expected, actual): |
| 590 | self.assertEndsWith(actual, expected) |
| 591 | |
| 592 | def test_basic_command(self): |
| 593 | 'Verify that the "py-list" command works' |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 594 | bt = self.get_stack_trace(script=self.get_sample_script(), |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 595 | cmds_after_breakpoint=['py-list']) |
| 596 | |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 597 | self.assertListing(' 5 \n' |
| 598 | ' 6 def bar(a, b, c):\n' |
| 599 | ' 7 baz(a, b, c)\n' |
| 600 | ' 8 \n' |
| 601 | ' 9 def baz(*args):\n' |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 602 | ' >10 id(42)\n' |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 603 | ' 11 \n' |
| 604 | ' 12 foo(1, 2, 3)\n', |
| 605 | bt) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 606 | |
| 607 | def test_one_abs_arg(self): |
| 608 | 'Verify the "py-list" command with one absolute argument' |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 609 | bt = self.get_stack_trace(script=self.get_sample_script(), |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 610 | cmds_after_breakpoint=['py-list 9']) |
| 611 | |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 612 | self.assertListing(' 9 def baz(*args):\n' |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 613 | ' >10 id(42)\n' |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 614 | ' 11 \n' |
| 615 | ' 12 foo(1, 2, 3)\n', |
| 616 | bt) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 617 | |
| 618 | def test_two_abs_args(self): |
| 619 | 'Verify the "py-list" command with two absolute arguments' |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 620 | bt = self.get_stack_trace(script=self.get_sample_script(), |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 621 | cmds_after_breakpoint=['py-list 1,3']) |
| 622 | |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 623 | self.assertListing(' 1 # Sample script for use by test_gdb.py\n' |
| 624 | ' 2 \n' |
| 625 | ' 3 def foo(a, b, c):\n', |
| 626 | bt) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 627 | |
| 628 | class StackNavigationTests(DebuggerTests): |
Victor Stinner | 50eb60e | 2010-04-20 22:32:07 +0000 | [diff] [blame] | 629 | @unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands") |
Victor Stinner | d208416 | 2011-12-19 13:42:24 +0100 | [diff] [blame] | 630 | @unittest.skipIf(python_is_optimized(), |
| 631 | "Python was compiled with optimizations") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 632 | def test_pyup_command(self): |
| 633 | 'Verify that the "py-up" command works' |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 634 | bt = self.get_stack_trace(script=self.get_sample_script(), |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 635 | cmds_after_breakpoint=['py-up']) |
| 636 | self.assertMultilineMatches(bt, |
| 637 | r'''^.* |
Antoine Pitrou | 4d09873 | 2011-11-26 01:42:03 +0100 | [diff] [blame] | 638 | #[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 639 | baz\(a, b, c\) |
| 640 | $''') |
| 641 | |
Victor Stinner | 50eb60e | 2010-04-20 22:32:07 +0000 | [diff] [blame] | 642 | @unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 643 | def test_down_at_bottom(self): |
| 644 | 'Verify handling of "py-down" at the bottom of the stack' |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 645 | bt = self.get_stack_trace(script=self.get_sample_script(), |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 646 | cmds_after_breakpoint=['py-down']) |
| 647 | self.assertEndsWith(bt, |
| 648 | 'Unable to find a newer python frame\n') |
| 649 | |
Victor Stinner | 50eb60e | 2010-04-20 22:32:07 +0000 | [diff] [blame] | 650 | @unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 651 | def test_up_at_top(self): |
| 652 | 'Verify handling of "py-up" at the top of the stack' |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 653 | bt = self.get_stack_trace(script=self.get_sample_script(), |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 654 | cmds_after_breakpoint=['py-up'] * 4) |
| 655 | self.assertEndsWith(bt, |
| 656 | 'Unable to find an older python frame\n') |
| 657 | |
Victor Stinner | 50eb60e | 2010-04-20 22:32:07 +0000 | [diff] [blame] | 658 | @unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands") |
Victor Stinner | d208416 | 2011-12-19 13:42:24 +0100 | [diff] [blame] | 659 | @unittest.skipIf(python_is_optimized(), |
| 660 | "Python was compiled with optimizations") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 661 | def test_up_then_down(self): |
| 662 | 'Verify "py-up" followed by "py-down"' |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 663 | bt = self.get_stack_trace(script=self.get_sample_script(), |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 664 | cmds_after_breakpoint=['py-up', 'py-down']) |
| 665 | self.assertMultilineMatches(bt, |
| 666 | r'''^.* |
Antoine Pitrou | 4d09873 | 2011-11-26 01:42:03 +0100 | [diff] [blame] | 667 | #[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 668 | baz\(a, b, c\) |
Antoine Pitrou | 4d09873 | 2011-11-26 01:42:03 +0100 | [diff] [blame] | 669 | #[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 10, in baz \(args=\(1, 2, 3\)\) |
Martin v. Löwis | 5ae6810 | 2010-04-21 22:38:42 +0000 | [diff] [blame] | 670 | id\(42\) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 671 | $''') |
| 672 | |
| 673 | class PyBtTests(DebuggerTests): |
Victor Stinner | d208416 | 2011-12-19 13:42:24 +0100 | [diff] [blame] | 674 | @unittest.skipIf(python_is_optimized(), |
| 675 | "Python was compiled with optimizations") |
Victor Stinner | e670c88 | 2011-05-13 17:40:15 +0200 | [diff] [blame] | 676 | def test_bt(self): |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 677 | 'Verify that the "py-bt" command works' |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 678 | bt = self.get_stack_trace(script=self.get_sample_script(), |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 679 | cmds_after_breakpoint=['py-bt']) |
| 680 | self.assertMultilineMatches(bt, |
| 681 | r'''^.* |
Victor Stinner | e670c88 | 2011-05-13 17:40:15 +0200 | [diff] [blame] | 682 | Traceback \(most recent call first\): |
| 683 | File ".*gdb_sample.py", line 10, in baz |
| 684 | id\(42\) |
| 685 | File ".*gdb_sample.py", line 7, in bar |
| 686 | baz\(a, b, c\) |
| 687 | File ".*gdb_sample.py", line 4, in foo |
| 688 | bar\(a, b, c\) |
| 689 | File ".*gdb_sample.py", line 12, in <module> |
| 690 | foo\(1, 2, 3\) |
| 691 | ''') |
| 692 | |
Victor Stinner | d208416 | 2011-12-19 13:42:24 +0100 | [diff] [blame] | 693 | @unittest.skipIf(python_is_optimized(), |
| 694 | "Python was compiled with optimizations") |
Victor Stinner | e670c88 | 2011-05-13 17:40:15 +0200 | [diff] [blame] | 695 | def test_bt_full(self): |
| 696 | 'Verify that the "py-bt-full" command works' |
| 697 | bt = self.get_stack_trace(script=self.get_sample_script(), |
| 698 | cmds_after_breakpoint=['py-bt-full']) |
| 699 | self.assertMultilineMatches(bt, |
| 700 | r'''^.* |
Antoine Pitrou | 4d09873 | 2011-11-26 01:42:03 +0100 | [diff] [blame] | 701 | #[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 702 | baz\(a, b, c\) |
Antoine Pitrou | 4d09873 | 2011-11-26 01:42:03 +0100 | [diff] [blame] | 703 | #[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 4, in foo \(a=1, b=2, c=3\) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 704 | bar\(a, b, c\) |
Antoine Pitrou | 4d09873 | 2011-11-26 01:42:03 +0100 | [diff] [blame] | 705 | #[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 12, in <module> \(\) |
Victor Stinner | d208416 | 2011-12-19 13:42:24 +0100 | [diff] [blame] | 706 | foo\(1, 2, 3\) |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 707 | ''') |
| 708 | |
David Malcolm | 8d37ffa | 2012-06-27 14:15:34 -0400 | [diff] [blame] | 709 | @unittest.skipUnless(_thread, |
| 710 | "Python was compiled without thread support") |
| 711 | def test_threads(self): |
| 712 | 'Verify that "py-bt" indicates threads that are waiting for the GIL' |
| 713 | cmd = ''' |
| 714 | from threading import Thread |
| 715 | |
| 716 | class TestThread(Thread): |
| 717 | # These threads would run forever, but we'll interrupt things with the |
| 718 | # debugger |
| 719 | def run(self): |
| 720 | i = 0 |
| 721 | while 1: |
| 722 | i += 1 |
| 723 | |
| 724 | t = {} |
| 725 | for i in range(4): |
| 726 | t[i] = TestThread() |
| 727 | t[i].start() |
| 728 | |
| 729 | # Trigger a breakpoint on the main thread |
| 730 | id(42) |
| 731 | |
| 732 | ''' |
| 733 | # Verify with "py-bt": |
| 734 | gdb_output = self.get_stack_trace(cmd, |
| 735 | cmds_after_breakpoint=['thread apply all py-bt']) |
| 736 | self.assertIn('Waiting for the GIL', gdb_output) |
| 737 | |
| 738 | # Verify with "py-bt-full": |
| 739 | gdb_output = self.get_stack_trace(cmd, |
| 740 | cmds_after_breakpoint=['thread apply all py-bt-full']) |
| 741 | self.assertIn('Waiting for the GIL', gdb_output) |
| 742 | |
| 743 | @unittest.skipIf(python_is_optimized(), |
| 744 | "Python was compiled with optimizations") |
| 745 | # Some older versions of gdb will fail with |
| 746 | # "Cannot find new threads: generic error" |
| 747 | # unless we add LD_PRELOAD=PATH-TO-libpthread.so.1 as a workaround |
| 748 | @unittest.skipUnless(_thread, |
| 749 | "Python was compiled without thread support") |
| 750 | def test_gc(self): |
| 751 | 'Verify that "py-bt" indicates if a thread is garbage-collecting' |
| 752 | cmd = ('from gc import collect\n' |
| 753 | 'id(42)\n' |
| 754 | 'def foo():\n' |
| 755 | ' collect()\n' |
| 756 | 'def bar():\n' |
| 757 | ' foo()\n' |
| 758 | 'bar()\n') |
| 759 | # Verify with "py-bt": |
| 760 | gdb_output = self.get_stack_trace(cmd, |
| 761 | cmds_after_breakpoint=['break update_refs', 'continue', 'py-bt'], |
| 762 | ) |
| 763 | self.assertIn('Garbage-collecting', gdb_output) |
| 764 | |
| 765 | # Verify with "py-bt-full": |
| 766 | gdb_output = self.get_stack_trace(cmd, |
| 767 | cmds_after_breakpoint=['break update_refs', 'continue', 'py-bt-full'], |
| 768 | ) |
| 769 | self.assertIn('Garbage-collecting', gdb_output) |
| 770 | |
| 771 | @unittest.skipIf(python_is_optimized(), |
| 772 | "Python was compiled with optimizations") |
| 773 | # Some older versions of gdb will fail with |
| 774 | # "Cannot find new threads: generic error" |
| 775 | # unless we add LD_PRELOAD=PATH-TO-libpthread.so.1 as a workaround |
| 776 | @unittest.skipUnless(_thread, |
| 777 | "Python was compiled without thread support") |
| 778 | def test_pycfunction(self): |
| 779 | 'Verify that "py-bt" displays invocations of PyCFunction instances' |
| 780 | cmd = ('from time import sleep\n' |
| 781 | 'def foo():\n' |
| 782 | ' sleep(1)\n' |
| 783 | 'def bar():\n' |
| 784 | ' foo()\n' |
| 785 | 'bar()\n') |
| 786 | # Verify with "py-bt": |
| 787 | gdb_output = self.get_stack_trace(cmd, |
| 788 | breakpoint='time_sleep', |
| 789 | cmds_after_breakpoint=['bt', 'py-bt'], |
| 790 | ) |
| 791 | self.assertIn('<built-in method sleep', gdb_output) |
| 792 | |
| 793 | # Verify with "py-bt-full": |
| 794 | gdb_output = self.get_stack_trace(cmd, |
| 795 | breakpoint='time_sleep', |
| 796 | cmds_after_breakpoint=['py-bt-full'], |
| 797 | ) |
| 798 | self.assertIn('#0 <built-in method sleep', gdb_output) |
| 799 | |
| 800 | |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 801 | class PyPrintTests(DebuggerTests): |
Victor Stinner | d208416 | 2011-12-19 13:42:24 +0100 | [diff] [blame] | 802 | @unittest.skipIf(python_is_optimized(), |
| 803 | "Python was compiled with optimizations") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 804 | def test_basic_command(self): |
| 805 | 'Verify that the "py-print" command works' |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 806 | bt = self.get_stack_trace(script=self.get_sample_script(), |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 807 | cmds_after_breakpoint=['py-print args']) |
| 808 | self.assertMultilineMatches(bt, |
| 809 | r".*\nlocal 'args' = \(1, 2, 3\)\n.*") |
| 810 | |
Vinay Sajip | 2549f87 | 2012-01-04 12:07:30 +0000 | [diff] [blame] | 811 | @unittest.skipIf(python_is_optimized(), |
| 812 | "Python was compiled with optimizations") |
Victor Stinner | 50eb60e | 2010-04-20 22:32:07 +0000 | [diff] [blame] | 813 | @unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 814 | def test_print_after_up(self): |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 815 | bt = self.get_stack_trace(script=self.get_sample_script(), |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 816 | cmds_after_breakpoint=['py-up', 'py-print c', 'py-print b', 'py-print a']) |
| 817 | self.assertMultilineMatches(bt, |
| 818 | r".*\nlocal 'c' = 3\nlocal 'b' = 2\nlocal 'a' = 1\n.*") |
| 819 | |
Victor Stinner | d208416 | 2011-12-19 13:42:24 +0100 | [diff] [blame] | 820 | @unittest.skipIf(python_is_optimized(), |
| 821 | "Python was compiled with optimizations") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 822 | def test_printing_global(self): |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 823 | bt = self.get_stack_trace(script=self.get_sample_script(), |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 824 | cmds_after_breakpoint=['py-print __name__']) |
| 825 | self.assertMultilineMatches(bt, |
| 826 | r".*\nglobal '__name__' = '__main__'\n.*") |
| 827 | |
Victor Stinner | d208416 | 2011-12-19 13:42:24 +0100 | [diff] [blame] | 828 | @unittest.skipIf(python_is_optimized(), |
| 829 | "Python was compiled with optimizations") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 830 | def test_printing_builtin(self): |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 831 | bt = self.get_stack_trace(script=self.get_sample_script(), |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 832 | cmds_after_breakpoint=['py-print len']) |
| 833 | self.assertMultilineMatches(bt, |
Antoine Pitrou | 4d09873 | 2011-11-26 01:42:03 +0100 | [diff] [blame] | 834 | r".*\nbuiltin 'len' = <built-in method len of module object at remote 0x-?[0-9a-f]+>\n.*") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 835 | |
| 836 | class PyLocalsTests(DebuggerTests): |
Victor Stinner | d208416 | 2011-12-19 13:42:24 +0100 | [diff] [blame] | 837 | @unittest.skipIf(python_is_optimized(), |
| 838 | "Python was compiled with optimizations") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 839 | def test_basic_command(self): |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 840 | bt = self.get_stack_trace(script=self.get_sample_script(), |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 841 | cmds_after_breakpoint=['py-locals']) |
| 842 | self.assertMultilineMatches(bt, |
| 843 | r".*\nargs = \(1, 2, 3\)\n.*") |
| 844 | |
Victor Stinner | 50eb60e | 2010-04-20 22:32:07 +0000 | [diff] [blame] | 845 | @unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands") |
Vinay Sajip | 2549f87 | 2012-01-04 12:07:30 +0000 | [diff] [blame] | 846 | @unittest.skipIf(python_is_optimized(), |
| 847 | "Python was compiled with optimizations") |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 848 | def test_locals_after_up(self): |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 849 | bt = self.get_stack_trace(script=self.get_sample_script(), |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 850 | cmds_after_breakpoint=['py-up', 'py-locals']) |
| 851 | self.assertMultilineMatches(bt, |
| 852 | r".*\na = 1\nb = 2\nc = 3\n.*") |
| 853 | |
| 854 | def test_main(): |
Antoine Pitrou | d0f3e07 | 2013-09-21 23:56:17 +0200 | [diff] [blame] | 855 | if support.verbose: |
| 856 | print("GDB version:") |
| 857 | for line in os.fsdecode(gdb_version).splitlines(): |
| 858 | print(" " * 4 + line) |
Martin v. Löwis | 5226fd6 | 2010-04-21 06:05:58 +0000 | [diff] [blame] | 859 | run_unittest(PrettyPrintTests, |
| 860 | PyListTests, |
| 861 | StackNavigationTests, |
| 862 | PyBtTests, |
| 863 | PyPrintTests, |
| 864 | PyLocalsTests |
Benjamin Peterson | 6a6666a | 2010-04-11 21:49:28 +0000 | [diff] [blame] | 865 | ) |
| 866 | |
| 867 | if __name__ == "__main__": |
| 868 | test_main() |