2020-02-09 04:40:54 +08:00
|
|
|
/* DWARF 2 abbreviations
|
|
|
|
|
2021-01-01 16:03:39 +08:00
|
|
|
Copyright (C) 1994-2021 Free Software Foundation, Inc.
|
2020-02-09 04:40:54 +08:00
|
|
|
|
|
|
|
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 <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include "defs.h"
|
Move DWARF code to dwarf2/ subdirectory
This moves all the remaining DWARF code to the new dwarf2
subdirectory. This is just a simple renaming, with updates to
includes as needed.
gdb/ChangeLog
2020-02-08 Tom Tromey <tom@tromey.com>
* dwarf2/expr.c: Rename from dwarf2expr.c.
* dwarf2/expr.h: Rename from dwarf2expr.h.
* dwarf2/frame-tailcall.c: Rename from dwarf2-frame-tailcall.c.
* dwarf2/frame-tailcall.h: Rename from dwarf2-frame-tailcall.h.
* dwarf2/frame.c: Rename from dwarf2-frame.c.
* dwarf2/frame.h: Rename from dwarf2-frame.h.
* dwarf2/index-cache.c: Rename from dwarf-index-cache.c.
* dwarf2/index-cache.h: Rename from dwarf-index-cache.h.
* dwarf2/index-common.c: Rename from dwarf-index-common.c.
* dwarf2/index-common.h: Rename from dwarf-index-common.h.
* dwarf2/index-write.c: Rename from dwarf-index-write.c.
* dwarf2/index-write.h: Rename from dwarf-index-write.h.
* dwarf2/loc.c: Rename from dwarf2loc.c.
* dwarf2/loc.h: Rename from dwarf2loc.h.
* dwarf2/read.c: Rename from dwarf2read.c.
* dwarf2/read.h: Rename from dwarf2read.h.
* dwarf2/abbrev.c, aarch64-tdep.c, alpha-tdep.c,
amd64-darwin-tdep.c, arc-tdep.c, arm-tdep.c, bfin-tdep.c,
compile/compile-c-symbols.c, compile/compile-cplus-symbols.c,
compile/compile-loc2c.c, cris-tdep.c, csky-tdep.c, findvar.c,
gdbtypes.c, guile/scm-type.c, h8300-tdep.c, hppa-bsd-tdep.c,
hppa-linux-tdep.c, i386-darwin-tdep.c, i386-linux-tdep.c,
i386-tdep.c, iq2000-tdep.c, m32c-tdep.c, m68hc11-tdep.c,
m68k-tdep.c, microblaze-tdep.c, mips-tdep.c, mn10300-tdep.c,
msp430-tdep.c, nds32-tdep.c, nios2-tdep.c, or1k-tdep.c,
riscv-tdep.c, rl78-tdep.c, rs6000-tdep.c, rx-tdep.c, s12z-tdep.c,
s390-tdep.c, score-tdep.c, sh-tdep.c, sparc-linux-tdep.c,
sparc-tdep.c, sparc64-linux-tdep.c, sparc64-tdep.c, tic6x-tdep.c,
tilegx-tdep.c, v850-tdep.c, xstormy16-tdep.c, xtensa-tdep.c:
Update.
* Makefile.in (COMMON_SFILES): Update.
(HFILES_NO_SRCDIR): Update.
Change-Id: Ied9ce1436cd27ac4a4cffef10ec92e396f181928
2020-02-09 04:40:54 +08:00
|
|
|
#include "dwarf2/read.h"
|
2020-02-09 04:40:54 +08:00
|
|
|
#include "dwarf2/abbrev.h"
|
|
|
|
#include "dwarf2/leb.h"
|
|
|
|
#include "bfd.h"
|
|
|
|
|
2020-02-09 04:40:54 +08:00
|
|
|
/* Hash function for an abbrev. */
|
|
|
|
|
|
|
|
static hashval_t
|
|
|
|
hash_abbrev (const void *item)
|
|
|
|
{
|
|
|
|
const struct abbrev_info *info = (const struct abbrev_info *) item;
|
2020-05-28 01:48:18 +08:00
|
|
|
/* Warning: if you change this next line, you must also update the
|
|
|
|
other code in this class using the _with_hash functions. */
|
2020-02-09 04:40:54 +08:00
|
|
|
return info->number;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Comparison function for abbrevs. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
eq_abbrev (const void *lhs, const void *rhs)
|
|
|
|
{
|
|
|
|
const struct abbrev_info *l_info = (const struct abbrev_info *) lhs;
|
|
|
|
const struct abbrev_info *r_info = (const struct abbrev_info *) rhs;
|
|
|
|
return l_info->number == r_info->number;
|
|
|
|
}
|
|
|
|
|
2020-02-09 04:40:54 +08:00
|
|
|
/* Abbreviation tables.
|
|
|
|
|
|
|
|
In DWARF version 2, the description of the debugging information is
|
|
|
|
stored in a separate .debug_abbrev section. Before we read any
|
|
|
|
dies from a section we read in all abbreviations and install them
|
|
|
|
in a hash table. */
|
|
|
|
|
2020-02-09 04:40:54 +08:00
|
|
|
abbrev_table::abbrev_table (sect_offset off)
|
|
|
|
: sect_off (off),
|
|
|
|
m_abbrevs (htab_create_alloc (20, hash_abbrev, eq_abbrev,
|
|
|
|
nullptr, xcalloc, xfree))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-09 04:40:54 +08:00
|
|
|
/* Add an abbreviation to the table. */
|
|
|
|
|
|
|
|
void
|
2020-05-28 01:48:18 +08:00
|
|
|
abbrev_table::add_abbrev (struct abbrev_info *abbrev)
|
2020-02-09 04:40:54 +08:00
|
|
|
{
|
2020-05-28 01:48:18 +08:00
|
|
|
void **slot = htab_find_slot_with_hash (m_abbrevs.get (), abbrev,
|
|
|
|
abbrev->number, INSERT);
|
2020-02-09 04:40:54 +08:00
|
|
|
*slot = abbrev;
|
2020-02-09 04:40:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read in an abbrev table. */
|
|
|
|
|
|
|
|
abbrev_table_up
|
2020-11-06 09:27:43 +08:00
|
|
|
abbrev_table::read (struct dwarf2_section_info *section,
|
2020-02-09 04:40:54 +08:00
|
|
|
sect_offset sect_off)
|
2020-02-09 04:40:54 +08:00
|
|
|
{
|
|
|
|
bfd *abfd = section->get_bfd_owner ();
|
|
|
|
const gdb_byte *abbrev_ptr;
|
|
|
|
struct abbrev_info *cur_abbrev;
|
|
|
|
|
|
|
|
abbrev_table_up abbrev_table (new struct abbrev_table (sect_off));
|
2021-03-07 00:16:59 +08:00
|
|
|
struct obstack *obstack = &abbrev_table->m_abbrev_obstack;
|
2020-02-09 04:40:54 +08:00
|
|
|
|
2020-11-06 09:27:43 +08:00
|
|
|
/* Caller must ensure this. */
|
|
|
|
gdb_assert (section->readin);
|
2020-02-09 04:40:54 +08:00
|
|
|
abbrev_ptr = section->buffer + to_underlying (sect_off);
|
|
|
|
|
2021-03-14 00:41:04 +08:00
|
|
|
while (true)
|
2020-02-09 04:40:54 +08:00
|
|
|
{
|
2021-03-14 00:41:04 +08:00
|
|
|
unsigned int bytes_read;
|
|
|
|
/* Loop until we reach an abbrev number of 0. */
|
|
|
|
unsigned int abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr,
|
|
|
|
&bytes_read);
|
|
|
|
if (abbrev_number == 0)
|
|
|
|
break;
|
|
|
|
abbrev_ptr += bytes_read;
|
|
|
|
|
2021-03-07 00:16:59 +08:00
|
|
|
/* Start without any attrs. */
|
|
|
|
obstack_blank (obstack, offsetof (abbrev_info, attrs));
|
|
|
|
cur_abbrev = (struct abbrev_info *) obstack_base (obstack);
|
2020-02-09 04:40:54 +08:00
|
|
|
|
2021-03-07 00:16:59 +08:00
|
|
|
/* Read in abbrev header. */
|
2020-02-09 04:40:54 +08:00
|
|
|
cur_abbrev->number = abbrev_number;
|
|
|
|
cur_abbrev->tag
|
2021-03-07 00:16:59 +08:00
|
|
|
= (enum dwarf_tag) read_unsigned_leb128 (abfd, abbrev_ptr,
|
|
|
|
&bytes_read);
|
2020-02-09 04:40:54 +08:00
|
|
|
abbrev_ptr += bytes_read;
|
|
|
|
cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
|
|
|
|
abbrev_ptr += 1;
|
|
|
|
|
2021-03-07 00:16:59 +08:00
|
|
|
/* Now read in declarations. */
|
|
|
|
int num_attrs = 0;
|
2020-02-09 04:40:54 +08:00
|
|
|
for (;;)
|
|
|
|
{
|
2021-03-07 00:16:59 +08:00
|
|
|
struct attr_abbrev cur_attr;
|
2020-02-09 04:40:54 +08:00
|
|
|
|
2021-03-07 00:16:59 +08:00
|
|
|
cur_attr.name
|
|
|
|
= (enum dwarf_attribute) read_unsigned_leb128 (abfd, abbrev_ptr,
|
|
|
|
&bytes_read);
|
2020-02-09 04:40:54 +08:00
|
|
|
abbrev_ptr += bytes_read;
|
2021-03-07 00:16:59 +08:00
|
|
|
cur_attr.form
|
|
|
|
= (enum dwarf_form) read_unsigned_leb128 (abfd, abbrev_ptr,
|
|
|
|
&bytes_read);
|
2020-02-09 04:40:54 +08:00
|
|
|
abbrev_ptr += bytes_read;
|
2021-03-07 00:16:59 +08:00
|
|
|
if (cur_attr.form == DW_FORM_implicit_const)
|
2020-02-09 04:40:54 +08:00
|
|
|
{
|
2021-03-07 00:16:59 +08:00
|
|
|
cur_attr.implicit_const = read_signed_leb128 (abfd, abbrev_ptr,
|
|
|
|
&bytes_read);
|
2020-02-09 04:40:54 +08:00
|
|
|
abbrev_ptr += bytes_read;
|
|
|
|
}
|
|
|
|
else
|
2021-03-07 00:16:59 +08:00
|
|
|
cur_attr.implicit_const = -1;
|
2020-02-09 04:40:54 +08:00
|
|
|
|
2021-03-07 00:16:59 +08:00
|
|
|
if (cur_attr.name == 0)
|
2020-02-09 04:40:54 +08:00
|
|
|
break;
|
|
|
|
|
2021-03-07 00:16:59 +08:00
|
|
|
++num_attrs;
|
|
|
|
obstack_grow (obstack, &cur_attr, sizeof (cur_attr));
|
2020-02-09 04:40:54 +08:00
|
|
|
}
|
|
|
|
|
2021-03-07 00:16:59 +08:00
|
|
|
cur_abbrev = (struct abbrev_info *) obstack_finish (obstack);
|
|
|
|
cur_abbrev->num_attrs = num_attrs;
|
2020-05-28 01:48:18 +08:00
|
|
|
abbrev_table->add_abbrev (cur_abbrev);
|
2020-02-09 04:40:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return abbrev_table;
|
|
|
|
}
|