blob: 0b1a4b086a6c0de1e9a82d748f9cc48240050b46 [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Return tag of given DIE.
Josh Stoneb849f812014-12-10 18:28:04 -08002 Copyright (C) 2003-2011, 2014 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02003 This file is part of elfutils.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00004 Written by Ulrich Drepper <drepper@redhat.com>, 2003.
5
Mark Wielaardde2ed972012-06-05 17:15:16 +02006 This file is free software; you can redistribute it and/or modify
7 it under the terms of either
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00008
Mark Wielaardde2ed972012-06-05 17:15:16 +02009 * the GNU Lesser General Public License as published by the Free
10 Software Foundation; either version 3 of the License, or (at
11 your option) any later version
12
13 or
14
15 * the GNU General Public License as published by the Free
16 Software Foundation; either version 2 of the License, or (at
17 your option) any later version
18
19 or both in parallel, as here.
20
21 elfutils is distributed in the hope that it will be useful, but
Ulrich Drepper361df7d2006-04-04 21:38:57 +000022 WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 General Public License for more details.
25
Mark Wielaardde2ed972012-06-05 17:15:16 +020026 You should have received copies of the GNU General Public License and
27 the GNU Lesser General Public License along with this program. If
28 not, see <http://www.gnu.org/licenses/>. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000029
30#ifdef HAVE_CONFIG_H
31# include <config.h>
32#endif
33
34#include "libdwP.h"
35
36
37Dwarf_Abbrev *
Ulrich Drepper077c65f2006-07-12 19:54:51 +000038internal_function
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000039__libdw_findabbrev (struct Dwarf_CU *cu, unsigned int code)
40{
41 Dwarf_Abbrev *abb;
42
Petr Machata02c56192011-03-10 01:50:32 +010043 /* Abbreviation code can never have a value of 0. */
44 if (unlikely (code == 0))
45 return DWARF_END_ABBREV;
46
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000047 /* See whether the entry is already in the hash table. */
48 abb = Dwarf_Abbrev_Hash_find (&cu->abbrev_hash, code, NULL);
49 if (abb == NULL)
50 while (cu->last_abbrev_offset != (size_t) -1l)
51 {
52 size_t length;
53
54 /* Find the next entry. It gets automatically added to the
55 hash table. */
56 abb = __libdw_getabbrev (cu->dbg, cu, cu->last_abbrev_offset, &length,
57 NULL);
58 if (abb == NULL || abb == DWARF_END_ABBREV)
59 {
60 /* Make sure we do not try to search for it again. */
61 cu->last_abbrev_offset = (size_t) -1l;
Ulrich Drepper35f08c42008-01-18 19:59:08 +000062 return DWARF_END_ABBREV;
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000063 }
64
65 cu->last_abbrev_offset += length;
66
67 /* Is this the code we are looking for? */
68 if (abb->code == code)
69 break;
70 }
71
Petr Machatabd1d16c2011-03-16 18:16:12 +010072 /* This is our second (or third, etc.) call to __libdw_findabbrev
73 and the code is invalid. */
74 if (unlikely (abb == NULL))
75 abb = DWARF_END_ABBREV;
76
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000077 return abb;
78}
79
80
81int
82dwarf_tag (die)
83 Dwarf_Die *die;
84{
Josh Stoneb849f812014-12-10 18:28:04 -080085 /* Find the abbreviation entry. */
86 Dwarf_Abbrev *abbrevp = __libdw_dieabbrev (die, NULL);
87 if (unlikely (abbrevp == DWARF_END_ABBREV))
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000088 {
89 __libdw_seterrno (DWARF_E_INVALID_DWARF);
90 return DW_TAG_invalid;
91 }
92
Josh Stoneb849f812014-12-10 18:28:04 -080093 return abbrevp->tag;
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000094}
95INTDEF(dwarf_tag)