[PATCH 3/3] Remove 'varsize-limit'

Tom Tromey tromey@adacore.com
Wed Sep 15 18:34:39 GMT 2021


This makes the Ada-specific "varsize-limit" a synonym for
"max-value-size", and removes the Ada-specific checks of the limit.

I am not certain of the history here, but it seems to me that this
code is fully obsolete now.  And, removing this makes it possible to
index large Ada arrays without triggering an error.  A new test case
is included to demonstrate this.
---
 gdb/NEWS                                      |  5 ++
 gdb/ada-lang.c                                | 52 -------------------
 gdb/ada-lang.h                                |  2 -
 gdb/ada-valprint.c                            |  6 ---
 gdb/testsuite/gdb.ada/varsize_limit.exp       |  9 ++--
 .../gdb.ada/varsize_limit/vsizelim.adb        | 12 +++++
 gdb/value.c                                   | 10 ++++
 7 files changed, 33 insertions(+), 63 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index f9485520438..4602f14384b 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -10,6 +10,11 @@ maint show backtrace-on-fatal-signal
   fatal signal.  This only supported on some platforms where the
   backtrace and backtrace_symbols_fd functions are available.
 
+set varsize-limit
+show varsize-limit
+  These are now deprecated aliases for "set max-value-size" and
+  "show max-value-size".
+
 * Python API
 
   ** New function gdb.add_history(), which takes a gdb.Value object
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 6680a4fd657..f54f081880b 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -247,9 +247,6 @@ struct ada_symbol_cache
   struct cache_entry *root[HASH_SIZE] {};
 };
 
-/* Maximum-sized dynamic type.  */
-static unsigned int varsize_limit;
-
 static const char ada_completer_word_break_characters[] =
 #ifdef VMS
   " \t\n!@#%^&*()+=|~`}{[]\";:?/,-";
@@ -524,10 +521,6 @@ coerce_unspec_val_to_type (struct value *val, struct type *type)
     {
       struct value *result;
 
-      /* Make sure that the object size is not unreasonable before
-	 trying to allocate some memory for it.  */
-      ada_ensure_varsize_limit (type);
-
       if (value_optimized_out (val))
 	result = allocate_optimized_out_value (type);
       else if (value_lazy (val)
@@ -589,17 +582,6 @@ lim_warning (const char *format, ...)
   va_end (args);
 }
 
-/* Issue an error if the size of an object of type T is unreasonable,
-   i.e. if it would be a bad idea to allocate a value of this type in
-   GDB.  */
-
-void
-ada_ensure_varsize_limit (const struct type *type)
-{
-  if (TYPE_LENGTH (type) > varsize_limit)
-    error (_("object size is larger than varsize-limit"));
-}
-
 /* Maximum value of a SIZE-byte signed integer type.  */
 static LONGEST
 max_of_size (int size)
@@ -1904,7 +1886,6 @@ ada_coerce_to_simple_array (struct value *arr)
 
       if (arrVal == NULL)
 	error (_("Bounds unavailable for null array pointer."));
-      ada_ensure_varsize_limit (TYPE_TARGET_TYPE (value_type (arrVal)));
       return value_ind (arrVal);
     }
   else if (ada_is_constrained_packed_array_type (value_type (arr)))
@@ -7534,12 +7515,6 @@ ada_template_to_fixed_record_type_1 (struct type *type,
 
 	  if (dval0 == NULL)
 	    {
-	      /* rtype's length is computed based on the run-time
-		 value of discriminants.  If the discriminants are not
-		 initialized, the type size may be completely bogus and
-		 GDB may fail to allocate a value for it.  So check the
-		 size first before creating the value.  */
-	      ada_ensure_varsize_limit (rtype);
 	      /* Using plain value_from_contents_and_address here
 		 causes problems because we will end up trying to
 		 resolve a type that is currently being
@@ -7580,14 +7555,6 @@ ada_template_to_fixed_record_type_1 (struct type *type,
 	  field_type = ada_get_base_type (field_type);
 	  field_type = ada_to_fixed_type (field_type, field_valaddr,
 					  field_address, dval, 0);
-	  /* If the field size is already larger than the maximum
-	     object size, then the record itself will necessarily
-	     be larger than the maximum object size.  We need to make
-	     this check now, because the size might be so ridiculously
-	     large (due to an uninitialized variable in the inferior)
-	     that it would cause an overflow when adding it to the
-	     record size.  */
-	  ada_ensure_varsize_limit (field_type);
 
 	  rtype->field (f).set_type (field_type);
 	  TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f);
@@ -7708,8 +7675,6 @@ ada_template_to_fixed_record_type_1 (struct type *type,
     }
 
   value_free_to_mark (mark);
-  if (TYPE_LENGTH (rtype) > varsize_limit)
-    error (_("record type with dynamic size is larger than varsize-limit"));
   return rtype;
 }
 
@@ -8156,8 +8121,6 @@ to_fixed_array_type (struct type *type0, struct value *dval,
 				      result, range_type);
 	  elt_type0 = TYPE_TARGET_TYPE (elt_type0);
 	}
-      if (!ignore_too_big && TYPE_LENGTH (result) > varsize_limit)
-	error (_("array type with dynamic size is larger than varsize-limit"));
     }
 
   /* We want to preserve the type name.  This can be useful when
@@ -10579,7 +10542,6 @@ ada_unop_ind_operation::evaluate (struct type *expect_type,
 		(ada_aligned_type
 		 (ada_check_typedef (TYPE_TARGET_TYPE (type))));
 	    }
-	  ada_ensure_varsize_limit (type);
 	  return value_zero (type, lval_memory);
 	}
       else if (type->code () == TYPE_CODE_INT)
@@ -10614,11 +10576,6 @@ ada_unop_ind_operation::evaluate (struct type *expect_type,
 			      (CORE_ADDR) value_as_address (arg1));
     }
 
-  struct type *target_type = (to_static_fixed_type
-			      (ada_aligned_type
-			       (ada_check_typedef (TYPE_TARGET_TYPE (type)))));
-  ada_ensure_varsize_limit (target_type);
-
   if (ada_is_array_descriptor_type (type))
     /* GDB allows dereferencing GNAT array descriptors.  */
     return ada_coerce_to_simple_array (arg1);
@@ -13580,15 +13537,6 @@ exception should cause a stop."),
 		     CATCH_PERMANENT,
 		     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,
 	    _("\
 List all Ada exception names.\n\
diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h
index a89ed29119a..0f52ba70649 100644
--- a/gdb/ada-lang.h
+++ b/gdb/ada-lang.h
@@ -149,8 +149,6 @@ struct ada_task_info
   int base_cpu;
 };
 
-extern void ada_ensure_varsize_limit (const struct type *type);
-
 extern int ada_get_field_index (const struct type *type,
 				const char *field_name,
 				int maybe_missing);
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index d516a4d134e..0153fdbf511 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -970,12 +970,6 @@ ada_val_print_ref (struct type *type, const gdb_byte *valaddr,
   if (ada_is_tagged_type (value_type (deref_val), 1))
     deref_val = ada_tag_value_at_base_address (deref_val);
 
-  /* Make sure that the object does not have an unreasonable size
-     before trying to print it.  This can happen for instance with
-     references to dynamic objects whose contents is uninitialized
-     (Eg: an array whose bounds are not set yet).  */
-  ada_ensure_varsize_limit (value_type (deref_val));
-
   if (value_lazy (deref_val))
     value_fetch_lazy (deref_val);
 
diff --git a/gdb/testsuite/gdb.ada/varsize_limit.exp b/gdb/testsuite/gdb.ada/varsize_limit.exp
index aca926a79ab..7cba87ce41b 100644
--- a/gdb/testsuite/gdb.ada/varsize_limit.exp
+++ b/gdb/testsuite/gdb.ada/varsize_limit.exp
@@ -31,10 +31,13 @@ if ![runto "vsizelim.adb:$bp_location" ] then {
   return
 }
 
-gdb_test_no_output "set varsize-limit 16"
+gdb_test "set varsize-limit 16" \
+    "Warning: command 'set varsize-limit' is deprecated.\r\nUse 'set max-value-size'."
 
 gdb_test "print small" " = \"1234567890\""
 
-gdb_test "print larger" "object size is larger than varsize-limit.*"
+gdb_test "print larger" "more than max-value-size.*"
 
-gdb_test "print name.all" "object size is larger than varsize-limit.*"
+gdb_test "print name.all" "more than max-value-size.*"
+
+gdb_test "print ba.data(5)" " = 5" "print array element"
diff --git a/gdb/testsuite/gdb.ada/varsize_limit/vsizelim.adb b/gdb/testsuite/gdb.ada/varsize_limit/vsizelim.adb
index 3b19e722eb2..8bf367cda0f 100644
--- a/gdb/testsuite/gdb.ada/varsize_limit/vsizelim.adb
+++ b/gdb/testsuite/gdb.ada/varsize_limit/vsizelim.adb
@@ -30,8 +30,20 @@ procedure VsizeLim is
    Name_Str : String_Ptr := new String'(Larger);
    Name : Big_String_Ptr := To_Ptr (Name_Str.all'Address);
 
+   type Table is array (Positive range <>) of Integer;
+   type Object (N : Integer) is record
+       Data : Table (1 .. N);
+   end record;
+
+   BA : Object := (N => 1_000_000, Data => (others => 0));
+
 begin
+   for I in 1 .. 10 loop
+      BA.Data(I) := I;
+   end loop;
+
    Do_Nothing (Small'Address); -- STOP
    Do_Nothing (Larger'Address);
    Do_Nothing (Name'Address);
+   Do_Nothing (BA'Address);
 end VsizeLim;
diff --git a/gdb/value.c b/gdb/value.c
index a9b0877089c..464b4aa0b47 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -4328,6 +4328,16 @@ prevents future values, larger than this size, from being allocated."),
 			    set_max_value_size,
 			    show_max_value_size,
 			    &setlist, &showlist);
+  set_show_commands vsize_limit
+    = add_setshow_zuinteger_unlimited_cmd ("varsize-limit", class_support,
+					   &max_value_size, _("\
+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);
+  deprecate_cmd (vsize_limit.set, "set max-value-size");
+
 #if GDB_SELF_TEST
   selftests::register_test ("ranges_contain", selftests::test_ranges_contain);
   selftests::register_test ("insert_into_bit_range_vector",
-- 
2.31.1



More information about the Gdb-patches mailing list