1 # Frame-filter commands.
2 # Copyright (C) 2013 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 """GDB commands for working with frame-filters."""
21 from gdb
.FrameIterator
import FrameIterator
22 from gdb
.FrameDecorator
import FrameDecorator
27 class SetFilterPrefixCmd(gdb
.Command
):
28 """Prefix command for 'set' frame-filter related operations."""
31 super(SetFilterPrefixCmd
, self
).__init
__("set frame-filter",
33 gdb
.COMPLETE_NONE
, True)
35 class ShowFilterPrefixCmd(gdb
.Command
):
36 """Prefix command for 'show' frame-filter related operations."""
38 super(ShowFilterPrefixCmd
, self
).__init
__("show frame-filter",
40 gdb
.COMPLETE_NONE
, True)
41 class InfoFrameFilter(gdb
.Command
):
42 """List all registered Python frame-filters.
44 Usage: info frame-filters
48 super(InfoFrameFilter
, self
).__init
__("info frame-filter",
51 def enabled_string(state
):
52 """Return "Yes" if filter is enabled, otherwise "No"."""
58 def list_frame_filters(self
, frame_filters
):
59 """ Internal worker function to list and print frame filters
63 frame_filters: The name of the dictionary, as
64 specified by GDB user commands.
67 sorted_frame_filters
= sorted(frame_filters
.items(),
68 key
=lambda i
: gdb
.frames
.get_priority(i
[1]),
71 if len(sorted_frame_filters
) == 0:
72 print(" No frame filters registered.")
74 print(" Priority Enabled Name")
75 for frame_filter
in sorted_frame_filters
:
76 name
= frame_filter
[0]
78 priority
= '{:<8}'.format(
79 str(gdb
.frames
.get_priority(frame_filter
[1])))
80 enabled
= '{:<7}'.format(
81 self
.enabled_string(gdb
.frames
.get_enabled(frame_filter
[1])))
82 except Exception as e
:
83 print(" Error printing filter '"+name
+"': "+str(e
))
85 print(" %s %s %s" % (priority
, enabled
, name
))
87 def print_list(self
, title
, filter_list
, blank_line
):
89 self
.list_frame_filters(filter_list
)
93 def invoke(self
, arg
, from_tty
):
94 self
.print_list("global frame-filters:", gdb
.frame_filters
, True)
96 cp
= gdb
.current_progspace()
97 self
.print_list("progspace %s frame-filters:" % cp
.filename
,
98 cp
.frame_filters
, True)
100 for objfile
in gdb
.objfiles():
101 self
.print_list("objfile %s frame-filters:" % objfile
.filename
,
102 objfile
.frame_filters
, False)
104 # Internal enable/disable functions.
106 def _enable_parse_arg(cmd_name
, arg
):
107 """ Internal worker function to take an argument from
108 enable/disable and return a tuple of arguments.
111 cmd_name: Name of the command invoking this function.
112 args: The argument as a string.
115 A tuple containing the dictionary, and the argument, or just
116 the dictionary in the case of "all".
119 argv
= gdb
.string_to_argv(arg
);
121 if argv
[0] == "all" and argc
> 1:
122 raise gdb
.GdbError(cmd_name
+ ": with 'all' " \
123 "you may not specify a filter.")
125 if argv
[0] != "all" and argc
!= 2:
126 raise gdb
.GdbError(cmd_name
+ " takes exactly two arguments.")
130 def _do_enable_frame_filter(command_tuple
, flag
):
131 """Worker for enabling/disabling frame_filters.
134 command_type: A tuple with the first element being the
135 frame filter dictionary, and the second being
136 the frame filter name.
137 flag: True for Enable, False for Disable.
140 list_op
= command_tuple
[0]
141 op_list
= gdb
.frames
.return_list(list_op
)
145 gdb
.frames
.set_enabled(item
, flag
)
147 frame_filter
= command_tuple
[1]
149 ff
= op_list
[frame_filter
]
151 msg
= "frame-filter '" + str(name
) + "' not found."
152 raise gdb
.GdbError(msg
)
154 gdb
.frames
.set_enabled(ff
, flag
)
156 def _complete_frame_filter_list(text
, word
, all_flag
):
157 """Worker for frame filter dictionary name completion.
160 text: The full text of the command line.
161 word: The most recent word of the command line.
162 all_flag: Whether to include the word "all" in completion.
165 A list of suggested frame filter dictionary name completions
166 from text/word analysis. This list can be empty when there
167 are no suggestions for completion.
170 filter_locations
= ["all", "global", "progspace"]
172 filter_locations
= ["global", "progspace"]
173 for objfile
in gdb
.objfiles():
174 filter_locations
.append(objfile
.filename
)
176 # If the user just asked for completions with no completion
177 # hints, just return all the frame filter dictionaries we know
180 return filter_locations
182 # Otherwise filter on what we know.
183 flist
= filter(lambda x
,y
=text
:x
.startswith(y
), filter_locations
)
185 # If we only have one completion, complete it and return it.
187 flist
[0] = flist
[0][len(text
)-len(word
):]
189 # Otherwise, return an empty list, or a list of frame filter
190 # dictionaries that the previous filter operation returned.
193 def _complete_frame_filter_name(word
, printer_dict
):
194 """Worker for frame filter name completion.
198 word: The most recent word of the command line.
200 printer_dict: The frame filter dictionary to search for frame
201 filter name completions.
203 Returns: A list of suggested frame filter name completions
204 from word analysis of the frame filter dictionary. This list
205 can be empty when there are no suggestions for completion.
208 printer_keys
= printer_dict
.keys()
212 flist
= filter(lambda x
,y
=word
:x
.startswith(y
), printer_keys
)
215 class EnableFrameFilter(gdb
.Command
):
216 """GDB command to disable the specified frame-filter.
218 Usage: enable frame-filter enable DICTIONARY [NAME]
220 DICTIONARY is the name of the frame filter dictionary on which to
221 operate. If dictionary is set to "all", perform operations on all
222 dictionaries. Named dictionaries are: "global" for the global
223 frame filter dictionary, "progspace" for the program space's frame
224 filter dictionary. If either all, or the two named dictionaries
225 are not specified, the dictionary name is assumed to be the name
226 of the object-file name.
228 NAME matches the name of the frame-filter to operate on. If
229 DICTIONARY is "all", NAME is ignored.
232 super(EnableFrameFilter
, self
).__init
__("enable frame-filter",
234 def complete(self
, text
, word
):
235 """Completion function for both frame filter dictionary, and
236 frame filter name."""
237 if text
.count(" ") == 0:
238 return _complete_frame_filter_list(text
, word
, True)
240 printer_list
= gdb
.frames
.return_list(text
.split()[0].rstrip())
241 return _complete_frame_filter_name(word
, printer_list
)
243 def invoke(self
, arg
, from_tty
):
244 command_tuple
= _enable_parse_arg("enable frame-filter", arg
)
245 _do_enable_frame_filter(command_tuple
, True)
248 class DisableFrameFilter(gdb
.Command
):
249 """GDB command to disable the specified frame-filter.
251 Usage: disable frame-filter disable DICTIONARY [NAME]
253 DICTIONARY is the name of the frame filter dictionary on which to
254 operate. If dictionary is set to "all", perform operations on all
255 dictionaries. Named dictionaries are: "global" for the global
256 frame filter dictionary, "progspace" for the program space's frame
257 filter dictionary. If either all, or the two named dictionaries
258 are not specified, the dictionary name is assumed to be the name
259 of the object-file name.
261 NAME matches the name of the frame-filter to operate on. If
262 DICTIONARY is "all", NAME is ignored.
265 super(DisableFrameFilter
, self
).__init
__("disable frame-filter",
268 def complete(self
, text
, word
):
269 """Completion function for both frame filter dictionary, and
270 frame filter name."""
271 if text
.count(" ") == 0:
272 return _complete_frame_filter_list(text
, word
, True)
274 printer_list
= gdb
.frames
.return_list(text
.split()[0].rstrip())
275 return _complete_frame_filter_name(word
, printer_list
)
277 def invoke(self
, arg
, from_tty
):
278 command_tuple
= _enable_parse_arg("disable frame-filter", arg
)
279 _do_enable_frame_filter(command_tuple
, False)
281 class SetFrameFilterPriority(gdb
.Command
):
282 """GDB command to set the priority of the specified frame-filter.
284 Usage: set frame-filter priority DICTIONARY NAME PRIORITY
286 DICTIONARY is the name of the frame filter dictionary on which to
287 operate. Named dictionaries are: "global" for the global frame
288 filter dictionary, "progspace" for the program space's framefilter
289 dictionary. If either of these two are not specified, the
290 dictionary name is assumed to be the name of the object-file name.
292 NAME matches the name of the frame filter to operate on.
294 PRIORITY is the an integer to assign the new priority to the frame
299 super(SetFrameFilterPriority
, self
).__init
__("set frame-filter " \
303 def _parse_pri_arg(self
, arg
):
304 """Internal worker to parse a priority from a tuple.
307 arg: Tuple which contains the arguments from the command.
310 A tuple containing the dictionary, name and priority from
314 gdb.GdbError: An error parsing the arguments.
317 argv
= gdb
.string_to_argv(arg
);
320 print("set frame-filter priority " \
321 "takes exactly three arguments.")
326 def _set_filter_priority(self
, command_tuple
):
327 """Internal worker for setting priority of frame-filters, by
328 parsing a tuple and calling _set_priority with the parsed
332 command_tuple: Tuple which contains the arguments from the
336 list_op
= command_tuple
[0]
337 frame_filter
= command_tuple
[1]
339 # GDB returns arguments as a string, so convert priority to
341 priority
= int(command_tuple
[2])
343 op_list
= gdb
.frames
.return_list(list_op
)
346 ff
= op_list
[frame_filter
]
348 msg
= "frame-filter '" + str(name
) + "' not found."
349 raise gdb
.GdbError(msg
)
351 gdb
.frames
.set_priority(ff
, priority
)
353 def complete(self
, text
, word
):
354 """Completion function for both frame filter dictionary, and
355 frame filter name."""
356 if text
.count(" ") == 0:
357 return _complete_frame_filter_list(text
, word
, False)
359 printer_list
= gdb
.frames
.return_list(text
.split()[0].rstrip())
360 return _complete_frame_filter_name(word
, printer_list
)
362 def invoke(self
, arg
, from_tty
):
363 command_tuple
= self
._parse
_pri
_arg
(arg
)
364 if command_tuple
!= None:
365 self
._set
_filter
_priority
(command_tuple
)
367 class ShowFrameFilterPriority(gdb
.Command
):
368 """GDB command to show the priority of the specified frame-filter.
370 Usage: show frame-filter priority DICTIONARY NAME
372 DICTIONARY is the name of the frame filter dictionary on which to
373 operate. Named dictionaries are: "global" for the global frame
374 filter dictionary, "progspace" for the program space's framefilter
375 dictionary. If either of these two are not specified, the
376 dictionary name is assumed to be the name of the object-file name.
378 NAME matches the name of the frame-filter to operate on.
382 super(ShowFrameFilterPriority
, self
).__init
__("show frame-filter " \
386 def _parse_pri_arg(self
, arg
):
387 """Internal worker to parse a dictionary and name from a
391 arg: Tuple which contains the arguments from the command.
394 A tuple containing the dictionary, and frame filter name.
397 gdb.GdbError: An error parsing the arguments.
400 argv
= gdb
.string_to_argv(arg
);
403 print("show frame-filter priority " \
404 "takes exactly two arguments.")
409 def get_filter_priority(self
, frame_filters
, name
):
410 """Worker for retrieving the priority of frame_filters.
413 frame_filters: Name of frame filter dictionary.
414 name: object to select printers.
417 The priority of the frame filter.
420 gdb.GdbError: A frame filter cannot be found.
423 op_list
= gdb
.frames
.return_list(frame_filters
)
428 msg
= "frame-filter '" + str(name
) + "' not found."
429 raise gdb
.GdbError(msg
)
431 return gdb
.frames
.get_priority(ff
)
433 def complete(self
, text
, word
):
434 """Completion function for both frame filter dictionary, and
435 frame filter name."""
437 if text
.count(" ") == 0:
438 return _complete_frame_filter_list(text
, word
, False)
440 printer_list
= frame
._return
_list
(text
.split()[0].rstrip())
441 return _complete_frame_filter_name(word
, printer_list
)
443 def invoke(self
, arg
, from_tty
):
444 command_tuple
= self
._parse
_pri
_arg
(arg
)
445 if command_tuple
== None:
447 filter_name
= command_tuple
[1]
448 list_name
= command_tuple
[0]
450 priority
= self
.get_filter_priority(list_name
, filter_name
);
451 except Exception as e
:
452 print("Error printing filter priority for '"+name
+"':"+str(e
))
454 print("Priority of filter '" + filter_name
+ "' in list '" \
455 + list_name
+ "' is: " + str(priority
))
459 ShowFilterPrefixCmd()
463 SetFrameFilterPriority()
464 ShowFrameFilterPriority()
This page took 0.040413 seconds and 4 git commands to generate.