xref: /netbsd-src/external/bsd/elftoolchain/dist/libdwarf/dwarf_get_aranges.3 (revision 82d56013d7b633d116a93943de88e08335357a7c)
1.\"	$NetBSD: dwarf_get_aranges.3,v 1.4 2020/11/26 22:51:35 jkoshy Exp $
2.\"
3.\" Copyright (c) 2011 Kai Wang
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
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.
14.\"
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
25.\" SUCH DAMAGE.
26.\"
27.\" Id: dwarf_get_aranges.3 3644 2018-10-15 19:55:01Z jkoshy
28.\"
29.Dd November 9, 2011
30.Dt DWARF_GET_ARANGES 3
31.Os
32.Sh NAME
33.Nm dwarf_get_aranges
34.Nd retrieve program address space mappings
35.Sh LIBRARY
36.Lb libdwarf
37.Sh SYNOPSIS
38.In libdwarf.h
39.Ft int
40.Fo dwarf_get_aranges
41.Fa "Dwarf_Debug dbg"
42.Fa "Dwarf_Arange **ar_list"
43.Fa "Dwarf_Signed *ar_cnt"
44.Fa "Dwarf_Error *err"
45.Fc
46.Sh DESCRIPTION
47The function
48.Fn dwarf_get_aranges
49retrieves address range information from the
50.Dq ".debug_aranges"
51DWARF section.
52Information about address ranges is returned using opaque descriptors
53of type
54.Vt Dwarf_Arange ,
55.Pp
56Argument
57.Ar dbg
58should reference a DWARF debug context allocated using
59.Xr dwarf_init 3 .
60.Pp
61Argument
62.Ar ar_list
63should point to a location which will be set to a pointer to an array
64of
65.Vt Dwarf_Arange
66descriptors.
67.Pp
68Argument
69.Ar ar_cnt
70should point to a location which will be set to the number of
71descriptors returned.
72.Pp
73If argument
74.Ar err
75is not NULL, it will be used to store error information in case of an
76error.
77.Ss Memory Management
78The memory area used for the array returned in argument
79.Ar ar_list
80is owned by
81.Lb libdwarf .
82Application code should not attempt to directly free this area.
83Portable applications should instead use
84.Xr dwarf_dealloc 3
85to indicate that the memory area may be freed.
86.Sh RETURN VALUES
87Function
88.Fn dwarf_get_aranges
89returns
90.Dv DW_DLV_OK
91when it succeeds.
92It returns
93.Dv DW_DLV_NO_ENTRY
94if there is no
95.Dq ".debug_aranges"
96section associated with the specified debugging context.
97In case of an error, it returns
98.Dv DW_DLV_ERROR
99and sets the argument
100.Ar err .
101.Sh EXAMPLES
102To loop through all the address lookup table entries, use:
103.Bd -literal -offset indent
104Dwarf_Debug dbg;
105Dwarf_Addr start;
106Dwarf_Arange *aranges;
107Dwarf_Off die_off;
108Dwarf_Signed i, cnt;
109Dwarf_Unsigned length;
110Dwarf_Error de;
111
112if (dwarf_get_aranges(dbg, &aranges, &cnt, &de) != DW_DLV_OK)
113	errx(EXIT_FAILURE, "dwarf_get_aranges: %s",
114	    dwarf_errmsg(de));
115
116for (i = 0; i < cnt; i++) {
117	if (dwarf_get_arange_info(aranges[i], &start, &length,
118	    &die_off, &de) != DW_DLV_OK) {
119		warnx("dwarf_get_arange_info: %s",
120		    dwarf_errmsg(de));
121		continue;
122	}
123	/* Do something with the returned information. */
124}
125.Ed
126.Sh ERRORS
127Function
128.Fn dwarf_get_aranges
129can fail with:
130.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY"
131.It Bq Er DW_DLE_ARGUMENT
132One of the arguments
133.Ar dbg ,
134.Ar ar_list
135or
136.Ar ar_cnt
137was NULL.
138.It Bq Er DW_DLE_NO_ENTRY
139The debugging context
140.Ar dbg
141did not contain a
142.Dq ".debug_aranges"
143string section.
144.El
145.Sh SEE ALSO
146.Xr dwarf 3 ,
147.Xr dwarf_get_arange 3 ,
148.Xr dwarf_get_arange_cu_header_offset 3 ,
149.Xr dwarf_get_arange_info 3 ,
150.Xr dwarf_get_cu_die_offset 3
151