Commit 59b75c3b authored by Mark Florisson's avatar Mark Florisson

'cy exec' and 'py-exec' multiline code support

parent 4f208e13
...@@ -1099,7 +1099,7 @@ class CyGlobals(CyLocals): ...@@ -1099,7 +1099,7 @@ class CyGlobals(CyLocals):
prefix=' ') prefix=' ')
class CyExec(CythonCommand): class CyExec(CythonCommand, libpython.PyExec):
name = '-cy-exec' name = '-cy-exec'
command_class = gdb.COMMAND_STACK command_class = gdb.COMMAND_STACK
completer_class = gdb.COMPLETE_NONE completer_class = gdb.COMPLETE_NONE
...@@ -1153,6 +1153,7 @@ class CyExec(CythonCommand): ...@@ -1153,6 +1153,7 @@ class CyExec(CythonCommand):
libpython.py_exec.invoke(expr, from_tty) libpython.py_exec.invoke(expr, from_tty)
return return
expr, input_type = self.readcode(expr)
executor = libpython.PythonCodeExecutor() executor = libpython.PythonCodeExecutor()
# get the dict of Cython globals and construct a dict in the inferior # get the dict of Cython globals and construct a dict in the inferior
...@@ -1163,7 +1164,7 @@ class CyExec(CythonCommand): ...@@ -1163,7 +1164,7 @@ class CyExec(CythonCommand):
try: try:
self._fill_locals_dict(executor, libpython.pointervalue(local_dict)) self._fill_locals_dict(executor, libpython.pointervalue(local_dict))
executor.evalcode(expr, global_dict, local_dict) executor.evalcode(expr, input_type, global_dict, local_dict)
finally: finally:
executor.decref(libpython.pointervalue(local_dict)) executor.decref(libpython.pointervalue(local_dict))
......
...@@ -1901,6 +1901,7 @@ py_cont = PyCont('py-cont') ...@@ -1901,6 +1901,7 @@ py_cont = PyCont('py-cont')
py_step.init_breakpoints() py_step.init_breakpoints()
Py_single_input = 256 Py_single_input = 256
Py_file_input = 257
Py_eval_input = 258 Py_eval_input = 258
def pointervalue(gdbval): def pointervalue(gdbval):
...@@ -1961,7 +1962,7 @@ class PythonCodeExecutor(object): ...@@ -1961,7 +1962,7 @@ class PythonCodeExecutor(object):
# Python strings. # Python strings.
gdb.parse_and_eval('Py_DecRef((PyObject *) %d)' % pointer) gdb.parse_and_eval('Py_DecRef((PyObject *) %d)' % pointer)
def evalcode(self, code, global_dict=None, local_dict=None): def evalcode(self, code, input_type, global_dict=None, local_dict=None):
""" """
Evaluate python code `code` given as a string in the inferior and Evaluate python code `code` given as a string in the inferior and
return the result as a gdb.Value. Returns a new reference in the return the result as a gdb.Value. Returns a new reference in the
...@@ -1989,7 +1990,7 @@ class PythonCodeExecutor(object): ...@@ -1989,7 +1990,7 @@ class PythonCodeExecutor(object):
(int) %(start)d, (int) %(start)d,
(PyObject *) %(globals)s, (PyObject *) %(globals)s,
(PyObject *) %(locals)d) (PyObject *) %(locals)d)
""" % dict(code=pointer, start=Py_single_input, """ % dict(code=pointer, start=input_type,
globals=globalsp, locals=localsp) globals=globalsp, locals=localsp)
with FetchAndRestoreError(): with FetchAndRestoreError():
...@@ -2077,7 +2078,27 @@ class FixGdbCommand(gdb.Command): ...@@ -2077,7 +2078,27 @@ class FixGdbCommand(gdb.Command):
class PyExec(gdb.Command): class PyExec(gdb.Command):
def readcode(self, expr):
if expr:
return expr, Py_single_input
else:
lines = []
while True:
try:
line = raw_input('>')
except EOFError:
break
else:
if line.rstrip() == 'end':
break
lines.append(line)
return '\n'.join(lines), Py_file_input
def invoke(self, expr, from_tty): def invoke(self, expr, from_tty):
expr, input_type = self.readcode(expr)
executor = PythonCodeExecutor() executor = PythonCodeExecutor()
global_dict = gdb.parse_and_eval('PyEval_GetGlobals()') global_dict = gdb.parse_and_eval('PyEval_GetGlobals()')
local_dict = gdb.parse_and_eval('PyEval_GetLocals()') local_dict = gdb.parse_and_eval('PyEval_GetLocals()')
...@@ -2087,7 +2108,7 @@ class PyExec(gdb.Command): ...@@ -2087,7 +2108,7 @@ class PyExec(gdb.Command):
"most recent Python function (relative to the " "most recent Python function (relative to the "
"selected frame).") "selected frame).")
executor.evalcode(expr, global_dict, local_dict) executor.evalcode(expr, input_type, global_dict, local_dict)
py_exec = FixGdbCommand('py-exec', '-py-exec') py_exec = FixGdbCommand('py-exec', '-py-exec')
_py_exec = PyExec("-py-exec", gdb.COMMAND_DATA, gdb.COMPLETE_NONE) _py_exec = PyExec("-py-exec", gdb.COMMAND_DATA, gdb.COMPLETE_NONE)
\ No newline at end of file
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