/*
Copyright (C) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
Portions Copyright (C) 2007-2010 David Anderson. 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., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
USA.
Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
Mountain View, CA 94043, or:
For further information regarding this notice, see:
*/
/* The address of the Free Software Foundation is
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
SGI has moved from the Crittenden Lane address.
*/
#include "config.h"
#include "dwarf_incl.h"
#include <stdio.h>
#include "dwarf_die_deliv.h"
/*
Given a form, and a pointer to the bytes encoding
a value of that form, val_ptr, this function returns
the length, in bytes, of a value of that form.
When using this function, check for a return of 0
a recursive DW_FORM_INDIRECT value.
*/
{
switch (form) {
default: /* Handles form = 0. */
return (form);
case DW_FORM_addr:
if(address_size) {
return address_size;
}
/* This should never happen, address_size should be set. */
return (dbg->de_pointer_size);
/* DWARF2 was wrong on the size of the attribute for
DW_FORM_ref_addr. We assume compilers are using the
corrected DWARF3 text (for 32bit pointer target objects pointer and
offsets are the same size anyway). */
case DW_FORM_ref_addr:
return (v_length_size);
case DW_FORM_block1:
case DW_FORM_block2:
val_ptr, sizeof(Dwarf_Half));
return (ret_value + sizeof(Dwarf_Half));
case DW_FORM_block4:
val_ptr, sizeof(Dwarf_ufixed));
return (ret_value + sizeof(Dwarf_ufixed));
case DW_FORM_data1:
return (1);
case DW_FORM_data2:
return (2);
case DW_FORM_data4:
return (4);
case DW_FORM_data8:
return (8);
case DW_FORM_string:
case DW_FORM_block:
case DW_FORM_exprloc:
return (length + leb128_length);
case DW_FORM_flag_present:
return (0);
case DW_FORM_flag:
return (1);
case DW_FORM_sec_offset:
/* If 32bit dwarf, is 4. Else is 64bit dwarf and is 8. */
return (v_length_size);
case DW_FORM_ref_udata:
return (leb128_length);
case DW_FORM_indirect:
{
if (form_indirect == DW_FORM_indirect) {
return (0); /* We are in big trouble: The true form
of DW_FORM_indirect is
DW_FORM_indirect? Nonsense. Should
never happen. */
}
}
case DW_FORM_ref1:
return (1);
case DW_FORM_ref2:
return (2);
case DW_FORM_ref4:
return (4);
case DW_FORM_ref8:
return (8);
case DW_FORM_sdata:
return (leb128_length);
case DW_FORM_strp:
return (v_length_size);
case DW_FORM_udata:
return (leb128_length);
}
}
/* We allow an arbitrary number of HT_MULTIPLE entries
before resizing. It seems up to 20 or 30
would work nearly as well.
We could have a different resize multiple than 'resize now'
test multiple, but for now we don't do that.
*/
/* Copy the old entries, updating each to be in
a new list. Don't delete anything. Leave the
htin with stale data. */
static void
{
unsigned k = 0;
for ( ; k < entry_in_count; ++k,++entry_in) {
/* Move_entry_to_new_hash. This reverses the
order of the entries, effectively, but
that does not seem significant. */
}
}
}
/*
This function returns a pointer to a Dwarf_Abbrev_List_s
struct for the abbrev with the given code. It puts the
struct on the appropriate hash table. It also adds all
the abbrev between the last abbrev added and this one to
the hash table. In other words, the .debug_abbrev section
is scanned sequentially from the top for an abbrev with
the given code. All intervening abbrevs are also put
into the hash table.
This function hashes the given code, and checks the chain
at that hash table entry to see if a Dwarf_Abbrev_List_s
with the given code exists. If yes, it returns a pointer
to that struct. Otherwise, it scans the .debug_abbrev
section from the last byte scanned for that CU till either
an abbrev with the given code is found, or an abbrev code
of 0 is read. It puts Dwarf_Abbrev_List_s entries for all
abbrev's read till that point into the hash table. The
hash table contains both a head pointer and a tail pointer
for each entry.
While the lists can move and entries can be moved between
lists on reallocation, any given Dwarf_Abbrev_list entry
never moves once allocated, so the pointer is safe to return.
Returns NULL on error.
*/
{
unsigned hashable_val;
if ( !hash_table_base->tb_entries ) {
if(! hash_table_base->tb_entries) {
return NULL;
}
} else if (hash_table_base->tb_total_abbrev_count >
/* Effectively multiplies by >= HT_MULTIPLE */
if(! newht.tb_entries) {
return NULL;
}
/* Copy the existing entries to the new table,
rehashing each.
*/
/* Dealloc only the entries hash table array, not the lists
of things pointed to by a hash table entry array. */
hash_table_base->tb_entries = 0;
/* Now overwrite the existing table descriptor with
the new, newly valid, contents. */
*hash_table_base = newht;
} /* Else is ok as is, add entry */
hashable_val = code;
hash_num = hashable_val %
/* Determine if the 'code' is the list of synonyms already. */
if (hash_abbrev_entry != NULL) {
/* This returns a pointer to an abbrev list entry, not
the list itself. */
return (hash_abbrev_entry);
}
/* End of abbrev's for this cu, since abbrev code is 0. */
if (*abbrev_ptr == 0) {
return (NULL);
}
do {
unsigned new_hashable_val;
if (inner_list_entry == NULL)
return (NULL);
/* Move_entry_to_new_hash */
/* Cycle thru the abbrev content, ignoring the content except
to find the end of the content. */
do {
}
/* return 1 if string ends before 'endptr' else
** return 0 meaning string is not properly terminated.
** Presumption is the 'endptr' pts to end of some dwarf section data.
*/
int
{
if (*start == 0) {
return 1; /* OK! */
}
++start;
++end;
}
return 0; /* FAIL! bad string! */
}
/*
A byte-swapping version of memcpy
for cross-endian use.
Only 2,4,8 should be lengths passed in.
*/
void *
{
if (len == 4) {
} else if (len == 8) {
} else if (len == 2) {
}
/* should NOT get below here: is not the intended use */
else if (len == 1) {
} else {
}
return orig_s1;
}
/*
This calculation used to be sprinkled all over.
Now brought to one place.
We try to accurately compute the size of a cu header
given a known cu header location ( an offset in .debug_info).
*/
/* ARGSUSED */
{
int local_length_size = 0;
int local_extension_size = 0;
return local_extension_size + /* initial extesion, if present
*/
local_length_size + /* Size of cu length field. */
sizeof(Dwarf_Half) + /* Size of version stamp field. */
local_length_size + /* Size of abbrev offset field. */
sizeof(Dwarf_Small); /* Size of address size field. */
}
/*
Pretend we know nothing about the CU
and just roughly compute the result.
*/
{
sizeof(Dwarf_Half) + /* Size of version stamp field. */
sizeof(Dwarf_Small); /* Size of address size field. */
}
/* Now that we delay loading .debug_info, we need to do the
load in more places. So putting the load
code in one place now instead of replicating it in multiple
places.
*/
int
{
/* Testing de_debug_info.dss_data allows us to avoid testing
de_debug_abbrev.dss_data.
One test instead of 2. .debug_info is useless
without .debug_abbrev. */
return DW_DLV_OK;
}
return res;
}
return res;
}
void
{
/* A Hash Table is an array with tb_table_entry_count struct
Dwarf_Hash_Table_s entries in the array. */
int hashnum = 0;
}
}
/* Frees all the entries at once: an array. */
}
/*
If no die provided the size value returned might be wrong.
If different compilation units have different address sizes
this may not give the correct value in all contexts if the die
pointer is NULL.
If the Elf offset size != address_size
(for example if address_size = 4 but recorded in elf64 object)
this may not give the correct value in all contexts if the die
pointer is NULL.
If the die pointer is non-NULL (in which case it must point to
a valid DIE) this will return the correct size.
*/
int
{
if(!die) {
return dbg->de_pointer_size;
}
return addrsize;
}