aboutsummaryrefslogtreecommitdiff
path: root/libdwarf/dwarf_child.3
blob: 1e32e58d44514fb0514bbdcca73223efcae57cdf (plain) (blame)
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
.\" Copyright (c) 2010,2014 Kai Wang
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $Id: dwarf_child.3 3127 2014-12-21 19:09:19Z jkoshy $
.\"
.Dd December 21, 2014
.Os
.Dt DWARF_CHILD 3
.Sh NAME
.Nm dwarf_child ,
.Nm dwarf_offdie ,
.Nm dwarf_offdie_b ,
.Nm dwarf_siblingof ,
.Nm dwarf_siblingof_b
.Nd retrieve DWARF Debugging Information Entry descriptors
.Sh LIBRARY
.Lb libdwarf
.Sh SYNOPSIS
.In libdwarf.h
.Ft int
.Fn dwarf_child "Dwarf_Die die" "Dwarf_Die *ret_die" "Dwarf_Error *err"
.Ft int
.Fo dwarf_offdie
.Fa "Dwarf_Debug dbg"
.Fa "Dwarf_Off offset"
.Fa "Dwarf_Die *ret_die"
.Fa "Dwarf_Error *err"
.Fc
.Ft int
.Fo dwarf_offdie_b
.Fa "Dwarf_Debug dbg"
.Fa "Dwarf_Off offset"
.Fa "Dwarf_Bool is_info"
.Fa "Dwarf_Die *ret_die"
.Fa "Dwarf_Error *err"
.Fc
.Ft int
.Fo dwarf_siblingof
.Fa "Dwarf_Debug dbg"
.Fa "Dwarf_Die die"
.Fa "Dwarf_Die *ret_die"
.Fa "Dwarf_Error *err"
.Fc
.Ft int
.Fo dwarf_siblingof_b
.Fa "Dwarf_Debug dbg"
.Fa "Dwarf_Die die"
.Fa "Dwarf_Die *ret_die"
.Fa "Dwarf_Bool is_info"
.Fa "Dwarf_Error *err"
.Fc
.Sh DESCRIPTION
These functions are used to retrieve and traverse DWARF
Debugging Information Entry (DIE) descriptors associated with
a compilation unit.
These descriptors are arranged in the form of a tree, traversable
using
.Dq child
and
.Dq sibling
links; see
.Xr dwarf 3
for more information.
DWARF Debugging Information Entry descriptors are represented
by the
.Vt Dwarf_Die
opaque type.
.Pp
Function
.Fn dwarf_child
retrieves the child of descriptor denoted by argument
.Ar die ,
and stores it in the location pointed to by argument
.Ar ret_die .
.Pp
Function
.Fn dwarf_siblingof
retrieves the sibling of the descriptor denoted by argument
.Ar die ,
and stores it in the location pointed to by argument
.Ar ret_die .
If argument
.Ar die
is NULL, the first debugging information entry descriptor for the
current compilation unit will be returned.
This function and function
.Fn dwarf_child
may be used together to traverse the tree of debugging information
entry descriptors for a compilation unit.
.Pp
Function
.Fn dwarf_siblingof_b
is identical to the function
.Fn dwarf_siblingof
except that it can retrieve the sibling descriptor from either the
current compilation unit or type unit.
If argument
.Ar is_info
is non-zero, the function behaves identically to function
.Fn dwarf_siblingof .
If argument
.Ar is_info
is zero, the descriptor referred by argument
.Ar die
should be associated with a debugging information entry in the
type unit.
The function will store the sibling of the descriptor in the location
pointed to by argument
.Ar ret_die .
If argument
.Ar is_info
is zero and argument
.Ar die
is
.Dv NULL ,
the first debugging information entry descriptor for the
current type unit will be returned.
.Pp
Function
.Fn dwarf_offdie
retrieves the debugging information entry descriptor at global offset
.Ar offset
in the
.Dq .debug_info
section of the object associated with argument
.Ar dbg .
The returned descriptor is written to the location pointed to by argument
.Ar ret_die .
.Pp
Function
.Fn dwarf_offdie_b
is identical to the function
.Fn dwarf_offdie
except that it can retrieve the debugging information entry descriptor at
global offset
.Ar offset
from either of the
.Dq .debug_info
and
.Dq .debug_types
sections of the object associated with argument
.Ar dbg .
If argument
.Ar is_info
is non-zero, the function will retrieve the debugging information
entry from the
.Dq .debug_info
section, otherwise the function will retrieve the debugging
information entry from the
.Dq .debug_types
section.
The returned descriptor is written to the location pointed to by argument
.Ar ret_die .
.Ss Memory Management
The memory area used for the
.Vt Dwarf_Die
descriptor returned in argument
.Ar ret_die
is allocated by the
.Lb libdwarf .
Application code should use function
.Fn dwarf_dealloc
with the allocation type
.Dv DW_DLA_DIE
to free the memory area when the
.Vt Dwarf_Die
descriptor is no longer needed.
.Sh RETURN VALUES
These functions return the following values:
.Bl -tag -width ".Bq Er DW_DLV_NO_ENTRY"
.It Bq Er DW_DLV_OK
The call succeeded.
.It Bq Er DW_DLV_ERROR
The requested operation failed.
Additional information about the error encountered will be recorded in
argument
.Ar err ,
if it is not NULL.
.It Bq Er DW_DLV_NO_ENTRY
For functions
.Fn dwarf_child ,
.Fn dwarf_siblingof
and
.Fn dwarf_siblingof_b ,
the descriptor denoted by argument
.Ar die
did not have a child or sibling.
.Pp
For functions
.Fn dwarf_offdie
and
.Fn dwarf_offdie_b ,
there was no debugging information entry at the offset specified by
argument
.Ar offset .
.El
.Sh ERRORS
These functions may fail with the following errors:
.Bl -tag -width ".Bq Er DW_DLE_DIE_NO_CU_CONTEXT"
.It Bq Er DW_DLE_ARGUMENT
Arguments
.Ar dbg ,
.Ar die
or
.Ar ret_die
were NULL.
.It Bq Er DW_DLE_DIE_NO_CU_CONTEXT
Argument
.Ar dbg
was not associated with a compilation unit.
.It Bq Er DW_DLE_NO_ENTRY
The descriptor denoted by argument
.Ar die
had no child or sibling, or there was no DWARF debugging information
entry at the offset specified by argument
.Va offset .
.El
.Sh EXAMPLES
To retrieve the first DWARF Debugging Information Entry descriptor for
the first compilation unit associated with a
.Vt Dwarf_Debug
instance, and to traverse all its children, use:
.Bd -literal -offset indent
Dwarf_Debug dbg;
Dwarf_Die die, die0;
Dwarf_Error de;

\&... allocate dbg using dwarf_init() etc ...

if (dwarf_next_cu_header(dbg, NULL, NULL, NULL, NULL, NULL, &de) !=
    DW_DLV_OK)
	errx(EXIT_FAILURE, "dwarf_next_cu_header: %s",
	    dwarf_errmsg(de));

/* Get the first DIE for the current compilation unit. */
die = NULL;
if (dwarf_siblingof(dbg, die, &die0, &de) != DW_DLV_OK)
	errx(EXIT_FAILURE, "dwarf_siblingof: %s", dwarf_errmsg(de));

/* Get the first child of this DIE. */
die = die0;
if (dwarf_child(die, &die0, &de) != DW_DLV_OK)
	errx(EXIT_FAILURE, "dwarf_child: %s", dwarf_errmsg(de));

/* Get the rest of children. */
do {
	die = die0;
	if (dwarf_siblingof(dbg, die, &die0, &de) == DW_DLV_ERROR)
		errx(EXIT_FAILURE, "dwarf_siblingof: %s",
		    dwarf_errmsg(de));
} while (die0 != NULL);
.Ed
.Sh SEE ALSO
.Xr dwarf 3 ,
.Xr dwarf_errmsg 3 ,
.Xr dwarf_get_die_infotypes_flag.3 ,
.Xr dwarf_next_cu_header 3