From: Mark Florisson Date: Fri, 25 Mar 2011 22:01:51 +0000 (+0100) Subject: Debugger: Added 'cy set' command X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=298ea9669c696ff20b1b915138d208edff5654c1;p=cython.git Debugger: Added 'cy set' command --- diff --git a/Cython/Debugger/Tests/test_libcython_in_gdb.py b/Cython/Debugger/Tests/test_libcython_in_gdb.py index 46dba686..683f4c7c 100644 --- a/Cython/Debugger/Tests/test_libcython_in_gdb.py +++ b/Cython/Debugger/Tests/test_libcython_in_gdb.py @@ -379,6 +379,16 @@ class TestExec(DebugTestCase): self.assertEqual('14', self.eval_command('some_random_var')) +class CySet(DebugTestCase): + + def test_cyset(self): + self.break_and_run('os.path.join("foo", "bar")') + + gdb.execute('cy set a = $cy_eval("{None: []}")') + stringvalue = self.read_var("a", cast_to=str) + self.assertEqual(stringvalue, "{None: []}") + + class TestCyEval(DebugTestCase): "Test the $cy_eval() gdb function." diff --git a/Cython/Debugger/libcython.py b/Cython/Debugger/libcython.py index e242bada..fc6a777b 100644 --- a/Cython/Debugger/libcython.py +++ b/Cython/Debugger/libcython.py @@ -625,6 +625,7 @@ class CyCy(CythonCommand): globals = CyGlobals.register(), exec_ = libpython.FixGdbCommand('cy exec', '-cy-exec'), _exec = CyExec.register(), + set = CySet.register(), # GDB functions cy_cname = CyCName('cy_cname'), @@ -1284,6 +1285,29 @@ class CyExec(CythonCommand, libpython.PyExec, EvaluateOrExecuteCodeMixin): executor.xdecref(self.evalcode(expr, executor.Py_single_input)) +class CySet(CythonCommand): + """ + Set a Cython variable to a certain value + + cy set my_cython_c_variable = 10 + cy set my_cython_py_variable = $cy_eval("{'doner': 'kebab'}") + """ + + name = 'cy set' + command_class = gdb.COMMAND_DATA + completer_class = gdb.COMPLETE_NONE + + @require_cython_frame + def invoke(self, expr, from_tty): + name_and_expr = expr.split('=', 1) + if len(name_and_expr) != 2: + raise gdb.GdbError("Invalid expression. Use 'cy set var = expr'.") + + varname, expr = name_and_expr + cname = self.cy.cy_cname.invoke(varname.strip()) + gdb.execute("set %s = %s" % (cname, expr)) + + # Functions class CyCName(gdb.Function, CythonBase):