From 1b61134393256db280b968d24ddf7bb22b6aabcc Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Wed, 29 Feb 2012 19:46:48 +0000 Subject: [Ada] avoid error message pollution with uninitialized tagged variable Consider the following function... 3 procedure Foo is 4 I : Integer := Ident (10); 5 Obj : Base; 6 begin 7 Obj.X := I; 8 Do_Nothing (Obj.X'Address); 9 end Foo; ... where type "Base" is defined as a plain tagged record. If the user stops execution before "Obj" gets initialized (for example, by inserting a breakpoint "on" the function - or in other words, by inserting a breakpoint using the function name as the location), one might get the following of output if you try printing the value of obj: (gdb) p obj object size is larger than varsize-limit object size is larger than varsize-limit object size is larger than varsize-limit $1 = object size is larger than varsize-limit (x => 4204154) Same thing with "info locals": (gdb) info locals i = 0 obj = object size is larger than varsize-limit (x => 4204154) We have also seen different error messages such as "Cannot read memory at 0x...". The error happens because we are trying to read the dispatch table of a tagged type variable before it gets initialized. So the errors might legitimately occur, and are supposed to be be contained. However, the way things are written in ada-lang.c:ada_tag_name, although the exception is in fact contained, the error message still gets to be printed out. This patch prevents this from happening by eliminating the use of catch_errors, and using a TRY_CATCH block instead. Doing this removed the need to use functions specifically fitted for catch_errors, and thus some other simplifications could me made. In the end, the code got reorganized a bit to better show the logic behind it, as well as the common patterns. gdb/ChangeLog: * ada-lang.c (struct tag_args): Delete. (ada_get_tsd_type): Function body moved up in source file. (ada_tag_name_1, ada_tag_name_2): Delete. (ada_get_tsd_from_tag): New function. (ada_tag_name_from_tsd): New function. (ada_tag_name): Use a TRY_CATCH block instead of catch_errors to determine the tag name. gdb/testsuite/ChangeLog: * gdb.ada/tagged_not_init: New testcase. --- gdb/testsuite/ChangeLog | 4 +++ gdb/testsuite/gdb.ada/tagged_not_init.exp | 36 +++++++++++++++++++++++++++ gdb/testsuite/gdb.ada/tagged_not_init/foo.adb | 24 ++++++++++++++++++ gdb/testsuite/gdb.ada/tagged_not_init/pck.adb | 26 +++++++++++++++++++ gdb/testsuite/gdb.ada/tagged_not_init/pck.ads | 31 +++++++++++++++++++++++ 5 files changed, 121 insertions(+) create mode 100644 gdb/testsuite/gdb.ada/tagged_not_init.exp create mode 100644 gdb/testsuite/gdb.ada/tagged_not_init/foo.adb create mode 100644 gdb/testsuite/gdb.ada/tagged_not_init/pck.adb create mode 100644 gdb/testsuite/gdb.ada/tagged_not_init/pck.ads (limited to 'gdb/testsuite') diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 2ff685a..9d6beea 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2012-02-29 Joel Brobecker + * gdb.ada/tagged_not_init: New testcase. + +2012-02-29 Joel Brobecker + * gdb.ada/arrayidx.exp: Adjust expected output for p_one_two_three. * gdb.ada/enum_idx_packed: New testcase. diff --git a/gdb/testsuite/gdb.ada/tagged_not_init.exp b/gdb/testsuite/gdb.ada/tagged_not_init.exp new file mode 100644 index 0000000..013d76a --- /dev/null +++ b/gdb/testsuite/gdb.ada/tagged_not_init.exp @@ -0,0 +1,36 @@ +# Copyright 2012 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" + +if { [skip_ada_tests] } { return -1 } + +set testdir "tagged_not_init" +set testfile "${testdir}/foo" +set srcfile ${srcdir}/${subdir}/${testfile}.adb +set binfile ${objdir}/${subdir}/${testfile} + +file mkdir ${objdir}/${subdir}/${testdir} +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "STOP" ${testdir}/foo.adb] +runto "foo.adb:$bp_location" + +gdb_test "print obj" " = \\(x => -?$decimal\\)" + diff --git a/gdb/testsuite/gdb.ada/tagged_not_init/foo.adb b/gdb/testsuite/gdb.ada/tagged_not_init/foo.adb new file mode 100644 index 0000000..aa345a2 --- /dev/null +++ b/gdb/testsuite/gdb.ada/tagged_not_init/foo.adb @@ -0,0 +1,24 @@ +-- Copyright 2012 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; use Pck; + +procedure Foo is + I : Integer := Ident (10); -- STOP + Obj : Base; +begin + Obj.X := I; + Do_Nothing (Obj.X'Address); +end Foo; diff --git a/gdb/testsuite/gdb.ada/tagged_not_init/pck.adb b/gdb/testsuite/gdb.ada/tagged_not_init/pck.adb new file mode 100644 index 0000000..5d6e760 --- /dev/null +++ b/gdb/testsuite/gdb.ada/tagged_not_init/pck.adb @@ -0,0 +1,26 @@ +-- Copyright 2012 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 Ident (I : Integer) return Integer is + begin + return I; + end Ident; + + procedure Do_Nothing (A : System.Address) is + begin + null; + end Do_Nothing; +end Pck; diff --git a/gdb/testsuite/gdb.ada/tagged_not_init/pck.ads b/gdb/testsuite/gdb.ada/tagged_not_init/pck.ads new file mode 100644 index 0000000..19d9295 --- /dev/null +++ b/gdb/testsuite/gdb.ada/tagged_not_init/pck.ads @@ -0,0 +1,31 @@ +-- Copyright 2012 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 System; + +package Pck is + type Base is tagged record + X : Integer := 42; + end record; + + type Extension is new Base with + record + Y : Float := 42.0; + end record; + + function Ident (I : Integer) return Integer; + + procedure Do_Nothing (A : System.Address); +end Pck; -- cgit v1.1