dwarf_cu.c revision 260684
1317017Sdim/*- 2317017Sdim * Copyright (c) 2007 John Birrell (jb@freebsd.org) 3353358Sdim * All rights reserved. 4353358Sdim * 5353358Sdim * Redistribution and use in source and binary forms, with or without 6317017Sdim * modification, are permitted provided that the following conditions 7317017Sdim * are met: 8317017Sdim * 1. Redistributions of source code must retain the above copyright 9317017Sdim * notice, this list of conditions and the following disclaimer. 10317017Sdim * 2. Redistributions in binary form must reproduce the above copyright 11317017Sdim * notice, this list of conditions and the following disclaimer in the 12319250Sdim * documentation and/or other materials provided with the distribution. 13353358Sdim * 14317017Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15317778Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16317969Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17317778Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18317017Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19317017Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20317017Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21317017Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22317017Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23317017Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24317017Sdim * SUCH DAMAGE. 25317017Sdim */ 26317017Sdim 27317017Sdim#include "_libdwarf.h" 28317017Sdim 29317017SdimELFTC_VCSID("$Id: dwarf_cu.c 2072 2011-10-27 03:26:49Z jkoshy $"); 30317017Sdim 31317017Sdimint 32317017Sdimdwarf_next_cu_header_b(Dwarf_Debug dbg, Dwarf_Unsigned *cu_length, 33317017Sdim Dwarf_Half *cu_version, Dwarf_Off *cu_abbrev_offset, 34317017Sdim Dwarf_Half *cu_pointer_size, Dwarf_Half *cu_offset_size, 35317017Sdim Dwarf_Half *cu_extension_size, Dwarf_Unsigned *cu_next_offset, 36317017Sdim Dwarf_Error *error) 37317017Sdim{ 38317017Sdim Dwarf_CU cu; 39317017Sdim int ret; 40317017Sdim 41341825Sdim if (dbg == NULL) { 42317017Sdim DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT); 43341825Sdim return (DW_DLV_ERROR); 44317017Sdim } 45317017Sdim 46317017Sdim if (dbg->dbg_cu_current == NULL) 47317017Sdim ret = _dwarf_info_first_cu(dbg, error); 48317017Sdim else 49317017Sdim ret = _dwarf_info_next_cu(dbg, error); 50317017Sdim 51317017Sdim if (ret == DW_DLE_NO_ENTRY) { 52317017Sdim DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY); 53317017Sdim return (DW_DLV_NO_ENTRY); 54317017Sdim } else if (ret != DW_DLE_NONE) 55317017Sdim return (DW_DLV_ERROR); 56317017Sdim 57317017Sdim if (dbg->dbg_cu_current == NULL) { 58317017Sdim DWARF_SET_ERROR(dbg, error, DW_DLE_NO_ENTRY); 59317017Sdim return (DW_DLV_NO_ENTRY); 60317017Sdim } 61317017Sdim cu = dbg->dbg_cu_current; 62317017Sdim 63317017Sdim if (cu_length) 64317017Sdim *cu_length = cu->cu_length; 65317017Sdim if (cu_version) 66341825Sdim *cu_version = cu->cu_version; 67341825Sdim if (cu_abbrev_offset) 68320397Sdim *cu_abbrev_offset = (Dwarf_Off) cu->cu_abbrev_offset; 69320397Sdim if (cu_pointer_size) 70320397Sdim *cu_pointer_size = cu->cu_pointer_size; 71320397Sdim if (cu_offset_size) { 72320397Sdim if (cu->cu_length_size == 4) 73320397Sdim *cu_offset_size = 4; 74320397Sdim else 75317017Sdim *cu_offset_size = 8; 76317017Sdim } 77317017Sdim if (cu_extension_size) { 78317017Sdim if (cu->cu_length_size == 4) 79317969Sdim *cu_extension_size = 0; 80317017Sdim else 81344779Sdim *cu_extension_size = 4; 82317017Sdim } 83353358Sdim if (cu_next_offset) 84353358Sdim *cu_next_offset = dbg->dbg_cu_current->cu_next_offset; 85353358Sdim 86353358Sdim return (DW_DLV_OK); 87317017Sdim} 88317017Sdim 89317017Sdimint 90317017Sdimdwarf_next_cu_header(Dwarf_Debug dbg, Dwarf_Unsigned *cu_length, 91320970Sdim Dwarf_Half *cu_version, Dwarf_Off *cu_abbrev_offset, 92320970Sdim Dwarf_Half *cu_pointer_size, Dwarf_Unsigned *cu_next_offset, 93317017Sdim Dwarf_Error *error) 94317017Sdim{ 95341825Sdim 96317017Sdim return (dwarf_next_cu_header_b(dbg, cu_length, cu_version, 97353358Sdim cu_abbrev_offset, cu_pointer_size, NULL, NULL, cu_next_offset, 98353358Sdim error)); 99317017Sdim} 100353358Sdim