1.\" $NetBSD: dwarf_get_abbrev.3,v 1.6 2024/03/03 17:37:31 christos 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_abbrev.3 3962 2022-03-12 15:56:10Z jkoshy 28.\" 29.Dd March 27, 2011 30.Dt DWARF_GET_ABBREV 3 31.Os 32.Sh NAME 33.Nm dwarf_get_abbrev 34.Nd retrieve abbreviation information 35.Sh LIBRARY 36.Lb libdwarf 37.Sh SYNOPSIS 38.In libdwarf.h 39.Ft int 40.Fo dwarf_get_abbrev 41.Fa "Dwarf_Debug dbg" 42.Fa "Dwarf_Unsigned offset" 43.Fa "Dwarf_Abbrev *ret_abbrev" 44.Fa "Dwarf_Unsigned *length" 45.Fa "Dwarf_Unsigned *attr_count" 46.Fa "Dwarf_Error *err" 47.Fc 48.Sh DESCRIPTION 49Function 50.Fn dwarf_get_abbrev 51retrieves information about an abbreviation from the DWARF abbreviations 52section, 53.Dq ".debug_abbrev" . 54Abbreviation information is returned using an opaque descriptor 55of type 56.Vt Dwarf_Abbrev . 57The returned 58.Vt Dwarf_Abbrev 59descriptor may then be passed to the other abbreviation related APIs 60in the DWARF(3) API to retrieve specific information about the 61abbreviation. 62.Pp 63Argument 64.Fa dbg 65should reference a DWARF debug context allocated using 66.Xr dwarf_init 3 . 67.Pp 68Argument 69.Fa offset 70should be an offset, relative to the 71.Dq ".debug_abbrev" 72section, to the start of an abbreviation entry. 73.Pp 74Argument 75.Fa ret_abbrev 76should point to a location that will hold a pointer to the 77returned 78.Vt Dwarf_Abbrev 79descriptor. 80.Pp 81Argument 82.Fa length 83should point to a location that will hold the number of bytes used 84by the abbrevation in the DWARF 85.Dq ".debug_abbrev" 86section. 87.Pp 88Argument 89.Fa attr_count 90should point to a location that will hold the number of 91attributes in the abbrevation. 92.Pp 93If argument 94.Fa err 95is not 96.Dv NULL , 97it will be used to store error information in case of an error. 98.Ss Memory Management 99The memory area used for the 100.Vt Dwarf_Abbrev 101descriptor returned in argument 102.Fa ret_abbrev 103is allocated by the 104.Lb libdwarf . 105Application code should use function 106.Fn dwarf_dealloc 107with the allocation type 108.Dv DW_DLA_ABBREV 109to free the memory area when the 110.Vt Dwarf_Abbrev 111descriptor is no longer needed. 112.Ss Application Programming Notes 113The last abbreviation entry in a standard DWARF abbreviation section 114will have a special length value of 1. 115.Sh RETURN VALUES 116Function 117.Fn dwarf_get_abbrev 118returns 119.Dv DW_DLV_OK 120when it succeeds. 121It returns 122.Dv DW_DLV_NO_ENTRY 123if there is no abbreviation information at offset 124.Fa offset . 125In case of an error, it returns 126.Dv DW_DLV_ERROR 127and sets the argument 128.Fa err . 129.Sh EXAMPLES 130To loop through all the abbreviation information associated with 131a DWARF debug context, use: 132.Bd -literal -offset indent 133Dwarf_Debug dbg; 134Dwarf_Abbrev ab; 135Dwarf_Off aboff; 136Dwarf_Unsigned length, attr_count; 137Dwarf_Half tag; 138Dwarf_Error de; 139int ret; 140 141while ((ret = dwarf_next_cu_header(dbg, NULL, NULL, &aboff, 142 NULL, NULL, &de)) == DW_DLV_OK) { 143 while ((ret = dwarf_get_abbrev(re->dbg, aboff, &ab, &length, 144 &attr_count, &de)) == DW_DLV_OK) { 145 if (length == 1) /* Last entry. */ 146 break; 147 aboff += length; 148 if (dwarf_get_abbrev_tag(ab, &tag, &de) != DW_DLV_OK) { 149 warnx("dwarf_get_abbrev_tag failed: %s", 150 dwarf_errmsg(de)); 151 continue; 152 } 153 if (ret != DW_DLV_OK) 154 warnx("dwarf_get_abbrev: %s", dwarf_errmsg(de)); 155} 156if (ret == DW_DLV_ERROR) 157 warnx("dwarf_next_cu_header: %s", dwarf_errmsg(de)); 158.Ed 159.Sh ERRORS 160Function 161.Fn dwarf_get_abbrev 162can fail with: 163.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY" 164.It Bq Er DW_DLE_ARGUMENT 165One of the arguments 166.Fa dbg , 167.Fa ret_abbrev , 168.Fa length 169or 170.Fa attr_count 171was 172.Dv NULL . 173.It Bq Er DW_DLE_NO_ENTRY 174There is no abbreviation information at offset 175.Fa offset . 176.El 177.Sh SEE ALSO 178.Xr dwarf 3 , 179.Xr dwarf_dealloc 3 , 180.Xr dwarf_get_abbrev_children_flag 3 , 181.Xr dwarf_get_abbrev_code 3 , 182.Xr dwarf_get_abbrev_entry 3 , 183.Xr dwarf_get_abbrev_tag 3 184