dwarf_init_finish.c revision 49d3bc91e27cd871b950d56c01398fa2f2e12ab4
/*
Copyright (C) 2000,2002,2003 Silicon Graphics, Inc. All Rights Reserved.
under the terms of version 2.1 of the GNU Lesser General Public License
as published by the Free Software Foundation.
This program is distributed in the hope that it would be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Further, this software is distributed without any warranty that it is
free of the rightful claim of any third person regarding infringement
or the like. Any license provided herein, whether implied or
otherwise, applies only to this software file. Patent licenses, if
any, provided herein do not apply to combinations of this program with
other software, or any other product whatsoever.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307,
USA.
Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky,
Mountain View, CA 94043, or:
For further information regarding this notice, see:
*/
#include "config.h"
#include "dwarf_incl.h"
#ifdef HAVE_ELF_H
#include <elf.h>
#endif
#ifdef __SGI_FAST_LIBELF
#include <libelf_sgi.h>
#else
#ifdef HAVE_LIBELF_H
#include <libelf.h>
#else
#ifdef HAVE_LIBELF_LIBELF_H
#endif
#endif
#endif /* !defined(__SGI_FAST_LIBELF) */
#include <gelf.h>
#include <strings.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include "dwarf_incl.h"
#define FALSE 0
#define TRUE 1
#ifdef __SGI_FAST_LIBELF
#else
#ifdef HAVE_ELF64_GETEHDR
#endif
#ifdef HAVE_ELF64_GETSHDR
#endif
#endif /* !defined(__SGI_FAST_LIBELF) */
/* This static is copied to the dbg on dbg init
so that the static need not be referenced at
run time, preserving better locality of
reference.
Value is 0 means do the string check.
Value non-zero means do not do the check.
*/
static Dwarf_Small _dwarf_assume_string_bad;
int
{
int oldval = _dwarf_assume_string_bad;
return oldval;
}
#ifdef __SGI_FAST_LIBELF
/*
This function translates an elf_sgi error code into a libdwarf
code.
*/
static int
{
switch (val) {
case ELF_SGI_ERROR_OK: return DW_DLE_NE;
case ELF_SGI_ERROR_BAD_ALLOC: return DW_DLE_MAF;
case ELF_SGI_ERROR_FORMAT: return DW_DLE_MDE;
case ELF_SGI_ERROR_ERRNO: return DW_DLE_IOF;
case ELF_SGI_ERROR_TOO_BIG: return DW_DLE_MOF;
default: return DW_DLE_LEE;
}
}
#endif
/*
Given an Elf ptr, set up dbg with pointers
to all the Dwarf data sections.
Return NULL on error.
This function is also responsible for determining
whether the given object contains Dwarf information
or not. The test currently used is that it contains
either a .debug_info or a .debug_frame section. If
not, it returns DW_DLV_NO_ENTRY causing dwarf_init() also to
return DW_DLV_NO_ENTRY. Earlier, we had thought of using only
added .debug_frame since there could be stripped objects
that have only a .debug_frame section for exception
processing.
DW_DLV_NO_ENTRY or DW_DLV_OK or DW_DLV_ERROR
*/
static int
{
#ifdef __SGI_FAST_LIBELF
enum elf_sgi_error_type sres;
unsigned char const* ehdr_ident;
#else
#ifdef HAVE_ELF64_GETEHDR
#endif
#ifdef HAVE_ELF64_GETSHDR
#endif
char *ehdr_ident;
#endif /* !defined(__SGI_FAST_LIBELF) */
char *scn_name;
int is_64bit;
int foundDwarf;
foundDwarf = FALSE;
#ifdef __SGI_FAST_LIBELF
if (sres != ELF_SGI_ERROR_OK) {
}
#else
}
#endif
#ifdef WORDS_BIGENDIAN
dbg->de_same_endian = 0;
dbg->de_big_endian_object = 0;
}
#else /* little endian */
dbg->de_big_endian_object = 0;
dbg->de_same_endian = 0;
}
#endif /* !WORDS_BIGENDIAN */
/* The following de_length_size is Not Too Significant.
Only used one calculation, and an appoximate one at that. */
#ifdef __SGI_FAST_LIBELF
/* We've already loaded the ELF header, so there's nothing to do here */
#else
#ifdef HAVE_ELF64_GETEHDR
if (is_64bit) {
}
} else
#endif
{
}
}
#endif /* !defined(__SGI_FAST_LIBELF) */
Other platforms make length 4 always. */
/* 4 here supports 32bit-offset dwarf2, as emitted by
cygnus tools, and the dwarfv2.1 64bit extension setting. */
}
/* We start at index 1 to skip the initial empty section. */
#ifdef __SGI_FAST_LIBELF
if (sres != ELF_SGI_ERROR_OK) {
}
if (sres != ELF_SGI_ERROR_OK) {
}
#else /* !defined(__SGI_FAST_LIBELF) */
}
#ifdef HAVE_ELF64_GETSHDR
if (is_64bit) {
}
== NULL) {
}
} else
#endif /* HAVE_ELF64_GETSHDR */
{
}
}
}
#endif /* !defined(__SGI_FAST_LIBELF) */
)
continue;
}
if (section_size == 0) {
/* Know no reason to allow empty debug_info section */
}
foundDwarf = TRUE;
}
}
if (section_size == 0) {
/* Know no reason to allow empty debug_abbrev section */
}
}
if (dbg->de_debug_aranges_index != 0) {
}
if (section_size == 0) {
/* a zero size section is just empty. Ok, no error */
continue;
}
}
if (dbg->de_debug_line_index != 0) {
}
if (section_size == 0) {
/* a zero size section is just empty. Ok, no error */
continue;
}
}
if (dbg->de_debug_frame_index != 0) {
}
if (section_size == 0) {
/* a zero size section is just empty. Ok, no error */
continue;
}
foundDwarf = TRUE;
/* gnu egcs-1.1.2 data */
if (dbg->de_debug_frame_eh_gnu_index != 0) {
}
if (section_size == 0) {
/* a zero size section is just empty. Ok, no error */
continue;
}
foundDwarf = TRUE;
}
if (dbg->de_debug_loc_index != 0) {
}
if (section_size == 0) {
/* a zero size section is just empty. Ok, no error */
continue;
}
}
if (dbg->de_debug_pubnames_index != 0) {
}
if (section_size == 0) {
/* a zero size section is just empty. Ok, no error */
continue;
}
}
if (dbg->de_debug_str_index != 0) {
}
if (section_size == 0) {
/* a zero size section is just empty. Ok, no error */
continue;
}
}
if (dbg->de_debug_funcnames_index != 0) {
}
if (section_size == 0) {
/* a zero size section is just empty. Ok, no error */
continue;
}
}
if (dbg->de_debug_typenames_index != 0) {
}
if (section_size == 0) {
/* a zero size section is just empty. Ok, no error */
continue;
}
}
if (dbg->de_debug_varnames_index != 0) {
}
if (section_size == 0) {
/* a zero size section is just empty. Ok, no error */
continue;
}
}
if (dbg->de_debug_weaknames_index != 0) {
}
if (section_size == 0) {
/* a zero size section is just empty. Ok, no error */
continue;
}
if (dbg->de_debug_macinfo_index != 0) {
}
if (section_size == 0) {
/* a zero size section is just empty. Ok, no error */
continue;
}
}
}
if (foundDwarf) {
return DW_DLV_OK;
}
return (DW_DLV_NO_ENTRY);
}
/*
The basic dwarf initializer function for consumers.
Return NULL on error.
*/
int
dwarf_init(int fd,
{
int res;
#ifdef __SGI_FAST_LIBELF
enum elf_sgi_error_type sres;
#else
#endif
dbg = _dwarf_get_debug();
}
}
}
if (access != DW_DLC_READ) {
}
#ifdef __SGI_FAST_LIBELF
elf = elf_sgi_new();
}
if (sres != ELF_SGI_ERROR_OK) {
}
#else
/* changed to mmap request per bug 281217. 6/95 */
#ifdef HAVE_ELF_C_READ_MMAP
/* ELF_C_READ_MMAP is an SGI IRIX specific enum value from IRIX
libelf.h meaning read but use mmap */
#else
/* ELF_C_READ is a portable value */
#endif
}
#endif /* !defined(__SGI_FAST_LIBELF) */
return (res);
}
/* call cannot fail: no malloc or free involved */
return (DW_DLV_OK);
}
/*
The alternate dwarf setup call for consumers
*/
int
{
int res;
dbg = _dwarf_get_debug();
}
if (access != DW_DLC_READ) {
}
dbg->de_elf_must_close = 0;
return (res);
}
/* this call cannot fail: allocates nothing, releases nothing */
return (DW_DLV_OK);
}
/*
Frees all memory that was not previously freed
by dwarf_dealloc.
Aside from certain categories.
*/
int
{
if(dbg->de_elf_must_close) {
/* Must do this *before* _dwarf_free_all_of_one_debug()
as that zeroes out dbg contents
*/
#ifdef __SGI_FAST_LIBELF
#else
#endif
}
if (res == DW_DLV_ERROR) {
}
return res;
}
/*
This function returns the Elf * pointer
associated with a Dwarf_Debug.
*/
int
{
return (DW_DLV_ERROR);
}
return (DW_DLV_OK);
}
#if defined(__i386)
static Dwarf_Small *
{
char *newdata;
return (NULL);
}
break;
}
return (NULL);
}
return (NULL);
}
continue;
"unexpected reloc type %d\n",
continue;
}
}
return ((Dwarf_Small *)newdata);
}
#endif
/*
Load the ELF section with the specified index and set the
pointer pointed to by section_data to the memory where it
was loaded.
*/
int
Dwarf_Error * error)
{
if (section_index == 0) {
return DW_DLV_NO_ENTRY;
}
/* check to see if the section is already loaded */
if (*section_data != NULL) {
return DW_DLV_OK;
}
{
#ifdef __SGI_FAST_LIBELF
enum elf_sgi_error_type sres;
(void**) section_data);
if (sres != ELF_SGI_ERROR_OK) {
}
#else
return DW_DLV_ERROR;
}
/*
When using libelf as a producer, section data may be stored
in multiple buffers. In libdwarf however, we only use libelf
as a consumer (there is a dwarf producer API, but it doesn't
use libelf). Because of this, this single call to elf_getdata
will retrieve the entire section in a single contiguous buffer.
*/
return DW_DLV_ERROR;
}
#if defined(__i386)
return (DW_DLV_ERROR); /* _dwarf_error is set for us */
#else
#endif
#endif /* !defined(__SGI_FAST_LIBELF) */
}
return DW_DLV_OK;
}