2 * SPDX-License-Identifier: MIT
4 * Copyright 2015 Antoine Busque <abusque@efficios.com>
6 * Babeltrace - DWARF Information Reader
16 struct bt_dwarf_cu
*bt_dwarf_cu_create(Dwarf
*dwarf_info
)
18 struct bt_dwarf_cu
*cu
;
24 cu
= g_new0(struct bt_dwarf_cu
, 1);
28 cu
->dwarf_info
= dwarf_info
;
36 void bt_dwarf_cu_destroy(struct bt_dwarf_cu
*cu
)
42 int bt_dwarf_cu_next(struct bt_dwarf_cu
*cu
)
45 Dwarf_Off next_offset
;
46 size_t cu_header_size
;
53 ret
= dwarf_nextcu(cu
->dwarf_info
, cu
->next_offset
, &next_offset
,
54 &cu_header_size
, NULL
, NULL
, NULL
);
56 /* ret is -1 on error, 1 if no next CU. */
60 cu
->offset
= cu
->next_offset
;
61 cu
->next_offset
= next_offset
;
62 cu
->header_size
= cu_header_size
;
69 struct bt_dwarf_die
*bt_dwarf_die_create(struct bt_dwarf_cu
*cu
)
71 Dwarf_Die
*dwarf_die
= NULL
;
72 struct bt_dwarf_die
*die
= NULL
;
78 dwarf_die
= g_new0(Dwarf_Die
, 1);
83 dwarf_die
= dwarf_offdie(cu
->dwarf_info
, cu
->offset
+ cu
->header_size
,
89 die
= g_new0(struct bt_dwarf_die
, 1);
95 die
->dwarf_die
= dwarf_die
;
107 void bt_dwarf_die_destroy(struct bt_dwarf_die
*die
)
113 g_free(die
->dwarf_die
);
118 int bt_dwarf_die_has_children(struct bt_dwarf_die
*die
)
120 return dwarf_haschildren(die
->dwarf_die
);
124 int bt_dwarf_die_child(struct bt_dwarf_die
*die
)
127 Dwarf_Die
*child_die
= NULL
;
134 child_die
= g_new0(Dwarf_Die
, 1);
140 ret
= dwarf_child(die
->dwarf_die
, child_die
);
142 /* ret is -1 on error, 1 if no child DIE. */
146 g_free(die
->dwarf_die
);
147 die
->dwarf_die
= child_die
;
157 int bt_dwarf_die_next(struct bt_dwarf_die
*die
)
160 Dwarf_Die
*next_die
= NULL
;
167 next_die
= g_new0(Dwarf_Die
, 1);
173 if (die
->depth
== 0) {
174 ret
= dwarf_child(die
->dwarf_die
, next_die
);
176 /* ret is -1 on error, 1 if no child DIE. */
182 ret
= dwarf_siblingof(die
->dwarf_die
, next_die
);
184 /* ret is -1 on error, 1 if we reached end of
185 * DIEs at this depth. */
190 g_free(die
->dwarf_die
);
191 die
->dwarf_die
= next_die
;
200 int bt_dwarf_die_get_tag(struct bt_dwarf_die
*die
, int *tag
)
208 _tag
= dwarf_tag(die
->dwarf_die
);
209 if (_tag
== DW_TAG_invalid
) {
221 int bt_dwarf_die_get_name(struct bt_dwarf_die
*die
, char **name
)
229 _name
= dwarf_diename(die
->dwarf_die
);
234 *name
= g_strdup(_name
);
246 int bt_dwarf_die_get_call_file(struct bt_dwarf_die
*die
, char **filename
)
250 const char *_filename
= NULL
;
251 Dwarf_Files
*src_files
= NULL
;
252 Dwarf_Attribute
*file_attr
= NULL
;
253 struct bt_dwarf_die
*cu_die
= NULL
;
255 if (!die
|| !filename
) {
259 file_attr
= g_new0(Dwarf_Attribute
, 1);
264 file_attr
= dwarf_attr(die
->dwarf_die
, DW_AT_call_file
, file_attr
);
269 ret
= dwarf_formsdata(file_attr
, &file_no
);
274 cu_die
= bt_dwarf_die_create(die
->cu
);
279 ret
= dwarf_getsrcfiles(cu_die
->dwarf_die
, &src_files
, NULL
);
284 _filename
= dwarf_filesrc(src_files
, file_no
, NULL
, NULL
);
289 *filename
= g_strdup(_filename
);
291 bt_dwarf_die_destroy(cu_die
);
297 bt_dwarf_die_destroy(cu_die
);
304 int bt_dwarf_die_get_call_line(struct bt_dwarf_die
*die
,
308 Dwarf_Attribute
*line_attr
= NULL
;
311 if (!die
|| !line_no
) {
315 line_attr
= g_new0(Dwarf_Attribute
, 1);
320 line_attr
= dwarf_attr(die
->dwarf_die
, DW_AT_call_line
, line_attr
);
325 ret
= dwarf_formudata(line_attr
, &_line_no
);
342 int bt_dwarf_die_contains_addr(struct bt_dwarf_die
*die
, uint64_t addr
,
347 ret
= dwarf_haspc(die
->dwarf_die
, addr
);
352 *contains
= (ret
== 1);
This page took 0.037208 seconds and 4 git commands to generate.