Path: blob/main/contrib/elftoolchain/libdwarf/dwarf_abbrev.c
39483 views
/*-1* Copyright (c) 2009,2011 Kai Wang2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526#include "_libdwarf.h"2728ELFTC_VCSID("$Id: dwarf_abbrev.c 2072 2011-10-27 03:26:49Z jkoshy $");2930int31dwarf_get_abbrev(Dwarf_Debug dbg, Dwarf_Unsigned offset,32Dwarf_Abbrev *return_abbrev, Dwarf_Unsigned *length,33Dwarf_Unsigned *attr_count, Dwarf_Error *error)34{35Dwarf_Abbrev ab;36int ret;3738if (dbg == NULL || return_abbrev == NULL || length == NULL ||39attr_count == NULL) {40DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);41return (DW_DLV_ERROR);42}4344ret = _dwarf_abbrev_parse(dbg, NULL, &offset, &ab, error);45if (ret != DW_DLE_NONE) {46if (ret == DW_DLE_NO_ENTRY) {47DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);48return (DW_DLV_NO_ENTRY);49} else50return (DW_DLV_ERROR);51}5253*return_abbrev = ab;54*length = ab->ab_length;55*attr_count = ab->ab_atnum;5657return (DW_DLV_OK);58}5960int61dwarf_get_abbrev_tag(Dwarf_Abbrev abbrev, Dwarf_Half *return_tag,62Dwarf_Error *error)63{6465if (abbrev == NULL || return_tag == NULL) {66DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);67return (DW_DLV_ERROR);68}6970*return_tag = (Dwarf_Half) abbrev->ab_tag;7172return (DW_DLV_OK);73}7475int76dwarf_get_abbrev_code(Dwarf_Abbrev abbrev, Dwarf_Unsigned *return_code,77Dwarf_Error *error)78{7980if (abbrev == NULL || return_code == NULL) {81DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);82return (DW_DLV_ERROR);83}8485*return_code = abbrev->ab_entry;8687return (DW_DLV_OK);88}8990int91dwarf_get_abbrev_children_flag(Dwarf_Abbrev abbrev, Dwarf_Signed *return_flag,92Dwarf_Error *error)93{9495if (abbrev == NULL || return_flag == NULL) {96DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);97return (DW_DLV_ERROR);98}99100*return_flag = (Dwarf_Signed) abbrev->ab_children;101102return (DW_DLV_OK);103}104105int106dwarf_get_abbrev_entry(Dwarf_Abbrev abbrev, Dwarf_Signed ndx,107Dwarf_Half *attr_num, Dwarf_Signed *form, Dwarf_Off *offset,108Dwarf_Error *error)109{110Dwarf_AttrDef ad;111int i;112113if (abbrev == NULL || attr_num == NULL || form == NULL ||114offset == NULL) {115DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);116return (DW_DLV_ERROR);117}118119if (ndx < 0 || (uint64_t) ndx >= abbrev->ab_atnum) {120DWARF_SET_ERROR(NULL, error, DW_DLE_NO_ENTRY);121return (DW_DLV_NO_ENTRY);122}123124ad = STAILQ_FIRST(&abbrev->ab_attrdef);125for (i = 0; i < ndx && ad != NULL; i++)126ad = STAILQ_NEXT(ad, ad_next);127128assert(ad != NULL);129130*attr_num = ad->ad_attrib;131*form = ad->ad_form;132*offset = ad->ad_offset;133134return (DW_DLV_OK);135}136137138