From patchwork Thu Jan 23 00:56:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 37475 Received: (qmail 79001 invoked by alias); 23 Jan 2020 00:57:22 -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 78938 invoked by uid 89); 23 Jan 2020 00:57:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=Joint, sk:read_at, sk:read_in, Harris X-HELO: gateway30.websitewelcome.com Received: from gateway30.websitewelcome.com (HELO gateway30.websitewelcome.com) (192.185.198.26) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Jan 2020 00:57:19 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway30.websitewelcome.com (Postfix) with ESMTP id E06C83E35 for ; Wed, 22 Jan 2020 18:57:17 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id uQo9iqizrLLpRuQo9isvBU; Wed, 22 Jan 2020 18:57:17 -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=QFG/fdxLzbh+QwJzja2k0Q6w6D452lgNua1iCRtmr74=; b=nDESziv9XbmlQxn36fEG5JG4M9 Y+DlkJzcTZHFjE7aiWvWyqOUIl3a8Xwyb7hWx8ZCO9c/t7vHQ+OaZvqYmyUY2axmQ4gblMevU2Zil OwBlbFz+L1lnr9ED+RSWCUWTM; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:40800 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1iuQo9-004Kfy-Lv; Wed, 22 Jan 2020 17:57:17 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 01/38] Create dwarf2/leb.[ch] Date: Wed, 22 Jan 2020 17:56:33 -0700 Message-Id: <20200123005710.7978-2-tom@tromey.com> In-Reply-To: <20200123005710.7978-1-tom@tromey.com> References: <20200123005710.7978-1-tom@tromey.com> This moves some scalar-unpacking code into a couple of new files, dwarf2/leb.h and dwarf2/leb.c. gdb/ChangeLog 2020-01-22 Tom Tromey * dwarf2read.h (read_unsigned_leb128): Don't declare. * dwarf2read.c (read_1_byte, read_1_signed_byte, read_2_bytes) (read_2_signed_bytes, read_3_bytes, read_4_bytes) (read_4_signed_bytes, read_8_bytes): Move to dwarf2/leb.h. (read_unsigned_leb128, read_signed_leb128): Move to dwarf2/leb.c. * dwarf2/leb.h: New file, from dwarf2read.c. * dwarf2/leb.c: New file, from dwarf2read.c. * dwarf2-frame.c (read_1_byte, read_4_bytes, read_8_bytes): Remove. * Makefile.in (CONFIG_SRC_SUBDIR): Add dwarf2. (COMMON_SFILES): Add dwarf2/leb.c. Change-Id: Idd19647686c8f959d226a95fdfca4db47c6e96d0 --- gdb/ChangeLog | 14 +++++ gdb/Makefile.in | 3 +- gdb/dwarf2-frame.c | 18 +------ gdb/dwarf2/leb.c | 85 +++++++++++++++++++++++++++++ gdb/dwarf2/leb.h | 92 ++++++++++++++++++++++++++++++++ gdb/dwarf2loc.c | 1 + gdb/dwarf2read.c | 130 +-------------------------------------------- gdb/dwarf2read.h | 2 - 8 files changed, 196 insertions(+), 149 deletions(-) create mode 100644 gdb/dwarf2/leb.c create mode 100644 gdb/dwarf2/leb.h diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 45d1586e85e..36d8523533a 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -551,7 +551,7 @@ CONFIG_INSTALL = @CONFIG_INSTALL@ CONFIG_UNINSTALL = @CONFIG_UNINSTALL@ HAVE_NATIVE_GCORE_TARGET = @HAVE_NATIVE_GCORE_TARGET@ -CONFIG_SRC_SUBDIR = arch cli mi compile tui unittests guile python \ +CONFIG_SRC_SUBDIR = arch cli dwarf2 mi compile tui unittests guile python \ target nat CONFIG_DEP_SUBDIR = $(addsuffix /$(DEPDIR),$(CONFIG_SRC_SUBDIR)) @@ -1002,6 +1002,7 @@ COMMON_SFILES = \ dwarf2expr.c \ dwarf2loc.c \ dwarf2read.c \ + dwarf2/leb.c \ eval.c \ event-loop.c \ event-top.c \ diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c index a043d48217b..9daa66b0a29 100644 --- a/gdb/dwarf2-frame.c +++ b/gdb/dwarf2-frame.c @@ -22,6 +22,7 @@ #include "defs.h" #include "dwarf2expr.h" #include "dwarf2.h" +#include "dwarf2/leb.h" #include "frame.h" #include "frame-base.h" #include "frame-unwind.h" @@ -1474,23 +1475,6 @@ const struct objfile_key> dwarf2_frame_objfile_data; -static unsigned int -read_1_byte (bfd *abfd, const gdb_byte *buf) -{ - return bfd_get_8 (abfd, buf); -} - -static unsigned int -read_4_bytes (bfd *abfd, const gdb_byte *buf) -{ - return bfd_get_32 (abfd, buf); -} - -static ULONGEST -read_8_bytes (bfd *abfd, const gdb_byte *buf) -{ - return bfd_get_64 (abfd, buf); -} static ULONGEST read_initial_length (bfd *abfd, const gdb_byte *buf, diff --git a/gdb/dwarf2/leb.c b/gdb/dwarf2/leb.c new file mode 100644 index 00000000000..d26b48b381c --- /dev/null +++ b/gdb/dwarf2/leb.c @@ -0,0 +1,85 @@ +/* Low-level DWARF 2 reading code + + Copyright (C) 1994-2020 Free Software Foundation, Inc. + + Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, + Inc. with support from Florida State University (under contract + with the Ada Joint Program Office), and Silicon Graphics, Inc. + Initial contribution by Brent Benson, Harris Computer Systems, Inc., + based on Fred Fish's (Cygnus Support) implementation of DWARF 1 + support. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "defs.h" +#include "dwarf2/leb.h" + +ULONGEST +read_unsigned_leb128 (bfd *abfd, const gdb_byte *buf, + unsigned int *bytes_read_ptr) +{ + ULONGEST result; + unsigned int num_read; + int shift; + unsigned char byte; + + result = 0; + shift = 0; + num_read = 0; + while (1) + { + byte = bfd_get_8 (abfd, buf); + buf++; + num_read++; + result |= ((ULONGEST) (byte & 127) << shift); + if ((byte & 128) == 0) + { + break; + } + shift += 7; + } + *bytes_read_ptr = num_read; + return result; +} + +LONGEST +read_signed_leb128 (bfd *abfd, const gdb_byte *buf, + unsigned int *bytes_read_ptr) +{ + ULONGEST result; + int shift, num_read; + unsigned char byte; + + result = 0; + shift = 0; + num_read = 0; + while (1) + { + byte = bfd_get_8 (abfd, buf); + buf++; + num_read++; + result |= ((ULONGEST) (byte & 127) << shift); + shift += 7; + if ((byte & 128) == 0) + { + break; + } + } + if ((shift < 8 * sizeof (result)) && (byte & 0x40)) + result |= -(((ULONGEST) 1) << shift); + *bytes_read_ptr = num_read; + return result; +} diff --git a/gdb/dwarf2/leb.h b/gdb/dwarf2/leb.h new file mode 100644 index 00000000000..b17ab881ba2 --- /dev/null +++ b/gdb/dwarf2/leb.h @@ -0,0 +1,92 @@ +/* Low-level DWARF 2 reading code + + Copyright (C) 1994-2020 Free Software Foundation, Inc. + + Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, + Inc. with support from Florida State University (under contract + with the Ada Joint Program Office), and Silicon Graphics, Inc. + Initial contribution by Brent Benson, Harris Computer Systems, Inc., + based on Fred Fish's (Cygnus Support) implementation of DWARF 1 + support. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef GDB_DWARF2_LEB_H +#define GDB_DWARF2_LEB_H + +/* Read dwarf information from a buffer. */ + +static inline unsigned int +read_1_byte (bfd *abfd, const gdb_byte *buf) +{ + return bfd_get_8 (abfd, buf); +} + +static inline int +read_1_signed_byte (bfd *abfd, const gdb_byte *buf) +{ + return bfd_get_signed_8 (abfd, buf); +} + +static inline unsigned int +read_2_bytes (bfd *abfd, const gdb_byte *buf) +{ + return bfd_get_16 (abfd, buf); +} + +static inline int +read_2_signed_bytes (bfd *abfd, const gdb_byte *buf) +{ + return bfd_get_signed_16 (abfd, buf); +} + +/* Read the next three bytes (little-endian order) as an unsigned integer. */ +static inline unsigned int +read_3_bytes (bfd *abfd, const gdb_byte *buf) +{ + unsigned int result = 0; + for (int i = 0; i < 3; ++i) + { + unsigned char byte = bfd_get_8 (abfd, buf); + buf++; + result |= ((unsigned int) byte << (i * 8)); + } + return result; +} + +static inline unsigned int +read_4_bytes (bfd *abfd, const gdb_byte *buf) +{ + return bfd_get_32 (abfd, buf); +} + +static inline int +read_4_signed_bytes (bfd *abfd, const gdb_byte *buf) +{ + return bfd_get_signed_32 (abfd, buf); +} + +static inline ULONGEST +read_8_bytes (bfd *abfd, const gdb_byte *buf) +{ + return bfd_get_64 (abfd, buf); +} + +extern LONGEST read_signed_leb128 (bfd *, const gdb_byte *, unsigned int *); + +extern ULONGEST read_unsigned_leb128 (bfd *, const gdb_byte *, unsigned int *); + +#endif /* GDB_DWARF2_LEB_H */ diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index 405b239ed42..9cfc852c9e1 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -38,6 +38,7 @@ #include "dwarf2loc.h" #include "dwarf2read.h" #include "dwarf2-frame.h" +#include "dwarf2/leb.h" #include "compile/compile.h" #include "gdbsupport/selftest.h" #include diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index dfa2f91d450..e7a474d17a4 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -32,6 +32,7 @@ #include "dwarf2read.h" #include "dwarf-index-cache.h" #include "dwarf-index-common.h" +#include "dwarf2/leb.h" #include "bfd.h" #include "elf-bfd.h" #include "symtab.h" @@ -1556,19 +1557,6 @@ static void read_attribute_reprocess (const struct die_reader_specs *reader, static CORE_ADDR read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index); -static unsigned int read_1_byte (bfd *, const gdb_byte *); - -static int read_1_signed_byte (bfd *, const gdb_byte *); - -static unsigned int read_2_bytes (bfd *, const gdb_byte *); - -/* Read the next three bytes (little-endian order) as an unsigned integer. */ -static unsigned int read_3_bytes (bfd *, const gdb_byte *); - -static unsigned int read_4_bytes (bfd *, const gdb_byte *); - -static ULONGEST read_8_bytes (bfd *, const gdb_byte *); - static CORE_ADDR read_address (bfd *, const gdb_byte *ptr, struct dwarf2_cu *, unsigned int *); @@ -1607,8 +1595,6 @@ static const char *read_indirect_string_at_offset static const char *read_indirect_string_from_dwz (struct objfile *objfile, struct dwz_file *, LONGEST); -static LONGEST read_signed_leb128 (bfd *, const gdb_byte *, unsigned int *); - static CORE_ADDR read_addr_index_from_leb128 (struct dwarf2_cu *, const gdb_byte *, unsigned int *); @@ -19730,63 +19716,6 @@ read_attribute (const struct die_reader_specs *reader, need_reprocess); } -/* Read dwarf information from a buffer. */ - -static unsigned int -read_1_byte (bfd *abfd, const gdb_byte *buf) -{ - return bfd_get_8 (abfd, buf); -} - -static int -read_1_signed_byte (bfd *abfd, const gdb_byte *buf) -{ - return bfd_get_signed_8 (abfd, buf); -} - -static unsigned int -read_2_bytes (bfd *abfd, const gdb_byte *buf) -{ - return bfd_get_16 (abfd, buf); -} - -static int -read_2_signed_bytes (bfd *abfd, const gdb_byte *buf) -{ - return bfd_get_signed_16 (abfd, buf); -} - -static unsigned int -read_3_bytes (bfd *abfd, const gdb_byte *buf) -{ - unsigned int result = 0; - for (int i = 0; i < 3; ++i) - { - unsigned char byte = bfd_get_8 (abfd, buf); - buf++; - result |= ((unsigned int) byte << (i * 8)); - } - return result; -} - -static unsigned int -read_4_bytes (bfd *abfd, const gdb_byte *buf) -{ - return bfd_get_32 (abfd, buf); -} - -static int -read_4_signed_bytes (bfd *abfd, const gdb_byte *buf) -{ - return bfd_get_signed_32 (abfd, buf); -} - -static ULONGEST -read_8_bytes (bfd *abfd, const gdb_byte *buf) -{ - return bfd_get_64 (abfd, buf); -} - static CORE_ADDR read_address (bfd *abfd, const gdb_byte *buf, struct dwarf2_cu *cu, unsigned int *bytes_read) @@ -20096,63 +20025,6 @@ read_indirect_line_string (struct dwarf2_per_objfile *dwarf2_per_objfile, str_offset); } -ULONGEST -read_unsigned_leb128 (bfd *abfd, const gdb_byte *buf, - unsigned int *bytes_read_ptr) -{ - ULONGEST result; - unsigned int num_read; - int shift; - unsigned char byte; - - result = 0; - shift = 0; - num_read = 0; - while (1) - { - byte = bfd_get_8 (abfd, buf); - buf++; - num_read++; - result |= ((ULONGEST) (byte & 127) << shift); - if ((byte & 128) == 0) - { - break; - } - shift += 7; - } - *bytes_read_ptr = num_read; - return result; -} - -static LONGEST -read_signed_leb128 (bfd *abfd, const gdb_byte *buf, - unsigned int *bytes_read_ptr) -{ - ULONGEST result; - int shift, num_read; - unsigned char byte; - - result = 0; - shift = 0; - num_read = 0; - while (1) - { - byte = bfd_get_8 (abfd, buf); - buf++; - num_read++; - result |= ((ULONGEST) (byte & 127) << shift); - shift += 7; - if ((byte & 128) == 0) - { - break; - } - } - if ((shift < 8 * sizeof (result)) && (byte & 0x40)) - result |= -(((ULONGEST) 1) << shift); - *bytes_read_ptr = num_read; - return result; -} - /* Given index ADDR_INDEX in .debug_addr, fetch the value. ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero. ADDR_SIZE is the size of addresses from the CU header. */ diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h index bc8087ba406..7961ffe10c2 100644 --- a/gdb/dwarf2read.h +++ b/gdb/dwarf2read.h @@ -442,8 +442,6 @@ struct signatured_type struct dwo_unit *dwo_unit; }; -ULONGEST read_unsigned_leb128 (bfd *, const gdb_byte *, unsigned int *); - /* This represents a '.dwz' file. */ struct dwz_file