From patchwork Thu Jan 23 00:57:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 37504 Received: (qmail 83095 invoked by alias); 23 Jan 2020 00:57:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 81054 invoked by uid 89); 23 Jan 2020 00:57:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=read_offset X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.47.125) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Jan 2020 00:57:29 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway22.websitewelcome.com (Postfix) with ESMTP id C246592F for ; Wed, 22 Jan 2020 18:57:27 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id uQoJiqj7PLLpRuQoJisvIx; Wed, 22 Jan 2020 18:57:27 -0600 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=iYzNypOwzdpwFcopKOF5qrJoG5hN6/VZKTkEqM4fMPE=; b=X9PuChFXc3b+UXdxNVSKoziagg ZDliJ4cE8IyuedPrWHilXcpts6kdoI9xskWlOL5pQ4ux0Ke4jtk9AerdBodRwO0aaVcAG2nS7yRI9 Lmg+FXZIZyM7jAjiBVKgVv/3k; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:40832 helo=bapiya.Home) by box5379.bluehost.com with esmtpa (Exim 4.92) (envelope-from ) id 1iuQoJ-004KqG-Js; Wed, 22 Jan 2020 17:57:27 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 32/38] Move read_offset_1 to leb.c Date: Wed, 22 Jan 2020 17:57:04 -0700 Message-Id: <20200123005710.7978-33-tom@tromey.com> In-Reply-To: <20200123005710.7978-1-tom@tromey.com> References: <20200123005710.7978-1-tom@tromey.com> This moves read_offset_1 to leb.c, as it is a low-level data-reading function. It is also renamed to remove the "_1", because gdb can use overloading now, and this is clearer. 2020-01-22 Tom Tromey * dwarf2/read.c (read_offset_1): Move to leb.c. (read_abbrev_offset, read_offset, dwarf_decode_line_header) (dwarf_decode_macro_bytes): Update. * dwarf2/leb.c (read_offset): Rename; move from read.c. * dwarf2/leb.h (read_offset): Declare. Change-Id: I048140598acfa76eade2cc529ab7933d4b9ca0b3 --- gdb/ChangeLog | 8 ++++++++ gdb/dwarf2/leb.c | 24 ++++++++++++++++++++++++ gdb/dwarf2/leb.h | 4 ++++ gdb/dwarf2/read.c | 36 +++++------------------------------- 4 files changed, 41 insertions(+), 31 deletions(-) diff --git a/gdb/dwarf2/leb.c b/gdb/dwarf2/leb.c index ef7314ed2b3..02faaa9954d 100644 --- a/gdb/dwarf2/leb.c +++ b/gdb/dwarf2/leb.c @@ -110,3 +110,27 @@ read_initial_length (bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read, return length; } + +/* See leb.h. */ + +LONGEST +read_offset (bfd *abfd, const gdb_byte *buf, unsigned int offset_size) +{ + LONGEST retval = 0; + + switch (offset_size) + { + case 4: + retval = bfd_get_32 (abfd, buf); + break; + case 8: + retval = bfd_get_64 (abfd, buf); + break; + default: + internal_error (__FILE__, __LINE__, + _("read_offset_1: bad switch [in module %s]"), + bfd_get_filename (abfd)); + } + + return retval; +} diff --git a/gdb/dwarf2/leb.h b/gdb/dwarf2/leb.h index 29fdffebfec..9c30cbea734 100644 --- a/gdb/dwarf2/leb.h +++ b/gdb/dwarf2/leb.h @@ -130,4 +130,8 @@ extern LONGEST read_initial_length (bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read, bool handle_nonstd = true); +/* Read an offset from the data stream. */ +extern LONGEST read_offset (bfd *abfd, const gdb_byte *buf, + unsigned int offset_size); + #endif /* GDB_DWARF2_LEB_H */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 9db6529c4b8..9ab3dc24938 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1290,8 +1290,6 @@ static LONGEST read_offset (bfd *, const gdb_byte *, const struct comp_unit_head *, unsigned int *); -static LONGEST read_offset_1 (bfd *, const gdb_byte *, unsigned int); - static sect_offset read_abbrev_offset (struct dwarf2_per_objfile *dwarf2_per_objfile, struct dwarf2_section_info *, sect_offset); @@ -6150,7 +6148,7 @@ read_abbrev_offset (struct dwarf2_per_objfile *dwarf2_per_objfile, info_ptr += 2; } - return (sect_offset) read_offset_1 (abfd, info_ptr, offset_size); + return (sect_offset) read_offset (abfd, info_ptr, offset_size); } /* Allocate a new partial symtab for file named NAME and mark this new @@ -19078,36 +19076,12 @@ read_offset (bfd *abfd, const gdb_byte *buf, const struct comp_unit_head *cu_header, unsigned int *bytes_read) { - LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); + LONGEST offset = read_offset (abfd, buf, cu_header->offset_size); *bytes_read = cu_header->offset_size; return offset; } -/* Read an offset from the data stream. */ - -static LONGEST -read_offset_1 (bfd *abfd, const gdb_byte *buf, unsigned int offset_size) -{ - LONGEST retval = 0; - - switch (offset_size) - { - case 4: - retval = bfd_get_32 (abfd, buf); - break; - case 8: - retval = bfd_get_64 (abfd, buf); - break; - default: - internal_error (__FILE__, __LINE__, - _("read_offset_1: bad switch [in module %s]"), - bfd_get_filename (abfd)); - } - - return retval; -} - static const gdb_byte * read_n_bytes (bfd *abfd, const gdb_byte *buf, unsigned int size) { @@ -19892,7 +19866,7 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu) return NULL; } } - lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); + lh->header_length = read_offset (abfd, line_ptr, offset_size); line_ptr += offset_size; lh->statement_program_start = line_ptr + lh->header_length; lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); @@ -23965,7 +23939,7 @@ dwarf_decode_macro_bytes (struct dwarf2_cu *cu, { LONGEST str_offset; - str_offset = read_offset_1 (abfd, mac_ptr, offset_size); + str_offset = read_offset (abfd, mac_ptr, offset_size); mac_ptr += offset_size; if (macinfo_type == DW_MACRO_define_sup @@ -24105,7 +24079,7 @@ dwarf_decode_macro_bytes (struct dwarf2_cu *cu, int is_dwz = section_is_dwz; const gdb_byte *new_mac_ptr; - offset = read_offset_1 (abfd, mac_ptr, offset_size); + offset = read_offset (abfd, mac_ptr, offset_size); mac_ptr += offset_size; if (macinfo_type == DW_MACRO_import_sup)