1 /* DWARF 2 abbreviations
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 #include "dwarf2read.h"
29 #include "dwarf2/abbrev.h"
30 #include "dwarf2/leb.h"
33 /* Abbreviation tables.
35 In DWARF version 2, the description of the debugging information is
36 stored in a separate .debug_abbrev section. Before we read any
37 dies from a section we read in all abbreviations and install them
40 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
43 abbrev_table::alloc_abbrev ()
45 struct abbrev_info
*abbrev
;
47 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
48 memset (abbrev
, 0, sizeof (struct abbrev_info
));
53 /* Add an abbreviation to the table. */
56 abbrev_table::add_abbrev (unsigned int abbrev_number
,
57 struct abbrev_info
*abbrev
)
59 unsigned int hash_number
;
61 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
62 abbrev
->next
= m_abbrevs
[hash_number
];
63 m_abbrevs
[hash_number
] = abbrev
;
66 /* Look up an abbrev in the table.
67 Returns NULL if the abbrev is not found. */
70 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
72 unsigned int hash_number
;
73 struct abbrev_info
*abbrev
;
75 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
76 abbrev
= m_abbrevs
[hash_number
];
80 if (abbrev
->number
== abbrev_number
)
82 abbrev
= abbrev
->next
;
87 /* Read in an abbrev table. */
90 abbrev_table_read_table (struct objfile
*objfile
,
91 struct dwarf2_section_info
*section
,
94 bfd
*abfd
= section
->get_bfd_owner ();
95 const gdb_byte
*abbrev_ptr
;
96 struct abbrev_info
*cur_abbrev
;
97 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
98 unsigned int abbrev_form
;
99 std::vector
<struct attr_abbrev
> cur_attrs
;
101 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
103 section
->read (objfile
);
104 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
105 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
106 abbrev_ptr
+= bytes_read
;
108 /* Loop until we reach an abbrev number of 0. */
109 while (abbrev_number
)
112 cur_abbrev
= abbrev_table
->alloc_abbrev ();
114 /* read in abbrev header */
115 cur_abbrev
->number
= abbrev_number
;
117 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
118 abbrev_ptr
+= bytes_read
;
119 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
122 /* now read in declarations */
125 LONGEST implicit_const
;
127 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
128 abbrev_ptr
+= bytes_read
;
129 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
130 abbrev_ptr
+= bytes_read
;
131 if (abbrev_form
== DW_FORM_implicit_const
)
133 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
135 abbrev_ptr
+= bytes_read
;
139 /* Initialize it due to a false compiler warning. */
143 if (abbrev_name
== 0)
146 cur_attrs
.emplace_back ();
147 struct attr_abbrev
&cur_attr
= cur_attrs
.back ();
148 cur_attr
.name
= (enum dwarf_attribute
) abbrev_name
;
149 cur_attr
.form
= (enum dwarf_form
) abbrev_form
;
150 cur_attr
.implicit_const
= implicit_const
;
151 ++cur_abbrev
->num_attrs
;
155 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
156 cur_abbrev
->num_attrs
);
157 memcpy (cur_abbrev
->attrs
, cur_attrs
.data (),
158 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
160 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
162 /* Get next abbreviation.
163 Under Irix6 the abbreviations for a compilation unit are not
164 always properly terminated with an abbrev number of 0.
165 Exit loop if we encounter an abbreviation which we have
166 already read (which means we are about to read the abbreviations
167 for the next compile unit) or if the end of the abbreviation
169 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
171 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
172 abbrev_ptr
+= bytes_read
;
173 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
This page took 0.033037 seconds and 4 git commands to generate.