aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2011-08-09 16:21:18 +0000
committerPedro Alves <palves@redhat.com>2011-08-09 16:21:18 +0000
commit9d8fa392330553fe114ae4137d15415aee2c547c (patch)
treea251e1e85a474b5acd1b00845f79d38480ca1a6a
parentb5503c7b66594da3ea6036c2a76aa42ee1c930c6 (diff)
downloadgdb-9d8fa392330553fe114ae4137d15415aee2c547c.zip
gdb-9d8fa392330553fe114ae4137d15415aee2c547c.tar.gz
gdb-9d8fa392330553fe114ae4137d15415aee2c547c.tar.bz2
2011-08-09 Pedro Alves <pedro@codesourcery.com>
gdb/ * printcmd.c (current_display_number): Update comment. (disable_current_display_cleanup): Delete. (do_one_display): Use make_cleanup_restore_integer. Gracefully catch errors thrown while evaluating and printing the display. gdb/testsuite/ * gdb.base/display.c (do_loops): New `p_i' local. * gdb.base/display.exp: Test displaying a variable that is temporarily at a bad address.
-rw-r--r--gdb/ChangeLog7
-rw-r--r--gdb/printcmd.c50
-rw-r--r--gdb/testsuite/ChangeLog6
-rw-r--r--gdb/testsuite/gdb.base/display.c2
-rw-r--r--gdb/testsuite/gdb.base/display.exp26
5 files changed, 69 insertions, 22 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0693787..7f87169 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2011-08-09 Pedro Alves <pedro@codesourcery.com>
+
+ * printcmd.c (current_display_number): Update comment.
+ (disable_current_display_cleanup): Delete.
+ (do_one_display): Use make_cleanup_restore_integer. Gracefully
+ catch errors thrown while evaluating and printing the display.
+
2011-08-09 Tom Tromey <tromey@redhat.com>
* mi/mi-cmd-break.c (mi_cmd_break_passcount): Fix typo.
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index f376595..b09b4ea 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -129,7 +129,7 @@ show_print_symbol_filename (struct ui_file *file, int from_tty,
}
/* Number of auto-display expression currently being displayed.
- So that we can disable it if we get an error or a signal within it.
+ So that we can disable it if we get a signal within it.
-1 when not doing one. */
int current_display_number;
@@ -1656,14 +1656,6 @@ undisplay_command (char *args, int from_tty)
dont_repeat ();
}
-/* Cleanup that just disables the current display. */
-
-static void
-disable_current_display_cleanup (void *arg)
-{
- disable_current_display ();
-}
-
/* Display a single auto-display.
Do nothing if the display cannot be printed in the current context,
or if the display is disabled. */
@@ -1723,8 +1715,8 @@ do_one_display (struct display *d)
if (!within_current_scope)
return;
+ old_chain = make_cleanup_restore_integer (&current_display_number);
current_display_number = d->number;
- old_chain = make_cleanup (disable_current_display_cleanup, NULL);
annotate_display_begin ();
printf_filtered ("%d", d->number);
@@ -1732,8 +1724,7 @@ do_one_display (struct display *d)
printf_filtered (": ");
if (d->format.size)
{
- CORE_ADDR addr;
- struct value *val;
+ volatile struct gdb_exception ex;
annotate_display_format ();
@@ -1755,18 +1746,26 @@ do_one_display (struct display *d)
else
printf_filtered (" ");
- val = evaluate_expression (d->exp);
- addr = value_as_address (val);
- if (d->format.format == 'i')
- addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr);
-
annotate_display_value ();
- do_examine (d->format, d->exp->gdbarch, addr);
+ TRY_CATCH (ex, RETURN_MASK_ERROR)
+ {
+ struct value *val;
+ CORE_ADDR addr;
+
+ val = evaluate_expression (d->exp);
+ addr = value_as_address (val);
+ if (d->format.format == 'i')
+ addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr);
+ do_examine (d->format, d->exp->gdbarch, addr);
+ }
+ if (ex.reason < 0)
+ fprintf_filtered (gdb_stdout, _("<error: %s>\n"), ex.message);
}
else
{
struct value_print_options opts;
+ volatile struct gdb_exception ex;
annotate_display_format ();
@@ -1784,16 +1783,23 @@ do_one_display (struct display *d)
get_formatted_print_options (&opts, d->format.format);
opts.raw = d->format.raw;
- print_formatted (evaluate_expression (d->exp),
- d->format.size, &opts, gdb_stdout);
+
+ TRY_CATCH (ex, RETURN_MASK_ERROR)
+ {
+ struct value *val;
+
+ val = evaluate_expression (d->exp);
+ print_formatted (val, d->format.size, &opts, gdb_stdout);
+ }
+ if (ex.reason < 0)
+ fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message);
printf_filtered ("\n");
}
annotate_display_end ();
gdb_flush (gdb_stdout);
- discard_cleanups (old_chain);
- current_display_number = -1;
+ do_cleanups (old_chain);
}
/* Display all of the values on the auto-display chain which can be
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 50d8423..35578ba 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2011-08-09 Pedro Alves <pedro@codesourcery.com>
+
+ * gdb.base/display.c (do_loops): New `p_i' local.
+ * gdb.base/display.exp: Test displaying a variable that is
+ temporarily at a bad address.
+
2011-08-08 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.dwarf2/dw2-op-stack-value.S: New file.
diff --git a/gdb/testsuite/gdb.base/display.c b/gdb/testsuite/gdb.base/display.c
index 332c45b..cd833e2 100644
--- a/gdb/testsuite/gdb.base/display.c
+++ b/gdb/testsuite/gdb.base/display.c
@@ -14,6 +14,8 @@ int do_loops()
int k=0;
int j=0;
float f=3.1415;
+ int *p_i = &i;
+
for( i = 0; i < LOOP; i++ ) { /* set breakpoint 1 here */
for( j = 0; j < LOOP; j++ ) {
for( k = 0; k < LOOP; k++ ) {
diff --git a/gdb/testsuite/gdb.base/display.exp b/gdb/testsuite/gdb.base/display.exp
index 2181c6a..fcf8511 100644
--- a/gdb/testsuite/gdb.base/display.exp
+++ b/gdb/testsuite/gdb.base/display.exp
@@ -119,6 +119,32 @@ gdb_test "undisp" \
"y"
+# Test displaying a variable that is temporarily at a bad address.
+# But if we can examine what's at memory address 0, then we'll also be
+# able to display it without error. Don't run the test in that case.
+set can_read_0 0
+gdb_test_multiple "x 0" "memory at address 0" {
+ -re "0x0:.*Cannot access memory at address 0x0.*$gdb_prompt $" { }
+ -re "0x0:.*Error accessing memory address 0x0.*$gdb_prompt $" { }
+ -re ".*$gdb_prompt $" {
+ set can_read_0 1
+ }
+}
+
+if { !$can_read_0 } {
+ gdb_test "disp *p_i" ".*: \\*p_i = 0"
+ gdb_test "p p_i = 0x0" " = \\(int \\*\\) 0x0"
+ gdb_test "display" ".*: \\*p_i = <error: .*>" "display bad address"
+ gdb_test "p p_i = &i" " = \\(int \\*\\) $hex"
+ gdb_test "display" ".*: \\*p_i = 0" "display good address"
+
+ gdb_test "undisp" \
+ "" \
+ "undisp all again" \
+ ".*Delete all auto-display expressions.*y or n. $" \
+ "y"
+}
+
gdb_test "disab 3" ".*.*" "disab 3"
gdb_test "cont" ".*Breakpoint 4.*" "watch off"