Commit 49623f86 authored by Mark Florisson's avatar Mark Florisson

Debugger: Detect whether the scope object and cell and free variables have...

Debugger: Detect whether the scope object and cell and free variables have been initialized for closures
parent 09c4d9a3
...@@ -384,7 +384,8 @@ class TestClosure(DebugTestCase): ...@@ -384,7 +384,8 @@ class TestClosure(DebugTestCase):
def test_inner(self): def test_inner(self):
self.break_and_run_func('inner') self.break_and_run_func('inner')
self.assertEqual('', gdb.execute('cy locals', to_string=True))
# Allow the Cython-generated code to initialize the scope variable # Allow the Cython-generated code to initialize the scope variable
gdb.execute('cy step') gdb.execute('cy step')
...@@ -394,10 +395,12 @@ class TestClosure(DebugTestCase): ...@@ -394,10 +395,12 @@ class TestClosure(DebugTestCase):
def test_outer(self): def test_outer(self):
self.break_and_run_func('outer') self.break_and_run_func('outer')
self.assertEqual('', gdb.execute('cy locals', to_string=True))
# Initialize scope with 'a' uninitialized # Initialize scope with 'a' uninitialized
gdb.execute('cy step') gdb.execute('cy step')
self.assertEqual('', gdb.execute('cy locals', to_string=True))
# Initialize 'a' to 1 # Initialize 'a' to 1
gdb.execute('cy step') gdb.execute('cy step')
print_result = gdb.execute('cy print a', to_string=True).strip() print_result = gdb.execute('cy print a', to_string=True).strip()
......
...@@ -393,12 +393,12 @@ class CythonBase(object): ...@@ -393,12 +393,12 @@ class CythonBase(object):
if islocal: if islocal:
cyvar = cython_func.locals[local_name] cyvar = cython_func.locals[local_name]
if '->' in cyvar.cname: if '->' in cyvar.cname:
# Closed over free variable # Closed over free variable
try: if self.get_cython_lineno() >= cython_func.lineno + 1:
gdb.parse_and_eval(cyvar.cname) if cyvar.type == PythonObject:
return long(gdb.parse_and_eval(cyvar.cname))
return True return True
except RuntimeError: return False
return False
cur_lineno = self.get_cython_lineno() cur_lineno = self.get_cython_lineno()
return (local_name in cython_func.arguments or return (local_name in cython_func.arguments or
...@@ -1302,17 +1302,16 @@ class CyCValue(CyCName): ...@@ -1302,17 +1302,16 @@ class CyCValue(CyCName):
@require_cython_frame @require_cython_frame
@gdb_function_value_to_unicode @gdb_function_value_to_unicode
def invoke(self, cyname, frame=None): def invoke(self, cyname, frame=None):
try: globals_dict = self.get_cython_globals_dict()
cython_function = self.get_cython_function(frame)
if self.is_initialized(cython_function, cyname):
cname = super(CyCValue, self).invoke(cyname, frame=frame) cname = super(CyCValue, self).invoke(cyname, frame=frame)
return gdb.parse_and_eval(cname) return gdb.parse_and_eval(cname)
except (gdb.GdbError, RuntimeError), e: elif cyname in globals_dict:
# variable exists but may not have been initialized yet, or may be return globals_dict[cyname]._gdbval
# in the globals dict of the Cython module else:
d = self.get_cython_globals_dict() raise gdb.GdbError("Variable %s is not initialized." % cyname)
if cyname in d:
return d[cyname]._gdbval
raise gdb.GdbError(str(e))
class CyLine(gdb.Function, CythonBase): class CyLine(gdb.Function, CythonBase):
......
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