aboutsummaryrefslogtreecommitdiff
path: root/libdwarf/dwarf_child.3
blob: 57549c01c66ee7abbb1d2dae26c7f9d426d01b0c (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
.\" Copyright (c) 2010 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 2122 2011-11-09 15:35:14Z jkoshy $
.\"
.Dd November 9, 2011
.Os
.Dt DWARF_CHILD 3
.Sh NAME
.Nm dwarf_child ,
.Nm dwarf_siblingof ,
.Nm dwarf_offdie
.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_siblingof
.Fa "Dwarf_Debug dbg"
.Fa "Dwarf_Die die"
.Fa "Dwarf_Die *ret_die"
.Fa "Dwarf_Error *err"
.Fc
.Ft int
.Fo dwarf_offdie
.Fa "Dwarf_Debug dbg"
.Fa "Dwarf_Off offset"
.Fa "Dwarf_Die *ret_die"
.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_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 .
.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
and
.Fn dwarf_siblingof ,
the descriptor denoted by argument
.Ar die
did not have a child or sibling.
For function
.Fn dwarf_offdie ,
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_next_cu_header 3