1*7304104dSAndroid Build Coastguard Worker /* Common interface for libebl modules.
2*7304104dSAndroid Build Coastguard Worker Copyright (C) 2000, 2001, 2002, 2003, 2005, 2013, 2014 Red Hat, Inc.
3*7304104dSAndroid Build Coastguard Worker Copyright (C) 2023 Mark J. Wielaard <[email protected]>
4*7304104dSAndroid Build Coastguard Worker This file is part of elfutils.
5*7304104dSAndroid Build Coastguard Worker
6*7304104dSAndroid Build Coastguard Worker This file is free software; you can redistribute it and/or modify
7*7304104dSAndroid Build Coastguard Worker it under the terms of either
8*7304104dSAndroid Build Coastguard Worker
9*7304104dSAndroid Build Coastguard Worker * the GNU Lesser General Public License as published by the Free
10*7304104dSAndroid Build Coastguard Worker Software Foundation; either version 3 of the License, or (at
11*7304104dSAndroid Build Coastguard Worker your option) any later version
12*7304104dSAndroid Build Coastguard Worker
13*7304104dSAndroid Build Coastguard Worker or
14*7304104dSAndroid Build Coastguard Worker
15*7304104dSAndroid Build Coastguard Worker * the GNU General Public License as published by the Free
16*7304104dSAndroid Build Coastguard Worker Software Foundation; either version 2 of the License, or (at
17*7304104dSAndroid Build Coastguard Worker your option) any later version
18*7304104dSAndroid Build Coastguard Worker
19*7304104dSAndroid Build Coastguard Worker or both in parallel, as here.
20*7304104dSAndroid Build Coastguard Worker
21*7304104dSAndroid Build Coastguard Worker elfutils is distributed in the hope that it will be useful, but
22*7304104dSAndroid Build Coastguard Worker WITHOUT ANY WARRANTY; without even the implied warranty of
23*7304104dSAndroid Build Coastguard Worker MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24*7304104dSAndroid Build Coastguard Worker General Public License for more details.
25*7304104dSAndroid Build Coastguard Worker
26*7304104dSAndroid Build Coastguard Worker You should have received copies of the GNU General Public License and
27*7304104dSAndroid Build Coastguard Worker the GNU Lesser General Public License along with this program. If
28*7304104dSAndroid Build Coastguard Worker not, see <http://www.gnu.org/licenses/>. */
29*7304104dSAndroid Build Coastguard Worker
30*7304104dSAndroid Build Coastguard Worker #ifndef _LIBEBL_CPU_H
31*7304104dSAndroid Build Coastguard Worker #define _LIBEBL_CPU_H 1
32*7304104dSAndroid Build Coastguard Worker
33*7304104dSAndroid Build Coastguard Worker #include <dwarf.h>
34*7304104dSAndroid Build Coastguard Worker #include <libeblP.h>
35*7304104dSAndroid Build Coastguard Worker
36*7304104dSAndroid Build Coastguard Worker #define EBLHOOK(name) EBLHOOK_1(BACKEND, name)
37*7304104dSAndroid Build Coastguard Worker #define EBLHOOK_1(a, b) EBLHOOK_2(a, b)
38*7304104dSAndroid Build Coastguard Worker #define EBLHOOK_2(a, b) a##b
39*7304104dSAndroid Build Coastguard Worker
40*7304104dSAndroid Build Coastguard Worker /* Constructor. */
41*7304104dSAndroid Build Coastguard Worker extern Ebl *EBLHOOK(init) (Elf *elf, GElf_Half machine, Ebl *eh);
42*7304104dSAndroid Build Coastguard Worker
43*7304104dSAndroid Build Coastguard Worker #include "ebl-hooks.h"
44*7304104dSAndroid Build Coastguard Worker
45*7304104dSAndroid Build Coastguard Worker #define HOOK(eh, name) eh->name = EBLHOOK(name)
46*7304104dSAndroid Build Coastguard Worker
47*7304104dSAndroid Build Coastguard Worker extern bool (*generic_debugscn_p) (const char *) attribute_hidden;
48*7304104dSAndroid Build Coastguard Worker
49*7304104dSAndroid Build Coastguard Worker /* Helper for retval. Return dwarf_tag (die), but calls return -1
50*7304104dSAndroid Build Coastguard Worker if there where previous errors that leave die NULL. */
51*7304104dSAndroid Build Coastguard Worker #define DWARF_TAG_OR_RETURN(die) \
52*7304104dSAndroid Build Coastguard Worker ({ Dwarf_Die *_die = (die); \
53*7304104dSAndroid Build Coastguard Worker if (_die == NULL) return -1; \
54*7304104dSAndroid Build Coastguard Worker dwarf_tag (_die); })
55*7304104dSAndroid Build Coastguard Worker
56*7304104dSAndroid Build Coastguard Worker /* Get a type die corresponding to DIE. Peel CV qualifiers off
57*7304104dSAndroid Build Coastguard Worker it. Returns zero if the DIE doesn't have a type, or the type
58*7304104dSAndroid Build Coastguard Worker is DW_TAG_unspecified_type. Returns -1 on error. Otherwise
59*7304104dSAndroid Build Coastguard Worker returns the result tag DW_AT value. */
60*7304104dSAndroid Build Coastguard Worker static inline int
dwarf_peeled_die_type(Dwarf_Die * die,Dwarf_Die * result)61*7304104dSAndroid Build Coastguard Worker dwarf_peeled_die_type (Dwarf_Die *die, Dwarf_Die *result)
62*7304104dSAndroid Build Coastguard Worker {
63*7304104dSAndroid Build Coastguard Worker Dwarf_Attribute attr_mem;
64*7304104dSAndroid Build Coastguard Worker Dwarf_Attribute *attr = dwarf_attr_integrate (die, DW_AT_type, &attr_mem);
65*7304104dSAndroid Build Coastguard Worker if (attr == NULL)
66*7304104dSAndroid Build Coastguard Worker /* The function has no return value, like a `void' function in C. */
67*7304104dSAndroid Build Coastguard Worker return 0;
68*7304104dSAndroid Build Coastguard Worker
69*7304104dSAndroid Build Coastguard Worker if (result == NULL)
70*7304104dSAndroid Build Coastguard Worker return -1;
71*7304104dSAndroid Build Coastguard Worker
72*7304104dSAndroid Build Coastguard Worker if (dwarf_formref_die (attr, result) == NULL)
73*7304104dSAndroid Build Coastguard Worker return -1;
74*7304104dSAndroid Build Coastguard Worker
75*7304104dSAndroid Build Coastguard Worker if (dwarf_peel_type (result, result) != 0)
76*7304104dSAndroid Build Coastguard Worker return -1;
77*7304104dSAndroid Build Coastguard Worker
78*7304104dSAndroid Build Coastguard Worker int tag = dwarf_tag (result);
79*7304104dSAndroid Build Coastguard Worker if (tag == DW_TAG_unspecified_type)
80*7304104dSAndroid Build Coastguard Worker return 0; /* Treat an unspecified type as if there was no type. */
81*7304104dSAndroid Build Coastguard Worker
82*7304104dSAndroid Build Coastguard Worker return tag;
83*7304104dSAndroid Build Coastguard Worker }
84*7304104dSAndroid Build Coastguard Worker
85*7304104dSAndroid Build Coastguard Worker static inline bool
dwarf_is_pointer(int tag)86*7304104dSAndroid Build Coastguard Worker dwarf_is_pointer (int tag)
87*7304104dSAndroid Build Coastguard Worker {
88*7304104dSAndroid Build Coastguard Worker return tag == DW_TAG_pointer_type
89*7304104dSAndroid Build Coastguard Worker || tag == DW_TAG_ptr_to_member_type
90*7304104dSAndroid Build Coastguard Worker || tag == DW_TAG_reference_type
91*7304104dSAndroid Build Coastguard Worker || tag == DW_TAG_rvalue_reference_type;
92*7304104dSAndroid Build Coastguard Worker }
93*7304104dSAndroid Build Coastguard Worker
94*7304104dSAndroid Build Coastguard Worker #define CASE_POINTER \
95*7304104dSAndroid Build Coastguard Worker case DW_TAG_pointer_type: \
96*7304104dSAndroid Build Coastguard Worker case DW_TAG_ptr_to_member_type: \
97*7304104dSAndroid Build Coastguard Worker case DW_TAG_reference_type: \
98*7304104dSAndroid Build Coastguard Worker case DW_TAG_rvalue_reference_type
99*7304104dSAndroid Build Coastguard Worker
100*7304104dSAndroid Build Coastguard Worker #endif /* libebl_CPU.h */
101