blob: 337a3e104d45c12e7ad112614dd757d533cdc1b3 [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Determine whether die has attribute specified of given type.
2 Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
3 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
4
5 This program is Open Source software; you can redistribute it and/or
6 modify it under the terms of the Open Software License version 1.0 as
7 published by the Open Source Initiative.
8
9 You should have received a copy of the Open Software License along
10 with this program; if not, you may obtain a copy of the Open Software
11 License version 1.0 from http://www.opensource.org/licenses/osl.php or
12 by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
13 3001 King Ranch Road, Ukiah, CA 95482. */
14
15#ifdef HAVE_CONFIG_H
16# include <config.h>
17#endif
18
19#include <libdwarfP.h>
20
21
22int
23dwarf_hasattr (die, attr, return_bool, error)
24 Dwarf_Die die;
25 Dwarf_Half attr;
26 Dwarf_Bool *return_bool;
27 Dwarf_Error *error;
28{
29 Dwarf_Debug dbg = die->cu->dbg;
30 Dwarf_Small *die_addr;
31 Dwarf_Word u128;
32 Dwarf_Abbrev abbrev;
33 Dwarf_Small *attrp;
34
35 /* Address of the given die. */
36 die_addr = die->addr;
37
38 /* Get abbrev code. */
39 get_uleb128 (u128, die_addr);
40 /* And get the abbreviation itself. */
41 abbrev = __libdwarf_get_abbrev (dbg, die->cu, u128, error);
42 if (abbrev == NULL)
43 return DW_DLV_ERROR;
44
45 /* This is where the attributes start. */
46 attrp = abbrev->attrp;
47
48 /* Search the name attribute. */
49 while (1)
50 {
51 Dwarf_Word attr_name;
52 Dwarf_Word attr_form;
53
54 /* Are we still in bounds? */
55 if (unlikely (attrp
56 >= ((Dwarf_Small *) dbg->sections[IDX_debug_abbrev].addr
57 + dbg->sections[IDX_debug_abbrev].size)))
58 {
59 __libdwarf_error (dbg, error, DW_E_INVALID_DWARF);
60 return DW_DLV_ERROR;
61 }
62
63 /* Get attribute name and form.
64
65 XXX We don't check whether this reads beyond the end of the
66 section. */
67 get_uleb128 (attr_name, attrp);
68 get_uleb128 (attr_form, attrp);
69
70 /* We can stop if we found the attribute with value zero. */
71 if (attr_name == 0 && attr_form == 0)
72 break;
73
74 /* Is this the name attribute? */
75 if (attr_name == attr)
76 {
77 *return_bool = 1;
78 return DW_DLV_OK;
79 }
80
81 /* Skip over the rest of this attribute (if there is any). */
82 if (attr_form != 0)
83 {
84 size_t len;
85
86 if (unlikely (__libdwarf_form_val_len (dbg, die->cu, attr_form,
87 die_addr, &len, error)
88 != DW_DLV_OK))
89 return DW_DLV_ERROR;
90
91 die_addr += len;
92 }
93 }
94
95 /* No such attribute present. */
96 *return_bool = 0;
97 return DW_DLV_OK;
98}