コード例 #1
0
ファイル: upvar.py プロジェクト: shengxiduan/gdb-helpers
 def invoke(self, n=1):
     for frame in FrameIterator(gdb.selected_frame()):
         if n <= 0:
             frame.select()
             break
         n = n - 1
     return 1
コード例 #2
0
ファイル: upvar.py プロジェクト: shengxiduan/gdb-helpers
 def invoke(self, name, limit):
     name = str(name)
     for frame in FrameIterator(gdb.selected_frame()):
         if limit <= 0:
             return gdb.Value(0)
         limit = limit - 1
         val = find_var(frame, name)
         if val is not None:
             return val
         raise gdb.GdbError("couldn't find %s" % name)
コード例 #3
0
def execute_frame_filters(frame, frame_low, frame_high):
    """ Internal function called from GDB that will execute the chain
    of frame filters.  Each filter is executed in priority order.
    After the execution completes, slice the iterator to frame_low -
    frame_high range.

    Arguments:
        frame: The initial frame.

        frame_low: The low range of the slice.  If this is a negative
        integer then it indicates a backward slice (ie bt -4) which
        counts backward from the last frame in the backtrace.

        frame_high: The high range of the slice.  If this is -1 then
        it indicates all frames until the end of the stack from
        frame_low.

    Returns:
        frame_iterator: The sliced iterator after all frame
        filters have had a change to execute, or None if no frame
        filters are registered.
    """

    # Get a sorted list of frame filters.
    sorted_list = list(_sort_list())

    # Check to see if there are any frame-filters.  If not, just
    # return None and let default backtrace printing occur.
    if len(sorted_list) == 0:
        return None

    frame_iterator = FrameIterator(frame)

    # Apply a basic frame decorator to all gdb.Frames.  This unifies
    # the interface.  Python 3.x moved the itertools.imap
    # functionality to map(), so check if it is available.
    if hasattr(itertools, "imap"):
        frame_iterator = itertools.imap(FrameDecorator, frame_iterator)
    else:
        frame_iterator = map(FrameDecorator, frame_iterator)

    for ff in sorted_list:
        frame_iterator = ff.filter(frame_iterator)

    # Slicing

    # Is this a slice from the end of the backtrace, ie bt -2?
    if frame_low < 0:
        count = 0
        slice_length = abs(frame_low)
        # We cannot use MAXLEN argument for deque as it is 2.6 onwards
        # and some GDB versions might be < 2.6.
        sliced = collections.deque()

        for frame_item in frame_iterator:
            if count >= slice_length:
                sliced.popleft()
            count = count + 1
            sliced.append(frame_item)

        return iter(sliced)

    # -1 for frame_high means until the end of the backtrace.  Set to
    # None if that is the case, to indicate to itertools.islice to
    # slice to the end of the iterator.
    if frame_high == -1:
        frame_high = None
    else:
        # As frames start from 0, add one to frame_high so islice
        # correctly finds the end
        frame_high = frame_high + 1

    sliced = itertools.islice(frame_iterator, frame_low, frame_high)

    return sliced