This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFA: fix PR 8079


As promised, here is the patch from PR 8079, with a few updates.

The bug concerns showing the user the expression as they typed it --
not the printed form of the parsed expression.  This is nice because
it means numeric constants show up the way they were typed, rather
than in the prevailing output radix.

I also made the same change to printcmd.c, so that `display'
expressions show up verbatim.

Built and regtested on x86-64 (compile farm).

Please review.

Tom

2009-01-07  Pierre Muller  <muller@ics.u-strasbg.fr>
	    Tom Tromey  <tromey@redhat.com>

	PR breakpoints/8079:
	* breakpoint.c (print_one_breakpoint): Use exp_string field
	to display expression of watchpoints.
	(mention): Likewise.
	(watch_command_1): Remove trailing whitespace from expression.
	* printcmd.c (struct display) <exp_string>: New field.
	(display_command): Set exp_string.
	(free_display): Free exp_string.
	(clear_displays): Use free_display.
	(do_one_display): Print exp_string.
	(display_info): Likewise.

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 2e25490..bb9b58e 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3494,8 +3494,7 @@ print_one_breakpoint_location (struct breakpoint *b,
 	if (opts.addressprint)
 	  ui_out_field_skip (uiout, "addr");
 	annotate_field (5);
-	print_expression (b->exp, stb->stream);
-	ui_out_field_stream (uiout, "what", stb);
+	ui_out_field_string (uiout, "what", b->exp_string);
 	break;
 
       case bp_breakpoint:
@@ -4893,15 +4892,11 @@ static void
 mention (struct breakpoint *b)
 {
   int say_where = 0;
-  struct cleanup *old_chain, *ui_out_chain;
-  struct ui_stream *stb;
+  struct cleanup *ui_out_chain;
   struct value_print_options opts;
 
   get_user_print_options (&opts);
 
-  stb = ui_out_stream_new (uiout);
-  old_chain = make_cleanup_ui_out_stream_delete (stb);
-
   /* FIXME: This is misplaced; mention() is called by things (like
      hitting a watchpoint) other than breakpoint creation.  It should
      be possible to clean this up and at the same time replace the
@@ -4921,8 +4916,7 @@ mention (struct breakpoint *b)
 	ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
 	ui_out_field_int (uiout, "number", b->number);
 	ui_out_text (uiout, ": ");
-	print_expression (b->exp, stb->stream);
-	ui_out_field_stream (uiout, "exp", stb);
+	ui_out_field_string (uiout, "exp", b->exp_string);
 	do_cleanups (ui_out_chain);
 	break;
       case bp_hardware_watchpoint:
@@ -4930,8 +4924,7 @@ mention (struct breakpoint *b)
 	ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
 	ui_out_field_int (uiout, "number", b->number);
 	ui_out_text (uiout, ": ");
-	print_expression (b->exp, stb->stream);
-	ui_out_field_stream (uiout, "exp", stb);
+	ui_out_field_string (uiout, "exp", b->exp_string);
 	do_cleanups (ui_out_chain);
 	break;
       case bp_read_watchpoint:
@@ -4939,8 +4932,7 @@ mention (struct breakpoint *b)
 	ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
 	ui_out_field_int (uiout, "number", b->number);
 	ui_out_text (uiout, ": ");
-	print_expression (b->exp, stb->stream);
-	ui_out_field_stream (uiout, "exp", stb);
+	ui_out_field_string (uiout, "exp", b->exp_string);
 	do_cleanups (ui_out_chain);
 	break;
       case bp_access_watchpoint:
@@ -4948,8 +4940,7 @@ mention (struct breakpoint *b)
 	ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
 	ui_out_field_int (uiout, "number", b->number);
 	ui_out_text (uiout, ": ");
-	print_expression (b->exp, stb->stream);
-	ui_out_field_stream (uiout, "exp", stb);
+	ui_out_field_string (uiout, "exp", b->exp_string);
 	do_cleanups (ui_out_chain);
 	break;
       case bp_breakpoint:
@@ -5018,7 +5009,6 @@ mention (struct breakpoint *b)
 
 	}
     }
-  do_cleanups (old_chain);
   if (ui_out_is_mi_like_p (uiout))
     return;
   printf_filtered ("\n");
@@ -5950,6 +5940,12 @@ watch_command_1 (char *arg, int accessflag, int from_tty)
   exp_start = arg;
   exp = parse_exp_1 (&arg, 0, 0);
   exp_end = arg;
+  /* Remove trailing whitespace from the expression before saving it.
+     This makes the eventual display of the expression string a bit
+     prettier.  */
+  while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t'))
+    --exp_end;
+
   exp_valid_block = innermost_block;
   mark = value_mark ();
   fetch_watchpoint_value (exp, &val, NULL, NULL);
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 0dfe80b..a51ba68 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -124,6 +124,8 @@ struct display
   {
     /* Chain link to next auto-display item.  */
     struct display *next;
+    /* The expression as the user typed it.  */
+    char *exp_string;
     /* Expression to be evaluated and displayed.  */
     struct expression *exp;
     /* Item number of this auto-display item.  */
@@ -1398,6 +1400,7 @@ display_command (char *exp, int from_tty)
 
       new = (struct display *) xmalloc (sizeof (struct display));
 
+      new->exp_string = xstrdup (exp);
       new->exp = expr;
       new->block = innermost_block;
       new->next = display_chain;
@@ -1416,6 +1419,7 @@ display_command (char *exp, int from_tty)
 static void
 free_display (struct display *d)
 {
+  xfree (d->exp_string);
   xfree (d->exp);
   xfree (d);
 }
@@ -1430,9 +1434,8 @@ clear_displays (void)
 
   while ((d = display_chain) != NULL)
     {
-      xfree (d->exp);
       display_chain = d->next;
-      xfree (d);
+      free_display (d);
     }
 }
 
@@ -1546,7 +1549,7 @@ do_one_display (struct display *d)
 
       annotate_display_expression ();
 
-      print_expression (d->exp, gdb_stdout);
+      puts_filtered (d->exp_string);
       annotate_display_expression_end ();
 
       if (d->format.count != 1 || d->format.format == 'i')
@@ -1574,7 +1577,7 @@ do_one_display (struct display *d)
 
       annotate_display_expression ();
 
-      print_expression (d->exp, gdb_stdout);
+      puts_filtered (d->exp_string);
       annotate_display_expression_end ();
 
       printf_filtered (" = ");
@@ -1654,7 +1657,7 @@ Num Enb Expression\n"));
 			 d->format.format);
       else if (d->format.format)
 	printf_filtered ("/%c ", d->format.format);
-      print_expression (d->exp, gdb_stdout);
+      puts_filtered (d->exp_string);
       if (d->block && !contained_in (get_selected_block (0), d->block))
 	printf_filtered (_(" (cannot be evaluated in the current context)"));
       printf_filtered ("\n");


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]