From patchwork Fri Jun 14 14:10:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 33117 Received: (qmail 76324 invoked by alias); 14 Jun 2019 14:10:13 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 76227 invoked by uid 89); 14 Jun 2019 14:10:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=ii, BREAK, II, displays X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 14 Jun 2019 14:10:11 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id C7060560BE; Fri, 14 Jun 2019 10:10:09 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 2XLanvOpU1QU; Fri, 14 Jun 2019 10:10:09 -0400 (EDT) Received: from murgatroyd.Home (174-29-48-168.hlrn.qwest.net [174.29.48.168]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 7297C56040; Fri, 14 Jun 2019 10:10:09 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Allow nested function displays Date: Fri, 14 Jun 2019 08:10:07 -0600 Message-Id: <20190614141007.31946-1-tromey@adacore.com> MIME-Version: 1.0 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 * block.c (contained_in): Remove BLOCK_FUNCTION check. gdb/testsuite/ChangeLog 2019-06-14 Tom Tromey * 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 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 . + +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 . + +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 . + +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 . + +package Pack is + + procedure Do_Nothing (S : String); + +end Pack;