Skip to content

Commit 2bd4f71

Browse files
committed
Fix test_gdb
1 parent 568304b commit 2bd4f71

File tree

3 files changed

+73
-67
lines changed

3 files changed

+73
-67
lines changed

Lib/test/test_gdb/test_backtrace.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ def test_bt(self):
2020
self.assertMultilineMatches(bt,
2121
r'''^.*
2222
Traceback \(most recent call first\):
23-
<built-in method id of module object .*>
24-
File ".*gdb_sample.py", line 10, in baz
25-
id\(42\)
26-
File ".*gdb_sample.py", line 7, in bar
23+
<built-in method _idfunc of module object .*>
24+
File ".*gdb_sample.py", line 11, in baz
25+
_idfunc\(42\)
26+
File ".*gdb_sample.py", line 8, in bar
2727
baz\(a, b, c\)
28-
File ".*gdb_sample.py", line 4, in foo
28+
File ".*gdb_sample.py", line 5, in foo
2929
bar\(a=a, b=b, c=c\)
30-
File ".*gdb_sample.py", line 12, in <module>
30+
File ".*gdb_sample.py", line 13, in <module>
3131
foo\(1, 2, 3\)
3232
''')
3333

@@ -39,11 +39,11 @@ def test_bt_full(self):
3939
cmds_after_breakpoint=['py-bt-full'])
4040
self.assertMultilineMatches(bt,
4141
r'''^.*
42-
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\)
42+
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 8, in bar \(a=1, b=2, c=3\)
4343
baz\(a, b, c\)
44-
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 4, in foo \(a=1, b=2, c=3\)
44+
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 5, in foo \(a=1, b=2, c=3\)
4545
bar\(a=a, b=b, c=c\)
46-
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 12, in <module> \(\)
46+
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 13, in <module> \(\)
4747
foo\(1, 2, 3\)
4848
''')
4949

@@ -55,6 +55,7 @@ def test_threads(self):
5555
'Verify that "py-bt" indicates threads that are waiting for the GIL'
5656
cmd = '''
5757
from threading import Thread
58+
from _typing import _idfunc
5859
5960
class TestThread(Thread):
6061
# These threads would run forever, but we'll interrupt things with the
@@ -70,7 +71,7 @@ def run(self):
7071
t[i].start()
7172
7273
# Trigger a breakpoint on the main thread
73-
id(42)
74+
_idfunc(42)
7475
7576
'''
7677
# Verify with "py-bt":
@@ -90,8 +91,8 @@ def run(self):
9091
# unless we add LD_PRELOAD=PATH-TO-libpthread.so.1 as a workaround
9192
def test_gc(self):
9293
'Verify that "py-bt" indicates if a thread is garbage-collecting'
93-
cmd = ('from gc import collect\n'
94-
'id(42)\n'
94+
cmd = ('from gc import collect; from _typing import _idfunc\n'
95+
'_idfunc(42)\n'
9596
'def foo():\n'
9697
' collect()\n'
9798
'def bar():\n'
@@ -113,11 +114,12 @@ def test_gc(self):
113114
"Python was compiled with optimizations")
114115
def test_wrapper_call(self):
115116
cmd = textwrap.dedent('''
117+
from typing import _idfunc
116118
class MyList(list):
117119
def __init__(self):
118120
super(*[]).__init__() # wrapper_call()
119121
120-
id("first break point")
122+
_idfunc("first break point")
121123
l = MyList()
122124
''')
123125
cmds_after_breakpoint = ['break wrapper_call', 'continue']

Lib/test/test_gdb/test_misc.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,42 @@ def test_basic_command(self):
3535
bt = self.get_stack_trace(script=SAMPLE_SCRIPT,
3636
cmds_after_breakpoint=['py-list'])
3737

38-
self.assertListing(' 5 \n'
39-
' 6 def bar(a, b, c):\n'
40-
' 7 baz(a, b, c)\n'
41-
' 8 \n'
42-
' 9 def baz(*args):\n'
43-
' >10 id(42)\n'
44-
' 11 \n'
45-
' 12 foo(1, 2, 3)\n',
38+
self.assertListing(' 6 \n'
39+
' 7 def bar(a, b, c):\n'
40+
' 8 baz(a, b, c)\n'
41+
' 9 \n'
42+
' 10 def baz(*args):\n'
43+
' >11 _idfunc(42)\n'
44+
' 12 \n'
45+
' 13 foo(1, 2, 3)\n',
4646
bt)
4747

4848
def test_one_abs_arg(self):
4949
'Verify the "py-list" command with one absolute argument'
5050
bt = self.get_stack_trace(script=SAMPLE_SCRIPT,
5151
cmds_after_breakpoint=['py-list 9'])
5252

53-
self.assertListing(' 9 def baz(*args):\n'
54-
' >10 id(42)\n'
55-
' 11 \n'
56-
' 12 foo(1, 2, 3)\n',
53+
self.assertListing(' 10 def baz(*args):\n'
54+
' >11 _idfunc(42)\n'
55+
' 12 \n'
56+
' 13 foo(1, 2, 3)\n',
5757
bt)
5858

5959
def test_two_abs_args(self):
6060
'Verify the "py-list" command with two absolute arguments'
6161
bt = self.get_stack_trace(script=SAMPLE_SCRIPT,
62-
cmds_after_breakpoint=['py-list 1,3'])
62+
cmds_after_breakpoint=['py-list 1,4'])
6363

6464
self.assertListing(' 1 # Sample script for use by test_gdb\n'
65-
' 2 \n'
66-
' 3 def foo(a, b, c):\n',
65+
' 2 from _typing import _idfunc\n'
66+
' 3 \n'
67+
' 4 def foo(a, b, c):\n',
6768
bt)
6869

6970
SAMPLE_WITH_C_CALL = """
7071
7172
from _testcapi import pyobject_vectorcall
73+
from _typing import _idfunc
7274
7375
def foo(a, b, c):
7476
bar(a, b, c)
@@ -77,7 +79,7 @@ def bar(a, b, c):
7779
pyobject_vectorcall(baz, (a, b, c), None)
7880
7981
def baz(*args):
80-
id(42)
82+
_idfunc(42)
8183
8284
foo(1, 2, 3)
8385
@@ -94,7 +96,7 @@ def test_pyup_command(self):
9496
cmds_after_breakpoint=['py-up', 'py-up'])
9597
self.assertMultilineMatches(bt,
9698
r'''^.*
97-
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
99+
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 13, in baz \(args=\(1, 2, 3\)\)
98100
#[0-9]+ <built-in method pyobject_vectorcall of module object at remote 0x[0-9a-f]+>
99101
$''')
100102

@@ -123,9 +125,9 @@ def test_up_then_down(self):
123125
cmds_after_breakpoint=['py-up', 'py-up', 'py-down'])
124126
self.assertMultilineMatches(bt,
125127
r'''^.*
126-
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
128+
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 13, in baz \(args=\(1, 2, 3\)\)
127129
#[0-9]+ <built-in method pyobject_vectorcall of module object at remote 0x[0-9a-f]+>
128-
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
130+
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 13, in baz \(args=\(1, 2, 3\)\)
129131
$''')
130132

131133
class PyPrintTests(DebuggerTests):

0 commit comments

Comments
 (0)