Commit c12526e9 authored by Mark Florisson's avatar Mark Florisson

Excluded cygdb from python 2.3 and 2.4 installations and made it 2.5 compatible

Made the distutils extension 2.3 compatible
Renamed the --debug flag to --gdb and --pyrex-debug to --pyrex-gdb
parent fae8606e
......@@ -28,7 +28,7 @@ Options:
Level indicates aggressiveness, default 0 releases nothing.
-w, --working <directory> Sets the working directory for Cython (the directory modules
are searched from)
--debug Output debug information for cygdb
--gdb Output debug information for cygdb
-D, --no-docstrings Remove docstrings.
-a, --annotate Produce a colorized HTML version of the source.
......@@ -115,8 +115,8 @@ def parse_command_line(args):
Options.convert_range = True
elif option == "--line-directives":
options.emit_linenums = True
elif option == "--debug":
options.debug = True
elif option == "--gdb":
options.gdb_debug = True
options.output_dir = os.curdir
elif option == '-2':
options.language_level = 2
......
......@@ -92,7 +92,7 @@ class CompilerCrash(CompileError):
CompileError.__init__(self, pos, message)
class NoElementTreeInstalledException(PyrexError):
"""raised when the user enabled options.debug but no ElementTree
"""raised when the user enabled options.gdb_debug but no ElementTree
implementation was found
"""
......
......@@ -87,7 +87,7 @@ class Context(object):
self.set_language_level(language_level)
self.debug_outputwriter = None
self.gdb_debug_outputwriter = None
def set_language_level(self, level):
self.language_level = level
......@@ -182,10 +182,10 @@ class Context(object):
from Cython.TestUtils import TreeAssertVisitor
test_support.append(TreeAssertVisitor())
if options.debug:
if options.gdb_debug:
from Cython.Debugger import DebugWriter
from ParseTreeTransforms import DebugTransform
self.debug_outputwriter = DebugWriter.CythonDebugWriter(
self.gdb_debug_outputwriter = DebugWriter.CythonDebugWriter(
options.output_dir)
debug_transform = [DebugTransform(self, options, result)]
else:
......@@ -814,5 +814,5 @@ default_options = dict(
evaluate_tree_assertions = False,
emit_linenums = False,
language_level = 2,
debug = False,
gdb_debug = False,
)
......@@ -299,7 +299,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
f = open_new_file(result.c_file)
rootwriter.copyto(f)
if options.debug:
if options.gdb_debug:
self._serialize_lineno_map(env, rootwriter)
f.close()
result.c_file_generated = 1
......@@ -308,7 +308,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
rootwriter.save_annotation(result.main_source_file, result.c_file)
def _serialize_lineno_map(self, env, ccodewriter):
tb = env.context.debug_outputwriter
tb = env.context.gdb_debug_outputwriter
markers = ccodewriter.buffer.allmarkers()
d = {}
......
......@@ -1586,7 +1586,7 @@ class DebugTransform(CythonTransform):
self.visited = set()
# our treebuilder and debug output writer
# (see Cython.Debugger.debug_output.CythonDebugWriter)
self.tb = self.context.debug_outputwriter
self.tb = self.context.gdb_debug_outputwriter
#self.c_output_file = options.output_file
self.c_output_file = result.c_file
......@@ -1626,7 +1626,7 @@ class DebugTransform(CythonTransform):
def visit_FuncDefNode(self, node):
self.visited.add(node.local_scope.qualified_name)
node.entry.visibility = 'extern'
# node.entry.visibility = 'extern'
if node.py_func is None:
pf_cname = ''
else:
......
import os
from Cython.Debugger import DebugWriter
from Cython.Compiler import Main
from Cython.Compiler import CmdLine
from Cython.TestUtils import TransformTest
from Cython.Compiler.ParseTreeTransforms import *
......@@ -149,7 +148,8 @@ class TestWithTransform(object): # (TransformTest): # Disabled!
class TestDebugTransform(TestLibCython.DebuggerTestCase):
def elem_hasattrs(self, elem, attrs):
return all(attr in elem.attrib for attr in attrs)
# we shall supporteth python 2.3 !
return all([attr in elem.attrib for attr in attrs])
def test_debug_info(self):
try:
......@@ -161,12 +161,13 @@ class TestDebugTransform(TestLibCython.DebuggerTestCase):
L = list(t.find('/Module/Globals'))
# assertTrue is retarded, use the normal assert statement
assert L
xml_globals = dict((e.attrib['name'], e.attrib['type']) for e in L)
xml_globals = dict(
[(e.attrib['name'], e.attrib['type']) for e in L])
self.assertEqual(len(L), len(xml_globals))
L = list(t.find('/Module/Functions'))
assert L
xml_funcs = dict((e.attrib['qualified_name'], e) for e in L)
xml_funcs = dict([(e.attrib['qualified_name'], e) for e in L])
self.assertEqual(len(L), len(xml_funcs))
# test globals
......@@ -176,8 +177,8 @@ class TestDebugTransform(TestLibCython.DebuggerTestCase):
# test functions
funcnames = 'codefile.spam', 'codefile.ham', 'codefile.eggs'
required_xml_attrs = 'name', 'cname', 'qualified_name'
assert all(f in xml_funcs for f in funcnames)
spam, ham, eggs = (xml_funcs[funcname] for funcname in funcnames)
assert all([f in xml_funcs for f in funcnames])
spam, ham, eggs = [xml_funcs[funcname] for funcname in funcnames]
self.assertEqual(spam.attrib['name'], 'spam')
self.assertNotEqual('spam', spam.attrib['cname'])
......
......@@ -17,8 +17,7 @@ import glob
import tempfile
import subprocess
def usage():
print("Usage: cygdb [PATH GDB_ARGUMENTS]")
usage = "Usage: cygdb [PATH [GDB_ARGUMENTS]]"
def make_command_file(path_to_debug_info, prefix_code='', no_import=False):
if not no_import:
......@@ -28,11 +27,8 @@ def make_command_file(path_to_debug_info, prefix_code='', no_import=False):
debug_files = glob.glob(pattern)
if not debug_files:
usage()
sys.exit('No debug files were found in %s. Aborting.' % (
os.path.abspath(path_to_debug_info)))
sys.exit('%s.\nNo debug files were found in %s. Aborting.' % (
usage, os.path.abspath(path_to_debug_info)))
fd, tempfilename = tempfile.mkstemp()
f = os.fdopen(fd, 'w')
......@@ -55,14 +51,28 @@ def make_command_file(path_to_debug_info, prefix_code='', no_import=False):
return tempfilename
def main(path_to_debug_info=os.curdir, gdb_argv=[], no_import=False):
def main(path_to_debug_info=None, gdb_argv=None, no_import=False):
"""
Start the Cython debugger. This tells gdb to import the Cython and Python
extensions (libpython.py and libcython.py) and it enables gdb's pending
breakpoints
extensions (libcython.py and libpython.py) and it enables gdb's pending
breakpoints.
path_to_debug_info is the path to the cython_debug directory
path_to_debug_info is the path to the Cython build directory
gdb_argv is the list of options to gdb
no_import tells cygdb whether it should import debug information
"""
if path_to_debug_info is None:
if len(sys.argv) > 1:
path_to_debug_info = sys.argv[1]
else:
path_to_debug_info = os.curdir
if gdb_argv is None:
gdb_argv = sys.argv[2:]
if path_to_debug_info == '--':
no_import = True
tempfilename = make_command_file(path_to_debug_info, no_import=no_import)
p = subprocess.Popen(['gdb', '-command', tempfilename] + gdb_argv)
while True:
......
from __future__ import with_statement
import os
import sys
import errno
......
......@@ -46,7 +46,7 @@ class DebuggerTestCase(unittest.TestCase):
ext = Cython.Distutils.extension.Extension(
'codefile',
['codefile.pyx'],
pyrex_debug=True,
pyrex_gdb=True,
extra_objects=['cfuncs.o'])
distutils.core.setup(
......
......@@ -594,8 +594,10 @@ class CyCy(CythonCommand):
command_class = gdb.COMMAND_NONE
completer_class = gdb.COMPLETE_COMMAND
def __init__(self, *args):
super(CythonCommand, self).__init__(*args, prefix=True)
def __init__(self, name, command_class, completer_class):
# keep the signature 2.5 compatible (i.e. do not use f(*a, k=v)
super(CythonCommand, self).__init__(name, command_class,
completer_class, prefix=True)
commands = dict(
import_ = CyImport.register(),
......@@ -1137,6 +1139,10 @@ class CyGlobals(CyLocals):
class CyExec(CythonCommand, libpython.PyExec):
"""
Execute Python code in the nearest Python or Cython frame.
"""
name = '-cy-exec'
command_class = gdb.COMMAND_STACK
completer_class = gdb.COMPLETE_NONE
......@@ -1206,42 +1212,8 @@ class CyExec(CythonCommand, libpython.PyExec):
self._fill_locals_dict(executor, libpython.pointervalue(local_dict))
executor.evalcode(expr, input_type, global_dict, local_dict)
finally:
# try:
# tp, val, tb = sys.exc_info()
# sys.exc_clear()
#
# try:
# long(gdb.parse_and_eval("(void *) 0")) == 0
# except RuntimeError:
# # At this point gdb is broken, just exit this shite, it
# # ain't getting better.
#
# # /home/mark/source/code/cython/Cython/Debugger/libcython.py:1206:
# # RuntimeWarning: tp_compare didn't return -1 or -2 for exception
# # long(gdb.parse_and_eval("(void *) 0")) == 0
# # Traceback (most recent call last):
# # File "/home/mark/source/code/cython/Cython/Debugger/libcython.py", line 1206,
# # in invoke
# # long(gdb.parse_and_eval("(void *) 0")) == 0
# # RuntimeError: Cannot convert value to int.
# # Error occurred in Python command: Cannot convert value to int.
# if sys.exc_info()[0] is None and val is not None:
# raise val, tb
#
# for name, value in libpython.PyDictObjectPtr(local_dict).iteritems():
# name = name.proxyval(set())
# cyvar = cython_function.locals.get(name)
# if cyvar is not None and cyvar.type == PythonObject:
# gdb.parse_and_eval('set %s = (PyObject *) %d' % (cyvar.cname,
# pointervalue(value._gdbval)))
# finally:
executor.decref(libpython.pointervalue(local_dict))
# if sys.exc_info()[0] is None and val is not None:
# raise val, tb
# Functions
......
#!/usr/bin/python
# NOTE: this file is taken from the Python source distribution
# It can be found under Tools/gdb/libpython.py
# It can be found under Tools/gdb/libpython.py. It is shipped with Cython
# because it's not installed as a python module, and because changes are only
# merged into new python versions (v3.2+).
'''
From gdb 7 onwards, gdb's build can be configured --with-python, allowing gdb
......
......@@ -43,8 +43,8 @@ class Optimization(object):
for flag, option in zip(self.flags, self.state):
if option is not None:
g = (opt for opt in option.split() if opt not in badoptions)
self.config_vars[flag] = ' '.join(g)
L = [opt for opt in option.split() if opt not in badoptions]
self.config_vars[flag] = ' '.join(L)
def restore_state(self):
"restore the original state"
......@@ -55,6 +55,16 @@ class Optimization(object):
optimization = Optimization()
try:
any
except NameError:
def any(it):
for x in it:
if x:
return True
return False
class build_ext(_build_ext.build_ext):
......@@ -81,13 +91,13 @@ class build_ext(_build_ext.build_ext):
"generate .pxi file for public declarations"),
('pyrex-directives=', None,
"compiler directive overrides"),
('pyrex-debug', None,
('pyrex-gdb', None,
"generate debug information for cygdb"),
])
boolean_options.extend([
'pyrex-cplus', 'pyrex-create-listing', 'pyrex-line-directives',
'pyrex-c-in-temp', 'pyrex-debug',
'pyrex-c-in-temp', 'pyrex-gdb',
])
def initialize_options(self):
......@@ -99,7 +109,7 @@ class build_ext(_build_ext.build_ext):
self.pyrex_directives = None
self.pyrex_c_in_temp = 0
self.pyrex_gen_pxi = 0
self.pyrex_debug = False
self.pyrex_gdb = False
def finalize_options (self):
_build_ext.build_ext.finalize_options(self)
......@@ -114,11 +124,11 @@ class build_ext(_build_ext.build_ext):
def run(self):
# We have one shot at this before build_ext initializes the compiler.
# If --pyrex-debug is in effect as a command line option or as option
# If --pyrex-gdb is in effect as a command line option or as option
# of any Extension module, disable optimization for the C or C++
# compiler.
if (self.pyrex_debug or any(getattr(ext, 'pyrex_debug', False)
for ext in self.extensions)):
if (self.pyrex_gdb or any([getattr(ext, 'pyrex_gdb', False)
for ext in self.extensions])):
optimization.disable_optimization()
_build_ext.build_ext.run(self)
......@@ -178,7 +188,7 @@ class build_ext(_build_ext.build_ext):
cplus = self.pyrex_cplus or getattr(extension, 'pyrex_cplus', 0) or \
(extension.language and extension.language.lower() == 'c++')
pyrex_gen_pxi = self.pyrex_gen_pxi or getattr(extension, 'pyrex_gen_pxi', 0)
pyrex_debug = self.pyrex_debug or getattr(extension, 'pyrex_debug', False)
pyrex_gdb = self.pyrex_gdb or getattr(extension, 'pyrex_gdb', False)
# Set up the include_path for the Cython compiler:
# 1. Start with the command line option.
# 2. Add in any (unique) paths from the extension
......@@ -264,7 +274,7 @@ class build_ext(_build_ext.build_ext):
emit_linenums = line_directives,
generate_pxi = pyrex_gen_pxi,
output_dir = output_dir,
debug = pyrex_debug)
gdb_debug = pyrex_gdb)
result = cython_compile(source, options=options,
full_module_name=module_name)
else:
......
......@@ -31,7 +31,7 @@ class Extension(_Extension.Extension):
put generated C files in temp directory.
pyrex_gen_pxi : boolean
generate .pxi file for public declarations
pyrex_debug : boolean
pyrex_gdb : boolean
generate Cython debug information for this extension for cygdb
"""
......@@ -58,7 +58,7 @@ class Extension(_Extension.Extension):
pyrex_cplus = 0,
pyrex_c_in_temp = 0,
pyrex_gen_pxi = 0,
pyrex_debug = False,
pyrex_gdb = False,
**kw):
_Extension.Extension.__init__(self, name, sources,
......@@ -84,7 +84,7 @@ class Extension(_Extension.Extension):
self.pyrex_cplus = pyrex_cplus
self.pyrex_c_in_temp = pyrex_c_in_temp
self.pyrex_gen_pxi = pyrex_gen_pxi
self.pyrex_debug = pyrex_debug
self.pyrex_gdb = pyrex_gdb
# class Extension
......
......@@ -5,15 +5,4 @@ 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()
......@@ -5,15 +5,4 @@ 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()
......@@ -70,6 +70,9 @@ else:
# specific to setup
setuptools_extra_args = {}
# tells whether to include cygdb (the script and the Cython.Debugger package
include_debugger = sys.version_info[:2] > (2, 4)
if 'setuptools' in sys.modules:
setuptools_extra_args['zip_safe'] = False
setuptools_extra_args['entry_points'] = {
......@@ -80,9 +83,13 @@ if 'setuptools' in sys.modules:
scripts = []
else:
if os.name == "posix":
scripts = ["bin/cython", "bin/cygdb"]
scripts = ["bin/cython"]
if include_debugger:
scripts.append('bin/cygdb')
else:
scripts = ["cython.py", "cygdb.py"]
scripts = ["cython.py"]
if include_debugger:
scripts.append('cygdb.py')
def compile_cython_modules(profile=False, compile_more=False, cython_with_refnanny=False):
source_root = os.path.abspath(os.path.dirname(__file__))
......@@ -247,6 +254,20 @@ setup_args.update(setuptools_extra_args)
from Cython import __version__ as version
packages = [
'Cython',
'Cython.Build',
'Cython.Compiler',
'Cython.Runtime',
'Cython.Distutils',
'Cython.Plex',
'Cython.Tests',
'Cython.Compiler.Tests',
]
if include_debugger:
packages.append('Cython.Debugger')
setup(
name = 'Cython',
version = version,
......@@ -287,17 +308,7 @@ setup(
],
scripts = scripts,
packages=[
'Cython',
'Cython.Build',
'Cython.Compiler',
'Cython.Runtime',
'Cython.Distutils',
'Cython.Plex',
'Cython.Debugger',
'Cython.Tests',
'Cython.Compiler.Tests',
],
packages=packages,
# pyximport
py_modules = ["pyximport/__init__",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment