xref: /minix3/external/bsd/elftoolchain/dist/libdwarf/dwarf_get_ranges.3 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc.\"	$NetBSD: dwarf_get_ranges.3,v 1.2 2014/03/09 16:58:04 christos Exp $
2*0a6a1f1dSLionel Sambuc.\"
3*0a6a1f1dSLionel Sambuc.\" Copyright (c) 2011 Kai Wang
4*0a6a1f1dSLionel Sambuc.\" All rights reserved.
5*0a6a1f1dSLionel Sambuc.\"
6*0a6a1f1dSLionel Sambuc.\" Redistribution and use in source and binary forms, with or without
7*0a6a1f1dSLionel Sambuc.\" modification, are permitted provided that the following conditions
8*0a6a1f1dSLionel Sambuc.\" are met:
9*0a6a1f1dSLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright
10*0a6a1f1dSLionel Sambuc.\"    notice, this list of conditions and the following disclaimer.
11*0a6a1f1dSLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright
12*0a6a1f1dSLionel Sambuc.\"    notice, this list of conditions and the following disclaimer in the
13*0a6a1f1dSLionel Sambuc.\"    documentation and/or other materials provided with the distribution.
14*0a6a1f1dSLionel Sambuc.\"
15*0a6a1f1dSLionel Sambuc.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*0a6a1f1dSLionel Sambuc.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*0a6a1f1dSLionel Sambuc.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*0a6a1f1dSLionel Sambuc.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*0a6a1f1dSLionel Sambuc.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*0a6a1f1dSLionel Sambuc.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*0a6a1f1dSLionel Sambuc.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*0a6a1f1dSLionel Sambuc.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*0a6a1f1dSLionel Sambuc.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*0a6a1f1dSLionel Sambuc.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*0a6a1f1dSLionel Sambuc.\" SUCH DAMAGE.
26*0a6a1f1dSLionel Sambuc.\"
27*0a6a1f1dSLionel Sambuc.\" Id: dwarf_get_ranges.3 2122 2011-11-09 15:35:14Z jkoshy
28*0a6a1f1dSLionel Sambuc.\"
29*0a6a1f1dSLionel Sambuc.Dd November 9, 2011
30*0a6a1f1dSLionel Sambuc.Os
31*0a6a1f1dSLionel Sambuc.Dt DWARF_GET_RANGES 3
32*0a6a1f1dSLionel Sambuc.Sh NAME
33*0a6a1f1dSLionel Sambuc.Nm dwarf_get_ranges
34*0a6a1f1dSLionel Sambuc.Nd retrieve non-contiguous address ranges
35*0a6a1f1dSLionel Sambuc.Sh LIBRARY
36*0a6a1f1dSLionel Sambuc.Lb libdwarf
37*0a6a1f1dSLionel Sambuc.Sh SYNOPSIS
38*0a6a1f1dSLionel Sambuc.In libdwarf.h
39*0a6a1f1dSLionel Sambuc.Ft int
40*0a6a1f1dSLionel Sambuc.Fo dwarf_get_ranges
41*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Debug dbg"
42*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Off offset"
43*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Ranges **ranges"
44*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Signed *cnt"
45*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Unsigned *byte_cnt"
46*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Error *err"
47*0a6a1f1dSLionel Sambuc.Fc
48*0a6a1f1dSLionel Sambuc.Ft int
49*0a6a1f1dSLionel Sambuc.Fo dwarf_get_ranges_a
50*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Debug dbg"
51*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Off offset"
52*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Die die"
53*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Ranges **ranges"
54*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Signed *cnt"
55*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Unsigned *byte_cnt"
56*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Error *err"
57*0a6a1f1dSLionel Sambuc.Fc
58*0a6a1f1dSLionel Sambuc.Sh DESCRIPTION
59*0a6a1f1dSLionel SambucFunction
60*0a6a1f1dSLionel Sambuc.Fn dwarf_get_ranges
61*0a6a1f1dSLionel Sambucretrieves information about the non-contiguous address ranges associated
62*0a6a1f1dSLionel Sambucwith a DWARF debugging information entry.
63*0a6a1f1dSLionel SambucInformation about address ranges is returned as an array of
64*0a6a1f1dSLionel Sambucdescriptors of type
65*0a6a1f1dSLionel Sambuc.Vt Dwarf_Ranges ,
66*0a6a1f1dSLionel Sambucwith each
67*0a6a1f1dSLionel Sambuc.Vt Dwarf_Ranges
68*0a6a1f1dSLionel Sambucdescriptor describing one address range entry.
69*0a6a1f1dSLionel Sambuc.Pp
70*0a6a1f1dSLionel SambucArgument
71*0a6a1f1dSLionel Sambuc.Ar dbg
72*0a6a1f1dSLionel Sambucshould reference a DWARF debug context allocated using
73*0a6a1f1dSLionel Sambuc.Xr dwarf_init 3 .
74*0a6a1f1dSLionel Sambuc.Pp
75*0a6a1f1dSLionel SambucArgument
76*0a6a1f1dSLionel Sambuc.Ar offset
77*0a6a1f1dSLionel Sambucis an offset, relative to the
78*0a6a1f1dSLionel Sambuc.Dq ".debug_ranges"
79*0a6a1f1dSLionel Sambucsection, to the start of the desired list of address ranges.
80*0a6a1f1dSLionel SambucThe offset of an address ranges list is indicated by the
81*0a6a1f1dSLionel Sambuc.Dv DW_AT_ranges
82*0a6a1f1dSLionel Sambucattribute of a debugging information entry.
83*0a6a1f1dSLionel Sambuc.Pp
84*0a6a1f1dSLionel SambucArgument
85*0a6a1f1dSLionel Sambuc.Ar die
86*0a6a1f1dSLionel Sambuc(function
87*0a6a1f1dSLionel Sambuc.Fn dwarf_get_ranges_a
88*0a6a1f1dSLionel Sambuconly) is ignored in this implementation; see the section
89*0a6a1f1dSLionel Sambuc.Sx "Compatibility Notes"
90*0a6a1f1dSLionel Sambucbelow.
91*0a6a1f1dSLionel Sambuc.Pp
92*0a6a1f1dSLionel SambucArgument
93*0a6a1f1dSLionel Sambuc.Ar ranges
94*0a6a1f1dSLionel Sambucshould point to a location that will be set to a pointer to an array
95*0a6a1f1dSLionel Sambucof
96*0a6a1f1dSLionel Sambuc.Vt Dwarf_Ranges
97*0a6a1f1dSLionel Sambucdescriptors.
98*0a6a1f1dSLionel Sambuc.Pp
99*0a6a1f1dSLionel SambucArgument
100*0a6a1f1dSLionel Sambuc.Ar cnt
101*0a6a1f1dSLionel Sambucshould point to a location that will be set to the number of entries
102*0a6a1f1dSLionel Sambucreturned.
103*0a6a1f1dSLionel SambucIf argument
104*0a6a1f1dSLionel Sambuc.Ar byte_cnt
105*0a6a1f1dSLionel Sambucis not NULL, it will be set to the number of bytes occupied by the
106*0a6a1f1dSLionel Sambucreturned entries in the
107*0a6a1f1dSLionel Sambuc.Dq ".debug_ranges"
108*0a6a1f1dSLionel Sambucsection.
109*0a6a1f1dSLionel Sambuc.Pp
110*0a6a1f1dSLionel SambucIf argument
111*0a6a1f1dSLionel Sambuc.Ar err
112*0a6a1f1dSLionel Sambucis not NULL, it will be used to store error information in case
113*0a6a1f1dSLionel Sambucof an error.
114*0a6a1f1dSLionel Sambuc.Pp
115*0a6a1f1dSLionel Sambuc.Vt Dwarf_Ranges
116*0a6a1f1dSLionel Sambucdescriptors are defined in the header file
117*0a6a1f1dSLionel Sambuc.In libdwarf.h ,
118*0a6a1f1dSLionel Sambucand consists of the following fields:
119*0a6a1f1dSLionel Sambuc.Bl -tag -width ".Va dwr_addr1"
120*0a6a1f1dSLionel Sambuc.It Va dwr_addr1
121*0a6a1f1dSLionel SambucThe first address offset, whose meaning depends on the type of the
122*0a6a1f1dSLionel Sambucentry.
123*0a6a1f1dSLionel Sambuc.It Va dwr_addr2
124*0a6a1f1dSLionel SambucThe second address offset, whose meaning depends on the type of the
125*0a6a1f1dSLionel Sambucentry.
126*0a6a1f1dSLionel Sambuc.It Va dwr_type
127*0a6a1f1dSLionel SambucThe type of this address range entry:
128*0a6a1f1dSLionel Sambuc.Bl -tag -width ".Dv DW_RANGES_ENTRY" -compact
129*0a6a1f1dSLionel Sambuc.It Dv DW_RANGES_ENTRY
130*0a6a1f1dSLionel SambucA range list entry.
131*0a6a1f1dSLionel SambucFor this type of entry, the fields
132*0a6a1f1dSLionel Sambuc.Va dwr_addr1
133*0a6a1f1dSLionel Sambucand
134*0a6a1f1dSLionel Sambuc.Va dwr_addr2
135*0a6a1f1dSLionel Sambuchold the beginning and ending offsets of the address range, respectively.
136*0a6a1f1dSLionel Sambuc.It Dv DW_RANGES_ADDRESS_SELECTION
137*0a6a1f1dSLionel SambucA base address selection entry.
138*0a6a1f1dSLionel SambucFor this type of entry, the field
139*0a6a1f1dSLionel Sambuc.Va dwr_addr1
140*0a6a1f1dSLionel Sambucis the value of the largest representable address offset, and
141*0a6a1f1dSLionel Sambuc.Va dwr_addr2
142*0a6a1f1dSLionel Sambucis a base address for the begining and ending address offsets of
143*0a6a1f1dSLionel Sambucsubsequent address range entries in the list.
144*0a6a1f1dSLionel Sambuc.It Dv DW_RANGES_END
145*0a6a1f1dSLionel SambucAn end of list mark.
146*0a6a1f1dSLionel SambucBoth
147*0a6a1f1dSLionel Sambuc.Va dwr_addr1
148*0a6a1f1dSLionel Sambucand
149*0a6a1f1dSLionel Sambuc.Va dwr_addr2
150*0a6a1f1dSLionel Sambucare set to 0.
151*0a6a1f1dSLionel Sambuc.El
152*0a6a1f1dSLionel Sambuc.El
153*0a6a1f1dSLionel Sambuc.Ss Memory Management
154*0a6a1f1dSLionel SambucThe memory area used for the array of
155*0a6a1f1dSLionel Sambuc.Vt Dwarf_Ranges
156*0a6a1f1dSLionel Sambucdescriptors returned in argument
157*0a6a1f1dSLionel Sambuc.Ar ranges
158*0a6a1f1dSLionel Sambucis owned by the
159*0a6a1f1dSLionel Sambuc.Lb libdwarf .
160*0a6a1f1dSLionel SambucThe application should not attempt to directly free this pointer.
161*0a6a1f1dSLionel SambucPortable code should instead use
162*0a6a1f1dSLionel Sambuc.Fn dwarf_ranges_dealloc
163*0a6a1f1dSLionel Sambucto indicate that the memory may be freed.
164*0a6a1f1dSLionel Sambuc.Sh COMPATIBILITY
165*0a6a1f1dSLionel SambucFunction
166*0a6a1f1dSLionel Sambuc.Fn dwarf_get_ranges_a
167*0a6a1f1dSLionel Sambucis identical to
168*0a6a1f1dSLionel Sambuc.Fn dwarf_get_ranges ,
169*0a6a1f1dSLionel Sambucexcept that it requires one additional argument
170*0a6a1f1dSLionel Sambuc.Ar die
171*0a6a1f1dSLionel Sambucdenoting the debugging information entry associated with
172*0a6a1f1dSLionel Sambucthe address range list.
173*0a6a1f1dSLionel SambucIn this implementation of the
174*0a6a1f1dSLionel Sambuc.Lb libdwarf ,
175*0a6a1f1dSLionel Sambucthe argument
176*0a6a1f1dSLionel Sambuc.Ar die
177*0a6a1f1dSLionel Sambucis ignored, and function
178*0a6a1f1dSLionel Sambuc.Fn dwarf_get_ranges_a
179*0a6a1f1dSLionel Sambucis only provided for compatibility with other implementations of the
180*0a6a1f1dSLionel SambucDWARF(3) API.
181*0a6a1f1dSLionel Sambuc.Sh RETURN VALUES
182*0a6a1f1dSLionel SambucThese functions
183*0a6a1f1dSLionel Sambucreturn
184*0a6a1f1dSLionel Sambuc.Dv DW_DLV_OK
185*0a6a1f1dSLionel Sambucwhen they succeed.
186*0a6a1f1dSLionel SambucThey return
187*0a6a1f1dSLionel Sambuc.Dv DW_DLV_NO_ENTRY
188*0a6a1f1dSLionel Sambucif there is no address range list at the specified offset
189*0a6a1f1dSLionel Sambuc.Ar offset .
190*0a6a1f1dSLionel SambucIn case of an error, they return
191*0a6a1f1dSLionel Sambuc.Dv DW_DLV_ERROR
192*0a6a1f1dSLionel Sambucand set the argument
193*0a6a1f1dSLionel Sambuc.Ar err .
194*0a6a1f1dSLionel Sambuc.Sh ERRORS
195*0a6a1f1dSLionel SambucThese function can fail with:
196*0a6a1f1dSLionel Sambuc.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY"
197*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_ARGUMENT
198*0a6a1f1dSLionel SambucOne of the arguments
199*0a6a1f1dSLionel Sambuc.Ar dbg ,
200*0a6a1f1dSLionel Sambuc.Ar ranges
201*0a6a1f1dSLionel Sambucor
202*0a6a1f1dSLionel Sambuc.Ar cnt
203*0a6a1f1dSLionel Sambucwas NULL.
204*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_NO_ENTRY
205*0a6a1f1dSLionel SambucThere is no address range list at the specified offset
206*0a6a1f1dSLionel Sambuc.Ar offset .
207*0a6a1f1dSLionel Sambuc.El
208*0a6a1f1dSLionel Sambuc.Sh EXAMPLE
209*0a6a1f1dSLionel SambucTo retrieve the address range list associated with a debugging
210*0a6a1f1dSLionel Sambucinformation entry, use:
211*0a6a1f1dSLionel Sambuc.Bd -literal -offset indent
212*0a6a1f1dSLionel SambucDwarf_Debug dbg;
213*0a6a1f1dSLionel SambucDwarf_Die die;
214*0a6a1f1dSLionel SambucDwarf_Error de;
215*0a6a1f1dSLionel SambucDwarf_Addr base;
216*0a6a1f1dSLionel SambucDwarf_Attribute *attr_list;
217*0a6a1f1dSLionel SambucDwarf_Ranges *ranges;
218*0a6a1f1dSLionel SambucDwarf_Signed cnt;
219*0a6a1f1dSLionel SambucDwarf_Unsigned off, attr_count, bytecnt;
220*0a6a1f1dSLionel Sambucint i, j;
221*0a6a1f1dSLionel Sambuc
222*0a6a1f1dSLionel Sambucif ((ret = dwarf_attrlist(die, &attr_list, &attr_count, &de)) !=
223*0a6a1f1dSLionel Sambuc    DW_DLV_OK)
224*0a6a1f1dSLionel Sambuc	errx(EXIT_FAILURE, "dwarf_attrlist failed: %s",
225*0a6a1f1dSLionel Sambuc	    dwarf_errmsg(de));
226*0a6a1f1dSLionel Sambuc
227*0a6a1f1dSLionel Sambucfor (i = 0; (Dwarf_Unsigned) i < attr_count; i++) {
228*0a6a1f1dSLionel Sambuc	if (dwarf_whatattr(attr_list[i], &attr, &de) != DW_DLV_OK) {
229*0a6a1f1dSLionel Sambuc		warnx("dwarf_whatattr failed: %s",
230*0a6a1f1dSLionel Sambuc		    dwarf_errmsg(de));
231*0a6a1f1dSLionel Sambuc		continue;
232*0a6a1f1dSLionel Sambuc	}
233*0a6a1f1dSLionel Sambuc	if (attr != DW_AT_ranges)
234*0a6a1f1dSLionel Sambuc		continue;
235*0a6a1f1dSLionel Sambuc	if (dwarf_formudata(attr_list[i], &off, &de) != DW_DLV_OK) {
236*0a6a1f1dSLionel Sambuc		warnx("dwarf_formudata failed: %s",
237*0a6a1f1dSLionel Sambuc		    dwarf_errmsg(de));
238*0a6a1f1dSLionel Sambuc		continue;
239*0a6a1f1dSLionel Sambuc	}
240*0a6a1f1dSLionel Sambuc	if (dwarf_get_ranges(dbg, (Dwarf_Off) off, &ranges, &cnt,
241*0a6a1f1dSLionel Sambuc	    &bytecnt, &de) != DW_DLV_OK)
242*0a6a1f1dSLionel Sambuc		continue;
243*0a6a1f1dSLionel Sambuc	for (j = 0; j < cnt; j++) {
244*0a6a1f1dSLionel Sambuc		if (ranges[j].dwr_type == DW_RANGES_END)
245*0a6a1f1dSLionel Sambuc			break;
246*0a6a1f1dSLionel Sambuc		else if (ranges[j].dwr_type ==
247*0a6a1f1dSLionel Sambuc		    DW_RANGES_ADDRESS_SELECTION)
248*0a6a1f1dSLionel Sambuc			base = ranges[j].dwr_addr2;
249*0a6a1f1dSLionel Sambuc		else {
250*0a6a1f1dSLionel Sambuc			/*
251*0a6a1f1dSLionel Sambuc			 * DW_RANGES_ENTRY entry.
252*0a6a1f1dSLionel Sambuc			 * .. Use dwr_addr1 and dwr_addr2 ..
253*0a6a1f1dSLionel Sambuc			 */
254*0a6a1f1dSLionel Sambuc		}
255*0a6a1f1dSLionel Sambuc	}
256*0a6a1f1dSLionel Sambuc}
257*0a6a1f1dSLionel Sambuc.Ed
258*0a6a1f1dSLionel Sambuc.Sh SEE ALSO
259*0a6a1f1dSLionel Sambuc.Xr dwarf 3 ,
260*0a6a1f1dSLionel Sambuc.Xr dwarf_ranges_dealloc 3
261