From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta034.useast.a.cloudfilter.net (omta034.useast.a.cloudfilter.net [44.202.169.33]) by sourceware.org (Postfix) with ESMTPS id 717B73858C74 for ; Fri, 16 Feb 2024 04:12:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 717B73858C74 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 717B73858C74 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708056744; cv=none; b=wNP/vlRvJg1ZWn4u8wWa0V7xh4s9Yi7qPYrFlQbeWgxKqNcTSWw+q++U4Izusus1PzOZ8aoBgXenkfsbjrieoLpPCxYTHsPdjWpyKCcuGkBLkajmOHTZYf7vY61jF6g1lzh88tHuuTimDuOjo7yNl1uVV4oZpEQcQFFU7O0f2hM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708056744; c=relaxed/simple; bh=7XgUKTzPhYwDG4ym7JwxldzInzqXXmCVMFQDjnb6cV4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=aXH2tRGi6OAtV4eGZhGsdX/9lT2lH3WU59eNKR3oX+3TXOdG8UccZGCjR0rBkHfPCkaEP5oIAscx3Lbma/eOAfYNZN/sWnsIKEIBKgtLoYga0g97Pt2hZBDuEzPyDr9vvDTd1PvMFhqXZS9wxjzqBd+z2X2Mx/kEkj2V/5bzsII= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5008a.ext.cloudfilter.net ([10.0.29.246]) by cmsmtp with ESMTPS id anerrc2D2AxAkapaIrifad; Fri, 16 Feb 2024 04:12:22 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id apaHrcDVsiHrbapaHrvqbt; Fri, 16 Feb 2024 04:12:21 +0000 X-Authority-Analysis: v=2.4 cv=WLzcXWsR c=1 sm=1 tr=0 ts=65cee0a5 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=k7vzHIieQBIA:10 a=Qbun_eYptAEA:10 a=aEjWlaCKJKJgr517Um8A:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=0/zh9m0L8b58D1bhDV3u0tlS7+qWSV0om/yZCqsGo/Y=; b=jdBVZ2ThAR6IfWFzACUCA/3xSN bCM6y1Dxt8v935k8s6QdD3hqvOTXHvBM6NggdJ/a5fELf5qUmsDRJfCEakeRuwjaPYGEgIj5p1CV1 shuBY3wK8iGyCUBcFxkabzAHI; Received: from 71-211-170-195.hlrn.qwest.net ([71.211.170.195]:39424 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1rapaG-003Ygr-2c; Thu, 15 Feb 2024 21:12:20 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Add obj_section::contains method Date: Thu, 15 Feb 2024 21:12:11 -0700 Message-ID: <20240216041211.447526-1-tom@tromey.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.170.195 X-Source-L: No X-Exim-ID: 1rapaG-003Ygr-2c X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-170-195.hlrn.qwest.net (localhost.localdomain) [71.211.170.195]:39424 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfHoLsFIWGqupw7Lnhifi5mv37rFUeL8Zf2EVtuHRtnyxS8qTuyLyax5fP2OwdtzO3NE67SQM3wu0WZHktRqBWU6D5eftnSWN8fXeoNRTNjhoCQ22SJ+X fGnDlRTR0cUtwrT3ZGciHNH2H6epqByeaFM2NtdBTT7wryk6nlGQOD5kP162B0wtA/YnHmT9mNTxa8Ap1tgZ1/EhqMkMLi1efUU= X-Spam-Status: No, score=-3022.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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: I noticed a number of spots checking whether an address is in an obj_section. This patch introduces a new method for this and changes some code to use it. Regression tested on x86-64 Fedora 38. --- gdb/minsyms.c | 2 +- gdb/objfiles.c | 2 +- gdb/objfiles.h | 6 ++++++ gdb/printcmd.c | 2 +- gdb/symfile.c | 3 +-- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/gdb/minsyms.c b/gdb/minsyms.c index 1b85424586f..543003f3bb9 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -716,7 +716,7 @@ frob_address (struct objfile *objfile, CORE_ADDR pc, { for (obj_section *iter : objfile->sections ()) { - if (pc >= iter->addr () && pc < iter->endaddr ()) + if (iter->contains (pc)) { *unrel_addr = unrelocated_addr (pc - iter->offset ()); return 1; diff --git a/gdb/objfiles.c b/gdb/objfiles.c index bcaae42a30f..d880b9304d2 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -1213,7 +1213,7 @@ is_addr_in_objfile (CORE_ADDR addr, const struct objfile *objfile) if (section_is_overlay (osect) && !section_is_mapped (osect)) continue; - if (osect->addr () <= addr && addr < osect->endaddr ()) + if (osect->contains (addr)) return true; } return false; diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 98e2355f7a9..13cc78e17e3 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -394,6 +394,12 @@ struct obj_section return this->addr () + bfd_section_size (this->the_bfd_section); } + /* True if ADDR is in this obj_section, false otherwise. */ + bool contains (CORE_ADDR addr) const + { + return addr >= this->addr () && addr < endaddr (); + } + /* BFD section pointer */ struct bfd_section *the_bfd_section; diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 7f47f489a94..679323c61cb 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -1499,7 +1499,7 @@ info_symbol_command (const char *arg, int from_tty) sect_addr = overlay_mapped_address (addr, osect); - if (osect->addr () <= sect_addr && sect_addr < osect->endaddr () + if (osect->contains (sect_addr) && (msymbol = lookup_minimal_symbol_by_pc_section (sect_addr, osect).minsym)) diff --git a/gdb/symfile.c b/gdb/symfile.c index 9d5ce7f6ad2..db6d76e78bf 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -3085,8 +3085,7 @@ pc_in_mapped_range (CORE_ADDR pc, struct obj_section *section) { if (section_is_overlay (section)) { - if (section->addr () <= pc - && pc < section->endaddr ()) + if (section->contains (pc)) return true; } -- 2.43.0