From 3fcded8f30b6b0c1930d4f82914476315027aa2e Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Tue, 27 Mar 2018 09:17:45 -0500 Subject: [PATCH] set varsize-limit: New GDB setting for maximum dynamic object size This is a command we somehow forgot to contribute at the time the Ada language was first contributed to the FSF. This command allows the user to change the maximum size we allow when reading memory from dynamic objects (the default is 65536 bytes). At the moment, this limit is only used by Ada, and so the implementation is kept inside ada-lang.c. However, it is conceivable that other language might want to use it also to handle the same kind of issues; for instance, this might be useful when handling dynamic types in C. So the name of the setting was made language-neutral, to allow for this. Note that an alias for "set var" needs to be introduced as well. We are not adding a test for that, since this is a feature that is already exercized by numerous existing tests. gdb/ChangeLog * NEWS: Add entry describing new "set|show varsize-limit" command. * ada-lang.c (_initialize_ada_language): Add "set/show varsize-limit" command. * printcmd.c (_initialize_printcmd): Add "set var" alias of "set variable". gdb/doc/ChangeLog: * gdb.texinfo (Ada Settings): New subsubsection. gdb/testsuite/ChangeLog: * gdb.ada/varsize_limit: New testcase. Tested on x86_64-linux. --- gdb/ChangeLog | 8 +++++ gdb/NEWS | 5 ++++ gdb/ada-lang.c | 7 +++++ gdb/doc/ChangeLog | 4 +++ gdb/doc/gdb.texinfo | 32 ++++++++++++++++++++ gdb/printcmd.c | 1 + gdb/testsuite/ChangeLog | 4 +++ gdb/testsuite/gdb.ada/varsize_limit.exp | 38 ++++++++++++++++++++++++ gdb/testsuite/gdb.ada/varsize_limit/pck.adb | 25 ++++++++++++++++ gdb/testsuite/gdb.ada/varsize_limit/pck.ads | 20 +++++++++++++ gdb/testsuite/gdb.ada/varsize_limit/vsizelim.adb | 23 ++++++++++++++ 11 files changed, 167 insertions(+) create mode 100644 gdb/testsuite/gdb.ada/varsize_limit.exp create mode 100644 gdb/testsuite/gdb.ada/varsize_limit/pck.adb create mode 100644 gdb/testsuite/gdb.ada/varsize_limit/pck.ads create mode 100644 gdb/testsuite/gdb.ada/varsize_limit/vsizelim.adb diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e78bfcb8795..79c981de219 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2018-03-27 Joel Brobecker + + * NEWS: Add entry describing new "set|show varsize-limit" command. + * ada-lang.c (_initialize_ada_language): Add "set/show varsize-limit" + command. + * printcmd.c (_initialize_printcmd): Add "set var" alias of + "set variable". + 2018-03-27 Simon Marchi * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and diff --git a/gdb/NEWS b/gdb/NEWS index 36790900de9..ef0313d97ad 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -12,6 +12,11 @@ set debug fbsd-nat show debug fbsd-nat Control display of debugging info regarding the FreeBSD native target. +set|show varsize-limit + This new setting allows the user to control the maximum size of Ada + objects being printed when those objects have a variable type, + instead of that maximum size being hardcoded to 65536 bytes. + * New targets RiscV ELF riscv*-*-elf diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 191b7e44247..505d0592446 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -14689,6 +14689,13 @@ With an argument, catch only exceptions with the given name."), CATCH_TEMPORARY); varsize_limit = 65536; + add_setshow_uinteger_cmd ("varsize-limit", class_support, + &varsize_limit, _("\ +Set the maximum number of bytes allowed in a variable-size object."), _("\ +Show the maximum number of bytes allowed in a variable-size object."), _("\ +Attempts to access an object whose size is not a compile-time constant\n\ +and exceeds this limit will cause an error."), + NULL, NULL, &setlist, &showlist); add_info ("exceptions", info_exceptions_command, _("\ diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 4da77deb85c..f11fa0c3e12 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,7 @@ +2018-03-27 Joel Brobecker + + * gdb.texinfo (Ada Settings): New subsubsection. + 2018-03-26 Tom Tromey PR backtrace/15582: diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index d37b107a51d..bd20b39c63d 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -16272,6 +16272,7 @@ to be difficult. * Ada Tasks and Core Files:: Tasking Support when Debugging Core Files * Ravenscar Profile:: Tasking Support when using the Ravenscar Profile +* Ada Settings:: New settable GDB parameters for Ada. * Ada Glitches:: Known peculiarities of Ada mode. @end menu @@ -16927,6 +16928,37 @@ using the Ravenscar Profile. @end table +@node Ada Settings +@subsubsection Ada Settings +@cindex Ada settings + +@table @code +@kindex set varsize-limit +@item set varsize-limit @var{size} +Prevent @value{GDBN} from attempting to evaluate objects whose size +is above the given limit (@var{size}) when those sizes are computed +from run-time quantities. This is typically the case when the object +has a variable size, such as an array whose bounds are not known at +compile time for example. Setting @var{size} to @code{unlimited} +removes the size limitation. By default, the limit is about 65KB. + +The purpose of having such a limit is to prevent @value{GDBN} from +trying to grab enormous chunks of virtual memory when asked to evaluate +a quantity whose bounds have been corrupted or have not yet been fully +initialized. The limit applies to the results of some subexpressions +as well as to complete expressions. For example, an expression denoting +a simple integer component, such as @code{x.y.z}, may fail if the size of +@code{x.y} is variable and exceeds @code{size}. On the other hand, +@value{GDBN} is sometimes clever; the expression @code{A(i)}, where +@code{A} is an array variable with non-constant size, will generally +succeed regardless of the bounds on @code{A}, as long as the component +size is less than @var{size}. + +@kindex show varsize-limit +@item show varsize-limit +Show the limit on types whose size is determined by run-time quantities. +@end table + @node Ada Glitches @subsubsection Known Peculiarities of Ada Mode @cindex Ada, problems diff --git a/gdb/printcmd.c b/gdb/printcmd.c index dd81d8fda13..58bdac61921 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -2737,6 +2737,7 @@ with $), a register (a few standard names starting with $), or an actual\n\ variable in the program being debugged. EXP is any valid expression.\n\ This may usually be abbreviated to simply \"set\"."), &setlist); + add_alias_cmd ("var", "variable", class_vars, 0, &setlist); c = add_com ("print", class_vars, print_command, _("\ Print value of expression EXP.\n\ diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 8dffab55da9..806744dd45b 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2018-03-27 Joel Brobecker + * gdb.ada/varsize_limit: New testcase. + +2018-03-27 Joel Brobecker + * gdb.ada/maint_with_ada.exp: Remove PR gdb/22670 setup_kfail. * gdb.ada/notcplusplus: New testcase. diff --git a/gdb/testsuite/gdb.ada/varsize_limit.exp b/gdb/testsuite/gdb.ada/varsize_limit.exp new file mode 100644 index 00000000000..b2017552760 --- /dev/null +++ b/gdb/testsuite/gdb.ada/varsize_limit.exp @@ -0,0 +1,38 @@ +# 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 vsizelim + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "STOP" ${testdir}/vsizelim.adb] +if ![runto "vsizelim.adb:$bp_location" ] then { + perror "Couldn't run ${testfile}" + return +} + +gdb_test_no_output "set varsize-limit 16" + +gdb_test "print small" " = \"1234567890\"" + +gdb_test "print larger" "object size is larger than varsize-limit.*" + + diff --git a/gdb/testsuite/gdb.ada/varsize_limit/pck.adb b/gdb/testsuite/gdb.ada/varsize_limit/pck.adb new file mode 100644 index 00000000000..d4acf86bcda --- /dev/null +++ b/gdb/testsuite/gdb.ada/varsize_limit/pck.adb @@ -0,0 +1,25 @@ +-- 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 + procedure Do_Nothing (A : System.Address) is + begin + null; + end Do_Nothing; + function Ident (S : String) return String is + begin + return S; + end Ident; +end Pck; diff --git a/gdb/testsuite/gdb.ada/varsize_limit/pck.ads b/gdb/testsuite/gdb.ada/varsize_limit/pck.ads new file mode 100644 index 00000000000..b0043facd97 --- /dev/null +++ b/gdb/testsuite/gdb.ada/varsize_limit/pck.ads @@ -0,0 +1,20 @@ +-- 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 System; +package Pck is + procedure Do_Nothing (A : System.Address); + function Ident (S : String) return String; +end Pck; diff --git a/gdb/testsuite/gdb.ada/varsize_limit/vsizelim.adb b/gdb/testsuite/gdb.ada/varsize_limit/vsizelim.adb new file mode 100644 index 00000000000..e65ebfd7b62 --- /dev/null +++ b/gdb/testsuite/gdb.ada/varsize_limit/vsizelim.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; use Pck; +procedure VsizeLim is + Small : String := Ident ("1234567890"); + Larger : String := Ident ("1234567890|1234567890|1234567890"); +begin + Do_Nothing (Small'Address); -- STOP + Do_Nothing (Larger'Address); +end VsizeLim; -- 2.11.4.GIT