From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway33.websitewelcome.com (gateway33.websitewelcome.com [192.185.146.210]) by sourceware.org (Postfix) with ESMTPS id 4DE90385E01F for ; Sun, 22 Mar 2020 18:45:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4DE90385E01F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway33.websitewelcome.com (Postfix) with ESMTP id EEA763CE8A for ; Sun, 22 Mar 2020 13:45:26 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id G5bCjxjTu1s2xG5bCjfayg; Sun, 22 Mar 2020 13:45:26 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: 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=07m7SNLDl62WiawuAJ80L1Jdgn3XcX0LUEFA+ozImzs=; b=KY82CN5GhjaQWdgzqVhjEon1tQ n8U8nanG8brK0wWPHeHXdt3dvoxQO5YMwZft1V9i9Xi1beSMrM/bQ1FGHViuUoWPVW5E5HeNM3GsQ tSpuPK5L3ohBNs66VpaoBVUOd; Received: from 97-118-117-21.hlrn.qwest.net ([97.118.117.21]:48304 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1jG5bC-000LNS-OW; Sun, 22 Mar 2020 12:45:26 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 07/22] Add dwarf2_section_info::read_string method Date: Sun, 22 Mar 2020 12:45:08 -0600 Message-Id: <20200322184523.28959-8-tom@tromey.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200322184523.28959-1-tom@tromey.com> References: <20200322184523.28959-1-tom@tromey.com> 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: 97.118.117.21 X-Source-L: No X-Exim-ID: 1jG5bC-000LNS-OW X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-118-117-21.hlrn.qwest.net (bapiya.Home) [97.118.117.21]:48304 X-Source-Auth: tom+tromey.com X-Email-Count: 8 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-23.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP, URIBL_CSS, URIBL_CSS_A 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: Sun, 22 Mar 2020 18:45:29 -0000 This moves a string-reading function to be a method on dwarf2_section_info, and then updates the users. gdb/ChangeLog 2020-03-22 Tom Tromey * dwarf2/section.h (struct dwarf2_section_info) : New method. * dwarf2/section.c: New method. From read_indirect_string_at_offset_from. * dwarf2/read.c (mapped_debug_names::namei_to_name): Update. (read_indirect_string_at_offset_from): Move to section.c. (read_indirect_string_at_offset): Rewrite. (read_indirect_line_string_at_offset): Remove. (read_indirect_string, read_indirect_line_string) (dwarf_decode_macro_bytes): Update. --- gdb/ChangeLog | 13 ++++++++++ gdb/dwarf2/read.c | 60 ++++++++------------------------------------ gdb/dwarf2/section.c | 17 +++++++++++++ gdb/dwarf2/section.h | 5 ++++ 4 files changed, 46 insertions(+), 49 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 52a53428d5b..75d028d95b1 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1256,8 +1256,7 @@ static const char *read_indirect_line_string const struct comp_unit_head *, unsigned int *); static const char *read_indirect_string_at_offset - (struct dwarf2_per_objfile *dwarf2_per_objfile, bfd *abfd, - LONGEST str_offset); + (struct dwarf2_per_objfile *dwarf2_per_objfile, LONGEST str_offset); static CORE_ADDR read_addr_index_from_leb128 (struct dwarf2_cu *, const gdb_byte *, @@ -5171,8 +5170,8 @@ mapped_debug_names::namei_to_name (uint32_t namei) const + namei * offset_size), offset_size, dwarf5_byte_order); - return read_indirect_string_at_offset - (dwarf2_per_objfile, dwarf2_per_objfile->objfile->obfd, namei_string_offs); + return read_indirect_string_at_offset (dwarf2_per_objfile, + namei_string_offs); } /* Find a slot in .debug_names for the object named NAME. If NAME is @@ -18770,52 +18769,14 @@ read_checked_initial_length_and_offset (bfd *abfd, const gdb_byte *buf, return length; } -/* Return pointer to string at section SECT offset STR_OFFSET with error - reporting strings FORM_NAME and SECT_NAME. */ - -static const char * -read_indirect_string_at_offset_from (struct objfile *objfile, - bfd *abfd, LONGEST str_offset, - struct dwarf2_section_info *sect, - const char *form_name, - const char *sect_name) -{ - sect->read (objfile); - if (sect->buffer == NULL) - error (_("%s used without %s section [in module %s]"), - form_name, sect_name, bfd_get_filename (abfd)); - if (str_offset >= sect->size) - error (_("%s pointing outside of %s section [in module %s]"), - form_name, sect_name, bfd_get_filename (abfd)); - gdb_assert (HOST_CHAR_BIT == 8); - if (sect->buffer[str_offset] == '\0') - return NULL; - return (const char *) (sect->buffer + str_offset); -} - /* Return pointer to string at .debug_str offset STR_OFFSET. */ static const char * read_indirect_string_at_offset (struct dwarf2_per_objfile *dwarf2_per_objfile, - bfd *abfd, LONGEST str_offset) -{ - return read_indirect_string_at_offset_from (dwarf2_per_objfile->objfile, - abfd, str_offset, - &dwarf2_per_objfile->str, - "DW_FORM_strp", ".debug_str"); -} - -/* Return pointer to string at .debug_line_str offset STR_OFFSET. */ - -static const char * -read_indirect_line_string_at_offset (struct dwarf2_per_objfile *dwarf2_per_objfile, - bfd *abfd, LONGEST str_offset) + LONGEST str_offset) { - return read_indirect_string_at_offset_from (dwarf2_per_objfile->objfile, - abfd, str_offset, - &dwarf2_per_objfile->line_str, - "DW_FORM_line_strp", - ".debug_line_str"); + return dwarf2_per_objfile->str.read_string (dwarf2_per_objfile->objfile, + str_offset, "DW_FORM_strp"); } /* Return pointer to string at .debug_str offset as read from BUF. @@ -18830,7 +18791,7 @@ read_indirect_string (struct dwarf2_per_objfile *dwarf2_per_objfile, bfd *abfd, { LONGEST str_offset = cu_header->read_offset (abfd, buf, bytes_read_ptr); - return read_indirect_string_at_offset (dwarf2_per_objfile, abfd, str_offset); + return read_indirect_string_at_offset (dwarf2_per_objfile, str_offset); } /* Return pointer to string at .debug_line_str offset as read from BUF. @@ -18845,8 +18806,9 @@ read_indirect_line_string (struct dwarf2_per_objfile *dwarf2_per_objfile, { LONGEST str_offset = cu_header->read_offset (abfd, buf, bytes_read_ptr); - return read_indirect_line_string_at_offset (dwarf2_per_objfile, abfd, - str_offset); + return dwarf2_per_objfile->line_str.read_string (dwarf2_per_objfile->objfile, + str_offset, + "DW_FORM_line_strp"); } /* Given index ADDR_INDEX in .debug_addr, fetch the value. @@ -23549,7 +23511,7 @@ dwarf_decode_macro_bytes (struct dwarf2_per_objfile *dwarf2_per_objfile, } else body = read_indirect_string_at_offset (dwarf2_per_objfile, - abfd, str_offset); + str_offset); } is_define = (macinfo_type == DW_MACRO_define diff --git a/gdb/dwarf2/section.c b/gdb/dwarf2/section.c index 9714368a5d2..776617911a2 100644 --- a/gdb/dwarf2/section.c +++ b/gdb/dwarf2/section.c @@ -187,3 +187,20 @@ dwarf2_section_info::read (struct objfile *objfile) bfd_section_name (sectp), bfd_get_filename (abfd)); } } + +const char * +dwarf2_section_info::read_string (struct objfile *objfile, LONGEST str_offset, + const char *form_name) +{ + read (objfile); + if (buffer == NULL) + error (_("%s used without %s section [in module %s]"), + form_name, get_name (), get_file_name ()); + if (str_offset >= size) + error (_("%s pointing outside of %s section [in module %s]"), + form_name, get_name (), get_file_name ()); + gdb_assert (HOST_CHAR_BIT == 8); + if (buffer[str_offset] == '\0') + return NULL; + return (const char *) (buffer + str_offset); +} diff --git a/gdb/dwarf2/section.h b/gdb/dwarf2/section.h index 555efecacd6..02f42df78c6 100644 --- a/gdb/dwarf2/section.h +++ b/gdb/dwarf2/section.h @@ -98,6 +98,11 @@ struct dwarf2_section_info buffer. */ void overflow_complaint () const; + /* Return pointer to string in this section at offset STR_OFFSET + with error reporting string FORM_NAME. */ + const char *read_string (struct objfile *objfile, LONGEST str_offset, + const char *form_name); + union { /* If this is a real section, the bfd section. */ -- 2.17.2