1.\" $NetBSD: dwarf_attrval_signed.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_attrval_signed.3 3640 2018-10-14 14:09:13Z jkoshy 28.\" 29.Dd December 26, 2016 30.Dt DWARF_ATTRVAL_SIGNED 3 31.Os 32.Sh NAME 33.Nm dwarf_attrval_flag , 34.Nm dwarf_attrval_signed , 35.Nm dwarf_attrval_string , 36.Nm dwarf_attrval_unsigned 37.Nd retrieve the value of an attribute within a DWARF debugging information entry 38.Sh LIBRARY 39.Lb libdwarf 40.Sh SYNOPSIS 41.In libdwarf.h 42.Ft int 43.Fo dwarf_attrval_flag 44.Fa "Dwarf_Die die" 45.Fa "Dwarf_Half attr" 46.Fa "Dwarf_Bool *ret" 47.Fa "Dwarf_Error *err" 48.Fc 49.Ft int 50.Fo dwarf_attrval_signed 51.Fa "Dwarf_Die die" 52.Fa "Dwarf_Half attr" 53.Fa "Dwarf_Signed *ret" 54.Fa "Dwarf_Error *err" 55.Fc 56.Ft int 57.Fo dwarf_attrval_string 58.Fa "Dwarf_Die die" 59.Fa "Dwarf_Half attr" 60.Fa "const char **ret" 61.Fa "Dwarf_Error *err" 62.Fc 63.Ft int 64.Fo dwarf_attrval_unsigned 65.Fa "Dwarf_Die die" 66.Fa "Dwarf_Half attr" 67.Fa "Dwarf_Unsigned *ret" 68.Fa "Dwarf_Error *err" 69.Fc 70.Sh DESCRIPTION 71These functions search the debugging information entry referenced 72by argument 73.Ar die 74for the attribute named by argument 75.Ar attr . 76If the named attribute is found, the functions set the location 77pointed to by argument 78.Ar ret 79to the value of the attribute. 80The argument 81.Ar err , 82if non NULL, 83will be used to return an error descriptor in case of an error. 84.Pp 85Function 86.Fn dwarf_attrval_flag 87sets the location pointed to by argument 88.Ar ret 89to either 0 or 1. If the form of the attribute named by argument 90.Ar attr 91is 92.Dv DW_FORM_flag , 93function 94.Fn dwarf_attrval_flag 95sets the location pointed to by argument 96.Ar ret 97to 1 if the attribute has a non-zero value, or to 0 otherwise. 98If the form of the attribute named by argument 99.Ar attr 100is 101.Dv DW_FORM_flag_present , 102function 103.Fn dwarf_attrval_flag 104unconditionally sets the location pointed to by argument 105.Ar ret 106to 1. 107The form of the attribute must be one of 108.Dv DW_FORM_flag 109or 110.Dv DW_FORM_flag_present . 111.Pp 112Function 113.Fn dwarf_attrval_signed 114stores the value for the attribute named by argument 115.Ar attr , 116into the location pointed to by argument 117.Ar ret . 118The attribute's value is treated as a signed integral quantity and is 119sign-extended as needed. 120The attribute named by the argument 121.Ar attr 122must belong to the 123.Dv CONSTANT 124class and must have one of the following forms: 125.Dv DW_FORM_data1 , 126.Dv DW_FORM_data2 , 127.Dv DW_FORM_data4 , 128.Dv DW_FORM_data8 129or 130.Dv DW_FORM_sdata . 131.Pp 132Function 133.Fn dwarf_attrval_string 134sets the location pointed to by argument 135.Ar ret 136to a pointer to a NUL-terminated string that is the value of the 137attribute named by argument 138.Ar attr . 139The form of the attribute must be one of 140.Dv DW_FORM_string 141or 142.Dv DW_FORM_strp . 143.Pp 144Function 145.Fn dwarf_attrval_unsigned 146stores the value for the attribute named by argument 147.Ar attr 148into the location pointed to by argument 149.Ar ret . 150The attribute's value is treated as an unsigned integral quantity, and 151is zero-extended as needed. 152The named attribute must belong to one of the 153.Dv CONSTANT , 154.Dv ADDRESS 155or 156.Dv REFERENCE 157classes and must have one of the following forms: 158.Dv DW_FORM_addr , 159.Dv DW_FORM_data1 , 160.Dv DW_FORM_data2 , 161.Dv DW_FORM_data4 , 162.Dv DW_FORM_data8 , 163.Dv DW_FORM_udata , 164.Dv DW_FORM_ref1 , 165.Dv DW_FORM_ref2 , 166.Dv DW_FORM_ref4 , 167.Dv DW_FORM_ref8 , 168or 169.Dv DW_FORM_ref_udata . 170.Pp 171If the attribute named by argument 172.Ar attr 173is 174.Dv DW_AT_type 175and is not present in the debugging information entry referenced by argument 176.Ar die , 177and if a 178.Dv DW_AT_abstract_origin 179or 180.Dv DW_AT_specification 181attribute is present in the debugging information entry, 182function 183.Fn dwarf_attrval_unsigned 184will search for the named attribute in the debugging information entry 185referenced by the 186.Dv DW_AT_abstract_origin 187or 188.Dv DW_AT_specification 189attribute. 190.Sh RETURN VALUES 191On success, these functions returns 192.Dv DW_DLV_OK . 193If the named attribute was not found in the specified debugging 194information entry descriptor these functions return 195.Dv DW_DLV_NO_ENTRY 196and set argument 197.Ar err . 198For other errors, these functions return 199.Dv DW_DLV_ERROR 200and set argument 201.Ar err . 202.Sh COMPATIBILITY 203These functions are extensions added by this implementation of the 204DWARF(3) API. 205.Sh ERRORS 206These functions may fail with the following errors: 207.Bl -tag -width ".Bq Er DW_DLE_ATTR_FORM_BAD" 208.It Bq Er DW_DLE_ARGUMENT 209Either of the arguments 210.Va die 211or 212.Va ret 213was NULL. 214.It Bq Er DW_DLE_NO_ENTRY 215Argument 216.Ar die 217did not contain an attribute corresponding to the value in argument 218.Ar attr . 219.It Bq Er DW_DLE_ATTR_FORM_BAD 220The attribute named by argument 221.Ar attr 222was not of a permitted form. 223.El 224.Sh SEE ALSO 225.Xr dwarf 3 , 226.Xr dwarf_attr 3 , 227.Xr dwarf_hasattr 3 228