summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.ada/scoped_watch
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@adacore.com>2017-03-03 17:31:13 +0100
committerJoel Brobecker <brobecker@adacore.com>2017-11-08 19:52:28 -0500
commit286acbb5c25c5895832d3dd3be3398d3f2d64fad (patch)
treef674472939f4612a6a1cb8eb2cf4989fff93e9ce /gdb/testsuite/gdb.ada/scoped_watch
parentb44ec61915f10a953ca85da5bf7a97911554f1aa (diff)
downloadbinutils-gdb-286acbb5c25c5895832d3dd3be3398d3f2d64fad.tar.gz
local variable watchpoint not deleted after leaving scope
When debugging an Ada program, and inserting a watchpoint tracking a local variable, the watchpoint doesn't get automatically deleted upon leaving that variable's scope. This watchpoint then starts creating problems later on, when trying to resume the program's execution from a location outside of the watchpoint's scope: (gdb) c Continuing. Breakpoint 2, foo_p708_025 () at foo_p708_025.adb:7 7 Do_Nothing (Val); (gdb) n No frame is currently executing in block pck.get_val. Command aborted. (gdb) c Continuing. No frame is currently executing in block pck.get_val. Command aborted. The expected output is the following: - The program's execution after the first continue should stop as soon as we reach the end of the watchpoint's scope, and the debugger should be deleting it. - Then we can continue until reaching breakpoint 2 above; - After which we should be able to do next/continue as usual. The reason the watchpoint is not automatically deleted at scope exit is because the watchpoint is not marked as being scope-specific (b->exp_valid_block is equal NULL), and this is because the symbol lookup for our local variable failed to set the innermost_block global variable during the lookup. More precisely, if we look at watch_command_1, we do the following: innermost_block = NULL; [...] exp = parse_exp_1 (&arg, 0, 0, 0); [...] exp_valid_block = innermost_block; Currently, innermost_block stays NULL after the call to parse_exp_1. Digging further, this innermost_block is typically set during symbol lookup when the symbol is considered to have a frame-relative address. For instance, in c-exp.y, we see some code like the following: if (symbol_read_needs_frame (sym.symbol)) { if (innermost_block == 0 || contained_in (sym.block, innermost_block)) innermost_block = sym.block; } We actually have the exact same mechanism in ada-exp.y, except that it vhas accidently been turned off. See write_var_from_sym, where we start with: if (orig_left_context == NULL && symbol_read_needs_frame (sym)) { if (innermost_block == 0 || contained_in (block, innermost_block)) innermost_block = block; } In this case, orig_left_context is a parameter, and looking at the point of call in write_var_or_type, we see: if (nsyms == 1) { write_var_from_sym (par_state, block, syms[0].block, syms[0].symbol); In the call above, the paramater we are interested in is "block", which is a parameter for write_var_or_type as well, except we explicitly override its value at the beginning when found to be NULL: if (block == NULL) block = expression_context_block; So the block we pass to write_var_from_sym is not NULL, and we therefore don't set innermost_block, which leads to the watchpoint no longer being marked as scope-specific. The handling of orig_left_context in write_var_from_sym was there to handle the case where a user writes an expression where the symbol is qualified with a scope (Eg: "function::variable"). But it appears that handling this is specifically here is no longer necessary, so this patch simply removes that parameter and the associated check, and then updates all the points of calls. Interestingly, this also affects GDB/MI, and in particular varobjs, because local variables are now properly reported as having a block, which causes the associated varob to have a "thread-id" field. This patch also adjusts a couple of Ada/gdb-mi tests. gdb/ChangeLog: * ada-exp.y (write_var_from_sym): Remove parameter "orig_left_context". Update all callers. gdb/testsuite/ChangeLog: * gdb.ada/scoped_watch: New testcase. * gdb.ada/watch_arg.exp: Adjust expected behavior to the behavior which is actually correct. * gdb.ada/mi_interface.exp: Add missing thread-id in expected varobj. * gdb.ada/mi_var_array.exp: Add missing thread-id in expected varobj.
Diffstat (limited to 'gdb/testsuite/gdb.ada/scoped_watch')
-rw-r--r--gdb/testsuite/gdb.ada/scoped_watch/foo_p708_025.adb25
-rw-r--r--gdb/testsuite/gdb.ada/scoped_watch/pck.adb44
-rw-r--r--gdb/testsuite/gdb.ada/scoped_watch/pck.ads21
3 files changed, 90 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.ada/scoped_watch/foo_p708_025.adb b/gdb/testsuite/gdb.ada/scoped_watch/foo_p708_025.adb
new file mode 100644
index 00000000000..d7d1cdfd47e
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/scoped_watch/foo_p708_025.adb
@@ -0,0 +1,25 @@
+-- Copyright 2017 Free Software Foundation, Inc.
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+with Pck; use Pck;
+
+procedure Foo_P708_025 is
+ Val : Integer;
+begin
+ Val := Get_Val (8, False);
+ Do_Nothing (Val);
+ Call_Me;
+ Increment (Val);
+end Foo_P708_025;
diff --git a/gdb/testsuite/gdb.ada/scoped_watch/pck.adb b/gdb/testsuite/gdb.ada/scoped_watch/pck.adb
new file mode 100644
index 00000000000..075bc618c99
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/scoped_watch/pck.adb
@@ -0,0 +1,44 @@
+-- Copyright 2017 Free Software Foundation, Inc.
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package body Pck is
+ function Get_Val (Seed: Integer; Off_By_One: Boolean) return Integer is
+ Result : Integer := Seed;
+ begin
+ if Off_By_One then -- START
+ Result := Result - 1;
+ end if;
+ Result := Result * 8;
+ if Off_By_One then
+ Result := Result + 1;
+ end if;
+ return Result;
+ end Get_Val;
+
+ procedure Do_Nothing (Val: in out Integer) is
+ begin
+ null;
+ end Do_Nothing;
+
+ procedure Call_Me is
+ begin
+ null;
+ end Call_Me;
+
+ procedure Increment (Val : in out Integer) is
+ begin
+ Val := Val + 1;
+ end Increment;
+end Pck;
diff --git a/gdb/testsuite/gdb.ada/scoped_watch/pck.ads b/gdb/testsuite/gdb.ada/scoped_watch/pck.ads
new file mode 100644
index 00000000000..f58558205cf
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/scoped_watch/pck.ads
@@ -0,0 +1,21 @@
+-- Copyright 2017 Free Software Foundation, Inc.
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package Pck is
+ function Get_Val (Seed: Integer; Off_By_One: Boolean) return Integer;
+ procedure Do_Nothing (Val: in out Integer);
+ procedure Call_Me;
+ procedure Increment (Val : in out Integer);
+end Pck;