Debugger: Detect whether the scope object and cell and free variables have been initi...
authorMark Florisson <markflorisson88@gmail.com>
Mon, 10 Jan 2011 22:57:08 +0000 (23:57 +0100)
committerMark Florisson <markflorisson88@gmail.com>
Mon, 10 Jan 2011 22:57:08 +0000 (23:57 +0100)
Cython/Debugger/Tests/test_libcython_in_gdb.py
Cython/Debugger/libcython.py

index 89ff7fdd5674b259f396ec3e902d82cb3a0fd6a7..295f8b297d50beea8ce2d834e3710778a51cdcbd 100644 (file)
@@ -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()
index d5f0c48db67f5e486659faef38efe0edf397589d..82d3479c2fbd60909a4bce73d8edde91944f5966 100644 (file)
@@ -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):