1 .\" $NetBSD: dwarf_get_ranges.3,v 1.2 2014/03/09 16:58:04 christos Exp $
3 .\" Copyright (c) 2011 Kai Wang
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 .\" Id: dwarf_get_ranges.3 2122 2011-11-09 15:35:14Z jkoshy
31 .Dt DWARF_GET_RANGES 3
34 .Nd retrieve non-contiguous address ranges
42 .Fa "Dwarf_Off offset"
43 .Fa "Dwarf_Ranges **ranges"
44 .Fa "Dwarf_Signed *cnt"
45 .Fa "Dwarf_Unsigned *byte_cnt"
46 .Fa "Dwarf_Error *err"
49 .Fo dwarf_get_ranges_a
51 .Fa "Dwarf_Off offset"
53 .Fa "Dwarf_Ranges **ranges"
54 .Fa "Dwarf_Signed *cnt"
55 .Fa "Dwarf_Unsigned *byte_cnt"
56 .Fa "Dwarf_Error *err"
61 retrieves information about the non-contiguous address ranges associated
62 with a DWARF debugging information entry.
63 Information about address ranges is returned as an array of
68 descriptor describing one address range entry.
72 should reference a DWARF debug context allocated using
77 is an offset, relative to the
79 section, to the start of the desired list of address ranges.
80 The offset of an address ranges list is indicated by the
82 attribute of a debugging information entry.
87 .Fn dwarf_get_ranges_a
88 only) is ignored in this implementation; see the section
89 .Sx "Compatibility Notes"
94 should point to a location that will be set to a pointer to an array
101 should point to a location that will be set to the number of entries
105 is not NULL, it will be set to the number of bytes occupied by the
106 returned entries in the
112 is not NULL, it will be used to store error information in case
116 descriptors are defined in the header file
118 and consists of the following fields:
119 .Bl -tag -width ".Va dwr_addr1"
121 The first address offset, whose meaning depends on the type of the
124 The second address offset, whose meaning depends on the type of the
127 The type of this address range entry:
128 .Bl -tag -width ".Dv DW_RANGES_ENTRY" -compact
129 .It Dv DW_RANGES_ENTRY
131 For this type of entry, the fields
135 hold the beginning and ending offsets of the address range, respectively.
136 .It Dv DW_RANGES_ADDRESS_SELECTION
137 A base address selection entry.
138 For this type of entry, the field
140 is the value of the largest representable address offset, and
142 is a base address for the begining and ending address offsets of
143 subsequent address range entries in the list.
153 .Ss Memory Management
154 The memory area used for the array of
156 descriptors returned in argument
160 The application should not attempt to directly free this pointer.
161 Portable code should instead use
162 .Fn dwarf_ranges_dealloc
163 to indicate that the memory may be freed.
166 .Fn dwarf_get_ranges_a
168 .Fn dwarf_get_ranges ,
169 except that it requires one additional argument
171 denoting the debugging information entry associated with
172 the address range list.
173 In this implementation of the
177 is ignored, and function
178 .Fn dwarf_get_ranges_a
179 is only provided for compatibility with other implementations of the
188 if there is no address range list at the specified offset
190 In case of an error, they return
195 These function can fail with:
196 .Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY"
197 .It Bq Er DW_DLE_ARGUMENT
204 .It Bq Er DW_DLE_NO_ENTRY
205 There is no address range list at the specified offset
209 To retrieve the address range list associated with a debugging
210 information entry, use:
211 .Bd -literal -offset indent
216 Dwarf_Attribute *attr_list;
217 Dwarf_Ranges *ranges;
219 Dwarf_Unsigned off, attr_count, bytecnt;
222 if ((ret = dwarf_attrlist(die, &attr_list, &attr_count, &de)) !=
224 errx(EXIT_FAILURE, "dwarf_attrlist failed: %s",
227 for (i = 0; (Dwarf_Unsigned) i < attr_count; i++) {
228 if (dwarf_whatattr(attr_list[i], &attr, &de) != DW_DLV_OK) {
229 warnx("dwarf_whatattr failed: %s",
233 if (attr != DW_AT_ranges)
235 if (dwarf_formudata(attr_list[i], &off, &de) != DW_DLV_OK) {
236 warnx("dwarf_formudata failed: %s",
240 if (dwarf_get_ranges(dbg, (Dwarf_Off) off, &ranges, &cnt,
241 &bytecnt, &de) != DW_DLV_OK)
243 for (j = 0; j < cnt; j++) {
244 if (ranges[j].dwr_type == DW_RANGES_END)
246 else if (ranges[j].dwr_type ==
247 DW_RANGES_ADDRESS_SELECTION)
248 base = ranges[j].dwr_addr2;
251 * DW_RANGES_ENTRY entry.
252 * .. Use dwr_addr1 and dwr_addr2 ..
260 .Xr dwarf_ranges_dealloc 3