]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/testsuite: Fix gdb.base/gcore-memory-usage with address sanitizer
authorGuinevere Larsen <guinevere@redhat.com>
Tue, 2 Sep 2025 12:58:32 +0000 (09:58 -0300)
committerGuinevere Larsen <guinevere@redhat.com>
Wed, 3 Sep 2025 11:55:16 +0000 (08:55 -0300)
The test gdb.base/gcore-memory-usage is meant to show that the memory
requirements of GDB's gcore command don't grow with the memory usage
of the inferior.  It was using hardcoded values for memory, but the
values were too small when building GDB with address sanitizer.  This
commit fixes one of the failures by increasing the limit on the first
gcore call.

But, rather than just increasing the hardcoded limit for the second
call, we instead save the amount of memory used in the first call and
ensure that the second call doesn't use more memory than the first.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33148
Approved-By: Tom de Vries <tdevries@suse.de>
gdb/testsuite/gdb.base/gcore-memory-usage.exp

index bd041f2d1a81788f1a708ea97f60b4b288003309..14b03a071cff746ae081ecf8937290cb1e1bc476 100644 (file)
@@ -47,8 +47,10 @@ proc get_mem_usage {pid prefix} {
 # This proc restarts GDB, runs the inferior with the desired
 # amount of memory, then checks how much memory is necessary
 # to run the gcore command.  It will return -1 if the gcore
-# command fails, 0 otherwise.
-proc run_test {megs} {
+# command fails, otherwise the amount of memory used by GDB
+# to generate that gcore.  MAX_MEM is the maximum amount of
+# memory GDB is allowed to use, in megabytes.
+proc run_test {megs max_mem} {
     with_test_prefix "$megs Mb" {
        clean_restart $::testfile
 
@@ -74,23 +76,24 @@ proc run_test {megs} {
        set diff_k [expr $mem_after - $mem_before]
        set diff [expr $diff_k/1024]
        verbose -log "The gcore command used $diff Mb ($diff_k Kb)"
-       # The original plan was to compare to a multiple of MEGS
-       # but since the requirements don't seem to go up as the
-       # inferior allocated more memory, we instead just hardcode
-       # 2 megs, since sometimes 1 is used.
-       gdb_assert {$diff < 2} "gdb did not use too much memory"
+       gdb_assert {$diff <= $max_mem} "gdb did not use too much memory"
 
        gdb_test_no_output "set spin=0" "Allow program to exit"
     }
-    return 0
+    return $diff
 }
 
 # If we couldn't create the first corefile, there's no point
-# in running the second part of the test.
-if {[run_test 4] != 0} {
+# in running the second part of the test.  The maximum amount
+# of memory allowed is the same as the memory used by the
+# inferior.
+set mem_limit [run_test 4 4]
+if {$mem_limit < 0} {
     return
 }
 # Surprisingly enough, the larger inferior doesn't seem to use
 # any extra memory, it usually uses less memory.  Which is good,
 # it means our memory requirements aren't growing with the inferior.
-run_test 64
+# This test ensures that it remains true that a larger inferior will
+# not grow the memory requirements.
+run_test 64 $mem_limit