* NEWS: Update.

* c-typeprint.c (c_type_print_base): Handle print_method and
	print_typedefs flags.
	* gdbcmd.h (setprinttypelist, showprinttypelist): Declare.
	* python/py-type.c (typy_str): Use LA_PRINT_TYPE and raw
	options.
	* typeprint.c (type_print_raw_options, default_ptype_flags):
	Update for new field.s
	(whatis_exp): Parse flags.  Use LA_PRINT_TYPE.
	(setprinttypelist, showprinttypelist, print_methods,
	print_typedefs): New globals.
	(set_print_type, show_print_type, set_print_type_methods,
	show_print_type_methods, set_print_type_typedefs,
	show_print_type_typedefs): New functions.
	(_initialize_typeprint): Update documentation.  Add "print
	type methods" and "print type typedefs" parameters.
	* typeprint.h (struct type_print_options) <print_methods,
	print_typedefs>: New fields.
doc
	* gdb.texinfo (Symbols): Document "set print type methods",
	"set print type typedefs", and flags to ptype and whatis.
This commit is contained in:
Tom Tromey 2012-11-12 17:26:21 +00:00
parent 6c8702eb92
commit 53342f27db
9 changed files with 250 additions and 8 deletions

View file

@ -1,3 +1,24 @@
2012-11-12 Tom Tromey <tromey@redhat.com>
* NEWS: Update.
* c-typeprint.c (c_type_print_base): Handle print_method and
print_typedefs flags.
* gdbcmd.h (setprinttypelist, showprinttypelist): Declare.
* python/py-type.c (typy_str): Use LA_PRINT_TYPE and raw
options.
* typeprint.c (type_print_raw_options, default_ptype_flags):
Update for new field.s
(whatis_exp): Parse flags. Use LA_PRINT_TYPE.
(setprinttypelist, showprinttypelist, print_methods,
print_typedefs): New globals.
(set_print_type, show_print_type, set_print_type_methods,
show_print_type_methods, set_print_type_typedefs,
show_print_type_typedefs): New functions.
(_initialize_typeprint): Update documentation. Add "print
type methods" and "print type typedefs" parameters.
* typeprint.h (struct type_print_options) <print_methods,
print_typedefs>: New fields.
2012-11-12 Tom Tromey <tromey@redhat.com> 2012-11-12 Tom Tromey <tromey@redhat.com>
* c-typeprint.c (cp_type_print_method_args): Add flags * c-typeprint.c (cp_type_print_method_args): Add flags

View file

@ -8,6 +8,9 @@
-nh Disables auto-loading of ~/.gdbinit, but still executes all the -nh Disables auto-loading of ~/.gdbinit, but still executes all the
other initialization files, unlike -nx which disables all of them. other initialization files, unlike -nx which disables all of them.
* The 'ptype' and 'whatis' commands now accept an argument to control
type formatting.
* Python scripting * Python scripting
** Vectors can be created with gdb.Type.vector. ** Vectors can be created with gdb.Type.vector.
@ -54,6 +57,18 @@ py [command]
(has been deprecated in GDB 7.5), and "info all-registers" should be used (has been deprecated in GDB 7.5), and "info all-registers" should be used
instead. instead.
* New options
set print type methods (on|off)
show print type methods
Control whether method declarations are displayed by "ptype".
The default is to show them.
set print type typedefs (on|off)
show print type typedefs
Control whether typedef definitions are displayed by "ptype".
The default is to show them.
* MI changes * MI changes
** Command parameter changes are now notified using new async record ** Command parameter changes are now notified using new async record

View file

@ -970,6 +970,8 @@ c_type_print_base (struct type *type, struct ui_file *stream,
between them. Make sure to count only method that we between them. Make sure to count only method that we
will display; artificial methods will be hidden. */ will display; artificial methods will be hidden. */
len = TYPE_NFN_FIELDS (type); len = TYPE_NFN_FIELDS (type);
if (!flags->print_methods)
len = 0;
real_len = 0; real_len = 0;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
@ -1136,7 +1138,7 @@ c_type_print_base (struct type *type, struct ui_file *stream,
/* Print typedefs defined in this class. */ /* Print typedefs defined in this class. */
if (TYPE_TYPEDEF_FIELD_COUNT (type) != 0) if (TYPE_TYPEDEF_FIELD_COUNT (type) != 0 && flags->print_typedefs)
{ {
if (TYPE_NFIELDS (type) != 0 || TYPE_NFN_FIELDS (type) != 0) if (TYPE_NFIELDS (type) != 0 || TYPE_NFN_FIELDS (type) != 0)
fprintf_filtered (stream, "\n"); fprintf_filtered (stream, "\n");

View file

@ -1,3 +1,8 @@
2012-11-12 Tom Tromey <tromey@redhat.com>
* gdb.texinfo (Symbols): Document "set print type methods",
"set print type typedefs", and flags to ptype and whatis.
2012-11-09 Andrew Burgess <aburgess@broadcom.com> 2012-11-09 Andrew Burgess <aburgess@broadcom.com>
* gdb.texinfo (GDB/MI Data Manipulation): Add fullname field to * gdb.texinfo (GDB/MI Data Manipulation): Add fullname field to

View file

@ -14990,6 +14990,42 @@ case-insensitive matches.
This command shows the current setting of case sensitivity for symbols This command shows the current setting of case sensitivity for symbols
lookups. lookups.
@kindex set print type methods
@item set print type methods
@itemx set print type methods on
@itemx set print type methods off
Normally, when @value{GDBN} prints a class, it displays any methods
declared in that class. You can control this behavior either by
passing the appropriate flag to @code{ptype}, or using @command{set
print type methods}. Specifying @code{on} will cause @value{GDBN} to
display the methods; this is the default. Specifying @code{off} will
cause @value{GDBN} to omit the methods.
@kindex show print type methods
@item show print type methods
This command shows the current setting of method display when printing
classes.
@kindex set print type typedefs
@item set print type typedefs
@itemx set print type typedefs on
@itemx set print type typedefs off
Normally, when @value{GDBN} prints a class, it displays any typedefs
defined in that class. You can control this behavior either by
passing the appropriate flag to @code{ptype}, or using @command{set
print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
display the typedef definitions; this is the default. Specifying
@code{off} will cause @value{GDBN} to omit the typedef definitions.
Note that this controls whether the typedef definition itself is
printed, not whether typedef names are substituted when printing other
types.
@kindex show print type typedefs
@item show print type typedefs
This command shows the current setting of typedef display when
printing classes.
@kindex info address @kindex info address
@cindex address of a symbol @cindex address of a symbol
@item info address @var{symbol} @item info address @var{symbol}
@ -15030,7 +15066,7 @@ __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
@end smallexample @end smallexample
@kindex whatis @kindex whatis
@item whatis [@var{arg}] @item whatis[/@var{flags}] [@var{arg}]
Print the data type of @var{arg}, which can be either an expression Print the data type of @var{arg}, which can be either an expression
or a name of a data type. With no argument, print the data type of or a name of a data type. With no argument, print the data type of
@code{$}, the last value in the value history. @code{$}, the last value in the value history.
@ -15060,8 +15096,34 @@ For C code, the type names may also have the form @samp{class
@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
@var{union-tag}} or @samp{enum @var{enum-tag}}. @var{union-tag}} or @samp{enum @var{enum-tag}}.
@var{flags} can be used to modify how the type is displayed.
Available flags are:
@table @code
@item r
Display in ``raw'' form. Normally, @value{GDBN} substitutes template
parameters and typedefs defined in a class when printing the class'
members. The @code{/r} flag disables this.
@item m
Do not print methods defined in the class.
@item M
Print methods defined in the class. This is the default, but the flag
exists in case you change the default with @command{set print type methods}.
@item t
Do not print typedefs defined in the class. Note that this controls
whether the typedef definition itself is printed, not whether typedef
names are substituted when printing other types.
@item T
Print typedefs defined in the class. This is the default, but the flag
exists in case you change the default with @command{set print type typedefs}.
@end table
@kindex ptype @kindex ptype
@item ptype [@var{arg}] @item ptype[/@var{flags}] [@var{arg}]
@code{ptype} accepts the same arguments as @code{whatis}, but prints a @code{ptype} accepts the same arguments as @code{whatis}, but prints a
detailed description of the type, instead of just the name of the type. detailed description of the type, instead of just the name of the type.
@xref{Expressions, ,Expressions}. @xref{Expressions, ,Expressions}.

View file

@ -112,6 +112,10 @@ extern struct cmd_list_element *setprintlist;
extern struct cmd_list_element *showprintlist; extern struct cmd_list_element *showprintlist;
extern struct cmd_list_element *setprinttypelist;
extern struct cmd_list_element *showprinttypelist;
extern struct cmd_list_element *setdebuglist; extern struct cmd_list_element *setdebuglist;
extern struct cmd_list_element *showdebuglist; extern struct cmd_list_element *showdebuglist;

View file

@ -30,6 +30,7 @@
#include "vec.h" #include "vec.h"
#include "bcache.h" #include "bcache.h"
#include "dwarf2loc.h" #include "dwarf2loc.h"
#include "typeprint.h"
typedef struct pyty_type_object typedef struct pyty_type_object
{ {
@ -954,7 +955,8 @@ typy_str (PyObject *self)
stb = mem_fileopen (); stb = mem_fileopen ();
old_chain = make_cleanup_ui_file_delete (stb); old_chain = make_cleanup_ui_file_delete (stb);
type_print (type_object_to_type (self), "", stb, -1); LA_PRINT_TYPE (type_object_to_type (self), "", stb, -1, 0,
&type_print_raw_options);
thetype = ui_file_xstrdup (stb, &length); thetype = ui_file_xstrdup (stb, &length);
do_cleanups (old_chain); do_cleanups (old_chain);

View file

@ -36,6 +36,8 @@
#include "exceptions.h" #include "exceptions.h"
#include "valprint.h" #include "valprint.h"
#include <errno.h> #include <errno.h>
#include <ctype.h>
#include "cli/cli-utils.h"
extern void _initialize_typeprint (void); extern void _initialize_typeprint (void);
@ -47,16 +49,22 @@ static void whatis_exp (char *, int);
const struct type_print_options type_print_raw_options = const struct type_print_options type_print_raw_options =
{ {
1 /* raw */ 1, /* raw */
1, /* print_methods */
1 /* print_typedefs */
}; };
/* The default flags for 'ptype' and 'whatis'. */ /* The default flags for 'ptype' and 'whatis'. */
static struct type_print_options default_ptype_flags = static struct type_print_options default_ptype_flags =
{ {
0 /* raw */ 0, /* raw */
1, /* print_methods */
1 /* print_typedefs */
}; };
/* Print a description of a type in the format of a /* Print a description of a type in the format of a
typedef for the current language. typedef for the current language.
NEW is the new name for a type TYPE. */ NEW is the new name for a type TYPE. */
@ -132,9 +140,46 @@ whatis_exp (char *exp, int show)
int top = -1; int top = -1;
int using_enc = 0; int using_enc = 0;
struct value_print_options opts; struct value_print_options opts;
struct type_print_options flags = default_ptype_flags;
if (exp) if (exp)
{ {
if (*exp == '/')
{
int seen_one = 0;
for (++exp; *exp && !isspace (*exp); ++exp)
{
switch (*exp)
{
case 'r':
flags.raw = 1;
break;
case 'm':
flags.print_methods = 0;
break;
case 'M':
flags.print_methods = 1;
break;
case 't':
flags.print_typedefs = 0;
break;
case 'T':
flags.print_typedefs = 1;
break;
default:
error (_("unrecognized flag '%c'"), *exp);
}
seen_one = 1;
}
if (!*exp && !seen_one)
error (_("flag expected"));
if (!isspace (*exp))
error (_("expected space after format"));
exp = skip_spaces (exp);
}
expr = parse_expression (exp); expr = parse_expression (exp);
old_chain = make_cleanup (free_current_contents, &expr); old_chain = make_cleanup (free_current_contents, &expr);
val = evaluate_type (expr); val = evaluate_type (expr);
@ -166,7 +211,7 @@ whatis_exp (char *exp, int show)
printf_filtered (" */\n"); printf_filtered (" */\n");
} }
type_print (type, "", gdb_stdout, show); LA_PRINT_TYPE (type, "", gdb_stdout, show, 0, &flags);
printf_filtered ("\n"); printf_filtered ("\n");
if (exp) if (exp)
@ -310,17 +355,97 @@ maintenance_print_type (char *typename, int from_tty)
} }
struct cmd_list_element *setprinttypelist;
struct cmd_list_element *showprinttypelist;
static void
set_print_type (char *arg, int from_tty)
{
printf_unfiltered (
"\"set print type\" must be followed by the name of a subcommand.\n");
help_list (setprintlist, "set print type ", -1, gdb_stdout);
}
static void
show_print_type (char *args, int from_tty)
{
cmd_show_list (showprinttypelist, from_tty, "");
}
static int print_methods = 1;
static void
set_print_type_methods (char *args, int from_tty, struct cmd_list_element *c)
{
default_ptype_flags.print_methods = print_methods;
}
static void
show_print_type_methods (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
fprintf_filtered (file, _("Printing of methods defined in a class in %s\n"),
value);
}
static int print_typedefs = 1;
static void
set_print_type_typedefs (char *args, int from_tty, struct cmd_list_element *c)
{
default_ptype_flags.print_typedefs = print_typedefs;
}
static void
show_print_type_typedefs (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
fprintf_filtered (file, _("Printing of typedefs defined in a class in %s\n"),
value);
}
void void
_initialize_typeprint (void) _initialize_typeprint (void)
{ {
add_com ("ptype", class_vars, ptype_command, _("\ add_com ("ptype", class_vars, ptype_command, _("\
Print definition of type TYPE.\n\ Print definition of type TYPE.\n\
Usage: ptype[/FLAGS] TYPE-NAME | EXPRESSION\n\
Argument may be a type name defined by typedef, or \"struct STRUCT-TAG\"\n\ Argument may be a type name defined by typedef, or \"struct STRUCT-TAG\"\n\
or \"class CLASS-NAME\" or \"union UNION-TAG\" or \"enum ENUM-TAG\".\n\ or \"class CLASS-NAME\" or \"union UNION-TAG\" or \"enum ENUM-TAG\".\n\
The selected stack frame's lexical context is used to look up the name.\n\ The selected stack frame's lexical context is used to look up the name.\n\
Contrary to \"whatis\", \"ptype\" always unrolls any typedefs.")); Contrary to \"whatis\", \"ptype\" always unrolls any typedefs.\n\
\n\
Available FLAGS are:\n\
/r print in \"raw\" form; do not substitute typedefs\n\
/m do not print methods defined in a class\n\
/M print methods defined in a class\n\
/t do not print typedefs defined in a class\n\
/T print typedefs defined in a class"));
add_com ("whatis", class_vars, whatis_command, add_com ("whatis", class_vars, whatis_command,
_("Print data type of expression EXP.\n\ _("Print data type of expression EXP.\n\
Only one level of typedefs is unrolled. See also \"ptype\".")); Only one level of typedefs is unrolled. See also \"ptype\"."));
add_prefix_cmd ("type", no_class, show_print_type,
_("Generic command for showing type-printing settings."),
&showprinttypelist, "show print type ", 0, &showprintlist);
add_prefix_cmd ("type", no_class, set_print_type,
_("Generic command for setting how types print."),
&setprinttypelist, "show print type ", 0, &setprintlist);
add_setshow_boolean_cmd ("methods", no_class, &print_methods,
_("\
Set printing of methods defined in classes."), _("\
Show printing of methods defined in classes."), NULL,
set_print_type_methods,
show_print_type_methods,
&setprinttypelist, &showprinttypelist);
add_setshow_boolean_cmd ("typedefs", no_class, &print_typedefs,
_("\
Set printing of typedefs defined in classes."), _("\
Show printing of typedefs defined in classes."), NULL,
set_print_type_typedefs,
show_print_type_typedefs,
&setprinttypelist, &showprinttypelist);
} }

View file

@ -27,6 +27,12 @@ struct type_print_options
{ {
/* True means that no special printing flags should apply. */ /* True means that no special printing flags should apply. */
unsigned int raw : 1; unsigned int raw : 1;
/* True means print methods in a class. */
unsigned int print_methods : 1;
/* True means print typedefs in a class. */
unsigned int print_typedefs : 1;
}; };
extern const struct type_print_options type_print_raw_options; extern const struct type_print_options type_print_raw_options;