From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 45F8D385DC05 for ; Sat, 11 Apr 2020 21:53:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 45F8D385DC05 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (unknown [192.222.164.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 94D1C1E827; Sat, 11 Apr 2020 17:53:46 -0400 (EDT) Subject: Re: [PATCH v3] Implement "info proc mappings" for NetBSD To: Kamil Rytarowski , gdb-patches@sourceware.org Cc: tom@tromey.com References: <20200402200916.26504-1-n54@gmx.com> <20200406093753.13772-1-n54@gmx.com> <5d7ee373-df4f-6a05-fda3-d8d6f4d1efcc@simark.ca> <154c0a3c-b59e-1e9b-504e-27bd7e47b2a6@gmx.com> From: Simon Marchi Message-ID: <9abfc854-16fd-247a-f3a6-edd69c03ed5b@simark.ca> Date: Sat, 11 Apr 2020 17:53:46 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <154c0a3c-b59e-1e9b-504e-27bd7e47b2a6@gmx.com> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Apr 2020 21:53:48 -0000 On 2020-04-11 5:28 p.m., Kamil Rytarowski wrote: > On 11.04.2020 23:05, Simon Marchi wrote: >> On 2020-04-06 5:37 a.m., Kamil Rytarowski wrote: >>> @@ -39,3 +42,148 @@ nbsd_nat_target::pid_to_exec_file (int pid) >>> return NULL; >>> return buf; >>> } >>> + >>> +/* Retrieve all the memory regions in the specified process. */ >>> + >>> +static gdb::unique_xmalloc_ptr >>> +nbsd_kinfo_get_vmmap (pid_t pid, size_t *size) >>> +{ >>> + int mib[5] = {CTL_VM, VM_PROC, VM_PROC_MAP, pid, >>> + sizeof (struct kinfo_vmentry)}; >>> + >>> + size_t length = 0; >>> + if (sysctl (mib, ARRAY_SIZE (mib), NULL, &length, NULL, 0)) >>> + { >>> + *size = 0; >>> + return NULL; >>> + } >>> + >>> + /* Prereserve more space. */ >>> + length = length * 5 / 3; >> >> Why is this needed? >> > > This length is volatile and can be larger on the 2nd sysctl(3) call. We > can call this function against a running process that can enlarge its > usage of address space in this time window. Ok, then please make the comment explain that. We can see that the expression increases length, but as a reader I have no idea why. Simon