def run(self, args): proc = self.proc dbg_obj = self.core.debugger listsize = dbg_obj.settings['listsize'] filename, first, last = parse_list_cmd(proc, args, listsize) curframe = proc.curframe if filename is None: return # Sometimes such as due to decompilation we might not really # have an idea based on the listing where we really are. # Setting "show_marks" to false will disable marking breakpoint # and current line numbers. show_marks = True filename = pyficache.unmap_file(pyficache.pyc2py(filename)) if filename == "<string>" and proc.curframe.f_code: # Deparse the code object into a temp file and remap the line from code # into the corresponding line of the tempfile co = proc.curframe.f_code temp_filename, name_for_code = deparse_and_cache(co, proc.errmsg) if temp_filename: filename = temp_filename show_marks = False pass # We now have range information. Do the listing. max_line = pyficache.size(filename) if max_line is None: self.errmsg('No file %s found; using "deparse" command instead to show source' % filename) proc.commands['deparse'].run(['deparse']) return canonic_filename = os.path.realpath(os.path.normcase(filename)) if first > max_line: self.errmsg('Bad start line %d - file "%s" has only %d lines' % (first, filename, max_line)) return if last > max_line: self.msg('End position changed to last line %d ' % max_line) last = max_line bplist = self.core.bpmgr.bplist opts = { 'reload_on_change' : self.settings['reload'], 'output' : self.settings['highlight'], 'strip_nl' : False, } if 'style' in self.settings: opts['style'] = self.settings['style'] if first <= 0: first = 1 try: for lineno in range(first, last+1): line = pyficache.getline(filename, lineno, opts) if line is None: line = linecache.getline(filename, lineno, proc.frame.f_globals) pass if line is None: self.msg('[EOF]') break else: line = line.rstrip('\n') s = proc._saferepr(lineno).rjust(3) if len(s) < 5: s += ' ' if (show_marks and (canonic_filename, lineno,) in list(bplist.keys())): bp = bplist[(canonic_filename, lineno,)][0] a_pad = '%02d' % bp.number s += bp.icon_char() else: s += ' ' a_pad = ' ' pass if (curframe and lineno == inspect.getlineno(curframe) and show_marks): s += '->' if 'plain' != self.settings['highlight']: s = colorize('bold', s) else: s += a_pad pass self.msg(s + '\t' + line) proc.list_lineno = lineno pass pass pass except KeyboardInterrupt: pass return False
def test_size(self): global TEST_DIR test_file = os.path.join(TEST_DIR, 'short-file') self.assertEqual(2, pyficache.size(test_file)) return
def run(self, args): """Get file information""" if len(args) == 0: if not self.proc.curframe: self.errmsg("No frame - no default file.") return False filename = self.proc.curframe.f_code.co_filename else: filename = args[0] pass m = filename + " is" filename_cache = self.core.filename_cache if filename in filename_cache: m += " cached in debugger" if filename_cache[filename] != filename: m += " as:" m = Mmisc.wrapped_lines(m, filename_cache[filename] + ".", self.settings["width"]) else: m += "." pass self.msg(m) else: matches = [file for file in file_list() if file.endswith(filename)] if len(matches) > 1: self.msg("Multiple files found ending filename string:") for match_file in matches: self.msg("\t%s" % match_file) pass elif len(matches) == 1: canonic_name = pyficache.unmap_file(matches[0]) m += " matched debugger cache file:\n " + canonic_name self.msg(m) else: self.msg(m + " not cached in debugger.") pass canonic_name = self.core.canonic(filename) self.msg(Mmisc.wrapped_lines("Canonic name:", canonic_name, self.settings["width"])) for name in (canonic_name, filename): if name in sys.modules: for key in [k for k, v in list(sys.modules.items()) if name == v]: self.msg("module: %s", key) pass pass pass for arg in args[1:]: processed_arg = False if arg in ["all", "size"]: if pyficache.size(canonic_name): self.msg("File has %d lines." % pyficache.size(canonic_name)) pass processed_arg = True pass if arg in ["all", "sha1"]: self.msg("SHA1 is %s." % pyficache.sha1(canonic_name)) processed_arg = True pass if arg in ["all", "brkpts"]: lines = pyficache.trace_line_numbers(canonic_name) if lines: self.section("Possible breakpoint line numbers:") fmt_lines = columnize.columnize(lines, ljust=False, arrange_vertical=False, lineprefix=" ") self.msg(fmt_lines) pass processed_arg = True pass if not processed_arg: self.errmsg("Don't understand sub-option %s." % arg) pass pass return
def run(self, args): filename, first, last = self.parse_list_cmd(args[1:]) curframe = self.proc.curframe if filename is None: return filename = pyc2py(filename) # We now have range information. Do the listing. max_line = pyficache.size(filename) if max_line is None: self.errmsg('No file %s found' % filename) return canonic_filename = os.path.realpath(os.path.normcase(filename)) if first > max_line: self.errmsg('Bad start line %d - file "%s" has only %d lines' % (first, filename, max_line)) return if last > max_line: self.msg('End position changed to last line %d ' % max_line) last = max_line bplist = self.core.bpmgr.bplist opts = { 'reload_on_change': self.settings['reload'], 'output': self.settings['highlight'], 'strip_nl': False } try: for lineno in range(first, last + 1): line = pyficache.getline(filename, lineno, opts) if line is None: line = linecache.getline(filename, lineno, self.proc.frame.f_globals) pass if line is None: self.msg('[EOF]') break else: line = line.rstrip('\n') s = self.proc._saferepr(lineno).rjust(3) if len(s) < 5: s += ' ' if ( canonic_filename, lineno, ) in list(bplist.keys()): bp = bplist[( canonic_filename, lineno, )][0] a_pad = '%02d' % bp.number s += bp.icon_char() else: s += ' ' a_pad = ' ' pass if curframe and lineno == inspect.getlineno(curframe) \ and filename == curframe.f_code.co_filename: s += '->' else: s += a_pad pass self.msg(s + '\t' + line) self.proc.list_lineno = lineno pass pass except KeyboardInterrupt: pass return False
def run(self, args): """Get file information""" if len(args) == 0: if not self.proc.curframe: self.errmsg("No frame - no default file.") return False filename = self.proc.curframe.f_code.co_filename else: filename = args[0] pass m = filename + ' is' filename_cache = self.core.filename_cache if filename in filename_cache: m += " cached in debugger" if filename_cache[filename] != filename: m += ' as:' m = Mmisc.wrapped_lines(m, filename_cache[filename] + '.', self.settings['width']) else: m += '.' pass self.msg(m) else: matches = [ file for file in self.file_list() if file.endswith(filename) ] if (len(matches) > 1): self.msg("Multiple files found ending filename string:") for match_file in matches: self.msg("\t%s" % match_file) pass elif len(matches) == 1: canonic_name = pyficache.unmap_file(matches[0]) m += " matched debugger cache file:\n " + canonic_name self.msg(m) else: self.msg(m + ' not cached in debugger.') pass canonic_name = self.core.canonic(filename) self.msg( Mmisc.wrapped_lines('Canonic name:', canonic_name, self.settings['width'])) for name in (canonic_name, filename): if name in sys.modules: for key in [ k for k, v in list(sys.modules.items()) if name == v ]: self.msg("module: %s", key) pass pass pass for arg in args[1:]: processed_arg = False if arg in ['all', 'size']: if pyficache.size(canonic_name): self.msg("File has %d lines." % pyficache.size(canonic_name)) pass processed_arg = True pass if arg in ['all', 'sha1']: self.msg("SHA1 is %s." % pyficache.sha1(canonic_name)) processed_arg = True pass if arg in ['all', 'brkpts']: lines = pyficache.trace_line_numbers(canonic_name) if lines: self.section("Possible breakpoint line numbers:") fmt_lines = columnize.columnize(lines, ljust=False, arrange_vertical=False, lineprefix=' ') self.msg(fmt_lines) pass processed_arg = True pass if not processed_arg: self.errmsg("Don't understand sub-option %s." % arg) pass pass return
def run(self, args): filename, first, last = self.parse_list_cmd(args[1:]) curframe = self.proc.curframe if filename is None: return m = re.search('^<frozen (.*)>', filename) if m and m.group(1): filename = m.group(1) canonic_filename = pyficache.unmap_file(filename) else: filename = pyc2py(filename) canonic_filename = os.path.realpath(os.path.normcase(filename)) max_line = pyficache.size(filename) # FIXME: Should use the below: # max_line = pyficache.maxline(filename) # We now have range information. Do the listing. if max_line is None: self.errmsg('No file %s found' % filename) return if first > max_line: self.errmsg('Bad start line %d - file "%s" has only %d lines' % (first, filename, max_line)) return if last > max_line: self.msg('End position changed to last line %d ' % max_line) last = max_line bplist = self.core.bpmgr.bplist opts = { 'reload_on_change' : self.settings['reload'], 'output' : self.settings['highlight'], 'strip_nl' : False, } if 'style' in self.settings: opts['style'] = self.settings['style'] try: for lineno in range(first, last+1): line = pyficache.getline(filename, lineno, opts) if line is None: line = linecache.getline(filename, lineno, self.proc.frame.f_globals) pass if line is None: self.msg('[EOF]') break else: line = line.rstrip('\n') s = self.proc._saferepr(lineno).rjust(3) if len(s) < 5: s += ' ' if (canonic_filename, lineno,) in list(bplist.keys()): bp = bplist[(canonic_filename, lineno,)][0] a_pad = '%02d' % bp.number s += bp.icon_char() else: s += ' ' a_pad = ' ' pass if curframe and lineno == inspect.getlineno(curframe): s += '->' if 'plain' != self.settings['highlight']: s = colorize('bold', s) else: s += a_pad pass self.msg(s + '\t' + line) self.proc.list_lineno = lineno pass pass except KeyboardInterrupt: pass return False
def run(self, args): filename, first, last = self.parse_list_cmd(args[1:]) curframe = self.proc.curframe if filename is None: return filename = pyc2py(filename) # We now have range information. Do the listing. max_line = pyficache.size(filename) if max_line is None: self.errmsg('No file %s found' % filename) return canonic_filename = os.path.realpath(os.path.normcase(filename)) if first > max_line: self.errmsg('Bad start line %d - file "%s" has only %d lines' % (first, filename, max_line)) return if last > max_line: self.msg('End position changed to last line %d ' % max_line) last = max_line bplist = self.core.bpmgr.bplist opts = { 'reload_on_change' : self.settings['reload'], 'output' : self.settings['highlight'], 'strip_nl' : False } try: for lineno in range(first, last+1): line = pyficache.getline(filename, lineno, opts) if line is None: line = linecache.getline(filename, lineno, self.proc.frame.f_globals) pass if line is None: self.msg('[EOF]') break else: line = line.rstrip('\n') s = self.proc._saferepr(lineno).rjust(3) if len(s) < 5: s += ' ' if (canonic_filename, lineno,) in list(bplist.keys()): bp = bplist[(canonic_filename, lineno,)][0] a_pad = '%02d' % bp.number s += bp.icon_char() else: s += ' ' a_pad = ' ' pass if curframe and lineno == inspect.getlineno(curframe) \ and filename == curframe.f_code.co_filename: s += '->' if 'plain' != self.settings['highlight']: s = colorize('bold', s) else: s += a_pad pass self.msg(s + '\t' + line) self.proc.list_lineno = lineno pass pass except KeyboardInterrupt: pass return False
def run(self, args): proc = self.proc dbg_obj = self.core.debugger listsize = dbg_obj.settings["listsize"] filename, first, last = parse_list_cmd(proc, args, listsize) curframe = proc.curframe if filename is None: return filename = pyficache.unmap_file( pyficache.resolve_name_to_path(filename)) # We now have range information. Do the listing. max_line = pyficache.size(filename) if max_line is None: bytecode = curframe.f_code if bytecode not in deparse_cache.keys(): self.errmsg( 'No file %s found; using "deparse" command instead to show source' % filename) proc.commands["deparse"].run(["deparse"]) return canonic_filename = osp.realpath(osp.normcase(filename)) if first > max_line: self.errmsg('Bad start line %d - file "%s" has only %d lines' % (first, filename, max_line)) return if last > max_line: self.msg("End position changed to last line %d " % max_line) last = max_line bplist = self.core.bpmgr.bplist opts = { "reload_on_change": self.settings["reload"], "output": self.settings["highlight"], "strip_nl": False, } if "style" in self.settings: opts["style"] = self.settings["style"] if first <= 0: first = 1 try: for lineno in range(first, last + 1): line = pyficache.getline(filename, lineno, opts) if line is None: line = linecache.getline(filename, lineno, proc.frame.f_globals) pass if line is None: self.msg("[EOF]") break else: line = line.rstrip("\n") s = proc._saferepr(lineno).rjust(3) if len(s) < 5: s += " " if ( canonic_filename, lineno, ) in list(bplist.keys()): bp = bplist[( canonic_filename, lineno, )][0] a_pad = "%02d" % bp.number s += bp.icon_char() else: s += " " a_pad = " " pass if curframe and lineno == inspect.getlineno(curframe): s += "->" if "plain" != self.settings["highlight"]: s = colorize("bold", s) else: s += a_pad pass self.msg(s + "\t" + line) proc.list_lineno = lineno pass pass pass except KeyboardInterrupt: pass return False
def run(self, args): proc = self.proc dbg_obj = self.core.debugger listsize = dbg_obj.settings['listsize'] filename, first, last = parse_list_cmd(proc, args, listsize) curframe = proc.curframe if filename is None: return filename = pyficache.unmap_file(pyficache.pyc2py(filename)) # We now have range information. Do the listing. max_line = pyficache.size(filename) if max_line is None: self.errmsg( 'No file %s found; using "deparse" command instead to show source' % filename) proc.commands['deparse'].run(['deparse']) return canonic_filename = os.path.realpath(os.path.normcase(filename)) if first > max_line: self.errmsg('Bad start line %d - file "%s" has only %d lines' % (first, filename, max_line)) return if last > max_line: self.msg('End position changed to last line %d ' % max_line) last = max_line bplist = self.core.bpmgr.bplist opts = { 'reload_on_change': self.settings['reload'], 'output': self.settings['highlight'], 'strip_nl': False, } if 'style' in self.settings: opts['style'] = self.settings['style'] if first <= 0: first = 1 try: for lineno in range(first, last + 1): line = pyficache.getline(filename, lineno, opts) if line is None: line = linecache.getline(filename, lineno, proc.frame.f_globals) pass if line is None: self.msg('[EOF]') break else: line = line.rstrip('\n') s = proc._saferepr(lineno).rjust(3) if len(s) < 5: s += ' ' if ( canonic_filename, lineno, ) in list(bplist.keys()): bp = bplist[( canonic_filename, lineno, )][0] a_pad = '%02d' % bp.number s += bp.icon_char() else: s += ' ' a_pad = ' ' pass if curframe and lineno == inspect.getlineno(curframe): s += '->' if 'plain' != self.settings['highlight']: s = colorize('bold', s) else: s += a_pad pass self.msg(s + '\t' + line) proc.list_lineno = lineno pass pass pass except KeyboardInterrupt: pass return False
def run(self, args): """**info files** [*filename* [**all** | **brkpts** | **lines** | **sha1** | **size**]] Show information about the current file. If no filename is given and the program is running then the current file associated with the current stack entry is used. Sub options which can be shown about a file are: * **brkpts** Line numbers where there are statement boundaries. These lines can be used in breakpoint commands. * **sha1** A SHA1 hash of the source text. The following may be useful in comparing source code. * **size** The number of lines in the file. * **all** All of the above information. """ if len(args) == 0: if not self.proc.curframe: self.errmsg("No frame - no default file.") return False filename = self.proc.curframe.f_code.co_filename else: filename = args[0] pass m = filename + " is" filename_cache = self.core.filename_cache if filename in filename_cache: m += " cached in debugger" if filename_cache[filename] != filename: m += " as:" m = Mmisc.wrapped_lines(m, filename_cache[filename] + ".", self.settings["width"]) else: m += "." pass self.msg(m) else: matches = [file for file in file_list() if file.endswith(filename)] if len(matches) > 1: self.msg("Multiple files found ending filename string:") for match_file in matches: self.msg("\t%s" % match_file) pass elif len(matches) == 1: canonic_name = pyficache.unmap_file(matches[0]) m += " matched debugger cache file:\n " + canonic_name self.msg(m) else: self.msg(m + " not cached in debugger.") pass canonic_name = self.core.canonic(filename) self.msg( Mmisc.wrapped_lines("Canonic name:", canonic_name, self.settings["width"])) for name in (canonic_name, filename): if name in sys.modules: for key in [ k for k, v in list(sys.modules.items()) if name == v ]: self.msg("module: %s", key) pass pass pass for arg in args[1:]: processed_arg = False if arg in ["all", "size"]: if pyficache.size(canonic_name): self.msg("File has %d lines." % pyficache.size(canonic_name)) pass processed_arg = True pass if arg in ["all", "sha1"]: self.msg("SHA1 is %s." % pyficache.sha1(canonic_name)) processed_arg = True pass if arg in ["all", "brkpts"]: lines = pyficache.trace_line_numbers(canonic_name) if lines: self.section("Possible breakpoint line numbers:") fmt_lines = columnize.columnize( list(lines), ljust=False, arrange_vertical=False, lineprefix=" ", ) self.msg(fmt_lines) pass processed_arg = True pass if not processed_arg: self.errmsg("Don't understand sub-option %s." % arg) pass pass return