PageRenderTime 33ms CodeModel.GetById 6ms RepoModel.GetById 1ms app.codeStats 0ms

/pydbgr/processor/command/skip.py

http://pydbgr.googlecode.com/
Python | 91 lines | 57 code | 12 blank | 22 comment | 10 complexity | a63b0cd3efa972506880b82f655a5700 MD5 | raw file
Possible License(s): GPL-3.0
  1. # -*- coding: utf-8 -*-
  2. # Copyright (C) 2009 Rocky Bernstein
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. import inspect, os
  17. from import_relative import import_relative
  18. # Our local modules
  19. Mbase_cmd = import_relative('base_cmd', top_name='pydbgr')
  20. Mcmdproc = import_relative('cmdproc', '..', 'pydbgr')
  21. Mbytecode = import_relative('bytecode', '...lib', 'pydbgr')
  22. class SkipCommand(Mbase_cmd.DebuggerCommand):
  23. """skip [count]
  24. Set the next line that will be executed. The line must be within the
  25. stopped or bottom-most execution frame."""
  26. aliases = ('sk',)
  27. category = 'running'
  28. execution_set = ['Running']
  29. min_args = 0
  30. max_args = 1
  31. name = os.path.basename(__file__).split('.')[0]
  32. need_stack = True
  33. short_help = 'Skip lines to be executed'
  34. def run(self, args):
  35. if not self.core.is_running(): return False
  36. if self.proc.curindex + 1 != len(self.proc.stack):
  37. self.errmsg("You can only skip within the bottom frame.")
  38. return False
  39. if self.proc.curframe.f_trace is None:
  40. self.errmsg("Sigh - operation can't be done here.")
  41. return False
  42. if len(args) == 1:
  43. count = 1
  44. else:
  45. msg = "skip: expecting a number, got %s." % args[1]
  46. count = self.proc.get_an_int(args[1], msg)
  47. pass
  48. co = self.proc.curframe.f_code
  49. offset = self.proc.curframe.f_lasti
  50. if count is None: return False
  51. lineno = Mbytecode.next_linestart(co, offset, count)
  52. if lineno < 0:
  53. self.errmsg('No next line found')
  54. return False
  55. try:
  56. # Set to change position, update our copy of the stack,
  57. # and display the new position
  58. self.proc.curframe.f_lineno = lineno
  59. self.proc.stack[self.proc.curindex] = \
  60. self.proc.stack[self.proc.curindex][0], lineno
  61. Mcmdproc.print_location(self.proc)
  62. except ValueError, e:
  63. self.errmsg('skip failed: %s' % e)
  64. return False
  65. pass
  66. if __name__ == '__main__':
  67. mock = import_relative('mock')
  68. d, cp = mock.dbg_setup()
  69. command = SkipCommand(cp)
  70. print 'skip when not running: ', command.run(['skip', '1'])
  71. command.core.execution_status = 'Running'
  72. cp.curframe = inspect.currentframe()
  73. cp.curindex = 0
  74. cp.stack = Mcmdproc.get_stack(cp.curframe, None, None)
  75. command.run(['skip', '1'])
  76. cp.curindex = len(cp.stack)-1
  77. command.run(['skip', '1'])
  78. pass