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
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_has_children(struct bt_dwarf_die
*die
)
137 return dwarf_haschildren(die
->dwarf_die
);
141 int bt_dwarf_die_child(struct bt_dwarf_die
*die
)
144 Dwarf_Die
*child_die
= NULL
;
151 child_die
= g_new0(Dwarf_Die
, 1);
157 ret
= dwarf_child(die
->dwarf_die
, child_die
);
159 /* ret is -1 on error, 1 if no child DIE. */
163 g_free(die
->dwarf_die
);
164 die
->dwarf_die
= child_die
;
174 int bt_dwarf_die_next(struct bt_dwarf_die
*die
)
177 Dwarf_Die
*next_die
= NULL
;
184 next_die
= g_new0(Dwarf_Die
, 1);
190 if (die
->depth
== 0) {
191 ret
= dwarf_child(die
->dwarf_die
, next_die
);
193 /* ret is -1 on error, 1 if no child DIE. */
199 ret
= dwarf_siblingof(die
->dwarf_die
, next_die
);
201 /* ret is -1 on error, 1 if we reached end of
202 * DIEs at this depth. */
207 g_free(die
->dwarf_die
);
208 die
->dwarf_die
= next_die
;
217 int bt_dwarf_die_get_tag(struct bt_dwarf_die
*die
, int *tag
)
225 _tag
= dwarf_tag(die
->dwarf_die
);
226 if (_tag
== DW_TAG_invalid
) {
238 int bt_dwarf_die_get_name(struct bt_dwarf_die
*die
, char **name
)
246 _name
= dwarf_diename(die
->dwarf_die
);
251 *name
= g_strdup(_name
);
263 int bt_dwarf_die_get_call_file(struct bt_dwarf_die
*die
, char **filename
)
267 const char *_filename
= NULL
;
268 Dwarf_Files
*src_files
= NULL
;
269 Dwarf_Attribute
*file_attr
= NULL
;
270 struct bt_dwarf_die
*cu_die
= NULL
;
272 if (!die
|| !filename
) {
276 file_attr
= g_new0(Dwarf_Attribute
, 1);
281 file_attr
= dwarf_attr(die
->dwarf_die
, DW_AT_call_file
, file_attr
);
286 ret
= dwarf_formsdata(file_attr
, &file_no
);
291 cu_die
= bt_dwarf_die_create(die
->cu
);
296 ret
= dwarf_getsrcfiles(cu_die
->dwarf_die
, &src_files
, NULL
);
301 _filename
= dwarf_filesrc(src_files
, file_no
, NULL
, NULL
);
306 *filename
= g_strdup(_filename
);
308 bt_dwarf_die_destroy(cu_die
);
314 bt_dwarf_die_destroy(cu_die
);
321 int bt_dwarf_die_get_call_line(struct bt_dwarf_die
*die
,
325 Dwarf_Attribute
*line_attr
= NULL
;
328 if (!die
|| !line_no
) {
332 line_attr
= g_new0(Dwarf_Attribute
, 1);
337 line_attr
= dwarf_attr(die
->dwarf_die
, DW_AT_call_line
, line_attr
);
342 ret
= dwarf_formudata(line_attr
, &_line_no
);
359 int bt_dwarf_die_contains_addr(struct bt_dwarf_die
*die
, uint64_t addr
,
364 ret
= dwarf_haspc(die
->dwarf_die
, addr
);
369 *contains
= (ret
== 1);
This page took 0.03814 seconds and 4 git commands to generate.