Index: head/contrib/elftoolchain/libdwarf/dwarf_attrval.c =================================================================== --- head/contrib/elftoolchain/libdwarf/dwarf_attrval.c (revision 310723) +++ head/contrib/elftoolchain/libdwarf/dwarf_attrval.c (revision 310724) @@ -1,212 +1,222 @@ /*- * Copyright (c) 2007 John Birrell (jb@freebsd.org) * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "_libdwarf.h" ELFTC_VCSID("$Id: dwarf_attrval.c 3159 2015-02-15 21:43:27Z emaste $"); int dwarf_attrval_flag(Dwarf_Die die, Dwarf_Half attr, Dwarf_Bool *valp, Dwarf_Error *err) { Dwarf_Attribute at; Dwarf_Debug dbg; dbg = die != NULL ? die->die_dbg : NULL; if (die == NULL || valp == NULL) { DWARF_SET_ERROR(dbg, err, DW_DLE_ARGUMENT); return (DW_DLV_ERROR); } *valp = 0; if ((at = _dwarf_attr_find(die, attr)) == NULL) { DWARF_SET_ERROR(dbg, err, DW_DLE_NO_ENTRY); return (DW_DLV_NO_ENTRY); } switch (at->at_form) { case DW_FORM_flag: case DW_FORM_flag_present: *valp = (Dwarf_Bool) (!!at->u[0].u64); break; default: DWARF_SET_ERROR(dbg, err, DW_DLE_ATTR_FORM_BAD); return (DW_DLV_ERROR); } return (DW_DLV_OK); } int dwarf_attrval_string(Dwarf_Die die, Dwarf_Half attr, const char **strp, Dwarf_Error *err) { Dwarf_Attribute at; Dwarf_Debug dbg; dbg = die != NULL ? die->die_dbg : NULL; if (die == NULL || strp == NULL) { DWARF_SET_ERROR(dbg, err, DW_DLE_ARGUMENT); return (DW_DLV_ERROR); } *strp = NULL; if ((at = _dwarf_attr_find(die, attr)) == NULL) { DWARF_SET_ERROR(dbg, err, DW_DLE_NO_ENTRY); return (DW_DLV_NO_ENTRY); } switch (at->at_form) { case DW_FORM_strp: *strp = at->u[1].s; break; case DW_FORM_string: *strp = at->u[0].s; break; default: DWARF_SET_ERROR(dbg, err, DW_DLE_ATTR_FORM_BAD); return (DW_DLV_ERROR); } return (DW_DLV_OK); } int dwarf_attrval_signed(Dwarf_Die die, Dwarf_Half attr, Dwarf_Signed *valp, Dwarf_Error *err) { Dwarf_Attribute at; Dwarf_Debug dbg; dbg = die != NULL ? die->die_dbg : NULL; if (die == NULL || valp == NULL) { DWARF_SET_ERROR(dbg, err, DW_DLE_ARGUMENT); return (DW_DLV_ERROR); } *valp = 0; if ((at = _dwarf_attr_find(die, attr)) == NULL) { DWARF_SET_ERROR(dbg, err, DW_DLE_NO_ENTRY); return (DW_DLV_NO_ENTRY); } switch (at->at_form) { case DW_FORM_data1: *valp = (int8_t) at->u[0].s64; break; case DW_FORM_data2: *valp = (int16_t) at->u[0].s64; break; case DW_FORM_data4: *valp = (int32_t) at->u[0].s64; break; case DW_FORM_data8: case DW_FORM_sdata: *valp = at->u[0].s64; break; default: DWARF_SET_ERROR(dbg, err, DW_DLE_ATTR_FORM_BAD); return (DW_DLV_ERROR); } return (DW_DLV_OK); } int dwarf_attrval_unsigned(Dwarf_Die die, Dwarf_Half attr, Dwarf_Unsigned *valp, Dwarf_Error *err) { Dwarf_Attribute at; Dwarf_Die die1; Dwarf_Unsigned val; Dwarf_Debug dbg; + int first; dbg = die != NULL ? die->die_dbg : NULL; if (die == NULL || valp == NULL) { DWARF_SET_ERROR(dbg, err, DW_DLE_ARGUMENT); return (DW_DLV_ERROR); } *valp = 0; - if ((at = _dwarf_attr_find(die, attr)) == NULL && attr != DW_AT_type) { - DWARF_SET_ERROR(dbg, err, DW_DLE_NO_ENTRY); - return (DW_DLV_NO_ENTRY); - } - die1 = NULL; - if (at == NULL && - (at = _dwarf_attr_find(die, DW_AT_abstract_origin)) != NULL) { + for (;;) { + if ((at = _dwarf_attr_find(die, attr)) != NULL || + attr != DW_AT_type) + break; + if ((at = _dwarf_attr_find(die, DW_AT_abstract_origin)) == + NULL && + (at = _dwarf_attr_find(die, DW_AT_specification)) == NULL) + break; + switch (at->at_form) { case DW_FORM_ref1: case DW_FORM_ref2: case DW_FORM_ref4: case DW_FORM_ref8: case DW_FORM_ref_udata: val = at->u[0].u64; - if ((die1 = _dwarf_die_find(die, val)) == NULL || - (at = _dwarf_attr_find(die1, attr)) == NULL) { - if (die1 != NULL) - dwarf_dealloc(dbg, die1, DW_DLA_DIE); + first = (die1 == NULL); + die1 = _dwarf_die_find(die, val); + if (!first) + dwarf_dealloc(dbg, die, DW_DLA_DIE); + if (die1 == NULL) { DWARF_SET_ERROR(dbg, err, DW_DLE_NO_ENTRY); return (DW_DLV_NO_ENTRY); } + die = die1; break; default: DWARF_SET_ERROR(dbg, err, DW_DLE_ATTR_FORM_BAD); return (DW_DLV_ERROR); } + } + + if (at == NULL) { + DWARF_SET_ERROR(dbg, err, DW_DLE_NO_ENTRY); + return (DW_DLV_NO_ENTRY); } switch (at->at_form) { case DW_FORM_addr: case DW_FORM_data1: case DW_FORM_data2: case DW_FORM_data4: case DW_FORM_data8: case DW_FORM_udata: case DW_FORM_ref1: case DW_FORM_ref2: case DW_FORM_ref4: case DW_FORM_ref8: case DW_FORM_ref_udata: *valp = at->u[0].u64; break; default: if (die1 != NULL) dwarf_dealloc(dbg, die1, DW_DLA_DIE); DWARF_SET_ERROR(dbg, err, DW_DLE_ATTR_FORM_BAD); return (DW_DLV_ERROR); } if (die1 != NULL) dwarf_dealloc(dbg, die1, DW_DLA_DIE); return (DW_DLV_OK); } Index: head/contrib/elftoolchain/libdwarf/dwarf_attrval_signed.3 =================================================================== --- head/contrib/elftoolchain/libdwarf/dwarf_attrval_signed.3 (revision 310723) +++ head/contrib/elftoolchain/libdwarf/dwarf_attrval_signed.3 (revision 310724) @@ -1,220 +1,225 @@ .\" Copyright (c) 2011 Kai Wang .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $Id: dwarf_attrval_signed.3 2980 2014-01-21 20:15:54Z kaiwang27 $ .\" -.Dd January 18, 2014 +.Dd December 26, 2016 .Os .Dt DWARF_ATTRVAL_SIGNED 3 .Sh NAME .Nm dwarf_attrval_flag , .Nm dwarf_attrval_signed , .Nm dwarf_attrval_string , .Nm dwarf_attrval_unsigned .Nd retrieve the value of an attribute within a DWARF debugging information entry .Sh LIBRARY .Lb libdwarf .Sh SYNOPSIS .In libdwarf.h .Ft int .Fo dwarf_attrval_flag .Fa "Dwarf_Die die" .Fa "Dwarf_Half attr" .Fa "Dwarf_Bool *ret" .Fa "Dwarf_Error *err" .Fc .Ft int .Fo dwarf_attrval_signed .Fa "Dwarf_Die die" .Fa "Dwarf_Half attr" .Fa "Dwarf_Signed *ret" .Fa "Dwarf_Error *err" .Fc .Ft int .Fo dwarf_attrval_string .Fa "Dwarf_Die die" .Fa "Dwarf_Half attr" .Fa "const char **ret" .Fa "Dwarf_Error *err" .Fc .Ft int .Fo dwarf_attrval_unsigned .Fa "Dwarf_Die die" .Fa "Dwarf_Half attr" .Fa "Dwarf_Unsigned *ret" .Fa "Dwarf_Error *err" .Fc .Sh DESCRIPTION These functions search the debugging information entry referenced by argument .Ar die for the attribute named by argument .Ar attr . If the named attribute is found, the functions set the location pointed to by argument .Ar ret to the value of the attribute. The argument .Ar err , if non NULL, will be used to return an error descriptor in case of an error. .Pp Function .Fn dwarf_attrval_flag sets the location pointed to by argument .Ar ret to either 0 or 1. If the form of the attribute named by argument .Ar attr is .Dv DW_FORM_flag , function .Fn dwarf_attrval_flag sets the location pointed to by argument .Ar ret to 1 if the attribute has a non-zero value, or to 0 otherwise. If the form of the attribute named by argument .Ar attr is .Dv DW_FORM_flag_present , function .Fn dwarf_attrval_flag unconditionally sets the location pointed to by argument .Ar ret to 1. The form of the attribute must be one of .Dv DW_FORM_flag or .Dv DW_FORM_flag_present . .Pp Function .Fn dwarf_attrval_signed stores the value for the attribute named by argument .Ar attr , into the location pointed to by argument .Ar ret . The attribute's value is treated as a signed integral quantity and is sign-extended as needed. The attribute named by the argument .Ar attr must belong to the .Dv CONSTANT class and must have one of the following forms: .Dv DW_FORM_data1 , .Dv DW_FORM_data2 , .Dv DW_FORM_data4 , .Dv DW_FORM_data8 or .Dv DW_FORM_sdata . .Pp Function .Fn dwarf_attrval_string sets the location pointed to by argument .Ar ret to a pointer to a NUL-terminated string that is the value of the attribute named by argument .Ar attr . The form of the attribute must be one of .Dv DW_FORM_string or .Dv DW_FORM_strp . .Pp Function .Fn dwarf_attrval_unsigned stores the value for the attribute named by argument .Ar attr into the location pointed to by argument .Ar ret . The attribute's value is treated as an unsigned integral quantity, and is zero-extended as needed. The named attribute must belong to one of the .Dv CONSTANT , .Dv ADDRESS or .Dv REFERENCE classes and must have one of the following forms: .Dv DW_FORM_addr , .Dv DW_FORM_data1 , .Dv DW_FORM_data2 , .Dv DW_FORM_data4 , .Dv DW_FORM_data8 , .Dv DW_FORM_udata , .Dv DW_FORM_ref1 , .Dv DW_FORM_ref2 , .Dv DW_FORM_ref4 , .Dv DW_FORM_ref8 , or .Dv DW_FORM_ref_udata . .Pp If the attribute named by argument .Ar attr -is not present in the debugging information entry referenced by -argument +is +.Dv DW_AT_type +and is not present in the debugging information entry referenced by argument .Ar die , and if a .Dv DW_AT_abstract_origin +or +.Dv DW_AT_specification attribute is present in the debugging information entry, function .Fn dwarf_attrval_unsigned will search for the named attribute in the debugging information entry referenced by the .Dv DW_AT_abstract_origin +or +.Dv DW_AT_specification attribute. .Sh RETURN VALUES On success, these functions returns .Dv DW_DLV_OK . If the named attribute was not found in the specified debugging information entry descriptor these functions return .Dv DW_DLV_NO_ENTRY and set argument .Ar err . For other errors, these functions return .Dv DW_DLV_ERROR and set argument .Ar err . .Sh COMPATIBILITY These functions are extensions added by this implementation of the DWARF(3) API. .Sh ERRORS These functions may fail with the following errors: .Bl -tag -width ".Bq Er DW_DLE_ATTR_FORM_BAD" .It Bq Er DW_DLE_ARGUMENT Either of the arguments .Va die or .Va ret was NULL. .It Bq Er DW_DLE_NO_ENTRY Argument .Ar die did not contain an attribute corresponding to the value in argument .Ar attr . .It Bq Er DW_DLE_ATTR_FORM_BAD The attribute named by argument .Ar attr was not of a permitted form. .El .Sh SEE ALSO .Xr dwarf 3 , .Xr dwarf_attr 3 , .Xr dwarf_hasattr 3