From a0dc7e649c44621a812930c93be0c61cdee3f8b6 Mon Sep 17 00:00:00 2001 From: Mark Florisson Date: Sat, 26 Mar 2011 11:19:26 +0100 Subject: [PATCH] Debugger: Update 'help' documentation --- .../Debugger/Tests/test_libpython_in_gdb.py | 4 +--- Cython/Debugger/libcython.py | 20 ++++++------------- Cython/Debugger/libpython.py | 18 +++++++++++++++-- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Cython/Debugger/Tests/test_libpython_in_gdb.py b/Cython/Debugger/Tests/test_libpython_in_gdb.py index e45adb22..fd1582ed 100644 --- a/Cython/Debugger/Tests/test_libpython_in_gdb.py +++ b/Cython/Debugger/Tests/test_libpython_in_gdb.py @@ -112,6 +112,4 @@ class TestPrettyPrinters(test_libcython_in_gdb.DebugTestCase): def test_frame_type(self): frame = self.pyobject_fromcode('PyEval_GetFrame()') - self.assertEqual(type(frame), libpython.PyFrameObjectPtr) - - + self.assertEqual(type(frame), libpython.PyFrameObjectPtr) \ No newline at end of file diff --git a/Cython/Debugger/libcython.py b/Cython/Debugger/libcython.py index fc6a777b..a1d4221e 100644 --- a/Cython/Debugger/libcython.py +++ b/Cython/Debugger/libcython.py @@ -592,6 +592,7 @@ class CyCy(CythonCommand): cy bt / cy backtrace cy list cy print + cy set cy locals cy globals cy exec @@ -1245,19 +1246,6 @@ class EvaluateOrExecuteCodeMixin(object): return result - - def _evalcode_python(self, executor, code, input_type): - global_dict = gdb.parse_and_eval('PyEval_GetGlobals()') - local_dict = gdb.parse_and_eval('PyEval_GetLocals()') - - if (libpython.pointervalue(global_dict) == 0 or - libpython.pointervalue(local_dict) == 0): - raise gdb.GdbError("Unable to find the locals or globals of the " - "most recent Python function (relative to the " - "selected frame).") - - return executor.evalcode(code, input_type, global_dict, local_dict) - def evalcode(self, code, input_type): """ Evaluate `code` in a Python or Cython stack frame using the given @@ -1266,7 +1254,7 @@ class EvaluateOrExecuteCodeMixin(object): frame = self._find_first_cython_or_python_frame() executor = libpython.PythonCodeExecutor() if self.is_python_function(frame): - return self._evalcode_python(executor, code, input_type) + return libpython._evalcode_python(executor, code, input_type) return self._evalcode_cython(executor, code, input_type) @@ -1291,6 +1279,10 @@ class CySet(CythonCommand): cy set my_cython_c_variable = 10 cy set my_cython_py_variable = $cy_eval("{'doner': 'kebab'}") + + This is equivalent to + + set $cy_value("my_cython_variable") = 10 """ name = 'cy set' diff --git a/Cython/Debugger/libpython.py b/Cython/Debugger/libpython.py index 44d9f33d..43b4353b 100644 --- a/Cython/Debugger/libpython.py +++ b/Cython/Debugger/libpython.py @@ -2463,6 +2463,20 @@ class FixGdbCommand(gdb.Command): self.fix_gdb() +def _evalcode_python(executor, code, input_type): + """ + Execute Python code in the most recent stack frame. + """ + global_dict = gdb.parse_and_eval('PyEval_GetGlobals()') + local_dict = gdb.parse_and_eval('PyEval_GetLocals()') + + if (pointervalue(global_dict) == 0 or pointervalue(local_dict) == 0): + raise gdb.GdbError("Unable to find the locals or globals of the " + "most recent Python function (relative to the " + "selected frame).") + + return executor.evalcode(code, input_type, global_dict, local_dict) + class PyExec(gdb.Command): def readcode(self, expr): @@ -2486,8 +2500,8 @@ class PyExec(gdb.Command): def invoke(self, expr, from_tty): expr, input_type = self.readcode(expr) executor = PythonCodeExecutor() - result = executor.evalcode(expr, input_type, global_dict, local_dict) - executor.xdecref(result) + executor.xdecref(_evalcode_python(executor, input_type, global_dict, + local_dict)) gdb.execute('set breakpoint pending on') -- 2.26.2