4 * Babeltrace - DWARF Information Reader
6 * Copyright 2015 Antoine Busque <abusque@efficios.com>
8 * Author: Antoine Busque <abusque@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 #include <babeltrace/dwarf.h>
33 struct bt_dwarf_cu
*bt_dwarf_cu_create(Dwarf
*dwarf_info
)
35 struct bt_dwarf_cu
*cu
;
41 cu
= g_new0(struct bt_dwarf_cu
, 1);
45 cu
->dwarf_info
= dwarf_info
;
53 void bt_dwarf_cu_destroy(struct bt_dwarf_cu
*cu
)
59 int bt_dwarf_cu_next(struct bt_dwarf_cu
*cu
)
62 Dwarf_Off next_offset
;
63 size_t cu_header_size
;
70 ret
= dwarf_nextcu(cu
->dwarf_info
, cu
->next_offset
, &next_offset
,
71 &cu_header_size
, NULL
, NULL
, NULL
);
73 /* ret is -1 on error, 1 if no next CU. */
77 cu
->offset
= cu
->next_offset
;
78 cu
->next_offset
= next_offset
;
79 cu
->header_size
= cu_header_size
;
86 struct bt_dwarf_die
*bt_dwarf_die_create(struct bt_dwarf_cu
*cu
)
88 Dwarf_Die
*dwarf_die
= NULL
;
89 struct bt_dwarf_die
*die
= NULL
;
95 dwarf_die
= g_new0(Dwarf_Die
, 1);
100 dwarf_die
= dwarf_offdie(cu
->dwarf_info
, cu
->offset
+ cu
->header_size
,
106 die
= g_new0(struct bt_dwarf_die
, 1);
112 die
->dwarf_die
= dwarf_die
;
124 void bt_dwarf_die_destroy(struct bt_dwarf_die
*die
)
130 g_free(die
->dwarf_die
);
135 int bt_dwarf_die_child(struct bt_dwarf_die
*die
)
138 Dwarf_Die
*child_die
= NULL
;
145 child_die
= g_new0(Dwarf_Die
, 1);
151 ret
= dwarf_child(die
->dwarf_die
, child_die
);
153 /* ret is -1 on error, 1 if no child DIE. */
157 g_free(die
->dwarf_die
);
158 die
->dwarf_die
= child_die
;
168 int bt_dwarf_die_next(struct bt_dwarf_die
*die
)
171 Dwarf_Die
*next_die
= NULL
;
178 next_die
= g_new0(Dwarf_Die
, 1);
184 if (die
->depth
== 0) {
185 ret
= dwarf_child(die
->dwarf_die
, next_die
);
187 /* ret is -1 on error, 1 if no child DIE. */
193 ret
= dwarf_siblingof(die
->dwarf_die
, next_die
);
195 /* ret is -1 on error, 1 if we reached end of
196 * DIEs at this depth. */
201 g_free(die
->dwarf_die
);
202 die
->dwarf_die
= next_die
;
211 int bt_dwarf_die_get_tag(struct bt_dwarf_die
*die
, int *tag
)
219 _tag
= dwarf_tag(die
->dwarf_die
);
220 if (_tag
== DW_TAG_invalid
) {
232 int bt_dwarf_die_get_name(struct bt_dwarf_die
*die
, char **name
)
240 _name
= dwarf_diename(die
->dwarf_die
);
245 *name
= strdup(_name
);
257 int bt_dwarf_die_get_call_file(struct bt_dwarf_die
*die
, char **filename
)
261 const char *_filename
= NULL
;
262 Dwarf_Files
*src_files
= NULL
;
263 Dwarf_Attribute
*file_attr
= NULL
;
264 struct bt_dwarf_die
*cu_die
= NULL
;
266 if (!die
|| !filename
) {
270 file_attr
= g_new0(Dwarf_Attribute
, 1);
275 file_attr
= dwarf_attr(die
->dwarf_die
, DW_AT_call_file
, file_attr
);
280 ret
= dwarf_formsdata(file_attr
, &file_no
);
285 cu_die
= bt_dwarf_die_create(die
->cu
);
290 ret
= dwarf_getsrcfiles(cu_die
->dwarf_die
, &src_files
, NULL
);
295 _filename
= dwarf_filesrc(src_files
, file_no
, NULL
, NULL
);
300 *filename
= strdup(_filename
);
302 bt_dwarf_die_destroy(cu_die
);
308 bt_dwarf_die_destroy(cu_die
);
315 int bt_dwarf_die_get_call_line(struct bt_dwarf_die
*die
,
319 Dwarf_Attribute
*line_attr
= NULL
;
322 if (!die
|| !line_no
) {
326 line_attr
= g_new0(Dwarf_Attribute
, 1);
331 line_attr
= dwarf_attr(die
->dwarf_die
, DW_AT_call_line
, line_attr
);
336 ret
= dwarf_formudata(line_attr
, &_line_no
);
353 int bt_dwarf_die_contains_addr(struct bt_dwarf_die
*die
, uint64_t addr
,
358 ret
= dwarf_haspc(die
->dwarf_die
, addr
);
363 *contains
= (ret
== 1);
This page took 0.036177 seconds and 4 git commands to generate.