Path: blob/main/contrib/elftoolchain/libdwarf/dwarf_cu.c
39483 views
/*-1* Copyright (c) 2007 John Birrell ([email protected])2* Copyright (c) 2014 Kai Wang3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627#include "_libdwarf.h"2829ELFTC_VCSID("$Id: dwarf_cu.c 3041 2014-05-18 15:11:03Z kaiwang27 $");3031int32dwarf_next_cu_header_c(Dwarf_Debug dbg, Dwarf_Bool is_info,33Dwarf_Unsigned *cu_length, Dwarf_Half *cu_version,34Dwarf_Off *cu_abbrev_offset, Dwarf_Half *cu_pointer_size,35Dwarf_Half *cu_offset_size, Dwarf_Half *cu_extension_size,36Dwarf_Sig8 *type_signature, Dwarf_Unsigned *type_offset,37Dwarf_Unsigned *cu_next_offset, Dwarf_Error *error)38{39Dwarf_CU cu;40int ret;4142if (dbg == NULL) {43DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);44return (DW_DLV_ERROR);45}4647if (is_info) {48if (dbg->dbg_cu_current == NULL)49ret = _dwarf_info_first_cu(dbg, error);50else51ret = _dwarf_info_next_cu(dbg, error);52} else {53if (dbg->dbg_tu_current == NULL)54ret = _dwarf_info_first_tu(dbg, error);55else56ret = _dwarf_info_next_tu(dbg, error);57}5859if (ret == DW_DLE_NO_ENTRY) {60DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);61return (DW_DLV_NO_ENTRY);62} else if (ret != DW_DLE_NONE)63return (DW_DLV_ERROR);6465if (is_info) {66if (dbg->dbg_cu_current == NULL) {67DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);68return (DW_DLV_NO_ENTRY);69}70cu = dbg->dbg_cu_current;71} else {72if (dbg->dbg_tu_current == NULL) {73DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);74return (DW_DLV_NO_ENTRY);75}76cu = dbg->dbg_tu_current;77}7879if (cu_length)80*cu_length = cu->cu_length;81if (cu_version)82*cu_version = cu->cu_version;83if (cu_abbrev_offset)84*cu_abbrev_offset = (Dwarf_Off) cu->cu_abbrev_offset;85if (cu_pointer_size)86*cu_pointer_size = cu->cu_pointer_size;87if (cu_offset_size) {88if (cu->cu_length_size == 4)89*cu_offset_size = 4;90else91*cu_offset_size = 8;92}93if (cu_extension_size) {94if (cu->cu_length_size == 4)95*cu_extension_size = 0;96else97*cu_extension_size = 4;98}99if (cu_next_offset)100*cu_next_offset = cu->cu_next_offset;101102if (!is_info) {103if (type_signature)104*type_signature = cu->cu_type_sig;105if (type_offset)106*type_offset = cu->cu_type_offset;107}108109return (DW_DLV_OK);110}111112113int114dwarf_next_cu_header_b(Dwarf_Debug dbg, Dwarf_Unsigned *cu_length,115Dwarf_Half *cu_version, Dwarf_Off *cu_abbrev_offset,116Dwarf_Half *cu_pointer_size, Dwarf_Half *cu_offset_size,117Dwarf_Half *cu_extension_size, Dwarf_Unsigned *cu_next_offset,118Dwarf_Error *error)119{120121return (dwarf_next_cu_header_c(dbg, 1, cu_length, cu_version,122cu_abbrev_offset, cu_pointer_size, cu_offset_size,123cu_extension_size, NULL, NULL, cu_next_offset, error));124}125126int127dwarf_next_cu_header(Dwarf_Debug dbg, Dwarf_Unsigned *cu_length,128Dwarf_Half *cu_version, Dwarf_Off *cu_abbrev_offset,129Dwarf_Half *cu_pointer_size, Dwarf_Unsigned *cu_next_offset,130Dwarf_Error *error)131{132133return (dwarf_next_cu_header_b(dbg, cu_length, cu_version,134cu_abbrev_offset, cu_pointer_size, NULL, NULL, cu_next_offset,135error));136}137138int139dwarf_next_types_section(Dwarf_Debug dbg, Dwarf_Error *error)140{141142/* Free resource allocated for current .debug_types section. */143_dwarf_type_unit_cleanup(dbg);144dbg->dbg_types_loaded = 0;145dbg->dbg_types_off = 0;146147/* Reset type unit pointer. */148dbg->dbg_tu_current = NULL;149150/* Search for the next .debug_types section. */151dbg->dbg_types_sec = _dwarf_find_next_types_section(dbg,152dbg->dbg_types_sec);153154if (dbg->dbg_types_sec == NULL) {155DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY);156return (DW_DLV_NO_ENTRY);157}158159return (DW_DLV_OK);160}161162163