From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CQnAJLBVsGn6+SEAWB0awg (envelope-from ) for ; Tue, 10 Mar 2026 13:32:32 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=e0gxMrGo; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 90ADB1E0DD; Tue, 10 Mar 2026 13:32:32 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.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,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 663CA1E089 for ; Tue, 10 Mar 2026 13:32:31 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 8893A4BAD154 for ; Tue, 10 Mar 2026 17:32:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8893A4BAD154 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=e0gxMrGo Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 737424B9DB7A for ; Tue, 10 Mar 2026 17:31:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 737424B9DB7A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=polymtl.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 737424B9DB7A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773163873; cv=none; b=Dg2R3UPPWKpN8eBebCzf5zJhjlXBk8nuCWsQIY0KvdDX2PlMflkmC4tegOl8GDixjRrC4dxCktYviGj8VbJTPWtnlreicMWhE1qP7kW5l1yS+ZL6hsRIEh1kiGjJvEd43pO/mvkPTldHomjTmSLtbhq4bDjJFr3ZTcE0/ISutN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773163873; c=relaxed/simple; bh=F6Zi7XF646cIdkInqGOnQES6LUqVx9SBaGQOu6hRU0s=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=arI2C09OLu401zXKcn8A//gk+0bUVkdYGuwA5O0t6hP2JoLiqgck83KjT8QAu9jWmoBpTM/MPbbQ66v4B4/HTQ3B5AaoYIfYaBdXw5pjWrjm5RTnxlhAH2vhDjtAZDNJbCuZZ0BbSWdf4AMQpLDq2SGikkeXISH+WFcUL48spPE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 737424B9DB7A Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 62AHV7sM140221 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Mar 2026 13:31:11 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 62AHV7sM140221 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1773163872; bh=yLlWu81/rZx08XjtjfBljoHoYt5O/+xcPNffpm0zOnU=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=e0gxMrGoZHhwt9ftku8pXYJomxwBSGCJcFq/GfY0+L1XSN83KXXpJRO9441fEpGag AbNi16//aQcvCqVd35LKuvAohhXhZosYnebW02z4darcAR0r2Ff4eIz6EsVpKaSWgl WdXpGxP/wQEAdMwR1PLnKDrWRmLNguMWsj3MxFFv6qti89WRQL0N5RVJUDMtpP/CJq peB7ZDd9qNvSXH/n3qTx44I0/1ShLXikyuCkQYUvRd8KHnc/TLYAa8uCmXDVfhPRU3 Wj14uIHGl3wzqG57idVegxic0Cd9ydRm1K6P7WA5EuA6OdnnbNgzNn7g+6zXAEWzsd jm/P5XKyN6dsw== Received: by simark.ca (Postfix) id ED19D1E0DD; Tue, 10 Mar 2026 13:31:06 -0400 (EDT) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 3/5] gdb/linux-tdep: make linux_find_memory_region_ftype a function_view Date: Tue, 10 Mar 2026 13:30:34 -0400 Message-ID: <20260310173104.676640-3-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260310173104.676640-1-simon.marchi@polymtl.ca> References: <20260310173104.676640-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Tue, 10 Mar 2026 17:31:07 +0000 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 From: Simon Marchi Make it a function_view and eliminate the `void *` callback data. Change the callback functions to lambda functions where they are used. Change-Id: I239b3650783fa06320f85c2a63273346af81344f --- gdb/linux-tdep.c | 153 ++++++++++++----------------------------------- 1 file changed, 39 insertions(+), 114 deletions(-) diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 53ee6d9579cc..36b7cc95b4eb 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -1365,12 +1365,9 @@ linux_core_xfer_siginfo (struct gdbarch *gdbarch, struct bfd &cbfd, return len; } -typedef bool linux_find_memory_region_ftype (ULONGEST vaddr, ULONGEST size, - ULONGEST offset, bool read, - bool write, bool exec, - bool modified, bool memory_tagged, - const std::string &filename, - void *data); +using linux_find_memory_region_ftype + = gdb::function_view; typedef bool linux_dump_mapping_p_ftype (filter_flags filterflags, const smaps_data &map); @@ -1580,8 +1577,7 @@ linux_address_in_memtag_page (CORE_ADDR address) static bool linux_find_memory_regions_full (struct gdbarch *gdbarch, linux_dump_mapping_p_ftype *should_dump_mapping_p, - linux_find_memory_region_ftype *func, - void *obfd) + linux_find_memory_region_ftype func) { pid_t pid; /* Default dump behavior of coredump_filter (0x33), according to @@ -1641,111 +1637,29 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch, && !func (map.start_address, map.end_address - map.start_address, map.offset, map.read, map.write, map.exec, /* MODIFIED is true because we want to dump the mapping. */ - true, map.vmflags.memory_tagging != 0, map.filename, obfd)) + true, map.vmflags.memory_tagging != 0, map.filename)) return false; } return true; } -/* A structure for passing information through - linux_find_memory_regions_full. */ - -struct linux_find_memory_regions_data -{ - /* The original callback. */ - - find_memory_region_ftype func; - - /* The original datum. */ - - void *obfd; -}; - -/* A callback for linux_find_memory_regions that converts between the - "full"-style callback and find_memory_region_ftype. */ - -static bool -linux_find_memory_regions_thunk (ULONGEST vaddr, ULONGEST size, - ULONGEST offset, - bool read, bool write, bool exec, - bool modified, bool memory_tagged, - const std::string &filename, void *arg) -{ - struct linux_find_memory_regions_data *data - = (struct linux_find_memory_regions_data *) arg; - - return data->func (vaddr, size, read, write, exec, modified, memory_tagged, - data->obfd); -} - /* A variant of linux_find_memory_regions_full that is suitable as the gdbarch find_memory_regions method. */ static bool linux_find_memory_regions (struct gdbarch *gdbarch, - find_memory_region_ftype func, void *obfd) -{ - struct linux_find_memory_regions_data data; - - data.func = func; - data.obfd = obfd; - - return linux_find_memory_regions_full (gdbarch, - dump_mapping_p, - linux_find_memory_regions_thunk, - &data); -} - -/* This is used to pass information from - linux_make_mappings_corefile_notes through - linux_find_memory_regions_full. */ - -struct linux_make_mappings_data -{ - /* Number of files mapped. */ - ULONGEST file_count; - - /* The obstack for the main part of the data. */ - struct obstack *data_obstack; - - /* The filename obstack. */ - struct obstack *filename_obstack; - - /* The architecture's "long" type. */ - struct type *long_type; -}; - -/* A callback for linux_find_memory_regions_full that updates the - mappings data for linux_make_mappings_corefile_notes. - - MEMORY_TAGGED is true if the memory region contains memory tags, false - otherwise. */ - -static bool -linux_make_mappings_callback (ULONGEST vaddr, ULONGEST size, ULONGEST offset, - bool read, bool write, bool exec, bool modified, - bool memory_tagged, const std::string &filename, - void *data) + find_memory_region_ftype func, void *data) { - struct linux_make_mappings_data *map_data - = (struct linux_make_mappings_data *) data; - gdb_byte buf[sizeof (ULONGEST)]; - - gdb_assert (filename.length () > 0); - - ++map_data->file_count; - - pack_long (buf, map_data->long_type, vaddr); - obstack_grow (map_data->data_obstack, buf, map_data->long_type->length ()); - pack_long (buf, map_data->long_type, vaddr + size); - obstack_grow (map_data->data_obstack, buf, map_data->long_type->length ()); - pack_long (buf, map_data->long_type, offset); - obstack_grow (map_data->data_obstack, buf, map_data->long_type->length ()); - - obstack_grow_str0 (map_data->filename_obstack, filename.c_str ()); + auto cb = [&] (ULONGEST vaddr, ULONGEST size, ULONGEST offset, bool read, + bool write, bool exec, bool modified, bool memory_tagged, + const std::string &filename) + { + return func (vaddr, size, read, write, exec, modified, memory_tagged, + data); + }; - return true; + return linux_find_memory_regions_full (gdbarch, dump_mapping_p, cb); } /* Write the file mapping data to the core file, if possible. OBFD is @@ -1757,18 +1671,12 @@ linux_make_mappings_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, gdb::unique_xmalloc_ptr ¬e_data, int *note_size) { - struct linux_make_mappings_data mapping_data; type_allocator alloc (gdbarch); struct type *long_type = init_integer_type (alloc, gdbarch_long_bit (gdbarch), 0, "long"); gdb_byte buf[sizeof (ULONGEST)]; - auto_obstack data_obstack, filename_obstack; - - mapping_data.file_count = 0; - mapping_data.data_obstack = &data_obstack; - mapping_data.filename_obstack = &filename_obstack; - mapping_data.long_type = long_type; + ULONGEST file_count = 0; /* Reserve space for the count. */ obstack_blank (&data_obstack, long_type->length ()); @@ -1777,16 +1685,33 @@ linux_make_mappings_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, pack_long (buf, long_type, 1); obstack_grow (&data_obstack, buf, long_type->length ()); - linux_find_memory_regions_full (gdbarch, - dump_note_entry_p, - linux_make_mappings_callback, - &mapping_data); + auto cb = [&] (ULONGEST vaddr, ULONGEST size, ULONGEST offset, bool read, + bool write, bool exec, bool modified, bool memory_tagged, + const std::string &filename) + { + gdb_assert (filename.length () > 0); + + ++file_count; + + pack_long (buf, long_type, vaddr); + obstack_grow (&data_obstack, buf, long_type->length ()); + pack_long (buf, long_type, vaddr + size); + obstack_grow (&data_obstack, buf, long_type->length ()); + pack_long (buf, long_type, offset); + obstack_grow (&data_obstack, buf, long_type->length ()); + + obstack_grow_str0 (&filename_obstack, filename.c_str ()); + + return true; + }; + + linux_find_memory_regions_full (gdbarch, dump_note_entry_p, cb); - if (mapping_data.file_count != 0) + if (file_count != 0) { /* Write the count to the obstack. */ - pack_long ((gdb_byte *) obstack_base (&data_obstack), - long_type, mapping_data.file_count); + pack_long ((gdb_byte *) obstack_base (&data_obstack), long_type, + file_count); /* Copy the filenames to the data obstack. */ int size = obstack_object_size (&filename_obstack); -- 2.53.0