17"""Internal functions for working with frame-filters."""
26def get_priority(filter_item):
27 """Internal worker function to return the frame-filter's priority
28 from a frame filter object. This
is a fail free function
as it
is
29 used
in sorting
and filtering. If a badly implemented frame
30 filter does
not implement the priority attribute,
return zero
31 (otherwise sorting/filtering will fail
and prevent other frame
32 filters
from executing).
35 filter_item: An object conforming to the frame filter
39 The priority of the frame filter
from the
"priority"
44 return getattr(filter_item,
"priority", 0)
47def set_priority(filter_item, priority):
48 """Internal worker function to set the frame-filter's priority.
51 filter_item: An object conforming to the frame filter
53 priority: The priority to assign as an integer.
56 filter_item.priority = priority
59def get_enabled(filter_item):
60 """Internal worker function to return a filter's enabled state
61 from a frame filter object. This
is a fail free function
as it
is
62 used
in sorting
and filtering. If a badly implemented frame
63 filter does
not implement the enabled attribute,
return False
64 (otherwise sorting/filtering will fail
and prevent other frame
65 filters
from executing).
68 filter_item: An object conforming to the frame filter
72 The enabled state of the frame filter
from the
"enabled"
79 return getattr(filter_item,
"enabled",
False)
82def set_enabled(filter_item, state):
83 """Internal Worker function to set the frame-filter's enabled
87 filter_item: An object conforming to the frame filter
89 state: True or False, depending on desired state.
92 filter_item.enabled = state
96 """Internal Worker function to return the frame filter
97 dictionary, depending on the name supplied as an argument. If the
98 name
is not "all",
"global" or "progspace", it
is assumed to name
102 name: The name of the list,
as specified by GDB user commands.
105 A dictionary object
for a single specified dictionary,
or a
106 list containing all the items
for "all"
109 gdb.GdbError: A dictionary of that name cannot be found.
118 glob = gdb.frame_filters.values()
120 return_iter = itertools.chain(glob, prog)
122 return_iter = itertools.chain(return_iter, objfile.frame_filters.values())
127 return gdb.frame_filters
129 if name ==
"progspace":
131 return cp.frame_filters
134 if name == objfile.filename:
135 return objfile.frame_filters
137 msg =
"Cannot find frame-filter dictionary for '" + name +
"'"
138 raise gdb.GdbError(msg)
142 """Internal Worker function to merge all known frame-filter
143 lists, prune any filters with the state set to
"disabled",
and
144 sort the list on the frame-filter
's "priority" attribute.
147 sorted_list: A sorted, pruned list of frame filters to
151 all_filters = return_list("all")
152 sorted_frame_filters = sorted(all_filters, key=get_priority, reverse=
True)
154 sorted_frame_filters = filter(get_enabled, sorted_frame_filters)
156 return sorted_frame_filters
159def execute_frame_filters(frame, frame_low, frame_high):
160 """Internal function called from GDB that will execute the chain
161 of frame filters. Each filter is executed
in priority order.
162 After the execution completes, slice the iterator to frame_low -
166 frame: The initial frame.
168 frame_low: The low range of the slice. If this
is a negative
169 integer then it indicates a backward slice (ie bt -4) which
170 counts backward
from the last frame
in the backtrace.
172 frame_high: The high range of the slice. If this
is -1 then
173 it indicates all frames until the end of the stack
from
177 frame_iterator: The sliced iterator after all frame
178 filters have had a change to execute,
or None if no frame
179 filters are registered.
183 sorted_list = list(_sort_list())
187 if len(sorted_list) == 0:
190 frame_iterator = FrameIterator(frame)
195 if hasattr(itertools,
"imap"):
196 frame_iterator = itertools.imap(FrameDecorator, frame_iterator)
198 frame_iterator = map(FrameDecorator, frame_iterator)
200 for ff
in sorted_list:
201 frame_iterator = ff.filter(frame_iterator)
208 slice_length = abs(frame_low)
211 sliced = collections.deque()
213 for frame_item
in frame_iterator:
214 if count >= slice_length:
217 sliced.append(frame_item)
229 frame_high = frame_high + 1
231 sliced = itertools.islice(frame_iterator, frame_low, frame_high)