Path: blob/main/contrib/elftoolchain/libdwarf/dwarf_arange.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_arange.c 2072 2011-10-27 03:26:49Z jkoshy $");2930int31dwarf_get_aranges(Dwarf_Debug dbg, Dwarf_Arange **arlist,32Dwarf_Signed *ret_arange_cnt, Dwarf_Error *error)33{3435if (dbg == NULL || arlist == NULL || ret_arange_cnt == NULL) {36DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);37return (DW_DLV_ERROR);38}3940if (dbg->dbg_arange_cnt == 0) {41if (_dwarf_arange_init(dbg, error) != DW_DLE_NONE)42return (DW_DLV_ERROR);43if (dbg->dbg_arange_cnt == 0) {44DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);45return (DW_DLV_NO_ENTRY);46}47}4849assert(dbg->dbg_arange_array != NULL);5051*arlist = dbg->dbg_arange_array;52*ret_arange_cnt = dbg->dbg_arange_cnt;5354return (DW_DLV_OK);55}5657int58dwarf_get_arange(Dwarf_Arange *arlist, Dwarf_Unsigned arange_cnt,59Dwarf_Addr addr, Dwarf_Arange *ret_arange, Dwarf_Error *error)60{61Dwarf_Arange ar;62Dwarf_Debug dbg;63int i;6465if (arlist == NULL) {66DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);67return (DW_DLV_ERROR);68}6970dbg = (*arlist)->ar_as->as_cu->cu_dbg;7172if (ret_arange == NULL || arange_cnt == 0) {73DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);74return (DW_DLV_ERROR);75}7677for (i = 0; (Dwarf_Unsigned)i < arange_cnt; i++) {78ar = arlist[i];79if (addr >= ar->ar_address && addr < ar->ar_address +80ar->ar_range) {81*ret_arange = ar;82return (DW_DLV_OK);83}84}8586DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);8788return (DW_DLV_NO_ENTRY);89}9091int92dwarf_get_cu_die_offset(Dwarf_Arange ar, Dwarf_Off *ret_offset,93Dwarf_Error *error)94{95Dwarf_CU cu;96Dwarf_ArangeSet as;9798if (ar == NULL) {99DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);100return (DW_DLV_ERROR);101}102103as = ar->ar_as;104assert(as != NULL);105cu = as->as_cu;106assert(cu != NULL);107108if (ret_offset == NULL) {109DWARF_SET_ERROR(cu->cu_dbg, error, DW_DLE_ARGUMENT);110return (DW_DLV_ERROR);111}112113*ret_offset = cu->cu_1st_offset;114115return (DW_DLV_OK);116}117118int119dwarf_get_arange_cu_header_offset(Dwarf_Arange ar, Dwarf_Off *ret_offset,120Dwarf_Error *error)121{122Dwarf_ArangeSet as;123124if (ar == NULL) {125DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);126return (DW_DLV_ERROR);127}128129as = ar->ar_as;130assert(as != NULL);131132if (ret_offset == NULL) {133DWARF_SET_ERROR(as->as_cu->cu_dbg, error, DW_DLE_ARGUMENT);134return (DW_DLV_ERROR);135}136137*ret_offset = as->as_cu_offset;138139return (DW_DLV_OK);140}141142int143dwarf_get_arange_info(Dwarf_Arange ar, Dwarf_Addr *start,144Dwarf_Unsigned *length, Dwarf_Off *cu_die_offset, Dwarf_Error *error)145{146Dwarf_CU cu;147Dwarf_ArangeSet as;148149if (ar == NULL) {150DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);151return (DW_DLV_ERROR);152}153154as = ar->ar_as;155assert(as != NULL);156cu = as->as_cu;157assert(cu != NULL);158159if (start == NULL || length == NULL ||160cu_die_offset == NULL) {161DWARF_SET_ERROR(cu->cu_dbg, error, DW_DLE_ARGUMENT);162return (DW_DLV_ERROR);163}164165*start = ar->ar_address;166*length = ar->ar_range;167*cu_die_offset = cu->cu_1st_offset;168169return (DW_DLV_OK);170}171172173