obj = getattr(obj, part) except (KeyError, AttributeError): return [] pre_prefix = '.'.join(dotted[:-1]) + '.' return [pre_prefix + n for n in dir(obj) if n.startswith(dotted[-1])] else: # Complete a simple name. return Mcomplete.complete_token(ns.keys(), prefix) def complete_id_and_builtins(cmd, prefix): if not cmd.proc.curframe: return [None] items = (list(cmd.proc.curframe.f_builtins.keys()) + complete_identifier(cmd, prefix)) return Mcomplete.complete_token(items, prefix) if __name__ == '__main__': import inspect from trepan.processor import cmdproc as Mcmdproc from trepan.processor.command import mock as Mmock from trepan.processor.command import base_cmd as mBaseCmd d = Mmock.MockDebugger() cmdproc = Mcmdproc.CommandProcessor(d.core) cmdproc.curframe = inspect.currentframe() cmd = mBaseCmd.DebuggerCommand(cmdproc) print(complete_identifier(cmd, '')) print(complete_identifier(cmd, 'M')) print(complete_id_and_builtins(cmd, 'M')) pass
def __init__(self, debugger, opts=None): """ Create a debugger object. But depending on the value of key 'start' inside hash `opts', we may or may not initially start tracing events (i.e. enter the debugger). See also `start' and `stop'. """ import trepan.bwprocessor as Mbwproc get_option = lambda key: Mmisc.option_set(opts, key, self.DEFAULT_INIT_OPTS) self.bpmgr = breakpoint.BreakpointManager() self.current_bp = None self.debugger = debugger # Threading lock ensures that we don't have other traced threads # running when we enter the debugger. Later we may want to have # a switch to control. self.debugger_lock = threading.Lock() self.filename_cache = {} # Initially the event parameter of the event hook. # We can however modify it, such as for breakpoints self.event = None # Is debugged program currently under execution? self.execution_status = 'Pre-execution' # main_dirname is the directory where the script resides. # Filenames in co_filename are often relative to this. self.main_dirname = os.curdir # What event processor and processor options do we use? self.processor = get_option('processor') proc_opts = get_option('proc_opts') if not self.processor: self.processor = Mcmdproc.CommandProcessor(self, opts=proc_opts) elif self.processor == 'bullwinkle': self.processor = Mbwproc.BWProcessor(self, opts=proc_opts) pass # What events are considered in stepping. Note: 'None' means *all*. self.step_events = None # How many line events to skip before entering event processor? # If stop_level is None all breaks are counted otherwise just # those which less than or equal to stop_level. self.step_ignore = get_option('step_ignore') # If stop_level is not None, then we are next'ing or # finish'ing and will ignore frames greater than stop_level. # We also will cache the last frame and thread number encountered # so we don't have to compute the current level all the time. self.last_frame = None self.last_level = 10000 self.last_thread = None self.stop_level = None self.stop_on_finish = False self.last_lineno = None self.last_filename = None self.different_line = None # The reason we have stopped, e.g. 'breakpoint hit', 'next', # 'finish', 'step', or 'exception'. self.stop_reason = '' self.trace_processor = Mtrace.PrintProcessor(self) # What routines (keyed by f_code) will we not trace into? self.ignore_filter = get_option('ignore_filter') self.search_path = sys.path # Source filename search path # When trace_hook_suspend is set True, we'll suspend # debugging. self.trace_hook_suspend = False self.until_condition = get_option('until_condition') return
pass self.msg(s + '\t' + line) self.proc.list_lineno = lineno pass pass except KeyboardInterrupt: pass return False if __name__ == '__main__': from mock import MockDebugger d = MockDebugger() command = ListCommand(d.core.processor) command.run(['list']) from trepan.processor import cmdproc command.proc = d.core.processor = cmdproc.CommandProcessor(d.core) command = ListCommand(d.core.processor) print('--' * 10) command.run(['list', __file__ + ':10']) print('--' * 10) command.run(['list', 'os', '10']) command.proc.frame = sys._getframe() command.proc.setup() print('--' * 10) command.run(['list']) print('--' * 10) Mbreak = __import__('trepan.processor.command.break', None, None, ['*'])
def dbg_setup(d = None): if d is None: d = MockDebugger() from trepan.processor import cmdproc cp = cmdproc.CommandProcessor(d.core) return d, cp