From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22153 invoked by alias); 15 Dec 2008 20:30:18 -0000 Received: (qmail 22104 invoked by uid 22791); 15 Dec 2008 20:30:17 -0000 X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 15 Dec 2008 20:29:42 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id mBFKTe38012982 for ; Mon, 15 Dec 2008 15:29:40 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id mBFKTdZO030216; Mon, 15 Dec 2008 15:29:39 -0500 Received: from opsy.redhat.com (vpn-13-69.rdu.redhat.com [10.11.13.69]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id mBFKTc8q019447; Mon, 15 Dec 2008 15:29:38 -0500 Received: by opsy.redhat.com (Postfix, from userid 500) id DD221508028; Mon, 15 Dec 2008 13:29:37 -0700 (MST) To: gdb-patches@sourceware.org Subject: RFA: fix pretty-printing in "bt full" From: Tom Tromey Reply-To: Tom Tromey Date: Mon, 15 Dec 2008 20:30:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-12/txt/msg00289.txt.bz2 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 * 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 *);