17 """GDB commands for working with pretty-printers."""
25 """Internal utility to parse a pretty-printer command argv.
28 arg: The arguments to the command. The format is:
29 [object-regexp [name-regexp]].
30 Individual printers in a collection are named as
31 printer-name;subprinter-name.
34 The result is a 3-tuple of compiled regular expressions, except that
35 the resulting compiled subprinter regexp is None if not provided.
38 SyntaxError: an error processing ARG
41 argv = gdb.string_to_argv(arg);
47 raise SyntaxError(
"too many arguments")
49 object_regexp = argv[0]
51 name_subname = argv[1].split(
";", 1)
52 name_regexp = name_subname[0]
53 if len(name_subname) == 2:
54 subname_regexp = name_subname[1]
59 object_re = re.compile(object_regexp)
61 raise SyntaxError(
"invalid object regexp: %s" % object_regexp)
63 name_re = re.compile (name_regexp)
65 raise SyntaxError(
"invalid name regexp: %s" % name_regexp)
66 if subname_regexp
is not None:
68 subname_re = re.compile(subname_regexp)
70 raise SyntaxError(
"invalid subname regexp: %s" % subname_regexp)
73 return(object_re, name_re, subname_re)
77 """Internal utility to see if printer (or subprinter) is enabled."""
78 if hasattr(printer,
"enabled"):
79 return printer.enabled
85 """GDB command to list all registered pretty-printers.
87 Usage: info pretty-printer [object-regexp [name-regexp]]
89 OBJECT-REGEXP is a regular expression matching the objects to list.
90 Objects are "global", the program space's file, and the objfiles within
93 NAME-REGEXP matches the name of the pretty-printer.
94 Individual printers in a collection are named as
95 printer-name;subprinter-name.
99 super(InfoPrettyPrinter, self).
__init__(
"info pretty-printer",
104 """Return "" if PRINTER is enabled, otherwise " [disabled]"."""
112 """Return the printer's name."""
113 if hasattr(printer,
"name"):
115 if hasattr(printer,
"__name__"):
116 return printer.__name__
124 """Print a list of pretty-printers."""
127 sorted_pretty_printers = sorted (copy.copy(pretty_printers),
129 for printer
in sorted_pretty_printers:
132 if name_re.match(name):
133 print (
" %s%s" % (name, enabled))
134 if (hasattr(printer,
"subprinters")
and
135 printer.subprinters
is not None):
136 sorted_subprinters = sorted (copy.copy(printer.subprinters),
138 for subprinter
in sorted_subprinters:
139 if (
not subname_re
or
140 subname_re.match(subprinter.name)):
145 def invoke1(self, title, printer_list,
146 obj_name_to_match, object_re, name_re, subname_re):
147 """Subroutine of invoke to simplify it."""
148 if printer_list
and object_re.match(obj_name_to_match):
153 """GDB calls this to perform the command."""
155 self.
invoke1(
"global pretty-printers:", gdb.pretty_printers,
156 "global", object_re, name_re, subname_re)
157 cp = gdb.current_progspace()
158 self.
invoke1(
"progspace %s pretty-printers:" % cp.filename,
159 cp.pretty_printers,
"progspace",
160 object_re, name_re, subname_re)
161 for objfile
in gdb.objfiles():
162 self.
invoke1(
" objfile %s pretty-printers:" % objfile.filename,
163 objfile.pretty_printers, objfile.filename,
164 object_re, name_re, subname_re)
168 """Return a 2-tuple of number of enabled and total printers."""
171 for printer
in pretty_printers:
172 if (hasattr(printer,
"subprinters")
173 and printer.subprinters
is not None):
175 for subprinter
in printer.subprinters:
178 total +=
len(printer.subprinters)
183 return (enabled, total)
187 """Return a 2-tuble of the enabled state and total number of all printers.
188 This includes subprinters.
193 enabled_count += t_enabled
194 total_count += t_total
196 enabled_count += t_enabled
197 total_count += t_total
198 for objfile
in gdb.objfiles():
200 enabled_count += t_enabled
201 total_count += t_total
202 return (enabled_count, total_count)
206 """Return TEXT pluralized if N != 1."""
208 return "%s%s" % (text, suffix)
214 """Print the number of printers enabled/disabled.
215 We count subprinters individually.
218 print (
"%d of %d printers enabled" % (enabled_count, total_count))
222 """Worker for enabling/disabling pretty-printers.
225 pretty_printers: list of pretty-printers
226 name_re: regular-expression object to select printers
227 subname_re: regular expression object to select subprinters or None
229 flag: True for Enable, False for Disable
232 The number of printers affected.
233 This is just for informational purposes for the user.
236 for printer
in pretty_printers:
237 if (hasattr(printer,
"name")
and name_re.match(printer.name)
or
238 hasattr(printer,
"__name__")
and name_re.match(printer.__name__)):
239 if (hasattr(printer,
"subprinters")
and
240 printer.subprinters
is not None):
244 for subprinter
in printer.subprinters:
248 printer.enabled = flag
253 for subprinter
in printer.subprinters:
254 if subname_re.match(subprinter.name):
259 subprinter.enabled = flag
275 printer.enabled = flag
280 """Internal worker for enabling/disabling pretty-printers."""
284 if object_re.match(
"global"):
286 name_re, subname_re, flag)
287 cp = gdb.current_progspace()
288 if object_re.match(
"progspace"):
290 name_re, subname_re, flag)
291 for objfile
in gdb.objfiles():
292 if object_re.match(objfile.filename):
294 name_re, subname_re, flag)
300 print (
"%d %s %s" % (total,
pluralize(
"printer", total), state))
317 """GDB command to enable the specified pretty-printer.
319 Usage: enable pretty-printer [object-regexp [name-regexp]]
321 OBJECT-REGEXP is a regular expression matching the objects to examine.
322 Objects are "global", the program space's file, and the objfiles within
325 NAME-REGEXP matches the name of the pretty-printer.
326 Individual printers in a collection are named as
327 printer-name;subprinter-name.
331 super(EnablePrettyPrinter, self).
__init__(
"enable pretty-printer",
335 """GDB calls this to perform the command."""
340 """GDB command to disable the specified pretty-printer.
342 Usage: disable pretty-printer [object-regexp [name-regexp]]
344 OBJECT-REGEXP is a regular expression matching the objects to examine.
345 Objects are "global", the program space's file, and the objfiles within
348 NAME-REGEXP matches the name of the pretty-printer.
349 Individual printers in a collection are named as
350 printer-name;subprinter-name.
354 super(DisablePrettyPrinter, self).
__init__(
"disable pretty-printer",
358 """GDB calls this to perform the command."""
363 """Call from a top level script to install the pretty-printer commands."""
def invoke(self, arg, from_tty)
def invoke(self, arg, from_tty)
def invoke1(self, title, printer_list, obj_name_to_match, object_re, name_re, subname_re)
def enabled_string(printer)
def count_all_enabled_printers()
def do_enable_pretty_printer(arg, flag)
def parse_printer_regexps(arg)
def show_pretty_printer_enabled_summary()
def list_pretty_printers(self, pretty_printers, name_re, subname_re)
def register_pretty_printer_commands()
def count_enabled_printers(pretty_printers)
def do_enable_pretty_printer_1(pretty_printers, name_re, subname_re, flag)
def invoke(self, arg, from_tty)
def printer_name(printer)
def printer_enabled_p(printer)
const ULONGEST const LONGEST len