1 /* Return DWARF attribute associated with a location expression op.
2 Copyright (C) 2013, 2014 Red Hat, Inc.
3 This file is part of elfutils.
5 This file is free software; you can redistribute it and/or modify
6 it under the terms of either
8 * the GNU Lesser General Public License as published by the Free
9 Software Foundation; either version 3 of the License, or (at
10 your option) any later version
14 * the GNU General Public License as published by the Free
15 Software Foundation; either version 2 of the License, or (at
16 your option) any later version
18 or both in parallel, as here.
20 elfutils is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received copies of the GNU General Public License and
26 the GNU Lesser General Public License along with this program. If
27 not, see <http://www.gnu.org/licenses/>. */
37 attr_form_cu (Dwarf_Attribute *attr)
39 /* If the attribute has block/expr form the data comes from the
40 .debug_info from the same cu as the attr. Otherwise it comes from
41 the .debug_loc data section. */
51 return attr->cu->dbg->fake_loc_cu;
56 dwarf_getlocation_attr (Dwarf_Attribute *attr, const Dwarf_Op *op, Dwarf_Attribute *result)
63 case DW_OP_implicit_value:
64 result->code = DW_AT_const_value;
65 result->form = DW_FORM_block;
66 result->valp = (unsigned char *) (uintptr_t) op->number2;
67 result->cu = attr_form_cu (attr);
70 case DW_OP_GNU_entry_value:
71 result->code = DW_AT_location;
72 result->form = DW_FORM_exprloc;
73 result->valp = (unsigned char *) (uintptr_t) op->number2;
74 result->cu = attr_form_cu (attr);
77 case DW_OP_GNU_const_type:
78 result->code = DW_AT_const_value;
79 result->form = DW_FORM_block1;
80 result->valp = (unsigned char *) (uintptr_t) op->number2;
81 result->cu = attr_form_cu (attr);
89 if (INTUSE(dwarf_getlocation_die) (attr, op, &die) != 0)
91 if (INTUSE(dwarf_attr) (&die, DW_AT_location, result) == NULL)
93 __libdw_empty_loc_attr (result);
99 case DW_OP_GNU_implicit_pointer:
102 if (INTUSE(dwarf_getlocation_die) (attr, op, &die) != 0)
104 if (INTUSE(dwarf_attr) (&die, DW_AT_location, result) == NULL
105 && INTUSE(dwarf_attr) (&die, DW_AT_const_value, result) == NULL)
107 __libdw_empty_loc_attr (result);
114 __libdw_seterrno (DWARF_E_INVALID_ACCESS);