1*5ac3bc71Schristos.\" $NetBSD: dwarf_get_ranges.3,v 1.6 2024/03/03 17:37:31 christos Exp $ 2e81373b4Schristos.\" 39dd9d0cfSchristos.\" Copyright (c) 2011 Kai Wang 49dd9d0cfSchristos.\" All rights reserved. 59dd9d0cfSchristos.\" 69dd9d0cfSchristos.\" Redistribution and use in source and binary forms, with or without 79dd9d0cfSchristos.\" modification, are permitted provided that the following conditions 89dd9d0cfSchristos.\" are met: 99dd9d0cfSchristos.\" 1. Redistributions of source code must retain the above copyright 109dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer. 119dd9d0cfSchristos.\" 2. Redistributions in binary form must reproduce the above copyright 129dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer in the 139dd9d0cfSchristos.\" documentation and/or other materials provided with the distribution. 149dd9d0cfSchristos.\" 159dd9d0cfSchristos.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 169dd9d0cfSchristos.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 179dd9d0cfSchristos.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 189dd9d0cfSchristos.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 199dd9d0cfSchristos.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 209dd9d0cfSchristos.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 219dd9d0cfSchristos.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 229dd9d0cfSchristos.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 239dd9d0cfSchristos.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 249dd9d0cfSchristos.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 259dd9d0cfSchristos.\" SUCH DAMAGE. 269dd9d0cfSchristos.\" 27cdbf1fe1Sjkoshy.\" Id: dwarf_get_ranges.3 3963 2022-03-12 16:07:32Z jkoshy 289dd9d0cfSchristos.\" 299dd9d0cfSchristos.Dd November 9, 2011 309dd9d0cfSchristos.Dt DWARF_GET_RANGES 3 31604b0842Sjkoshy.Os 329dd9d0cfSchristos.Sh NAME 339dd9d0cfSchristos.Nm dwarf_get_ranges 349dd9d0cfSchristos.Nd retrieve non-contiguous address ranges 359dd9d0cfSchristos.Sh LIBRARY 369dd9d0cfSchristos.Lb libdwarf 379dd9d0cfSchristos.Sh SYNOPSIS 389dd9d0cfSchristos.In libdwarf.h 399dd9d0cfSchristos.Ft int 409dd9d0cfSchristos.Fo dwarf_get_ranges 419dd9d0cfSchristos.Fa "Dwarf_Debug dbg" 429dd9d0cfSchristos.Fa "Dwarf_Off offset" 439dd9d0cfSchristos.Fa "Dwarf_Ranges **ranges" 449dd9d0cfSchristos.Fa "Dwarf_Signed *cnt" 459dd9d0cfSchristos.Fa "Dwarf_Unsigned *byte_cnt" 469dd9d0cfSchristos.Fa "Dwarf_Error *err" 479dd9d0cfSchristos.Fc 489dd9d0cfSchristos.Ft int 499dd9d0cfSchristos.Fo dwarf_get_ranges_a 509dd9d0cfSchristos.Fa "Dwarf_Debug dbg" 519dd9d0cfSchristos.Fa "Dwarf_Off offset" 529dd9d0cfSchristos.Fa "Dwarf_Die die" 539dd9d0cfSchristos.Fa "Dwarf_Ranges **ranges" 549dd9d0cfSchristos.Fa "Dwarf_Signed *cnt" 559dd9d0cfSchristos.Fa "Dwarf_Unsigned *byte_cnt" 569dd9d0cfSchristos.Fa "Dwarf_Error *err" 579dd9d0cfSchristos.Fc 589dd9d0cfSchristos.Sh DESCRIPTION 599dd9d0cfSchristosFunction 609dd9d0cfSchristos.Fn dwarf_get_ranges 619dd9d0cfSchristosretrieves information about the non-contiguous address ranges associated 629dd9d0cfSchristoswith a DWARF debugging information entry. 639dd9d0cfSchristosInformation about address ranges is returned as an array of 649dd9d0cfSchristosdescriptors of type 659dd9d0cfSchristos.Vt Dwarf_Ranges , 669dd9d0cfSchristoswith each 679dd9d0cfSchristos.Vt Dwarf_Ranges 689dd9d0cfSchristosdescriptor describing one address range entry. 699dd9d0cfSchristos.Pp 709dd9d0cfSchristosArgument 71cdbf1fe1Sjkoshy.Fa dbg 729dd9d0cfSchristosshould reference a DWARF debug context allocated using 739dd9d0cfSchristos.Xr dwarf_init 3 . 749dd9d0cfSchristos.Pp 759dd9d0cfSchristosArgument 76cdbf1fe1Sjkoshy.Fa offset 779dd9d0cfSchristosis an offset, relative to the 789dd9d0cfSchristos.Dq ".debug_ranges" 799dd9d0cfSchristossection, to the start of the desired list of address ranges. 809dd9d0cfSchristosThe offset of an address ranges list is indicated by the 819dd9d0cfSchristos.Dv DW_AT_ranges 829dd9d0cfSchristosattribute of a debugging information entry. 839dd9d0cfSchristos.Pp 849dd9d0cfSchristosArgument 85cdbf1fe1Sjkoshy.Fa die 869dd9d0cfSchristos(function 879dd9d0cfSchristos.Fn dwarf_get_ranges_a 889dd9d0cfSchristosonly) is ignored in this implementation; see the section 899dd9d0cfSchristos.Sx "Compatibility Notes" 909dd9d0cfSchristosbelow. 919dd9d0cfSchristos.Pp 929dd9d0cfSchristosArgument 93cdbf1fe1Sjkoshy.Fa ranges 949dd9d0cfSchristosshould point to a location that will be set to a pointer to an array 959dd9d0cfSchristosof 969dd9d0cfSchristos.Vt Dwarf_Ranges 979dd9d0cfSchristosdescriptors. 989dd9d0cfSchristos.Pp 999dd9d0cfSchristosArgument 100cdbf1fe1Sjkoshy.Fa cnt 1019dd9d0cfSchristosshould point to a location that will be set to the number of entries 1029dd9d0cfSchristosreturned. 1039dd9d0cfSchristosIf argument 104cdbf1fe1Sjkoshy.Fa byte_cnt 105cdbf1fe1Sjkoshyis not 106cdbf1fe1Sjkoshy.Dv NULL , 107cdbf1fe1Sjkoshyit will be set to the number of bytes occupied by the 1089dd9d0cfSchristosreturned entries in the 1099dd9d0cfSchristos.Dq ".debug_ranges" 1109dd9d0cfSchristossection. 1119dd9d0cfSchristos.Pp 1129dd9d0cfSchristosIf argument 113cdbf1fe1Sjkoshy.Fa err 114cdbf1fe1Sjkoshyis not 115cdbf1fe1Sjkoshy.Dv NULL , 116cdbf1fe1Sjkoshyit will be used to store error information in case of an error. 1179dd9d0cfSchristos.Pp 1189dd9d0cfSchristos.Vt Dwarf_Ranges 1199dd9d0cfSchristosdescriptors are defined in the header file 1209dd9d0cfSchristos.In libdwarf.h , 1219dd9d0cfSchristosand consists of the following fields: 1229dd9d0cfSchristos.Bl -tag -width ".Va dwr_addr1" 1239dd9d0cfSchristos.It Va dwr_addr1 1249dd9d0cfSchristosThe first address offset, whose meaning depends on the type of the 1259dd9d0cfSchristosentry. 1269dd9d0cfSchristos.It Va dwr_addr2 1279dd9d0cfSchristosThe second address offset, whose meaning depends on the type of the 1289dd9d0cfSchristosentry. 1299dd9d0cfSchristos.It Va dwr_type 1309dd9d0cfSchristosThe type of this address range entry: 1319dd9d0cfSchristos.Bl -tag -width ".Dv DW_RANGES_ENTRY" -compact 1329dd9d0cfSchristos.It Dv DW_RANGES_ENTRY 1339dd9d0cfSchristosA range list entry. 1349dd9d0cfSchristosFor this type of entry, the fields 1359dd9d0cfSchristos.Va dwr_addr1 1369dd9d0cfSchristosand 1379dd9d0cfSchristos.Va dwr_addr2 1389dd9d0cfSchristoshold the beginning and ending offsets of the address range, respectively. 1399dd9d0cfSchristos.It Dv DW_RANGES_ADDRESS_SELECTION 1409dd9d0cfSchristosA base address selection entry. 1419dd9d0cfSchristosFor this type of entry, the field 1429dd9d0cfSchristos.Va dwr_addr1 1439dd9d0cfSchristosis the value of the largest representable address offset, and 1449dd9d0cfSchristos.Va dwr_addr2 14542bd3019Schristosis a base address for the beginning and ending address offsets of 1469dd9d0cfSchristossubsequent address range entries in the list. 1479dd9d0cfSchristos.It Dv DW_RANGES_END 1489dd9d0cfSchristosAn end of list mark. 1499dd9d0cfSchristosBoth 1509dd9d0cfSchristos.Va dwr_addr1 1519dd9d0cfSchristosand 1529dd9d0cfSchristos.Va dwr_addr2 1539dd9d0cfSchristosare set to 0. 1549dd9d0cfSchristos.El 1559dd9d0cfSchristos.El 1569dd9d0cfSchristos.Ss Memory Management 1579dd9d0cfSchristosThe memory area used for the array of 1589dd9d0cfSchristos.Vt Dwarf_Ranges 1599dd9d0cfSchristosdescriptors returned in argument 160cdbf1fe1Sjkoshy.Fa ranges 1619dd9d0cfSchristosis owned by the 1629dd9d0cfSchristos.Lb libdwarf . 1639dd9d0cfSchristosThe application should not attempt to directly free this pointer. 1649dd9d0cfSchristosPortable code should instead use 1659dd9d0cfSchristos.Fn dwarf_ranges_dealloc 1669dd9d0cfSchristosto indicate that the memory may be freed. 1679dd9d0cfSchristos.Sh RETURN VALUES 1689dd9d0cfSchristosThese functions 1699dd9d0cfSchristosreturn 1709dd9d0cfSchristos.Dv DW_DLV_OK 1719dd9d0cfSchristoswhen they succeed. 1729dd9d0cfSchristosThey return 1739dd9d0cfSchristos.Dv DW_DLV_NO_ENTRY 1749dd9d0cfSchristosif there is no address range list at the specified offset 175cdbf1fe1Sjkoshy.Fa offset . 1769dd9d0cfSchristosIn case of an error, they return 1779dd9d0cfSchristos.Dv DW_DLV_ERROR 1789dd9d0cfSchristosand set the argument 179cdbf1fe1Sjkoshy.Fa err . 180604b0842Sjkoshy.Sh EXAMPLES 1819dd9d0cfSchristosTo retrieve the address range list associated with a debugging 1829dd9d0cfSchristosinformation entry, use: 1839dd9d0cfSchristos.Bd -literal -offset indent 1849dd9d0cfSchristosDwarf_Debug dbg; 1859dd9d0cfSchristosDwarf_Die die; 1869dd9d0cfSchristosDwarf_Error de; 1879dd9d0cfSchristosDwarf_Addr base; 1889dd9d0cfSchristosDwarf_Attribute *attr_list; 1899dd9d0cfSchristosDwarf_Ranges *ranges; 1909dd9d0cfSchristosDwarf_Signed cnt; 1919dd9d0cfSchristosDwarf_Unsigned off, attr_count, bytecnt; 1929dd9d0cfSchristosint i, j; 1939dd9d0cfSchristos 1949dd9d0cfSchristosif ((ret = dwarf_attrlist(die, &attr_list, &attr_count, &de)) != 1959dd9d0cfSchristos DW_DLV_OK) 1969dd9d0cfSchristos errx(EXIT_FAILURE, "dwarf_attrlist failed: %s", 1979dd9d0cfSchristos dwarf_errmsg(de)); 1989dd9d0cfSchristos 1999dd9d0cfSchristosfor (i = 0; (Dwarf_Unsigned) i < attr_count; i++) { 2009dd9d0cfSchristos if (dwarf_whatattr(attr_list[i], &attr, &de) != DW_DLV_OK) { 2019dd9d0cfSchristos warnx("dwarf_whatattr failed: %s", 2029dd9d0cfSchristos dwarf_errmsg(de)); 2039dd9d0cfSchristos continue; 2049dd9d0cfSchristos } 2059dd9d0cfSchristos if (attr != DW_AT_ranges) 2069dd9d0cfSchristos continue; 2079dd9d0cfSchristos if (dwarf_formudata(attr_list[i], &off, &de) != DW_DLV_OK) { 2089dd9d0cfSchristos warnx("dwarf_formudata failed: %s", 2099dd9d0cfSchristos dwarf_errmsg(de)); 2109dd9d0cfSchristos continue; 2119dd9d0cfSchristos } 2129dd9d0cfSchristos if (dwarf_get_ranges(dbg, (Dwarf_Off) off, &ranges, &cnt, 2139dd9d0cfSchristos &bytecnt, &de) != DW_DLV_OK) 2149dd9d0cfSchristos continue; 2159dd9d0cfSchristos for (j = 0; j < cnt; j++) { 2169dd9d0cfSchristos if (ranges[j].dwr_type == DW_RANGES_END) 2179dd9d0cfSchristos break; 2189dd9d0cfSchristos else if (ranges[j].dwr_type == 2199dd9d0cfSchristos DW_RANGES_ADDRESS_SELECTION) 2209dd9d0cfSchristos base = ranges[j].dwr_addr2; 2219dd9d0cfSchristos else { 2229dd9d0cfSchristos /* 2239dd9d0cfSchristos * DW_RANGES_ENTRY entry. 2249dd9d0cfSchristos * .. Use dwr_addr1 and dwr_addr2 .. 2259dd9d0cfSchristos */ 2269dd9d0cfSchristos } 2279dd9d0cfSchristos } 2289dd9d0cfSchristos} 2299dd9d0cfSchristos.Ed 230604b0842Sjkoshy.Sh COMPATIBILITY 231604b0842SjkoshyFunction 232604b0842Sjkoshy.Fn dwarf_get_ranges_a 233604b0842Sjkoshyis identical to 234604b0842Sjkoshy.Fn dwarf_get_ranges , 235604b0842Sjkoshyexcept that it requires one additional argument 236cdbf1fe1Sjkoshy.Fa die 237604b0842Sjkoshydenoting the debugging information entry associated with 238604b0842Sjkoshythe address range list. 239604b0842SjkoshyIn this implementation of the 240604b0842Sjkoshy.Lb libdwarf , 241604b0842Sjkoshythe argument 242cdbf1fe1Sjkoshy.Fa die 243604b0842Sjkoshyis ignored, and function 244604b0842Sjkoshy.Fn dwarf_get_ranges_a 245604b0842Sjkoshyis only provided for compatibility with other implementations of the 246604b0842SjkoshyDWARF(3) API. 247604b0842Sjkoshy.Sh ERRORS 248604b0842SjkoshyThese function can fail with: 249604b0842Sjkoshy.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY" 250604b0842Sjkoshy.It Bq Er DW_DLE_ARGUMENT 251604b0842SjkoshyOne of the arguments 252cdbf1fe1Sjkoshy.Fa dbg , 253cdbf1fe1Sjkoshy.Fa ranges 254604b0842Sjkoshyor 255cdbf1fe1Sjkoshy.Fa cnt 256cdbf1fe1Sjkoshywas 257cdbf1fe1Sjkoshy.Dv NULL . 258604b0842Sjkoshy.It Bq Er DW_DLE_NO_ENTRY 259604b0842SjkoshyThere is no address range list at the specified offset 260cdbf1fe1Sjkoshy.Fa offset . 261604b0842Sjkoshy.El 2629dd9d0cfSchristos.Sh SEE ALSO 2639dd9d0cfSchristos.Xr dwarf 3 , 2649dd9d0cfSchristos.Xr dwarf_ranges_dealloc 3 265