Back to index

python3.2  3.2.2
Public Member Functions
libpython.PyList Class Reference

List of all members.

Public Member Functions

def __init__
def invoke

Detailed Description

List the current Python source code, if any

Use
   py-list START
to list at a different line number within the python source.

Use
   py-list START, END
to list a specific range of lines within the python source.

Definition at line 1458 of file libpython.py.


Constructor & Destructor Documentation

def libpython.PyList.__init__ (   self)

Definition at line 1470 of file libpython.py.

01470 
01471     def __init__(self):
01472         gdb.Command.__init__ (self,
01473                               "py-list",
01474                               gdb.COMMAND_FILES,
01475                               gdb.COMPLETE_NONE)
01476 

Here is the caller graph for this function:


Member Function Documentation

def libpython.PyList.invoke (   self,
  args,
  from_tty 
)

Definition at line 1477 of file libpython.py.

01477 
01478     def invoke(self, args, from_tty):
01479         import re
01480 
01481         start = None
01482         end = None
01483 
01484         m = re.match(r'\s*(\d+)\s*', args)
01485         if m:
01486             start = int(m.group(0))
01487             end = start + 10
01488 
01489         m = re.match(r'\s*(\d+)\s*,\s*(\d+)\s*', args)
01490         if m:
01491             start, end = map(int, m.groups())
01492 
01493         frame = Frame.get_selected_python_frame()
01494         if not frame:
01495             print 'Unable to locate python frame'
01496             return
01497 
01498         pyop = frame.get_pyop()
01499         if not pyop:
01500             print 'Unable to read information on python frame'
01501             return
01502 
01503         filename = pyop.filename()
01504         lineno = pyop.current_line_num()
01505 
01506         if start is None:
01507             start = lineno - 5
01508             end = lineno + 5
01509 
01510         if start<1:
01511             start = 1
01512 
01513         try:
01514             f = open(os_fsencode(filename), 'r')
01515         except IOError as err:
01516             sys.stdout.write('Unable to open %s: %s\n'
01517                              % (filename, err))
01518             return
01519         with f:
01520             all_lines = f.readlines()
01521             # start and end are 1-based, all_lines is 0-based;
01522             # so [start-1:end] as a python slice gives us [start, end] as a
01523             # closed interval
01524             for i, line in enumerate(all_lines[start-1:end]):
01525                 linestr = str(i+start)
01526                 # Highlight current line:
01527                 if i + start == lineno:
01528                     linestr = '>' + linestr
01529                 sys.stdout.write('%4s    %s' % (linestr, line))
01530 
01531 
01532 # ...and register the command:
01533 PyList()

Here is the call graph for this function:


The documentation for this class was generated from the following file: