-
Notifications
You must be signed in to change notification settings - Fork 2
/
reflP.h
145 lines (119 loc) · 4.55 KB
/
reflP.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Copyright (C) 2011, 2013 Petr Machata <pmachata@redhat.com>
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _REFLP_H_INCLUDED
#define _REFLP_H_INCLUDED
#include <elfutils/libdwfl.h>
#include "refl.h"
enum __refl_major_errcode
{
REFL_E_NOERROR,
REFL_E_REFL,
REFL_E_SYSTEM,
REFL_E_DWFL,
REFL_E_DWARF,
};
enum __refl_minor_errcode
{
REFL_ME_DWARF,
REFL_ME_NOT_FOUND,
REFL_ME_MISMATCH,
};
struct refl
{
Dwfl *dwfl;
};
struct refl_method
{
Dwarf_Die die;
char const *name;
};
struct refl_type
{
Dwarf_Die die;
size_t size;
};
struct refl_object
{
struct refl_type *type;
void *data;
};
void __refl_seterr_2 (enum __refl_major_errcode major, int minor);
void __refl_seterr (enum __refl_major_errcode major);
void *__refl_malloc (size_t size);
struct refl_method *__refl_method_begin (Dwarf_Die *die);
struct refl_type *__refl_type_begin (Dwarf_Die *die);
void __refl_type_free (struct refl_type *type);
struct refl_object *__refl_object_begin (struct refl_type *type, void *data);
struct refl_object *__refl_object_begin_inline (struct refl_type *type,
size_t size);
/* Iterate die tree rooted at ROOT. At each die, CALLBACK is called
with that die and DATA. If CALLBACK returns refl_cb_next, the
iteration continues; on return of refl_cb_fail, iteration stops and
a negative value is returned. On return of refl_cb_stop, the
iteration stops, current die is copied to RET, and non-negative
value is returned. */
int __refl_die_tree (Dwarf_Die *root, Dwarf_Die *ret, bool recurse,
enum refl_cb_status (*callback) (Dwarf_Die *die,
void *data),
void *data);
/* Like above, but exclude ROOT itself from iteration. */
int __refl_die_children (Dwarf_Die *root, Dwarf_Die *ret, bool recurse,
enum refl_cb_status (*callback) (Dwarf_Die *die,
void *data),
void *data);
/* Iterate all CU's in module. Calls __refl_die_tree under the hood,
the protocol is the same. */
int __refl_each_die (Dwfl_Module *module, Dwarf_Die *root, Dwarf_Die *ret,
enum refl_cb_status (*callback) (Dwarf_Die *die,
void *data),
void *data);
/* Wrapper around dwarf_attr_integrate that sets error on failure. */
Dwarf_Attribute *__refl_attr_integrate (Dwarf_Die *die, int name,
Dwarf_Attribute *mem);
/* Find DW_AT_name of DIE and return the corresponding string. Return
NULL and set an error if it fails or name is unavailable. */
char const *__refl_die_name (Dwarf_Die *die);
struct __refl_die_attr_pred
{
int at_name;
enum refl_cb_status (*callback) (Dwarf_Attribute *attr, void *data);
void *data;
};
/* Callback for die iteration. Use as an argument to __refl_die_tree
and friends. DATA shall be a pointer to struct __refl_die_tree.
An attribute named DATA->at_name is looked up in each visited die,
and if present, DATA->callback is called with that attribute and
DATA->data as arguments. */
enum refl_cb_status __refl_die_attr_pred (Dwarf_Die *die, void *data);
/* Callback for __refl_die_attr_pred. ATTR shall be a string
attribute, whose value is compared to DATA. Iteration stops, if
the two match. */
enum refl_cb_status __refl_attr_match_string (Dwarf_Attribute *attr,
void *data);
/* Wrapper around dwarf_attr_integrate that sets error on failure. */
Dwarf_Attribute *__refl_attr_integrate (Dwarf_Die *die, int name,
Dwarf_Attribute *mem);
/* Find DW_AT_name of DIE and return the corresponding string. Return
NULL and set an error if it fails or name is unavailable. */
char const *__refl_die_name (Dwarf_Die *die);
/* Find DW_AT_type of DIE and return the corresponding Die. Return
NULL and set an error if it fails or type is unavailable. */
Dwarf_Die *__refl_die_type (Dwarf_Die *die, Dwarf_Die *ret_mem);
/* Strip const and volatile qualifiers from a type die DIE. Return
NULL and set an error if it fails. */
Dwarf_Die *__refl_die_strip_cvq (Dwarf_Die *die, Dwarf_Die *ret_mem);
#endif//_REFLP_H_INCLUDED