-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathobjects.h
252 lines (218 loc) · 6.08 KB
/
objects.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/*
Copyright(C) 2016, Red Hat, Inc., Jerome Marchand
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/>.
*/
/*
* Internal representation of symbols
*/
#ifndef _OBJECTS_H
#define _OBJECTS_H
#include <stdbool.h>
#include <stdio.h>
#include "list.h"
#include "utils.h"
#ifdef DEBUG
#define debug(args...) do { printf(args); } while (0)
#else
#define debug(args...)
#endif
struct set;
enum merge_flag {
MERGE_DEFAULT = 0,
MERGE_FLAG_DECL_MERGE = 1 << 0,
MERGE_FLAG_VER_IGNORE = 1 << 1,
MERGE_FLAG_DECL_EQ = 1 << 2,
};
typedef enum {
__type_reffile,
__type_struct,
__type_union,
__type_enum,
__type_func,
__type_ptr,
__type_typedef,
__type_array,
__type_var, /* a variable, member of an union or a function argument */
__type_struct_member,
__type_qualifier, /* a type qualifier such as "const" or "volatile" */
__type_base,
__type_constant, /* An element of an enumeration */
__type_assembly,
__type_weak,
NR_OBJ_TYPES
} obj_types;
struct obj;
typedef struct obj_list {
struct obj *member;
struct obj_list *next;
} obj_list_t;
typedef struct obj_list_head {
obj_list_t *first, *last;
struct obj *object;
} obj_list_head_t;
/*
* Structure representing symbols. Several field are overloaded.
*
* type: type of the symbol (such as struct, function, pointer, base
* type...)
* is_bitfield: (var) It's a bitfield
* first_bit, last_bit: (var) bit range within the offset.
* name: name of the symbol
* ref_record: (reffile) pointer to the referenced record (only while
* generating records, otherwise base_type with string is used)
* base_type: (base type) the type of the symbol,
* (qualifier) the type qualifier (const or volatile)
* (reffile) path to the file
* alignment: value of DW_AT_alignment attribute or 0 if not present
* member_list: (struct, union, enum) list of members
* (function) list of arguments
* ptr: (pointer) object pointed to
* (typedef) defined type
* (function) return type
* (var) type
* constant: (constant) constant value of an enumeration
* index: (array) index of array
* link: (weak) weak alias link
* offset: (var) offset of a struct member
* depend_rec_node: (reffile) node from dependents field of record where
* this obj references.
*
* Note the dual parent/child relationship with the n-ary member_list and the
* the unary ptr. Only functions uses both.
*/
typedef struct obj {
obj_types type;
unsigned char is_bitfield, first_bit, last_bit;
union {
const char *name;
struct record *ref_record;
};
const char *base_type;
unsigned alignment;
unsigned int byte_size;
obj_list_head_t *member_list;
struct obj *ptr, *parent;
union {
unsigned long constant;
unsigned long index;
char *link;
unsigned long offset;
struct list_node *depend_rec_node;
};
char *ns;
} obj_t;
static inline bool has_offset(obj_t *o)
{
return o->type == __type_struct_member;
}
static inline bool has_constant(obj_t *o)
{
return o->type == __type_constant;
}
static inline bool has_index(obj_t *o)
{
return o->type == __type_array;
}
static inline bool is_bitfield(obj_t *o)
{
return o->is_bitfield != 0;
}
static inline bool is_terminal(obj_t *o)
{
switch (o->type) {
case __type_reffile:
case __type_base:
case __type_constant:
return true;
default:
return false;
}
}
static inline bool is_unary(obj_t *o)
{
switch (o->type) {
case __type_ptr:
case __type_typedef:
case __type_array:
case __type_var:
case __type_struct_member:
case __type_qualifier:
return true;
default:
return false;
}
}
static inline bool is_n_ary(obj_t *o)
{
switch (o->type) {
case __type_struct:
case __type_union:
case __type_enum:
case __type_func:
return true;
default:
return false;
}
}
static inline bool is_weak(obj_t *o)
{
return o->type == __type_weak;
}
/*
* Display options
*
* Used for show and compare commands.
*/
struct dopt {
int no_offset; /* Don't display struct offset */
};
extern struct dopt display_options;
/* Return values for tree walk callbacks */
typedef enum {
CB_CONT = 0, /* Continue tree walk */
CB_SKIP, /* Skip the children of this node */
CB_FAIL, /* Failed: stop the walk */
} cb_ret_t;
typedef int cb_t(obj_t *o, void *args);
obj_list_t *obj_list_new(obj_t *obj);
obj_list_head_t *obj_list_head_new(obj_t *obj);
void obj_list_add(obj_list_head_t *head, obj_t *obj);
void obj_free(obj_t *o);
obj_t *obj_struct_new(char *name);
obj_t *obj_union_new(char *name);
obj_t *obj_enum_new(char *name);
obj_t *obj_constant_new(char *name);
obj_t *obj_reffile_new();
obj_t *obj_func_new_add(char *name, obj_t *obj);
obj_t *obj_typedef_new_add(char *name, obj_t *obj);
obj_t *obj_var_new_add(char *name, obj_t *obj);
obj_t *obj_struct_member_new_add(char *name, obj_t *obj);
obj_t *obj_ptr_new_add(obj_t *obj);
obj_t *obj_array_new_add(obj_t *obj);
obj_t *obj_qualifier_new_add(obj_t *obj);
obj_t *obj_assembly_new(char *name);
obj_t *obj_weak_new(char *name);
obj_t *obj_basetype_new(char *base_type);
void obj_print_tree(obj_t *root);
void obj_print_tree__prefix(obj_t *root, const char *prefix, FILE *stream);
int obj_debug_tree(obj_t *root);
void obj_fill_parent(obj_t *root);
int obj_walk_tree(obj_t *root, cb_t cb, void *args);
int obj_walk_tree3(obj_t *o, cb_t cb_pre, cb_t cb_in, cb_t cb_post,
void *args, bool ptr_first);
int obj_hide_kabi(obj_t *root, bool show_new_field);
obj_t *obj_parse(FILE *file, char *fn);
obj_t *obj_merge(obj_t *o1, obj_t *o2, unsigned int flags);
void obj_dump(obj_t *o, FILE *f);
bool obj_eq(obj_t *o1, obj_t *o2, bool ignore_versions);
bool obj_same_declarations(obj_t *o1, obj_t *o2, struct set *processed);
#endif