def find_and_set_debugged_frame(self, frame, thread_id): """The dance we have to do to set debugger frame state to *frame*, which is in the thread with id *thread_id*. We may need to the hide initial debugger frames. """ thread = threading._active[thread_id] thread_name = thread.getName() if ( not self.settings["dbg_trepan"] and thread_name == Mthread.current_thread_name() ): # The frame we came in on ('current_thread_name') is # the same as the one we want to switch to. In this case # we need to some debugger frames are in this stack so # we need to remove them. newframe = Mthread.find_debugged_frame(frame) if newframe is not None: frame = newframe pass # FIXME: else: we might be blocked on other threads which are # about to go into the debugger it not for the fact this one got there # first. Possibly in the future we want # to hide the blocks into threading of that locking code as well. # Set stack to new frame self.stack, self.curindex = get_stack(frame, None, self.proc) self.proc.stack, self.proc.curindex = self.stack, self.curindex self.proc.frame_thread_name = thread_name return
def find_and_set_debugged_frame(self, frame, thread_id): '''The dance we have to do to set debugger frame state to *frame*, which is in the thread with id *thread_id*. We may need to the hide initial debugger frames. ''' thread = threading._active[thread_id] thread_name = thread.getName() if (not self.settings['dbg_trepan'] and thread_name == Mthread.current_thread_name()): # The frame we came in on ('current_thread_name') is # the same as the one we want to switch to. In this case # we need to some debugger frames are in this stack so # we need to remove them. newframe = Mthread.find_debugged_frame(frame) if newframe is not None: frame = newframe pass # FIXME: else: we might be blocked on other threads which are # about to go into the debugger it not for the fact this one got there # first. Possibly in the future we want # to hide the blocks into threading of that locking code as well. # Set stack to new frame self.stack, self.curindex = Mcmdproc.get_stack(frame, None, self.proc) self.proc.stack, self.proc.curindex = self.stack, self.curindex self.proc.frame_thread_name = thread_name return
def nest_me(cp, command, i): import inspect if i > 1: cp.curframe = inspect.currentframe() cp.stack, cp.curindex = cmdproc.get_stack(cp.curframe, None, None, cp) print('-' * 10) command.run(['backtrace']) print('-' * 10) command.run(['backtrace', '1']) else: nest_me(cp, command, i+1) return
def nest_me(cp, command, i): import inspect if i > 1: cp.curframe = inspect.currentframe() cp.stack, cp.curindex = cmdproc.get_stack(cp.curframe, None, None, cp) print('-' * 10) command.run(['backtrace']) print('-' * 10) command.run(['backtrace', '1']) else: nest_me(cp, command, i + 1) return
def nest_me(cp, command, i): if i > 1: cp.curframe = inspect.currentframe() cp.stack, cp.curindex = get_stack(cp.curframe, None, None, cp) command.run(["down"]) print("-" * 10) command.run(["down", "1"]) print("-" * 10) command.run(["down", "-1"]) print("-" * 10) else: nest_me(cp, command, i + 1) return
def nest_me(cp, command, i): if i > 1: cp.curframe = inspect.currentframe() cp.stack, cp.curindex = Mcmdproc.get_stack(cp.curframe, None, None, cp) command.run(['down']) print('-' * 10) command.run(['down', '1']) print('-' * 10) command.run(['down', '-1']) print('-' * 10) else: nest_me(cp, command, i+1) return
def nest_me(cp, command, i): import inspect if i > 1: cp.curframe = inspect.currentframe() cp.stack, cp.curindex = Mcmdproc.get_stack(cp.curframe, None, None, cp) command.run(['up']) print '-' * 10 command.run(['up', '-2']) print '-' * 10 command.run(['up', '-3']) print '-' * 10 else: nest_me(cp, command, i+1) return
def nest_me(cp, command, i): import inspect if i > 1: cp.curframe = inspect.currentframe() cp.stack, cp.curindex = Mcmdproc.get_stack(cp.curframe, None, None, cp) command.run(['up']) print '-' * 10 command.run(['up', '-2']) print '-' * 10 command.run(['up', '-3']) print '-' * 10 else: nest_me(cp, command, i + 1) return
def nest_me(cp, command, i): import inspect if i > 1: cp.curframe = inspect.currentframe() cp.stack, cp.curindex = Mcmdproc.get_stack(cp.curframe, None, None, cp) command.run(["up"]) print("-" * 10) command.run(["up", "-2"]) print("-" * 10) command.run(["up", "-3"]) print("-" * 10) else: nest_me(cp, command, i + 1) return
def run(self, args): Mcmdfns.run_set_bool(self, args) if self.debugger.settings[self.name]: # Put a stack frame in the list of frames so we have # something to inspect. frame = inspect.currentframe() # Also give access to the top-level debugger self.proc.stack, self.proc.curindex = Mcmdproc.get_stack(frame, None, self.proc) self.proc.curframe = self.proc.stack[self.proc.curindex][0] # Remove ignored debugger functions. self.save_ignore_filter = self.core.ignore_filter self.core.ignore_filter = None else: self.core.ignore_filter = self.save_ignore_filter pass return
def run(self, args): Mcmdfns.run_set_bool(self, args) if self.debugger.settings[self.name]: # Put a stack frame in the list of frames so we have # something to inspect. frame = inspect.currentframe() # Also give access to the top-level debugger self.proc.stack, self.proc.curindex = Mcmdproc.get_stack( frame, None, self.proc) self.proc.curframe = self.proc.stack[self.proc.curindex][0] # Remove ignored debugger functions. self.save_ignore_filter = self.core.ignore_filter self.core.ignore_filter = None else: self.core.ignore_filter = self.save_ignore_filter pass return
if len(args) <= 1: lineno = inspect.getlineno(curframe) else: lineno = proc.get_an_int(args[1], "The 'clear' command argument when given should be " "a line number. Got %s", min_value=1) if lineno is None: return linenos = self.core.bpmgr.delete_breakpoints_by_lineno(filename, lineno) if len(linenos) == 0: self.errmsg("No breakpoint at line %d" % lineno) elif len(linenos) == 1: self.msg("Deleted breakpoint %d" % linenos[0]) elif len(linenos) > 1: self.msg("Deleted breakpoints %s" % ' '.join([str(i) for i in linenos])) return if __name__ == '__main__': from trepan import debugger as Mdebugger from trepan.processor import cmdproc as Mcmdproc d = Mdebugger.Trepan() cp = d.core.processor cp.curframe = inspect.currentframe() cp.stack, cp.curindex = Mcmdproc.get_stack(cp.curframe, None, None, cp) command = ClearCommand(d.core.processor) command.run(['clear']) pass
if m: self.msg(" module:\t%s" % m) except: try: f = inspect.getfile(value) self.msg(" file: %s" % f) except: pass pass return False pass if __name__ == "__main__": from trepan.processor import cmdproc as Mcmdproc from trepan.processor.command import mock as Mmock d, cp = Mmock.dbg_setup() command = WhatisCommand(cp) cp.curframe = inspect.currentframe() cp.stack, cp.curindex = Mcmdproc.get_stack(cp.curframe, None, None, cp) words = """5 1+2 thing len trepan os.path.basename WhatisCommand cp __name__ Mmock Mbase_cmd.DebuggerCommand""".split() for thing in words: cp.cmd_argstr = thing command.run(["whatis", thing]) print("-" * 10) pass
lineno = proc.get_an_int( args[1], "The 'clear' command argument when given should be " "a line number. Got %s", min_value=1, ) if lineno is None: return linenos = self.core.bpmgr.delete_breakpoints_by_lineno(filename, lineno) if len(linenos) == 0: self.errmsg("No breakpoint at line %d" % lineno) elif len(linenos) == 1: self.msg("Deleted breakpoint %d" % linenos[0]) elif len(linenos) > 1: self.msg("Deleted breakpoints %s" % " ".join([str(i) for i in linenos])) return if __name__ == "__main__": from trepan.debugger import Trepan from trepan.processor.cmdproc import get_stack d = Trepan() cp = d.core.processor cp.curframe = inspect.currentframe() cp.stack, cp.curindex = get_stack(cp.curframe, None, None, cp) command = ClearCommand(d.core.processor) command.run(["clear"]) pass
lineno = self.proc.get_an_int(args[1], ("jump: a line number is required, " + "got %s.") % args[1]) if lineno is None: return False try: # Set to change position, update our copy of the stack, # and display the new position print(self.proc.curframe.f_trace) self.proc.curframe.f_lineno = lineno self.proc.stack[self.proc.curindex] = \ self.proc.stack[self.proc.curindex][0], lineno Mcmdproc.print_location(self.proc) except ValueError as e: self.errmsg('jump failed: %s' % e) return False pass if __name__ == '__main__': from trepan.processor.command import mock d, cp = mock.dbg_setup() command = JumpCommand(cp) print('jump when not running: ', command.run(['jump', '1'])) command.core.execution_status = 'Running' cp.curframe = inspect.currentframe() cp.curindex = 0 cp.stack = Mcmdproc.get_stack(cp.curframe, None, None) command.run(['jump', '1']) cp.curindex = len(cp.stack)-1 command.run(['jump', '1']) pass
if lineno < 0: self.errmsg('No next line found') return False try: # Set to change position, update our copy of the stack, # and display the new position self.proc.curframe.f_lineno = lineno self.proc.stack[self.proc.curindex] = \ self.proc.stack[self.proc.curindex][0], lineno Mcmdproc.print_location(self.proc) except ValueError: _, e, _ = sys.exc_info() self.errmsg('skip failed: %s' % e) return False pass if __name__ == '__main__': from trepan.processor.command import mock d, cp = mock.dbg_setup() command = SkipCommand(cp) print('skip when not running: ', command.run(['skip', '1'])) command.core.execution_status = 'Running' cp.curframe = inspect.currentframe() cp.curindex = 0 cp.stack = Mcmdproc.get_stack(cp.curframe, None, None) command.run(['skip', '1']) cp.curindex = len(cp.stack)-1 command.run(['skip', '1']) pass