From patchwork Fri Jan 5 07:44:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 25222 Received: (qmail 123427 invoked by alias); 5 Jan 2018 07:44:42 -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 123415 invoked by uid 89); 5 Jan 2018 07:44:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.4 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.2 spammy=pckt, handing, interests 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, 05 Jan 2018 07:44:39 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 13BF4117820 for ; Fri, 5 Jan 2018 02:44:38 -0500 (EST) 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 SfVOiuR+8Nsp for ; Fri, 5 Jan 2018 02:44:38 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 02BBC11780E for ; Fri, 5 Jan 2018 02:44:38 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4233) id F11574F2; Fri, 5 Jan 2018 02:44:37 -0500 (EST) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [pushed/Ada] memory error printing component of record from convenience variable Date: Fri, 5 Jan 2018 02:44:35 -0500 Message-Id: <1515138275-121023-1-git-send-email-brobecker@adacore.com> Hello, Consider the following situation Ada code: type Kind_T is (One, Two, Three); type Time_Set_T is array (Kind_T) of Integer; type T is record Started : Time_Set_T; end record; Null_T : constant T := (Started => (others => 0)); My_Item : Pck.T := Pck.Null_T; Trying to print the value of My_Item.Started is no problem: (gdb) p item.started $1 = (0, 0, 0) However, if you save My_Item into a convenience variable first, and then try to print a component of that record, you get an unexpected memory error, instead of getting the same result. For instance: (gdb) set variable $item := item (gdb) p $item.started Cannot access memory at address 0x0 The issue occurs when, after we extracted the component from the convenience variable, we next try to "fix" it (which is ada-lang speak for resolving the type into a static type). This is done in ada_to_fixed_value, which delegates to ada_to_fixed_value_create via: val = ada_to_fixed_value_create (value_type (val), value_address (val), val); And looking at ada_to_fixed_value_create, we see that: struct type *type = ada_to_fixed_type (type0, 0, address, NULL, 1); if (type == type0 && val0 != NULL) return val0; else return value_from_contents_and_address (type, 0, address); The part that interests us, in this case, is the "else" branch, where we obviously make the implicit assumption that our object has an address, which is not true, in this case, because we are actually dealing with a convenience variable. This patch plugs that hole by adding special handing for situations where val does not live in memory. In that case, we just create a not_lval value using val's contents. gdb/ChangeLog: * ada-lang.c (ada_to_fixed_value_create): Add handling of the case where VALUE_LVAL (val0) is not lval_memory. gdb/testsuite/ChangeLog: * gdb.ada/convvar_comp: New testcase. Tested on x86_64-linux. Pushed to master. Thank you, diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e7c34a5..3efb697 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-01-05 Joel Brobecker + + * ada-lang.c (ada_to_fixed_value_create): Add handling of + the case where VALUE_LVAL (val0) is not lval_memory. + 2018-01-05 Xavier Roirand * ada-valprint.c (print_optional_low_bound): Handle diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 4ecf7b0..85e50cc 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -9344,8 +9344,16 @@ ada_to_fixed_value_create (struct type *type0, CORE_ADDR address, if (type == type0 && val0 != NULL) return val0; - else - return value_from_contents_and_address (type, 0, address); + + if (VALUE_LVAL (val0) != lval_memory) + { + /* Our value does not live in memory; it could be a convenience + variable, for instance. Create a not_lval value using val0's + contents. */ + return value_from_contents (type, value_contents (val0)); + } + + return value_from_contents_and_address (type, 0, address); } /* A value representing VAL, but with a standard (static-sized) type diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index a2b8abf..ecc7110 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-01-05 Joel Brobecker + + * gdb.ada/convvar_comp: New testcase. + 2018-01-05 Xavier Roirand * testsuite/gdb.ada/array_char_idx/pck.ads (Table): New type. diff --git a/gdb/testsuite/gdb.ada/convvar_comp.exp b/gdb/testsuite/gdb.ada/convvar_comp.exp new file mode 100644 index 0000000..d82ec5f --- /dev/null +++ b/gdb/testsuite/gdb.ada/convvar_comp.exp @@ -0,0 +1,34 @@ +# Copyright 2018 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 pb16_063 + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } { + return -1 +} + +clean_restart ${testfile} + +if ![runto "break_me" ] then { + perror "Couldn't run ${testfile}" + return +} + +gdb_test_no_output "set variable \$item := item" + +gdb_test "print \$item.started" \ + " = \\(0, 0, 0\\)" diff --git a/gdb/testsuite/gdb.ada/convvar_comp/pb16_063.adb b/gdb/testsuite/gdb.ada/convvar_comp/pb16_063.adb new file mode 100644 index 0000000..6d808f4 --- /dev/null +++ b/gdb/testsuite/gdb.ada/convvar_comp/pb16_063.adb @@ -0,0 +1,23 @@ +-- Copyright 2018 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 Pck; + +procedure PB16_063 is + My_Item : Pck.T; + Ignored : Boolean; +begin + My_Item := Pck.Null_T; + Ignored := Pck.Break_Me (My_Item); +end PB16_063; diff --git a/gdb/testsuite/gdb.ada/convvar_comp/pck.adb b/gdb/testsuite/gdb.ada/convvar_comp/pck.adb new file mode 100644 index 0000000..09f13d1 --- /dev/null +++ b/gdb/testsuite/gdb.ada/convvar_comp/pck.adb @@ -0,0 +1,21 @@ +-- Copyright 2018 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 Pck is + function Break_Me (Item : T) return Boolean is + begin + return False; + end Break_Me; +end Pck; diff --git a/gdb/testsuite/gdb.ada/convvar_comp/pck.ads b/gdb/testsuite/gdb.ada/convvar_comp/pck.ads new file mode 100644 index 0000000..0f46132 --- /dev/null +++ b/gdb/testsuite/gdb.ada/convvar_comp/pck.ads @@ -0,0 +1,29 @@ +-- Copyright 2018 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 Pck is + + type Kind_T is (One, Two, Three); + -- type Kind_T is new Integer range 1 .. 3; + type Time_Set_T is array (Kind_T) of Integer; + + type T is record + Started : Time_Set_T; + end record; + + Null_T : constant T := (Started => (others => 0)); + + function Break_Me (Item : T) return Boolean; +end Pck;