summaryrefslogtreecommitdiffstats
path: root/rtemstoolkit/elftoolchain/libdwarf/dwarf_get_ranges.3
blob: 15bad4dfd7ac59db64865c4c07ae90572993896c (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
.\" Copyright (c) 2011 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_get_ranges.3 3182 2015-04-10 16:08:10Z emaste $
.\"
.Dd November 9, 2011
.Os
.Dt DWARF_GET_RANGES 3
.Sh NAME
.Nm dwarf_get_ranges
.Nd retrieve non-contiguous address ranges
.Sh LIBRARY
.Lb libdwarf
.Sh SYNOPSIS
.In libdwarf.h
.Ft int
.Fo dwarf_get_ranges
.Fa "Dwarf_Debug dbg"
.Fa "Dwarf_Off offset"
.Fa "Dwarf_Ranges **ranges"
.Fa "Dwarf_Signed *cnt"
.Fa "Dwarf_Unsigned *byte_cnt"
.Fa "Dwarf_Error *err"
.Fc
.Ft int
.Fo dwarf_get_ranges_a
.Fa "Dwarf_Debug dbg"
.Fa "Dwarf_Off offset"
.Fa "Dwarf_Die die"
.Fa "Dwarf_Ranges **ranges"
.Fa "Dwarf_Signed *cnt"
.Fa "Dwarf_Unsigned *byte_cnt"
.Fa "Dwarf_Error *err"
.Fc
.Sh DESCRIPTION
Function
.Fn dwarf_get_ranges
retrieves information about the non-contiguous address ranges associated
with a DWARF debugging information entry.
Information about address ranges is returned as an array of
descriptors of type
.Vt Dwarf_Ranges ,
with each
.Vt Dwarf_Ranges
descriptor describing one address range entry.
.Pp
Argument
.Ar dbg
should reference a DWARF debug context allocated using
.Xr dwarf_init 3 .
.Pp
Argument
.Ar offset
is an offset, relative to the
.Dq ".debug_ranges"
section, to the start of the desired list of address ranges.
The offset of an address ranges list is indicated by the
.Dv DW_AT_ranges
attribute of a debugging information entry.
.Pp
Argument
.Ar die
(function
.Fn dwarf_get_ranges_a
only) is ignored in this implementation; see the section
.Sx "Compatibility Notes"
below.
.Pp
Argument
.Ar ranges
should point to a location that will be set to a pointer to an array
of
.Vt Dwarf_Ranges
descriptors.
.Pp
Argument
.Ar cnt
should point to a location that will be set to the number of entries
returned.
If argument
.Ar byte_cnt
is not NULL, it will be set to the number of bytes occupied by the
returned entries in the
.Dq ".debug_ranges"
section.
.Pp
If argument
.Ar err
is not NULL, it will be used to store error information in case
of an error.
.Pp
.Vt Dwarf_Ranges
descriptors are defined in the header file
.In libdwarf.h ,
and consists of the following fields:
.Bl -tag -width ".Va dwr_addr1"
.It Va dwr_addr1
The first address offset, whose meaning depends on the type of the
entry.
.It Va dwr_addr2
The second address offset, whose meaning depends on the type of the
entry.
.It Va dwr_type
The type of this address range entry:
.Bl -tag -width ".Dv DW_RANGES_ENTRY" -compact
.It Dv DW_RANGES_ENTRY
A range list entry.
For this type of entry, the fields
.Va dwr_addr1
and
.Va dwr_addr2
hold the beginning and ending offsets of the address range, respectively.
.It Dv DW_RANGES_ADDRESS_SELECTION
A base address selection entry.
For this type of entry, the field
.Va dwr_addr1
is the value of the largest representable address offset, and
.Va dwr_addr2
is a base address for the beginning and ending address offsets of
subsequent address range entries in the list.
.It Dv DW_RANGES_END
An end of list mark.
Both
.Va dwr_addr1
and
.Va dwr_addr2
are set to 0.
.El
.El
.Ss Memory Management
The memory area used for the array of
.Vt Dwarf_Ranges
descriptors returned in argument
.Ar ranges
is owned by the
.Lb libdwarf .
The application should not attempt to directly free this pointer.
Portable code should instead use
.Fn dwarf_ranges_dealloc
to indicate that the memory may be freed.
.Sh COMPATIBILITY
Function
.Fn dwarf_get_ranges_a
is identical to
.Fn dwarf_get_ranges ,
except that it requires one additional argument
.Ar die
denoting the debugging information entry associated with
the address range list.
In this implementation of the
.Lb libdwarf ,
the argument
.Ar die
is ignored, and function
.Fn dwarf_get_ranges_a
is only provided for compatibility with other implementations of the
DWARF(3) API.
.Sh RETURN VALUES
These functions
return
.Dv DW_DLV_OK
when they succeed.
They return
.Dv DW_DLV_NO_ENTRY
if there is no address range list at the specified offset
.Ar offset .
In case of an error, they return
.Dv DW_DLV_ERROR
and set the argument
.Ar err .
.Sh ERRORS
These function can fail with:
.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY"
.It Bq Er DW_DLE_ARGUMENT
One of the arguments
.Ar dbg ,
.Ar ranges
or
.Ar cnt
was NULL.
.It Bq Er DW_DLE_NO_ENTRY
There is no address range list at the specified offset
.Ar offset .
.El
.Sh EXAMPLE
To retrieve the address range list associated with a debugging
information entry, use:
.Bd -literal -offset indent
Dwarf_Debug dbg;
Dwarf_Die die;
Dwarf_Error de;
Dwarf_Addr base;
Dwarf_Attribute *attr_list;
Dwarf_Ranges *ranges;
Dwarf_Signed cnt;
Dwarf_Unsigned off, attr_count, bytecnt;
int i, j;

if ((ret = dwarf_attrlist(die, &attr_list, &attr_count, &de)) !=
    DW_DLV_OK)
	errx(EXIT_FAILURE, "dwarf_attrlist failed: %s",
	    dwarf_errmsg(de));

for (i = 0; (Dwarf_Unsigned) i < attr_count; i++) {
	if (dwarf_whatattr(attr_list[i], &attr, &de) != DW_DLV_OK) {
		warnx("dwarf_whatattr failed: %s",
		    dwarf_errmsg(de));
		continue;
	}
	if (attr != DW_AT_ranges)
		continue;
	if (dwarf_formudata(attr_list[i], &off, &de) != DW_DLV_OK) {
		warnx("dwarf_formudata failed: %s",
		    dwarf_errmsg(de));
		continue;
	}
	if (dwarf_get_ranges(dbg, (Dwarf_Off) off, &ranges, &cnt,
	    &bytecnt, &de) != DW_DLV_OK)
		continue;
	for (j = 0; j < cnt; j++) {
		if (ranges[j].dwr_type == DW_RANGES_END)
			break;
		else if (ranges[j].dwr_type ==
		    DW_RANGES_ADDRESS_SELECTION)
			base = ranges[j].dwr_addr2;
		else {
			/*
			 * DW_RANGES_ENTRY entry.
			 * .. Use dwr_addr1 and dwr_addr2 ..
			 */
		}
	}
}
.Ed
.Sh SEE ALSO
.Xr dwarf 3 ,
.Xr dwarf_ranges_dealloc 3