verify with pybt bpo45207 ignore function methvarargs not defined message in stderr some older versions of gdb will fail with cannot find new threads generic error unless we add ldpreloadpathtolibpthread so 1 as a workaround gdb will also generate many erroneous errors such as function methvarargs not defined this is because we are calling functions from an external module testcapimodule rather than compiledin functions it seems difficult to suppress these see also the comment in debuggertests getstacktrace various optimizations multiply the code paths by which these are called so test a variety of calling conventions xxx bound methods don t yet give nice tracebacks testcapi methinstance if support verbose printf test call call flushtrue self checkfuncname cmd def testpycfunctionnoargsself self checkpycfunction methnoargs def testpycfunctionoself self checkpycfunction metho def testpycfunctionvarargsself self checkpycfunction methvarargs def testpycfunctionvarargskeywordsself self checkpycfunction methvarargskeywords def testpycfunctionfastcallself self checkpycfunction methfastcall def testpycfunctionfastcallkeywordsself self checkpycfunction methfastcallkeywords verify with py bt bpo 45207 ignore function meth_varargs not defined message in stderr some older versions of gdb will fail with cannot find new threads generic error unless we add ld_preload path to libpthread so 1 as a workaround gdb will also generate many erroneous errors such as function meth_varargs not defined this is because we are calling functions from an external module _testcapimodule rather than compiled in functions it seems difficult to suppress these see also the comment in debuggertests get_stack_trace various optimizations multiply the code paths by which these are called so test a variety of calling conventions xxx bound methods don t yet give nice tracebacks _testcapi methinstance import _testcapi def foo call def bar foo bar
import textwrap
import unittest
from test import support

from .util import setup_module, DebuggerTests


def setUpModule():
    setup_module()


@unittest.skipIf(support.python_is_optimized(),
                 "Python was compiled with optimizations")
@support.requires_resource('cpu')
class CFunctionTests(DebuggerTests):
    def check(self, func_name, cmd):
        
        gdb_output = self.get_stack_trace(
            cmd,
            breakpoint=func_name,
            cmds_after_breakpoint=['bt', 'py-bt'],
            
            
            ignore_stderr=True,
        )
        self.assertIn(f'<built-in method {func_name}', gdb_output)

    
    
    
    
    
    
    
    
    
    def check_pycfunction(self, func_name, args):
        'Verify that "py-bt" displays invocations of PyCFunction instances'

        if support.verbose:
            print()

        
        
        for obj in (
            '_testcapi',
            '_testcapi.MethClass',
            '_testcapi.MethClass()',
            '_testcapi.MethStatic()',

            
            
        ):
            with self.subTest(f'{obj}.{func_name}'):
                call = f'{obj}.{func_name}({args})'
                cmd = textwrap.dedent(f)
                if support.verbose:
                    print(f'  test call: {call}', flush=True)

                self.check(func_name, cmd)

    def test_pycfunction_noargs(self):
        self.check_pycfunction('meth_noargs', '')

    def test_pycfunction_o(self):
        self.check_pycfunction('meth_o', '[]')

    def test_pycfunction_varargs(self):
        self.check_pycfunction('meth_varargs', '')

    def test_pycfunction_varargs_keywords(self):
        self.check_pycfunction('meth_varargs_keywords', '')

    def test_pycfunction_fastcall(self):
        self.check_pycfunction('meth_fastcall', '')

    def test_pycfunction_fastcall_keywords(self):
        self.check_pycfunction('meth_fastcall_keywords', '')