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