コード例 #1
0
    def setUp(self):
        if not test_gdb():
            return

        super(GdbDebuggerTestCase, self).setUp()

        prefix_code = textwrap.dedent('''\
            python

            import os
            import sys
            import traceback

            def excepthook(type, value, tb):
                traceback.print_exception(type, value, tb)
                sys.stderr.flush()
                sys.stdout.flush()
                os._exit(1)

            sys.excepthook = excepthook

            # Have tracebacks end up on sys.stderr (gdb replaces sys.stderr
            # with an object that calls gdb.write())
            sys.stderr = sys.__stderr__

            end
            ''')

        code = textwrap.dedent('''\
            python

            from Cython.Debugger.Tests import test_libcython_in_gdb
            test_libcython_in_gdb.main(version=%r)

            end
            ''' % (sys.version_info[:2], ))

        self.gdb_command_file = cygdb.make_command_file(
            self.tempdir, prefix_code)

        with open(self.gdb_command_file, 'a') as f:
            f.write(code)

        args = [
            'gdb', '-batch', '-x', self.gdb_command_file, '-n', '--args',
            sys.executable, '-c', 'import codefile'
        ]

        paths = []
        path = os.environ.get('PYTHONPATH')
        if path:
            paths.append(path)
        paths.append(
            os.path.dirname(os.path.dirname(os.path.abspath(Cython.__file__))))
        env = dict(os.environ, PYTHONPATH=os.pathsep.join(paths))

        self.p = subprocess.Popen(args,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE,
                                  env=env)
コード例 #2
0
    def setUp(self):
        if not test_gdb():
            return

        super(GdbDebuggerTestCase, self).setUp()

        prefix_code = textwrap.dedent('''\
            python

            import os
            import sys
            import traceback

            def excepthook(type, value, tb):
                traceback.print_exception(type, value, tb)
                os._exit(1)

            sys.excepthook = excepthook

            # Have tracebacks end up on sys.stderr (gdb replaces sys.stderr
            # with an object that calls gdb.write())
            sys.stderr = sys.__stderr__

            end
            ''')

        code = textwrap.dedent('''\
            python

            from Cython.Debugger.Tests import test_libcython_in_gdb
            test_libcython_in_gdb.main(version=%r)

            end
            ''' % (sys.version_info[:2],))

        self.gdb_command_file = cygdb.make_command_file(self.tempdir,
                                                        prefix_code)

        f = open(self.gdb_command_file, 'a')
        try:
            f.write(code)
        finally:
            f.close()

        args = ['gdb', '-batch', '-x', self.gdb_command_file, '-n', '--args',
                sys.executable, '-c', 'import codefile']

        paths = []
        path = os.environ.get('PYTHONPATH')
        if path:
            paths.append(path)
        paths.append(os.path.dirname(os.path.dirname(
            os.path.abspath(Cython.__file__))))
        env = dict(os.environ, PYTHONPATH=os.pathsep.join(paths))

        self.p = subprocess.Popen(
            args,
            stdout=open(os.devnull, 'w'),
            stderr=subprocess.PIPE,
            env=env)
コード例 #3
0
    def setUp(self):
        if not test_gdb():
            return

        super(GdbDebuggerTestCase, self).setUp()

        prefix_code = textwrap.dedent('''\
            python

            import os
            import sys
            import traceback

            def excepthook(type, value, tb):
                traceback.print_exception(type, value, tb)
                os._exit(1)

            sys.excepthook = excepthook

            # Have tracebacks end up on sys.stderr (gdb replaces sys.stderr
            # with an object that calls gdb.write())
            sys.stderr = sys.__stderr__

            end
            ''')

        code = textwrap.dedent('''\
            python

            from Cython.Debugger.Tests import test_libcython_in_gdb
            test_libcython_in_gdb.main(version=%r)

            end
            ''' % (sys.version_info[:2], ))

        self.gdb_command_file = cygdb.make_command_file(
            self.tempdir, prefix_code)

        f = open(self.gdb_command_file, 'a')
        try:
            f.write(code)
        finally:
            f.close()

        args = [
            'gdb', '-batch', '-x', self.gdb_command_file, '-n', '--args',
            sys.executable, '-c', 'import codefile'
        ]

        paths = []
        path = os.environ.get('PYTHONPATH')
        if path:
            paths.append(path)
        paths.append(
            os.path.dirname(os.path.dirname(os.path.abspath(Cython.__file__))))
        env = dict(os.environ, PYTHONPATH=os.pathsep.join(paths))

        try:
            p = subprocess.Popen(['gdb', '-v'], stdout=subprocess.PIPE)
            have_gdb = True
        except OSError:
            # gdb was not installed
            have_gdb = False
        else:
            gdb_version = p.stdout.read().decode('ascii')
            p.wait()
            p.stdout.close()

        if have_gdb:
            # Based on Lib/test/test_gdb.py
            regex = "^GNU gdb [^\d]*(\d+)\.(\d+)"
            gdb_version_number = list(
                map(int,
                    re.search(regex, gdb_version).groups()))

            if gdb_version_number >= [7, 2]:
                python_version_script = tempfile.NamedTemporaryFile(mode='w+')
                python_version_script.write(
                    'python import sys; print("%s %s" % sys.version_info[:2])')
                python_version_script.flush()
                p = subprocess.Popen(
                    ['gdb', '-batch', '-x', python_version_script.name],
                    stdout=subprocess.PIPE)
                python_version = p.stdout.read().decode('ascii')
                p.wait()
                try:
                    python_version_number = list(
                        map(int, python_version.split()))
                except ValueError:
                    have_gdb = False

        # Be Python 3 compatible
        if (not have_gdb or gdb_version_number < [7, 2]
                or python_version_number < [2, 6]):
            self.p = None
            warnings.warn(
                'Skipping gdb tests, need gdb >= 7.2 with Python >= 2.6')
        else:
            self.p = subprocess.Popen(args,
                                      stdout=open(os.devnull, 'w'),
                                      stderr=subprocess.PIPE,
                                      env=env)
コード例 #4
0
ファイル: TestLibCython.py プロジェクト: dagss/cython
    def setUp(self):
        super(GdbDebuggerTestCase, self).setUp()

        prefix_code = textwrap.dedent('''\
            python

            import os
            import sys
            import traceback

            def excepthook(type, value, tb):
                traceback.print_exception(type, value, tb)
                os._exit(1)

            sys.excepthook = excepthook

            # Have tracebacks end up on sys.stderr (gdb replaces sys.stderr
            # with an object that calls gdb.write())
            sys.stderr = sys.__stderr__

            end
            ''')

        code = textwrap.dedent('''\
            python

            from Cython.Debugger.Tests import test_libcython_in_gdb
            test_libcython_in_gdb.main(version=%r)

            end
            ''' % (sys.version_info[:2],))

        self.gdb_command_file = cygdb.make_command_file(self.tempdir,
                                                        prefix_code)

        with open(self.gdb_command_file, 'a') as f:
            f.write(code)

        args = ['gdb', '-batch', '-x', self.gdb_command_file, '-n', '--args',
                sys.executable, '-c', 'import codefile']

        paths = []
        path = os.environ.get('PYTHONPATH')
        if path:
            paths.append(path)
        paths.append(os.path.dirname(os.path.dirname(
            os.path.abspath(Cython.__file__))))
        env = dict(os.environ, PYTHONPATH=os.pathsep.join(paths))

        try:
            p = subprocess.Popen(['gdb', '-v'], stdout=subprocess.PIPE)
            have_gdb = True
        except OSError:
            # gdb was not installed
            have_gdb = False
        else:
            gdb_version = p.stdout.read().decode('ascii')
            p.wait()
            p.stdout.close()

        if have_gdb:
            # Based on Lib/test/test_gdb.py
            regex = "^GNU gdb [^\d]*(\d+)\.(\d+)"
            gdb_version_number = re.search(regex, gdb_version).groups()

        # Be Python 3 compatible
        if not have_gdb or list(map(int, gdb_version_number)) < [7, 2]:
            self.p = None
            warnings.warn('Skipping gdb tests, need gdb >= 7.2')
        else:
            self.p = subprocess.Popen(
                args,
                stdout=open(os.devnull, 'w'),
                stderr=subprocess.PIPE,
                env=env)
コード例 #5
0
ファイル: cygdb.py プロジェクト: vdeolali/AdvPyClass
#!C:\cygwin\home\vdeolali\Python\Class\D4\advpy\Scripts\python2.7.exe

import sys

from Cython.Debugger import Cygdb as cygdb

if __name__ == '__main__':
    cygdb.main()
コード例 #6
0
ファイル: cygdb.py プロジェクト: geekkuldeep/djangoPro
#!/usr/bin/env python

import sys

from Cython.Debugger import Cygdb as cygdb

if __name__ == '__main__':
    cygdb.main()
コード例 #7
0
ファイル: cygdb.py プロジェクト: ekohl/essig
#!/usr/bin/env python

import sys

from Cython.Debugger import Cygdb as cygdb

if __name__ == '__main__':
    if len(sys.argv) > 1:
        path_to_debug_info = sys.argv[1]
        
        no_import = False
        if path_to_debug_info == '--':
            no_import = True
        
        cygdb.main(path_to_debug_info, 
                   gdb_argv=sys.argv[2:],
                   no_import=no_import)
    else:
        cygdb.main()
コード例 #8
0
ファイル: TestLibCython.py プロジェクト: denik/cython
    def setUp(self):
        if not test_gdb():
            return

        super(GdbDebuggerTestCase, self).setUp()

        prefix_code = textwrap.dedent(
            """\
            python

            import os
            import sys
            import traceback

            def excepthook(type, value, tb):
                traceback.print_exception(type, value, tb)
                os._exit(1)

            sys.excepthook = excepthook

            # Have tracebacks end up on sys.stderr (gdb replaces sys.stderr
            # with an object that calls gdb.write())
            sys.stderr = sys.__stderr__

            end
            """
        )

        code = textwrap.dedent(
            """\
            python

            from Cython.Debugger.Tests import test_libcython_in_gdb
            test_libcython_in_gdb.main(version=%r)

            end
            """
            % (sys.version_info[:2],)
        )

        self.gdb_command_file = cygdb.make_command_file(self.tempdir, prefix_code)

        f = open(self.gdb_command_file, "a")
        try:
            f.write(code)
        finally:
            f.close()

        args = ["gdb", "-batch", "-x", self.gdb_command_file, "-n", "--args", sys.executable, "-c", "import codefile"]

        paths = []
        path = os.environ.get("PYTHONPATH")
        if path:
            paths.append(path)
        paths.append(os.path.dirname(os.path.dirname(os.path.abspath(Cython.__file__))))
        env = dict(os.environ, PYTHONPATH=os.pathsep.join(paths))

        try:
            p = subprocess.Popen(["gdb", "-v"], stdout=subprocess.PIPE)
            have_gdb = True
        except OSError:
            # gdb was not installed
            have_gdb = False
        else:
            gdb_version = p.stdout.read().decode("ascii")
            p.wait()
            p.stdout.close()

        if have_gdb:
            # Based on Lib/test/test_gdb.py
            regex = "^GNU gdb [^\d]*(\d+)\.(\d+)"
            gdb_version_number = list(map(int, re.search(regex, gdb_version).groups()))

            if gdb_version_number >= [7, 2]:
                python_version_script = tempfile.NamedTemporaryFile(mode="w+")
                python_version_script.write('python import sys; print("%s %s" % sys.version_info[:2])')
                python_version_script.flush()
                p = subprocess.Popen(["gdb", "-batch", "-x", python_version_script.name], stdout=subprocess.PIPE)
                python_version = p.stdout.read().decode("ascii")
                p.wait()
                try:
                    python_version_number = list(map(int, python_version.split()))
                except ValueError:
                    have_gdb = False

        # Be Python 3 compatible
        if not have_gdb or gdb_version_number < [7, 2] or python_version_number < [2, 6]:
            self.p = None
            warnings.warn("Skipping gdb tests, need gdb >= 7.2 with Python >= 2.6")
        else:
            self.p = subprocess.Popen(args, stdout=open(os.devnull, "w"), stderr=subprocess.PIPE, env=env)