PageRenderTime 41ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/pydbgr/processor/command/info_subcmd/program.py

http://pydbgr.googlecode.com/
Python | 91 lines | 67 code | 6 blank | 18 comment | 14 complexity | 7f2ef24557dc0e23bbf8559fab9d8b27 MD5 | raw file
Possible License(s): GPL-3.0
  1. # -*- coding: utf-8 -*-
  2. # Copyright (C) 2008, 2009 Rocky Bernstein <rocky@gnu.org>
  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 sys
  17. from import_relative import import_relative
  18. # Our local modules
  19. # FIXME: Until import_relative is fixed up...
  20. import_relative('processor', '....', 'pydbgr')
  21. Mbase_subcmd = import_relative('base_subcmd', '..', 'pydbgr')
  22. Mmisc = import_relative('misc', '....', 'pydbgr')
  23. class InfoProgram(Mbase_subcmd.DebuggerSubcommand):
  24. 'Execution status of the program.'
  25. min_abbrev = 1 # Need at least info p
  26. need_stack = True
  27. short_help = 'Execution status of the program'
  28. def run(self, args):
  29. """Execution status of the program."""
  30. mainfile = self.core.filename(None)
  31. if self.core.is_running():
  32. if mainfile:
  33. part1 = "Python program '%s' is stopped" % mainfile
  34. else:
  35. part1 = 'Program is stopped'
  36. pass
  37. if self.proc.event:
  38. msg = 'via a %s event.' % self.proc.event
  39. else:
  40. msg = '.'
  41. self.msg(Mmisc.wrapped_lines(part1, msg,
  42. self.settings['width']))
  43. if self.proc.curframe:
  44. self.msg("PC offset is %d." % self.proc.curframe.f_lasti)
  45. if self.proc.event == 'return':
  46. val = self.proc.event_arg
  47. part1 = 'Return value is'
  48. self.msg(Mmisc.wrapped_lines(part1, self.proc._saferepr(val),
  49. self.settings['width']))
  50. pass
  51. elif self.proc.event == 'exception':
  52. exc_type, exc_value, exc_tb = self.proc.event_arg
  53. self.msg('Exception type: %s' %
  54. self.proc._saferepr(exc_type))
  55. if exc_value:
  56. self.msg('Exception value: %s' %
  57. self.proc._saferepr(exc_value))
  58. pass
  59. pass
  60. self.msg('It stopped %s.' % self.core.stop_reason)
  61. if self.proc.event in ['signal', 'exception', 'c_exception']:
  62. self.msg('Note: we are stopped *after* running the line shown.')
  63. pass
  64. else:
  65. if mainfile:
  66. part1 = "Python program '%s'" % mainfile
  67. msg = "is not currently running. "
  68. self.msg(Mmisc.wrapped_lines(part1, msg,
  69. self.settings['width']))
  70. else:
  71. self.msg('No Python program is currently running.')
  72. pass
  73. self.msg(self.core.execution_status)
  74. pass
  75. return False
  76. pass
  77. if __name__ == '__main__':
  78. mock = import_relative('mock', '..')
  79. Minfo = import_relative('info', '..')
  80. Mdebugger = import_relative('debugger', '....')
  81. d = Mdebugger.Debugger()
  82. d, cp = mock.dbg_setup(d)
  83. i = Minfo.InfoCommand(cp)
  84. sub = InfoProgram(i)
  85. sub.run([])