Commit e29bdf17 authored by Mark Florisson's avatar Mark Florisson

Added commands 'cy cont' and 'cy step'

parent b465df68
...@@ -452,6 +452,8 @@ class CyCy(CythonCommand): ...@@ -452,6 +452,8 @@ class CyCy(CythonCommand):
break_ = CyBreak.register(), break_ = CyBreak.register(),
step = CyStep.register(), step = CyStep.register(),
next = CyNext.register(), next = CyNext.register(),
run = CyRun.register(),
cont = CyCont.register(),
list = CyList.register(), list = CyList.register(),
print_ = CyPrint.register(), print_ = CyPrint.register(),
locals = CyLocals.register(), locals = CyLocals.register(),
...@@ -705,6 +707,32 @@ class CyNext(CythonCodeStepper): ...@@ -705,6 +707,32 @@ class CyNext(CythonCodeStepper):
super(CythonCodeStepper, self).invoke(*args, **kwargs) super(CythonCodeStepper, self).invoke(*args, **kwargs)
class CyRun(CythonCodeStepper):
"""
Run a Cython program. This is like the 'run' command, except that it
displays Cython or Python source lines as well
"""
name = 'cy run'
def invoke(self, *args):
self.result = gdb.execute('run', to_string=True)
self.end_stepping()
class CyCont(CythonCodeStepper):
"""
Continue a Cython program. This is like the 'run' command, except that it
displays Cython or Python source lines as well.
"""
name = 'cy cont'
def invoke(self, *args):
self.result = gdb.execute('cont', to_string=True)
self.end_stepping()
class CyList(CythonCommand): class CyList(CythonCommand):
""" """
List Cython source code. To disable to customize colouring see the cy_* List Cython source code. To disable to customize colouring see the cy_*
......
...@@ -1542,29 +1542,29 @@ class GenericCodeStepper(gdb.Command): ...@@ -1542,29 +1542,29 @@ class GenericCodeStepper(gdb.Command):
depending on the 'stepper' argument. depending on the 'stepper' argument.
""" """
stepper = False
def __init__(self, name, stepper=False): def __init__(self, name, stepper=False):
super(GenericCodeStepper, self).__init__(name, super(GenericCodeStepper, self).__init__(name,
gdb.COMMAND_RUNNING, gdb.COMMAND_RUNNING,
gdb.COMPLETE_NONE) gdb.COMPLETE_NONE)
self.stepper = stepper self.stepper = stepper
def _init_stepping(self): def init_stepping(self):
self.beginframe = gdb.selected_frame() self.beginframe = gdb.selected_frame()
self.beginline = self.lineno(self.beginframe) self.beginline = self.lineno(self.beginframe)
if not self.stepper: if not self.stepper:
self.depth = self._stackdepth(self.beginframe) self.depth = self._stackdepth(self.beginframe)
def _next_step(self, gdb_command): def next_step(self, gdb_command):
""" """
Teturns whether to continue stepping. This method sets the instance Teturns whether to continue stepping. This method sets the instance
attributes 'result' and 'stopped_running'. 'result' hold the output attribute 'result'. 'result' hold the output of the executed gdb
of the executed gdb command ('step' or 'next') command ('step' or 'next')
""" """
self.result = gdb.execute(gdb_command, to_string=True) self.result = gdb.execute(gdb_command, to_string=True)
self.stopped_running = gdb.inferiors()[0].pid == 0
if self.stopped_running: if self.stopped():
# We stopped running
return False return False
newframe = gdb.selected_frame() newframe = gdb.selected_frame()
...@@ -1586,8 +1586,9 @@ class GenericCodeStepper(gdb.Command): ...@@ -1586,8 +1586,9 @@ class GenericCodeStepper(gdb.Command):
return not (hit_breakpoint or new_lineno or is_relevant_function) return not (hit_breakpoint or new_lineno or is_relevant_function)
def _end_stepping(self): def end_stepping(self):
if self.stopped_running: "requires that the instance attribute self.result is set"
if self.stopped():
sys.stdout.write(self.result) sys.stdout.write(self.result)
else: else:
frame = gdb.selected_frame() frame = gdb.selected_frame()
...@@ -1598,6 +1599,9 @@ class GenericCodeStepper(gdb.Command): ...@@ -1598,6 +1599,9 @@ class GenericCodeStepper(gdb.Command):
else: else:
print output print output
def stopped(self):
return gdb.inferiors()[0].pid == 0
def _stackdepth(self, frame): def _stackdepth(self, frame):
depth = 0 depth = 0
while frame: while frame:
...@@ -1618,11 +1622,11 @@ class GenericCodeStepper(gdb.Command): ...@@ -1618,11 +1622,11 @@ class GenericCodeStepper(gdb.Command):
gdb_command= 'next' gdb_command= 'next'
for nthstep in xrange(nsteps): for nthstep in xrange(nsteps):
self._init_stepping() self.init_stepping()
while self._next_step(gdb_command): while self.next_step(gdb_command):
pass pass
self._end_stepping() self.end_stepping()
class PythonCodeStepper(GenericCodeStepper): class PythonCodeStepper(GenericCodeStepper):
......
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