@@ -838,6 +838,7 @@ def test_gc(self):
838
838
)
839
839
self .assertIn ('Garbage-collecting' , gdb_output )
840
840
841
+
841
842
@unittest .skipIf (python_is_optimized (),
842
843
"Python was compiled with optimizations" )
843
844
# Some older versions of gdb will fail with
@@ -847,38 +848,48 @@ def test_pycfunction(self):
847
848
'Verify that "py-bt" displays invocations of PyCFunction instances'
848
849
# Various optimizations multiply the code paths by which these are
849
850
# called, so test a variety of calling conventions.
850
- for py_name , py_args , c_name , expected_frame_number in (
851
- ('gmtime' , '' , 'time_gmtime' , 1 ), # METH_VARARGS
852
- ('len' , '[]' , 'builtin_len' , 1 ), # METH_O
853
- ('locals' , '' , 'builtin_locals' , 1 ), # METH_NOARGS
854
- ('iter' , '[]' , 'builtin_iter' , 1 ), # METH_FASTCALL
855
- ('sorted' , '[]' , 'builtin_sorted' , 1 ), # METH_FASTCALL|METH_KEYWORDS
851
+ for func_name , args , expected_frame in (
852
+ ('meth_varargs' , '' , 1 ),
853
+ ('meth_varargs_keywords' , '' , 1 ),
854
+ ('meth_o' , '[]' , 1 ),
855
+ ('meth_noargs' , '' , 1 ),
856
+ ('meth_fastcall' , '' , 1 ),
857
+ ('meth_fastcall_keywords' , '' , 1 ),
856
858
):
857
- with self .subTest (c_name ):
858
- cmd = ('from time import gmtime\n ' # (not always needed)
859
- 'def foo():\n '
860
- f' { py_name } ({ py_args } )\n '
861
- 'def bar():\n '
862
- ' foo()\n '
863
- 'bar()\n ' )
864
- # Verify with "py-bt":
865
- gdb_output = self .get_stack_trace (
866
- cmd ,
867
- breakpoint = c_name ,
868
- cmds_after_breakpoint = ['bt' , 'py-bt' ],
869
- )
870
- self .assertIn (f'<built-in method { py_name } ' , gdb_output )
871
-
872
- # Verify with "py-bt-full":
873
- gdb_output = self .get_stack_trace (
874
- cmd ,
875
- breakpoint = c_name ,
876
- cmds_after_breakpoint = ['py-bt-full' ],
877
- )
878
- self .assertIn (
879
- f'#{ expected_frame_number } <built-in method { py_name } ' ,
880
- gdb_output ,
881
- )
859
+ for obj in (
860
+ '_testcapi' ,
861
+ '_testcapi.MethClass' ,
862
+ '_testcapi.MethClass()' ,
863
+ '_testcapi.MethStatic()' ,
864
+
865
+ # XXX: bound methods don't yet give nice tracebacks
866
+ # '_testcapi.MethInstance()',
867
+ ):
868
+ with self .subTest (f'{ obj } .{ func_name } ' ):
869
+ cmd = ('import _testcapi\n ' # (not always needed)
870
+ 'def foo():\n '
871
+ f' { obj } .{ func_name } ({ args } )\n '
872
+ 'def bar():\n '
873
+ ' foo()\n '
874
+ 'bar()\n ' )
875
+ # Verify with "py-bt":
876
+ gdb_output = self .get_stack_trace (
877
+ cmd ,
878
+ breakpoint = func_name ,
879
+ cmds_after_breakpoint = ['bt' , 'py-bt' ],
880
+ )
881
+ self .assertIn (f'<built-in method { func_name } ' , gdb_output )
882
+
883
+ # Verify with "py-bt-full":
884
+ gdb_output = self .get_stack_trace (
885
+ cmd ,
886
+ breakpoint = func_name ,
887
+ cmds_after_breakpoint = ['py-bt-full' ],
888
+ )
889
+ self .assertIn (
890
+ f'#{ expected_frame } <built-in method { func_name } ' ,
891
+ gdb_output ,
892
+ )
882
893
883
894
@unittest .skipIf (python_is_optimized (),
884
895
"Python was compiled with optimizations" )
0 commit comments