diff mbox

Allow nested function displays

Message ID 20190614141007.31946-1-tromey@adacore.com
State New
Headers show

Commit Message

Tom Tromey June 14, 2019, 2:10 p.m. UTC
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-06-14  Tom Tromey  <tromey@adacore.com>

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

gdb/testsuite/ChangeLog
2019-06-14  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                                 |  4 +++
 gdb/block.c                                   |  4 ---
 gdb/testsuite/ChangeLog                       |  7 +++++
 gdb/testsuite/gdb.ada/display_nested.exp      | 29 ++++++++++++++++++
 gdb/testsuite/gdb.ada/display_nested/foo.adb  | 30 +++++++++++++++++++
 gdb/testsuite/gdb.ada/display_nested/pack.adb | 23 ++++++++++++++
 gdb/testsuite/gdb.ada/display_nested/pack.ads | 20 +++++++++++++
 7 files changed, 113 insertions(+), 4 deletions(-)
 create mode 100644 gdb/testsuite/gdb.ada/display_nested.exp
 create mode 100644 gdb/testsuite/gdb.ada/display_nested/foo.adb
 create mode 100644 gdb/testsuite/gdb.ada/display_nested/pack.adb
 create mode 100644 gdb/testsuite/gdb.ada/display_nested/pack.ads

Comments

Tom Tromey July 30, 2019, 6:28 p.m. UTC | #1
>>>>> "Tom" == Tom Tromey <tromey@adacore.com> writes:

Tom> In Ada, it's possible to have nested functions.  However,
Tom> block.c:contained_in does not recognize this.  Normally, this is no
Tom> problem, but if gdb is stopped inside a nested function, then you can
Tom> end up in the unexpected situation that "print" of an expression will
Tom> work, whereas "display" of the same expression will not -- because
Tom> contained_in returns 0.

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

I'm going to check this in now.

Tom
Sergio Durigan Junior Aug. 2, 2019, 10:55 p.m. UTC | #2
On Tuesday, July 30 2019, Tom Tromey wrote:

>>>>>> "Tom" == Tom Tromey <tromey@adacore.com> writes:
>
> Tom> In Ada, it's possible to have nested functions.  However,
> Tom> block.c:contained_in does not recognize this.  Normally, this is no
> Tom> problem, but if gdb is stopped inside a nested function, then you can
> Tom> end up in the unexpected situation that "print" of an expression will
> Tom> work, whereas "display" of the same expression will not -- because
> Tom> contained_in returns 0.
>
> Tom> This patch simply removes the BLOCK_FUNCTION check from contained_in.
> Tom> The rationale here is that in languages without nested functions, this
> Tom> will not cause any issues.
>
> I'm going to check this in now.

Hi Tom,

BuildBot has caught a regression with this patch:

  https://sourceware.org/ml/gdb-testers/2019-q3/msg01858.html

  PASS -> FAIL: gdb.fortran/nested-funcs.exp: print index at BP1, one frame up
  PASS -> FAIL: gdb.fortran/nested-funcs.exp: print index at BP_inner
  PASS -> FAIL: gdb.fortran/nested-funcs.exp: print index at BP_main
  PASS -> FAIL: gdb.fortran/nested-funcs.exp: print index at BP_outer
  PASS -> FAIL: gdb.fortran/nested-funcs.exp: print v_state%code at BP_inner
  PASS -> FAIL: gdb.fortran/nested-funcs.exp: print v_state%code at BP_main

I have also caught it while preparing a new Fedora GDB release :-).  I
haven't investigated it further (there are other regressions that I also
need to report), but let me know if you need a hand.

Thanks,
Tom Tromey Aug. 7, 2019, 1:16 p.m. UTC | #3
>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:

Sergio> BuildBot has caught a regression with this patch:

Sergio>   https://sourceware.org/ml/gdb-testers/2019-q3/msg01858.html

Sergio>   PASS -> FAIL: gdb.fortran/nested-funcs.exp: print index at BP1, one frame up
Sergio>   PASS -> FAIL: gdb.fortran/nested-funcs.exp: print index at BP_inner
Sergio>   PASS -> FAIL: gdb.fortran/nested-funcs.exp: print index at BP_main
Sergio>   PASS -> FAIL: gdb.fortran/nested-funcs.exp: print index at BP_outer
Sergio>   PASS -> FAIL: gdb.fortran/nested-funcs.exp: print v_state%code at BP_inner
Sergio>   PASS -> FAIL: gdb.fortran/nested-funcs.exp: print v_state%code at BP_main

Sergio> I have also caught it while preparing a new Fedora GDB release :-).  I
Sergio> haven't investigated it further (there are other regressions that I also
Sergio> need to report), but let me know if you need a hand.

I couldn't reproduce this on my Fedora 29 machine.  All the gdb.fortran
tests pass (with the exception of two KFAILs).

Do you know if I need an older or newer gfortran?  Or maybe some
debuginfo package?

thanks,
Tom
Sergio Durigan Junior Aug. 7, 2019, 4:14 p.m. UTC | #4
On Wednesday, August 07 2019, Tom Tromey wrote:

>>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:
>
> Sergio> BuildBot has caught a regression with this patch:
>
> Sergio>   https://sourceware.org/ml/gdb-testers/2019-q3/msg01858.html
>
> Sergio>   PASS -> FAIL: gdb.fortran/nested-funcs.exp: print index at BP1, one frame up
> Sergio>   PASS -> FAIL: gdb.fortran/nested-funcs.exp: print index at BP_inner
> Sergio>   PASS -> FAIL: gdb.fortran/nested-funcs.exp: print index at BP_main
> Sergio>   PASS -> FAIL: gdb.fortran/nested-funcs.exp: print index at BP_outer
> Sergio>   PASS -> FAIL: gdb.fortran/nested-funcs.exp: print v_state%code at BP_inner
> Sergio>   PASS -> FAIL: gdb.fortran/nested-funcs.exp: print v_state%code at BP_main
>
> Sergio> I have also caught it while preparing a new Fedora GDB release :-).  I
> Sergio> haven't investigated it further (there are other regressions that I also
> Sergio> need to report), but let me know if you need a hand.
>
> I couldn't reproduce this on my Fedora 29 machine.  All the gdb.fortran
> tests pass (with the exception of two KFAILs).
>
> Do you know if I need an older or newer gfortran?  Or maybe some
> debuginfo package?

I tried reproducing it on a F29 VM I have around, and the error did not
manifest here either.  However, I can always reproduce it on my F30
box.  The versions are:

F29: GNU Fortran (GCC) 8.3.1 20190223 (Red Hat 8.3.1-2)

F30: GNU Fortran (GCC) 9.1.1 20190503 (Red Hat 9.1.1-1)

I don't have any special debuginfo file installed here.  Let me know if
you still can't reproduce with a newer gfortran.

Thanks,
Tom Tromey Aug. 13, 2019, 3:27 p.m. UTC | #5
>> I couldn't reproduce this on my Fedora 29 machine.  All the gdb.fortran
>> tests pass (with the exception of two KFAILs).

Sergio> I tried reproducing it on a F29 VM I have around, and the error did not
Sergio> manifest here either.  However, I can always reproduce it on my F30
Sergio> box.

I built my own gfortran and I was able to reproduce the problem.

Tom
diff mbox

Patch

diff --git a/gdb/block.c b/gdb/block.c
index 63c7d9f3955..5c6faa85045 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -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);
diff --git a/gdb/testsuite/gdb.ada/display_nested.exp b/gdb/testsuite/gdb.ada/display_nested.exp
new file mode 100644
index 00000000000..9a66264881e
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/display_nested.exp
@@ -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
index 00000000000..543e993ea48
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/display_nested/foo.adb
@@ -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
index 00000000000..fa2d6073117
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/display_nested/pack.adb
@@ -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
index 00000000000..133d070b96a
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/display_nested/pack.ads
@@ -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;