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."
globals = CyGlobals.register(),
exec_ = libpython.FixGdbCommand('cy exec', '-cy-exec'),
_exec = CyExec.register(),
+ set = CySet.register(),
# GDB functions
cy_cname = CyCName('cy_cname'),
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):