From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 8E5zL2GPvGeQLzwAWB0awg (envelope-from ) for ; Mon, 24 Feb 2025 10:25:21 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=R+EOGVLX; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=3N+i1SfA; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=jC4KojC4; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=oepmlRp/; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id BE6F51E105; Mon, 24 Feb 2025 10:25:21 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id C8C581E05C for ; Mon, 24 Feb 2025 10:25:20 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 76A393858C31 for ; Mon, 24 Feb 2025 15:25:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76A393858C31 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=R+EOGVLX; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=3N+i1SfA; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=jC4KojC4; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=oepmlRp/ Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id C1B973858C54 for ; Mon, 24 Feb 2025 15:24:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C1B973858C54 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C1B973858C54 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1740410679; cv=none; b=iKkG/h3H2gjjrVI/fMGb11CZ+5F9mz1oG9imYdZeg2wYR7z2+c1N8qvH63+EewVQfsouqf/vj3iUzxhb3ZTUH/UjphSqoU68o9fsZwWMRP5SSvEWkVqBg4X/FJ774xk/KSWXuOH0fWSFedpRkVchN7wK46R1RzL7I2Ue8g2QfA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1740410679; c=relaxed/simple; bh=n8e+WDGOtoFGCehsm1OCOM7mFlRYZh+VRMIT4h/p8Rs=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:To:From; b=IBi3lczBd4ajYSGFS3XtI3+U+nhslY7I9oj0jZnRZRe9vYXEDal1NhZj1EZLzGIhjTiW2mIz9FGx5BTtkg5ml0PVfLZaUmKEBLGt/JaVJfh0z6OPHMpJ0wcCJnaYieoMQiAfdp45bAO+oZl70v+hfYHRIzi6tM4sRj6tC8WHoZo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C1B973858C54 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A78161F441; Mon, 24 Feb 2025 15:24:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1740410677; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0hO1XS+HY6rNpzM0ELftDF4zX6OeAKovWyBm0tBC6X0=; b=R+EOGVLX1RmCUSmcArtFn7OgynCEUIEhLKNVC6Hff6914XXONAoO5+CgqgTs4K0Icz5DT7 k74YHKQgKAiePvSMJ9aeYo+7p5oXSV4BM+6IqTUDhkfJ+2Nz5rUVADvFf9L1G7rp/K1RHc BRjdIYwPzyA8xWrvEVFf2NkJr4qfMwM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1740410677; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0hO1XS+HY6rNpzM0ELftDF4zX6OeAKovWyBm0tBC6X0=; b=3N+i1SfAqHMz3Ec7cYW1W+MrwwmrXJujmNkSXh79vIgyalEaDitx464JUSW6p3JwSdgtv0 lMQepNut3rBjSdDQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1740410676; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0hO1XS+HY6rNpzM0ELftDF4zX6OeAKovWyBm0tBC6X0=; b=jC4KojC4vgcUfNSCLfdWUl57Bd4haoiYltjzPJHuFjIeInRrYsHU85o3qmFQQGpmt+FRWH GvoojIAsA3EIy/oZ5HmBB1H9IDcGG68d4B9cOVjvQF8EQMZM85offoMygSJTmzDJSKK//v NkqJCSfZqx7pNzxsbXbd3IOWH1+s/mc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1740410676; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0hO1XS+HY6rNpzM0ELftDF4zX6OeAKovWyBm0tBC6X0=; b=oepmlRp/V6FOIZrJq70vNiW4vkS4OeLB2t2j15+Ue4JzUy9APALJAEc/nImx4lJDZeR5CV l2Qy1k96iT314iCg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8CFD913332; Mon, 24 Feb 2025 15:24:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id sW/XIDSPvGcIWgAAD6G6ig (envelope-from ); Mon, 24 Feb 2025 15:24:36 +0000 Message-ID: <5f6b3d35-bb54-45d3-9256-4c8714b9fc22@suse.de> Date: Mon, 24 Feb 2025 16:24:58 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdb/testsuite: add test for memory requirements of gcore To: Guinevere Larsen , gdb-patches@sourceware.org References: <20250224140407.252987-1-guinevere@redhat.com> Content-Language: en-US From: Tom de Vries In-Reply-To: <20250224140407.252987-1-guinevere@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FROM_HAS_DN(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; MID_RHS_MATCH_FROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo, suse.de:mid, gnu.org:url] X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On 2/24/25 15:04, Guinevere Larsen wrote: > For a long time, Fedora has been carrying an out-of-tree patch with a > similar test to the one proposed in this patch, that ensures that the > memory requirements don't grow with the inferior's memory. It's been > so long that the context for why this test exists has been lost, but > it looked like it could be interesting for upstream. > > The test runs twice, once with the inferior allocating 4Mb of memory, > and the other allocating 64Mb. My plan was to find the rate at which > things increase based on inferior size, and have that tested to ensure > we're not growing that requirement accidentally, but my testing > actually showed memory requirements going down as the inferior increases, > so instead I just hardcoded that we need less than 2Mb for the command, > and it can be tweaked later if necessary. I tried out the test-case, and it passed for me, but after doing: ... $ echo "1" | sudo tee /proc/sys/kernel/yama/ptrace_scope ... I get: ... (gdb) attach 29408^M Attaching to program: /data/vries/gdb/leap-15-6/build/gdb/testsuite/outputs/gdb.base/gcore-memory-usage/gcore-memory-usage, process 29408^M ptrace: Operation not permitted.^M (gdb) PASS: gdb.base/gcore-memory-usage.exp: 4 Mb: attach 29408 PASS: gdb.base/gcore-memory-usage.exp: 4 Mb: before: Managed to read the memory usage gcore /data/vries/gdb/leap-15-6/build/gdb/testsuite/outputs/gdb.base/gcore-memory-usage/gcore-memory-usage.core^M You can't do that without a process to debug.^M (gdb) FAIL: gdb.base/gcore-memory-usage.exp: 4 Mb: create the corefile ... So, this is missing "require can_spawn_for_attach". Thanks, - Tom > --- > gdb/testsuite/gdb.base/gcore-memory-usage.c | 37 +++++++ > gdb/testsuite/gdb.base/gcore-memory-usage.exp | 97 +++++++++++++++++++ > 2 files changed, 134 insertions(+) > create mode 100644 gdb/testsuite/gdb.base/gcore-memory-usage.c > create mode 100644 gdb/testsuite/gdb.base/gcore-memory-usage.exp > > diff --git a/gdb/testsuite/gdb.base/gcore-memory-usage.c b/gdb/testsuite/gdb.base/gcore-memory-usage.c > new file mode 100644 > index 00000000000..514fdb905cf > --- /dev/null > +++ b/gdb/testsuite/gdb.base/gcore-memory-usage.c > @@ -0,0 +1,37 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2025 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 . */ > + > + > +#include > +#include > +#include > + > +int main(int argc, char **argv) > +{ > + /* Use argv to calculate how many megabytes to allocate. > + Do this to see how much gcore memory usage increases > + based on inferior dynamic memory. */ > + int megs = atoi (argv[1]); > + char *p = malloc (megs * 1024 * 1024); > + > + /* Wait a long time so GDB can attach to this. */ > + sleep (10); > + > + /* Let's be nice citizens :). */ > + free (p); > + return 0; > +} > diff --git a/gdb/testsuite/gdb.base/gcore-memory-usage.exp b/gdb/testsuite/gdb.base/gcore-memory-usage.exp > new file mode 100644 > index 00000000000..cdb6d73c11b > --- /dev/null > +++ b/gdb/testsuite/gdb.base/gcore-memory-usage.exp > @@ -0,0 +1,97 @@ > +# Copyright (C) 2025 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 . > + > +# Test that gcore doesn't end up using excessive memory. > + > +require {istarget "*-*-linux*"} > + > +standard_testfile > + > +if {[build_executable "failed to prepare" $testfile $srcfile {debug}] == -1} { > + return -1 > +} > + > +# Read the proc_pid_status page, to find how much memory the given > +# PID is using. This is meant to be used to find the > +# memory usage for the GDB in this test. > +# Returns memory usage in Kb, or -1 if it couldn't be found. > +proc get_mem_usage {pid prefix} { > + set fd [open "/proc/$pid/status"] > + set memory -1 > + while {[gets $fd line] != -1} { > + if {[regexp {VmSize:\s*([0-9]+) kB} $line full mem]} { > + set memory $mem > + break > + } > + } > + close $fd > + > + gdb_assert {$memory != -1} "$prefix: Managed to read the memory usage" > + > + return $memory > +} > + > +# 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} { > + with_test_prefix "$megs Mb" { > + clean_restart $::testfile > + > + set bin [standard_output_file $::testfile] > + set corefile [standard_output_file "${::testfile}.core"] > + set inferior_pid [eval exec $bin $megs &] > + set gdb_pid [exp_pid -i [board_info host fileid]] > + > + # wait for memory allocation to finish. > + sleep 1 > + > + # Get the important info. > + gdb_test "attach $inferior_pid" "Attaching to.*" > + set mem_before [get_mem_usage $gdb_pid before] > + if {![gdb_gcore_cmd $corefile "create the corefile"]} { > + return -1 > + } > + set mem_after [get_mem_usage $gdb_pid after] > + > + # Do the main part of the test: How much is the memory > + # usage of GDB going to grow after using the gcore command. > + 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 as much memory as the inferior" > + > + # Kill the inferior so we don't have to wait until the process > + # finishes. > + gdb_test "signal SIGKILL" ".*The program no longer exists." > + } > + return 0 > +} > + > +# 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} { > + 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