1.\" $NetBSD: dwarf_get_abbrev_entry.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_entry.3 3962 2022-03-12 15:56:10Z jkoshy 28.\" 29.Dd April 02, 2011 30.Dt DWARF_GET_ABBREV_ENTRY 3 31.Os 32.Sh NAME 33.Nm dwarf_get_abbrev_entry 34.Nd retrieve attribute information from an abbreviation descriptor 35.Sh LIBRARY 36.Lb libdwarf 37.Sh SYNOPSIS 38.In libdwarf.h 39.Ft int 40.Fo dwarf_get_abbrev_entry 41.Fa "Dwarf_Abbrev abbrev" 42.Fa "Dwarf_Signed ndx" 43.Fa "Dwarf_Half *code" 44.Fa "Dwarf_Signed *form" 45.Fa "Dwarf_Off *offset" 46.Fa "Dwarf_Error *err" 47.Fc 48.Sh DESCRIPTION 49Function 50.Fn dwarf_get_abbrev_entry 51retrieves attribute information from a DWARF abbreviation descriptor. 52.Pp 53Argument 54.Fa abbrev 55should be a valid abbreviation descriptor, as returned by function 56.Xr dwarf_get_abbrev 3 . 57.Pp 58Argument 59.Fa ndx 60specifies the 0-based index of the attribute. 61The total count of the attributes contained in the abbreviation 62entry can be retrieved using the function 63.Xr dwarf_get_abbrev 3 . 64.Pp 65Argument 66.Fa code 67should point to a location which will hold a returned 68attribute code. 69.Pp 70Argument 71.Fa form 72should point to a location which will hold the returned 73form of the attribute. 74.Pp 75Argument 76.Fa offset 77should point to a location which will hold a returned offset, relative 78to the 79.Dq ".debug_abbrev" 80section, for the specified attribute. 81.Pp 82If argument 83.Fa err 84is not 85.Dv NULL , 86it will be used to return an error descriptor in case of an error. 87.Sh RETURN VALUES 88Function 89.Fn dwarf_get_abbrev_entry 90returns 91.Dv DW_DLV_OK 92when it succeeds. 93It returns 94.Dv DW_DLV_NO_ENTRY 95if the attribute index specified by argument 96.Fa ndx 97is out of range. 98In case of an error, it returns 99.Dv DW_DLV_ERROR 100and sets the argument 101.Fa err . 102.Sh EXAMPLES 103To loop through all the attribute entries contained in the 104abbreviation section, use: 105.Bd -literal -offset indent 106Dwarf_Debug dbg; 107Dwarf_Abbrev ab; 108Dwarf_Off aboff, atoff; 109Dwarf_Signed form; 110Dwarf_Half attr; 111Dwarf_Unsigned length, attr_count; 112Dwarf_Error de; 113int i, ret; 114 115/* ...allocate 'dbg' using dwarf_init(3) ... */ 116 117while ((ret = dwarf_next_cu_header(dbg, NULL, NULL, &aboff, 118 NULL, NULL, &de)) == DW_DLV_OK) { 119 while ((ret = dwarf_get_abbrev(dbg, aboff, &ab, &length, 120 &attr_count, &de)) == DW_DLV_OK) { 121 if (length == 1) /* Last entry. */ 122 break; 123 aboff += length; 124 for (i = 0; (Dwarf_Unsigned) i < attr_count; i++) { 125 if (dwarf_get_abbrev_entry(ab, i, 126 &attr, &form, &atoff, &de) != DW_DLV_OK) { 127 warnx("dwarf_get_abbrev_entry failed:" 128 " %s", dwarf_errmsg(de)); 129 continue; 130 } 131 /* .. use the retrieved information ... */ 132 } 133 } 134 135 if (ret != DW_DLV_OK) 136 warnx("dwarf_get_abbrev: %s", dwarf_errmsg(de)); 137} 138 139if (ret == DW_DLV_ERROR) 140 warnx("dwarf_next_cu_header: %s", dwarf_errmsg(de)); 141.Ed 142.Sh ERRORS 143Function 144.Fn dwarf_get_abbrev_entry 145can fail with: 146.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY" 147.It Bq Er DW_DLE_ARGUMENT 148One of the arguments 149.Fa abbrev , 150.Fa code , 151.Fa form 152or 153.Fa offset 154was 155.Dv NULL . 156.It Bq Er DW_DLE_NO_ENTRY 157The attribute index specified by argument 158.Fa ndx 159was out of range. 160.El 161.Sh SEE ALSO 162.Xr dwarf 3 , 163.Xr dwarf_get_abbrev 3 164