dwarf_die_deliv.c revision 49d3bc91e27cd871b950d56c01398fa2f2e12ab4
/*
Copyright (C) 2000,2001,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
#include <stdio.h>
#include "dwarf_die_deliv.h"
/*
For a given Dwarf_Debug dbg, this function checks
if a CU that includes the given offset has been read
or not. If yes, it returns the Dwarf_CU_Context
for the CU. Otherwise it returns NULL. Being an
internal routine, it is assumed that a valid dbg
is passed.
**This is a sequential search. May be too slow.
If debug_info and debug_abbrev not loaded, this will
wind up returning NULL. So no need to load before calling
this.
*/
static Dwarf_CU_Context
{
return (NULL);
}
+ cu_context->cc_extension_size) {
return (cu_context);
}
}
}
+ cu_context->cc_extension_size) {
return (cu_context);
}
}
return (NULL);
}
/*
This routine checks the dwarf_offdie() list of
CU contexts for the right CU context.
*/
static Dwarf_CU_Context
{
return (cu_context);
return (NULL);
}
/*
This function is used to create a CU Context for
a compilation-unit that begins at offset in
.debug_info. The CU Context is attached to the
list of CU Contexts for this dbg. It is assumed
that the CU at offset has not been read before,
and so do not call this routine before making
sure of this with _dwarf_find_CU_Context().
Returns NULL on error. As always, being an
internal routine, assumes a good dbg.
This function must always set a dwarf error code
before returning NULL. Always.
*/
static Dwarf_CU_Context
{
int local_extension_size = 0;
int local_length_size;
if (cu_context == NULL) {
return (NULL);
}
/* READ_AREA_LENGTH updates cu_ptr for consumed bytes */
cu_ptr, sizeof(Dwarf_Half));
cu_ptr += sizeof(Dwarf_Half);
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (NULL);
}
} else {
}
return (cu_context);
}
/*
Returns offset of next compilation-unit thru next_cu_offset
pointer.
It basically sequentially moves from one
cu to the next. The current cu is recorded
internally by libdwarf.
*/
int
Dwarf_Error * error)
{
/* Offset for current and new CU. */
/* CU Context for current CU. */
/* ***** BEGIN CODE ***** */
return (DW_DLV_ERROR);
}
/*
Get offset into .debug_info of next CU. If dbg has no context,
this has to be the first one. */
new_offset = 0;
if (!dbg->de_debug_info) {
return res;
}
}
} else {
}
/*
Check that there is room in .debug_info beyond the new offset
for at least a new cu header. If not, return 0 to indicate end
of debug_info section, and reset de_cu_debug_info_offset to
enable looping back through the cu's. */
return (DW_DLV_NO_ENTRY);
}
/* Check if this CU has been read before. */
/* If not, make CU Context for it. */
if (cu_context == NULL) {
if (cu_context == NULL) {
/* Error if CU Context could not be made. Since
_dwarf_make_CU_Context has already registered an error
we do not do that here: we let the lower error pass
thru. */
return (DW_DLV_ERROR);
}
}
if (cu_header_length != NULL)
if (version_stamp != NULL)
if (abbrev_offset != NULL)
if (address_size != NULL)
return (DW_DLV_OK);
}
/*
This function does two slightly different things
depending on the input flag want_AT_sibling. If
this flag is true, it checks if the input die has
a DW_AT_sibling attribute. If it does it returns
a pointer to the start of the sibling die in the
.debug_info section. Otherwise it behaves the
same as the want_AT_sibling false case.
If the want_AT_sibling flag is false, it returns
a pointer to the immediately adjacent die in the
.debug_info section.
Die_info_end points to the end of the .debug_info
portion for the cu the die belongs to. It is used
to check that the search for the next die does not
cross the end of the current cu. Cu_info_start points
to the start of the .debug_info portion for the
current cu, and is used to add to the offset for
DW_AT_sibling attributes. Finally, has_die_child
is a pointer to a Dwarf_Bool that is set true if
the present die has children, false otherwise.
However, in case want_AT_child is true and the die
has a DW_AT_sibling attribute *has_die_child is set
false to indicate that the children are being skipped.
*/
static Dwarf_Byte_Ptr
{
if (abbrev_code == 0) {
return NULL;
}
if (abbrev_list == NULL) {
return (NULL);
}
do {
if (attr_form == DW_FORM_indirect) {
/* READ_UNALIGNED does update info_ptr */
}
switch (attr_form) {
case DW_FORM_ref1:
break;
case DW_FORM_ref2:
info_ptr, sizeof(Dwarf_Half));
break;
case DW_FORM_ref4:
info_ptr, sizeof(Dwarf_ufixed));
break;
case DW_FORM_ref8:
info_ptr, sizeof(Dwarf_Unsigned));
break;
case DW_FORM_ref_udata:
offset =
break;
default:
return (NULL);
}
/* Reset *has_die_child to indicate children skipped. */
*has_die_child = false;
return (NULL);
} else {
return (cu_info_start + offset);
}
}
if (attr_form != 0) {
if (info_ptr > die_info_end) {
return (NULL);
}
}
return (info_ptr);
}
/*
Given a Dwarf_Debug dbg, and a Dwarf_Die die, it returns
a Dwarf_Die for the sibling of die. In case die is NULL,
it returns (thru ptr) a Dwarf_Die for the first die in the current
cu in dbg. Returns DW_DLV_ERROR on error.
It is assumed that every sibling chain including those with
only one element is terminated with a NULL die, except a
chain with only a NULL die.
The algorithm moves from one die to the adjacent one. It
returns when the depth of children it sees equals the number
of sibling chain terminations. A single count, child_depth
is used to track the depth of children and sibling terminations
encountered. Child_depth is incremented when a die has the
Has-Child flag set unless the child happens to be a NULL die.
Child_depth is decremented when a die has Has-Child false,
and the adjacent die is NULL. Algorithm returns when
child_depth is 0.
**NOTE: Do not modify input die, since it is used at the end.
*/
int
{
return (DW_DLV_ERROR);
}
/* Find root die of cu */
/* die_info_end is untouched here, need not be set in this
branch. */
/* If we've not loaded debug_info, de_cu_context will be NULL,
so no need to laod */
return (DW_DLV_ERROR);
}
} else {
/* Find sibling die. */
/* We cannot have a legal die unless debug_info was loaded, so
no need to load debug_info here. */
if (*die_info_ptr == 0) {
return (DW_DLV_NO_ENTRY);
}
if ((*die_info_ptr) == 0) {
return (DW_DLV_NO_ENTRY);
}
child_depth = 0;
do {
cu_info_start, true,
&has_child);
if (die_info_ptr == NULL) {
return (DW_DLV_ERROR);
}
if ((*die_info_ptr) == 0 && has_child) {
die_info_ptr++;
has_child = false;
}
if ((*die_info_ptr) == 0)
for (; child_depth > 0 && *die_info_ptr == 0;
child_depth--, die_info_ptr++);
else
} while (child_depth != 0);
}
return (DW_DLV_NO_ENTRY);
}
if ((*die_info_ptr) == 0) {
return (DW_DLV_NO_ENTRY);
}
return (DW_DLV_ERROR);
}
if (abbrev_code == 0) {
/* Zero means a null DIE */
return (DW_DLV_NO_ENTRY);
}
ab_tag !=
return (DW_DLV_ERROR);
}
return (DW_DLV_OK);
}
int
{
/* NULL die has no child. */
if ((*die_info_ptr) == 0)
return (DW_DLV_NO_ENTRY);
die_info_end, NULL, false,
if (die_info_ptr == NULL) {
return (DW_DLV_ERROR);
}
if (!has_die_child)
return (DW_DLV_NO_ENTRY);
return (DW_DLV_ERROR);
}
if (abbrev_code == 0) {
/* We have arrived at a null DIE, at the end of a CU or the end
of a list of siblings. */
*caller_ret_die = 0;
return DW_DLV_NO_ENTRY;
}
return (DW_DLV_ERROR);
}
return (DW_DLV_OK);
}
/*
Given a die offset, this returns
a pointer to a DIE thru *new_die.
It is up to the caller to do a
dwarf_dealloc(dbg,*new_die,DW_DLE_DIE);
*/
int
{
Dwarf_Off new_cu_offset = 0;
return (DW_DLV_ERROR);
}
if (cu_context == NULL)
if (cu_context == NULL) {
return res;
}
do {
if ((new_cu_offset +
return (DW_DLV_ERROR);
}
if (cu_context == NULL) {
/* Error if CU Context could not be made. Since
_dwarf_make_CU_Context has already registered an
error we do not do that here: we let the lower error
pass thru. */
return (DW_DLV_ERROR);
}
} else {
}
} while (offset >= new_cu_offset);
}
return (DW_DLV_ERROR);
}
if (abbrev_code == 0) {
/* we are at a null DIE (or there is a bug). */
*new_die = 0;
return DW_DLV_NO_ENTRY;
}
return (DW_DLV_ERROR);
}
return (DW_DLV_OK);
}