This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RFA: fix pretty-printing in "bt full"
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 15 Dec 2008 13:29:37 -0700
- Subject: RFA: fix pretty-printing in "bt full"
- Reply-to: Tom Tromey <tromey at redhat dot com>
Consider this program:
struct s {
int x;
int y;
};
int func2 (struct s val) { return val.y + 5; }
int main (int argc, char **argv)
{
struct s a;
a.x = 5;
a.y = 7;
return func2 (a) != 12;
}
If I set a breakpoint on func2, run, and then invoke "bt full", I see:
(gdb) bt full
#0 func2 (val={x = 5, y = 7}) at b.c:6
No locals.
#1 0x080483a9 in main (argc=1, argv=0xbffff7b4) at b.c:14
a = {
x = 5,
y = 7
}
Note the odd indentation of "a" (there is a tab before "a = ", so you
may need to take your mail program's tab settings into account. On my
terminal this is visually like 8 spaces).
This patch fixes the problem by changing print_variable_value to
accept an indentation argument, like the various val_print functions
do.
After the patch the output looks like this:
(gdb) bt full
#0 func2 (val={x = 5, y = 7}) at b.c:6
No locals.
#1 0x080483a9 in main (argc=1, argv=0xbffff7a4) at b.c:14
a = {
x = 5,
y = 7
}
I think this looks nicer, because the contents of "a" are indented
underneath "a".
Built and regtested on x86-64 (compile farm).
Please review.
thanks,
Tom
2008-12-15 Tom Tromey <tromey@redhat.com>
* stack.c (print_block_frame_locals): Print spaces, not tabs.
Pass indentation level to print_variable_value.
(print_frame_arg_vars): Update.
* value.h (print_variable_value): Update.
* printcmd.c (print_variable_value): Add 'indent' argument. Use
common_val_print.
* f-valprint.c (info_common_command): Update.
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index f893b49..26fe220 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -567,7 +567,7 @@ info_common_command (char *comname, int from_tty)
while (entry != NULL)
{
printf_filtered ("%s = ", SYMBOL_PRINT_NAME (entry->symbol));
- print_variable_value (entry->symbol, fi, gdb_stdout);
+ print_variable_value (entry->symbol, fi, gdb_stdout, 0);
printf_filtered ("\n");
entry = entry->next;
}
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 6d6b915..47dbc98 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1731,17 +1731,20 @@ disable_display_command (char *args, int from_tty)
/* Print the value in stack frame FRAME of a variable specified by a
- struct symbol. */
+ struct symbol. STREAM is the ui_file on which to print the value.
+ INDENT is used to control indentation of sub-parts of the value; it
+ should be set to the number of indentation levels already emitted
+ at the point at which this function is called. */
void
print_variable_value (struct symbol *var, struct frame_info *frame,
- struct ui_file *stream)
+ struct ui_file *stream, int indent)
{
struct value *val = read_var_value (var, frame);
struct value_print_options opts;
get_user_print_options (&opts);
- value_print (val, stream, &opts);
+ common_val_print (val, stream, indent, &opts, current_language);
}
static void
diff --git a/gdb/stack.c b/gdb/stack.c
index 3c1019b..dab332a 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -1375,10 +1375,10 @@ print_block_frame_locals (struct block *b, struct frame_info *frame,
break;
values_printed = 1;
for (j = 0; j < num_tabs; j++)
- fputs_filtered ("\t", stream);
+ fputs_filtered (" ", stream);
fputs_filtered (SYMBOL_PRINT_NAME (sym), stream);
fputs_filtered (" = ", stream);
- print_variable_value (sym, frame, stream);
+ print_variable_value (sym, frame, stream, 4 * num_tabs);
fprintf_filtered (stream, "\n");
break;
@@ -1591,7 +1591,7 @@ print_frame_arg_vars (struct frame_info *frame, struct ui_file *stream)
sym2 = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
b, VAR_DOMAIN, NULL);
- print_variable_value (sym2, frame, stream);
+ print_variable_value (sym2, frame, stream, 0);
fprintf_filtered (stream, "\n");
}
}
diff --git a/gdb/value.h b/gdb/value.h
index a882004..6c4499b 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -559,7 +559,8 @@ extern int val_print_string (CORE_ADDR addr, int len, int width,
extern void print_variable_value (struct symbol *var,
struct frame_info *frame,
- struct ui_file *stream);
+ struct ui_file *stream,
+ int indent);
extern int check_field (struct type *, const char *);