diff options
author | Joel Brobecker <brobecker@adacore.com> | 2014-12-08 10:37:00 -0500 |
---|---|---|
committer | Joel Brobecker <brobecker@adacore.com> | 2014-12-13 11:00:24 -0500 |
commit | c1b5a1a6e732a65350af930c499b23018f8663cc (patch) | |
tree | 3f1780b967531dc51b7067e7ed53cc0d1252de7e /gdb/testsuite/gdb.ada | |
parent | 3c46a02f5083c4a9c07b563d44b8b6ded6d85bb1 (diff) | |
download | gdb-c1b5a1a6e732a65350af930c499b23018f8663cc.zip gdb-c1b5a1a6e732a65350af930c499b23018f8663cc.tar.gz gdb-c1b5a1a6e732a65350af930c499b23018f8663cc.tar.bz2 |
Internal error trying to print uninitialized string.
Trying to print the value of a string whose size is not known at
compile-time before it gets assigned a value can lead to the following
internal error:
(gdb) p my_str
$1 =
/[...]/utils.c:1089: internal-error: virtual memory exhausted.
What happens is that my_str is described as a reference to an array
type whose bounds are dynamic. During the read of that variable's
value (in default_read_var_value), we end up resolving dynamic types
which, for reference types, makes us also resolve the target of that
reference type. This means we resolve our variable to a reference
to an array whose bounds are undefined, and unfortunately very far
appart.
So, when we pass that value to ada-valprint, and in particular to
da_val_print_ref, we eventually try to allocate too large of a buffer
corresponding to the (bogus) size of our array, hence the internal
error.
This patch fixes the problem by adding a size_check before trying
to print the dereferenced value. To perform this check, a function
that was previously specific to ada-lang.c (check_size) gets
exported, and renamed to something less prone to name collisions
(ada_ensure_varsize_limit).
gdb/ChangeLog:
* ada-lang.h (ada_ensure_varsize_limit): Declare.
* ada-lang.c (check_size): Remove advance declaration.
(ada_ensure_varsize_limit): Renames check_size.
Replace calls to check_size by calls to ada_ensure_varsize_limit
throughout.
* ada-valprint.c (ada_val_print_ref): Add call to
ada_ensure_varsize_limit. Add comment explaining why.
gdb/testsuite/ChangeLog:
* gdb.ada/str_uninit: New testcase.
Diffstat (limited to 'gdb/testsuite/gdb.ada')
-rw-r--r-- | gdb/testsuite/gdb.ada/str_uninit.exp | 40 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/str_uninit/parse.adb | 22 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/str_uninit/pck.adb | 28 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/str_uninit/pck.ads | 24 |
4 files changed, 114 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.ada/str_uninit.exp b/gdb/testsuite/gdb.ada/str_uninit.exp new file mode 100644 index 0000000..706d57d --- /dev/null +++ b/gdb/testsuite/gdb.ada/str_uninit.exp @@ -0,0 +1,40 @@ +# Copyright 2014 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 parse + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "START" ${testdir}/parse.adb] +if ![runto "parse.adb:$bp_location" ] then { + perror "Couldn't run ${testfile}" + return +} + +# Print MY_STR. Since the string has not been initialized, including +# its bounds, anything can happen, including an error. The purpose +# of this test is just to verify that we do not get an _internal_ +# error. +gdb_test "print my_str" " = .*" + +# Just to be certain that the debugger is really still alive, +# try printing something really simple. +gdb_test "print 1235813" " = 1235813" diff --git a/gdb/testsuite/gdb.ada/str_uninit/parse.adb b/gdb/testsuite/gdb.ada/str_uninit/parse.adb new file mode 100644 index 0000000..8567377 --- /dev/null +++ b/gdb/testsuite/gdb.ada/str_uninit/parse.adb @@ -0,0 +1,22 @@ +-- Copyright 2014 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 Pck; use Pck; + +procedure Parse is + My_Str : String := Foos; -- START +begin + Do_Nothing (My_Str'Address); +end Parse; diff --git a/gdb/testsuite/gdb.ada/str_uninit/pck.adb b/gdb/testsuite/gdb.ada/str_uninit/pck.adb new file mode 100644 index 0000000..bfc5305 --- /dev/null +++ b/gdb/testsuite/gdb.ada/str_uninit/pck.adb @@ -0,0 +1,28 @@ +-- Copyright 2011-2014 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 Pck is + + procedure Do_Nothing (A : System.Address) is + begin + null; + end Do_Nothing; + + function Foos return String is + begin + return "string"; + end Foos; + +end Pck; diff --git a/gdb/testsuite/gdb.ada/str_uninit/pck.ads b/gdb/testsuite/gdb.ada/str_uninit/pck.ads new file mode 100644 index 0000000..e109375 --- /dev/null +++ b/gdb/testsuite/gdb.ada/str_uninit/pck.ads @@ -0,0 +1,24 @@ +-- Copyright 2011-2014 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 System; + +package Pck is + + procedure Do_Nothing (A : System.Address); + + function Foos return String; + +end Pck; |