Allow nested function displays
authorTom Tromey <tromey@adacore.com>
Thu, 6 Jun 2019 17:20:51 +0000 (11:20 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 30 Jul 2019 18:34:51 +0000 (12:34 -0600)
In Ada, it's possible to have nested functions.  However,
block.c:contained_in does not recognize this.  Normally, this is no
problem, but if gdb is stopped inside a nested function, then you can
end up in the unexpected situation that "print" of an expression will
work, whereas "display" of the same expression will not -- because
contained_in returns 0.

This patch simply removes the BLOCK_FUNCTION check from contained_in.
The rationale here is that in languages without nested functions, this
will not cause any issues.

gdb/ChangeLog
2019-07-30  Tom Tromey  <tromey@adacore.com>

* block.c (contained_in): Remove BLOCK_FUNCTION check.

gdb/testsuite/ChangeLog
2019-07-30  Tom Tromey  <tromey@adacore.com>

* gdb.ada/display_nested.exp: New file.
* gdb.ada/display_nested/foo.adb: New file.
* gdb.ada/display_nested/pack.adb: New file.
* gdb.ada/display_nested/pack.ads: New file.

gdb/ChangeLog
gdb/block.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/display_nested.exp [new file with mode: 0644]
gdb/testsuite/gdb.ada/display_nested/foo.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/display_nested/pack.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/display_nested/pack.ads [new file with mode: 0644]

index 4d9ec41c696c0a3f7f01b55c0bca3e2854253a08..44ab7226fada7c5335d581cfe005988b5bd23243 100644 (file)
@@ -1,3 +1,7 @@
+2019-07-30  Tom Tromey  <tromey@adacore.com>
+
+       * block.c (contained_in): Remove BLOCK_FUNCTION check.
+
 2019-07-30  Kevin Buettner  <kevinb@redhat.com>
 
        * printcmd.c (print_address_symbolic): Print negative offsets.
index 63c7d9f3955a4e149eeeb8a3c574c039b41302f2..5c6faa850457efecf76c13a3ed2bb8f2f8edc5d2 100644 (file)
@@ -79,10 +79,6 @@ contained_in (const struct block *a, const struct block *b)
     {
       if (a == b)
        return 1;
-      /* If A is a function block, then A cannot be contained in B,
-         except if A was inlined.  */
-      if (BLOCK_FUNCTION (a) != NULL && !block_inlined_p (a))
-        return 0;
       a = BLOCK_SUPERBLOCK (a);
     }
   while (a != NULL);
index 8dde64d4b0842a4c0fa6ff1285fc5aa400986740..d88157cb0da2565ab90b40b028d228fa490bd12b 100644 (file)
@@ -1,3 +1,10 @@
+2019-07-30  Tom Tromey  <tromey@adacore.com>
+
+       * gdb.ada/display_nested.exp: New file.
+       * gdb.ada/display_nested/foo.adb: New file.
+       * gdb.ada/display_nested/pack.adb: New file.
+       * gdb.ada/display_nested/pack.ads: New file.
+
 2019-07-30  Christian Biesinger  <cbiesinger@google.com>
 
        * gdb.python/py-symbol.c: Add a static variable and one in an anonymous
diff --git a/gdb/testsuite/gdb.ada/display_nested.exp b/gdb/testsuite/gdb.ada/display_nested.exp
new file mode 100644 (file)
index 0000000..9a66264
--- /dev/null
@@ -0,0 +1,29 @@
+# Copyright 2019 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/>.
+
+load_lib "ada.exp"
+
+standard_ada_testfile foo
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable debug] != ""} {
+    return -1
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "BREAK" ${testdir}/foo.adb]
+runto "foo.adb:$bp_location"
+
+gdb_test "display s(I..I+5)" [string_to_regexp "1: s(I..I+5) = \"test s\""]
diff --git a/gdb/testsuite/gdb.ada/display_nested/foo.adb b/gdb/testsuite/gdb.ada/display_nested/foo.adb
new file mode 100644 (file)
index 0000000..543e993
--- /dev/null
@@ -0,0 +1,30 @@
+--  Copyright 2019 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 Pack; use Pack;
+
+procedure Foo is
+   S : String := "test string";
+   I : Natural := S'First;
+begin
+  declare
+    procedure Nested is
+    begin
+       Do_Nothing (S);         --  BREAK
+    end Nested;
+  begin
+    Nested;
+  end;
+end Foo;
diff --git a/gdb/testsuite/gdb.ada/display_nested/pack.adb b/gdb/testsuite/gdb.ada/display_nested/pack.adb
new file mode 100644 (file)
index 0000000..fa2d607
--- /dev/null
@@ -0,0 +1,23 @@
+--  Copyright 2019 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 Pack is
+
+   procedure Do_Nothing (S : String) is
+   begin
+      null;
+   end Do_Nothing;
+
+end Pack;
diff --git a/gdb/testsuite/gdb.ada/display_nested/pack.ads b/gdb/testsuite/gdb.ada/display_nested/pack.ads
new file mode 100644 (file)
index 0000000..133d070
--- /dev/null
@@ -0,0 +1,20 @@
+--  Copyright 2019 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 Pack is
+
+   procedure Do_Nothing (S : String);
+
+end Pack;