From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from alt-proxy28.mail.unifiedlayer.com (alt-proxy28.mail.unifiedlayer.com [74.220.216.123]) by sourceware.org (Postfix) with ESMTPS id 1BF8C3858C52 for ; Tue, 21 Mar 2023 19:18:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1BF8C3858C52 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw10.mail.unifiedlayer.com (unknown [10.0.90.125]) by progateway1.mail.pro1.eigbox.com (Postfix) with ESMTP id EF29E10038615 for ; Tue, 21 Mar 2023 19:18:31 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id ehV9p64paRSTPehV9p7Lzv; Tue, 21 Mar 2023 19:18:31 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=VeEygHl9 c=1 sm=1 tr=0 ts=641a0307 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10:nop_charset_1 a=k__wU0fu6RkA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=ZPYF-xXZonbc6vsVp0gA:9 a=QEXdDO2ut3YA:10:nop_charset_2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=edxM7Y1gUCwwMZyLH0hqVaP0VkLMHrYLMSzrXysi3LU=; b=l89MH8O3rBjKp1kJ3AV2L/+3lZ wXOCK65xWHadMwSWEOhMt7MgfUFEPpQiOeKC785TfZVBnHi5FcCWYILdauMSG39dumgo4N2rJ2gPi nsH/rDG+jKv19defBdKAnP7o/; Received: from 71-211-185-113.hlrn.qwest.net ([71.211.185.113]:53618 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pehV9-00150d-Jc for gdb-patches@sourceware.org; Tue, 21 Mar 2023 13:18:31 -0600 From: Tom Tromey Date: Tue, 21 Mar 2023 13:18:26 -0600 Subject: [PATCH 1/6] Use function_view in gdb_bfd_lookup_symbol MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230321-submit-unrelocated-type-v1-1-2a1fb6117abf@tromey.com> References: <20230321-submit-unrelocated-type-v1-0-2a1fb6117abf@tromey.com> In-Reply-To: <20230321-submit-unrelocated-type-v1-0-2a1fb6117abf@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.185.113 X-Source-L: No X-Exim-ID: 1pehV9-00150d-Jc X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-185-113.hlrn.qwest.net ([192.168.0.21]) [71.211.185.113]:53618 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3025.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_ABUSEAT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This changes gdb_bfd_lookup_symbol to use a function_view. This simplifies the code a little bit. --- gdb/solib-dsbt.c | 17 +++++++---------- gdb/solib-frv.c | 15 ++++++--------- gdb/solib-svr4.c | 20 +++++++++----------- gdb/solib.c | 29 ++++++++++++----------------- gdb/solib.h | 14 +++++--------- 5 files changed, 39 insertions(+), 56 deletions(-) diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c index 557df74eb00..866087ef3a5 100644 --- a/gdb/solib-dsbt.c +++ b/gdb/solib-dsbt.c @@ -662,14 +662,6 @@ enable_break_failure_warning (void) "and track explicitly loaded dynamic code.")); } -/* Helper function for gdb_bfd_lookup_symbol. */ - -static int -cmp_name (const asymbol *sym, const void *data) -{ - return (strcmp (sym->name, (const char *) data) == 0); -} - /* The dynamic linkers has, as part of its debugger interface, support for arranging for the inferior to hit a breakpoint after mapping in the shared libraries. This function enables that breakpoint. @@ -759,8 +751,13 @@ enable_break (void) = info->interp_plt_sect_low + bfd_section_size (interp_sect); } - addr = gdb_bfd_lookup_symbol (tmp_bfd.get (), cmp_name, - "_dl_debug_state"); + addr = (gdb_bfd_lookup_symbol + (tmp_bfd.get (), + [] (const asymbol *sym) + { + return strcmp (sym->name, "_dl_debug_state") == 0; + })); + if (addr != 0) { if (solib_dsbt_debug) diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c index 38aed7a6ca4..240b4da5d9d 100644 --- a/gdb/solib-frv.c +++ b/gdb/solib-frv.c @@ -472,14 +472,6 @@ enable_break_failure_warning (void) "and track explicitly loaded dynamic code.")); } -/* Helper function for gdb_bfd_lookup_symbol. */ - -static int -cmp_name (const asymbol *sym, const void *data) -{ - return (strcmp (sym->name, (const char *) data) == 0); -} - /* Arrange for dynamic linker to hit breakpoint. The dynamic linkers has, as part of its debugger interface, support @@ -602,7 +594,12 @@ enable_break2 (void) interp_plt_sect_low + bfd_section_size (interp_sect); } - addr = gdb_bfd_lookup_symbol (tmp_bfd.get (), cmp_name, "_dl_debug_addr"); + addr = (gdb_bfd_lookup_symbol + (tmp_bfd.get (), + [] (const asymbol *sym) + { + return strcmp (sym->name, "_dl_debug_addr") == 0; + })); if (addr == 0) { diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index b3f6b6adaf2..5a728939111 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -2301,14 +2301,6 @@ svr4_create_solib_event_breakpoints (svr4_info *info, struct gdbarch *gdbarch, } } -/* Helper function for gdb_bfd_lookup_symbol. */ - -static int -cmp_name_and_sec_flags (const asymbol *sym, const void *data) -{ - return (strcmp (sym->name, (const char *) data) == 0 - && (sym->section->flags & (SEC_CODE | SEC_DATA)) != 0); -} /* Arrange for dynamic linker to hit breakpoint. Both the SunOS and the SVR4 dynamic linkers have, as part of their @@ -2553,9 +2545,15 @@ enable_break (struct svr4_info *info, int from_tty) /* Now try to set a breakpoint in the dynamic linker. */ for (bkpt_namep = solib_break_names; *bkpt_namep != NULL; bkpt_namep++) { - sym_addr = gdb_bfd_lookup_symbol (tmp_bfd.get (), - cmp_name_and_sec_flags, - *bkpt_namep); + sym_addr + = (gdb_bfd_lookup_symbol + (tmp_bfd.get (), + [=] (const asymbol *sym) + { + return (strcmp (sym->name, *bkpt_namep) == 0 + && ((sym->section->flags & (SEC_CODE | SEC_DATA)) + != 0)); + })); if (sym_addr != 0) break; } diff --git a/gdb/solib.c b/gdb/solib.c index ce10fc5aaf2..e6bccc85ca7 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -1475,13 +1475,11 @@ show_auto_solib_add (struct ui_file *file, int from_tty, /* Lookup the value for a specific symbol from dynamic symbol table. Look up symbol from ABFD. MATCH_SYM is a callback function to determine whether to pick up a symbol. DATA is the input of this callback - function. Return NULL if symbol is not found. */ + function. Return 0 if symbol is not found. */ CORE_ADDR -gdb_bfd_lookup_symbol_from_symtab (bfd *abfd, - int (*match_sym) (const asymbol *, - const void *), - const void *data) +gdb_bfd_lookup_symbol_from_symtab + (bfd *abfd, gdb::function_view match_sym) { long storage_needed = bfd_get_symtab_upper_bound (abfd); CORE_ADDR symaddr = 0; @@ -1499,7 +1497,7 @@ gdb_bfd_lookup_symbol_from_symtab (bfd *abfd, { asymbol *sym = *symbol_table++; - if (match_sym (sym, data)) + if (match_sym (sym)) { struct gdbarch *gdbarch = target_gdbarch (); symaddr = sym->value; @@ -1675,10 +1673,8 @@ gdb_bfd_read_elf_soname (const char *filename) if symbol is not found. */ static CORE_ADDR -bfd_lookup_symbol_from_dyn_symtab (bfd *abfd, - int (*match_sym) (const asymbol *, - const void *), - const void *data) +bfd_lookup_symbol_from_dyn_symtab + (bfd *abfd, gdb::function_view match_sym) { long storage_needed = bfd_get_dynamic_symtab_upper_bound (abfd); CORE_ADDR symaddr = 0; @@ -1695,7 +1691,7 @@ bfd_lookup_symbol_from_dyn_symtab (bfd *abfd, { asymbol *sym = *symbol_table++; - if (match_sym (sym, data)) + if (match_sym (sym)) { /* BFD symbols are section relative. */ symaddr = sym->value + sym->section->vma; @@ -1709,20 +1705,19 @@ bfd_lookup_symbol_from_dyn_symtab (bfd *abfd, /* Lookup the value for a specific symbol from symbol table and dynamic symbol table. Look up symbol from ABFD. MATCH_SYM is a callback function to determine whether to pick up a symbol. DATA is the - input of this callback function. Return NULL if symbol is not + input of this callback function. Return 0 if symbol is not found. */ CORE_ADDR -gdb_bfd_lookup_symbol (bfd *abfd, - int (*match_sym) (const asymbol *, const void *), - const void *data) +gdb_bfd_lookup_symbol + (bfd *abfd, gdb::function_view match_sym) { - CORE_ADDR symaddr = gdb_bfd_lookup_symbol_from_symtab (abfd, match_sym, data); + CORE_ADDR symaddr = gdb_bfd_lookup_symbol_from_symtab (abfd, match_sym); /* On FreeBSD, the dynamic linker is stripped by default. So we'll have to check the dynamic string table too. */ if (symaddr == 0) - symaddr = bfd_lookup_symbol_from_dyn_symtab (abfd, match_sym, data); + symaddr = bfd_lookup_symbol_from_dyn_symtab (abfd, match_sym); return symaddr; } diff --git a/gdb/solib.h b/gdb/solib.h index 24c365a0ae0..77e023002ed 100644 --- a/gdb/solib.h +++ b/gdb/solib.h @@ -28,6 +28,7 @@ struct program_space; #include "gdb_bfd.h" #include "symfile-add-flags.h" +#include "gdbsupport/function-view.h" /* Value of the 'set debug solib' configuration variable. */ @@ -107,18 +108,13 @@ extern bool libpthread_name_p (const char *name); /* Look up symbol from both symbol table and dynamic string table. */ -extern CORE_ADDR gdb_bfd_lookup_symbol (bfd *abfd, - int (*match_sym) (const asymbol *, - const void *), - const void *data); +extern CORE_ADDR gdb_bfd_lookup_symbol + (bfd *abfd, gdb::function_view match_sym); /* Look up symbol from symbol table. */ -extern CORE_ADDR gdb_bfd_lookup_symbol_from_symtab (bfd *abfd, - int (*match_sym) - (const asymbol *, - const void *), - const void *data); +extern CORE_ADDR gdb_bfd_lookup_symbol_from_symtab + (bfd *abfd, gdb::function_view match_sym); /* Scan for DESIRED_DYNTAG in .dynamic section of ABFD. If DESIRED_DYNTAG is found, 1 is returned and the corresponding PTR and PTR_ADDR are set. */ -- 2.39.1