Blame libdw/dwarf_tag.c

Packit 032894
/* Return tag of given DIE.
Packit 032894
   Copyright (C) 2003-2011, 2014 Red Hat, Inc.
Packit 032894
   This file is part of elfutils.
Packit 032894
   Written by Ulrich Drepper <drepper@redhat.com>, 2003.
Packit 032894
Packit 032894
   This file is free software; you can redistribute it and/or modify
Packit 032894
   it under the terms of either
Packit 032894
Packit 032894
     * the GNU Lesser General Public License as published by the Free
Packit 032894
       Software Foundation; either version 3 of the License, or (at
Packit 032894
       your option) any later version
Packit 032894
Packit 032894
   or
Packit 032894
Packit 032894
     * the GNU General Public License as published by the Free
Packit 032894
       Software Foundation; either version 2 of the License, or (at
Packit 032894
       your option) any later version
Packit 032894
Packit 032894
   or both in parallel, as here.
Packit 032894
Packit 032894
   elfutils is distributed in the hope that it will be useful, but
Packit 032894
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 032894
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 032894
   General Public License for more details.
Packit 032894
Packit 032894
   You should have received copies of the GNU General Public License and
Packit 032894
   the GNU Lesser General Public License along with this program.  If
Packit 032894
   not, see <http://www.gnu.org/licenses/>.  */
Packit 032894
Packit 032894
#ifdef HAVE_CONFIG_H
Packit 032894
# include <config.h>
Packit 032894
#endif
Packit 032894
Packit 032894
#include "libdwP.h"
Packit 032894
Packit 032894
Packit 032894
Dwarf_Abbrev *
Packit 032894
internal_function
Packit 032894
__libdw_findabbrev (struct Dwarf_CU *cu, unsigned int code)
Packit 032894
{
Packit 032894
  Dwarf_Abbrev *abb;
Packit 032894
Packit 032894
  /* Abbreviation code can never have a value of 0.  */
Packit 032894
  if (unlikely (code == 0))
Packit 032894
    return DWARF_END_ABBREV;
Packit 032894
Packit 032894
  /* See whether the entry is already in the hash table.  */
Packit 032894
  abb = Dwarf_Abbrev_Hash_find (&cu->abbrev_hash, code);
Packit 032894
  if (abb == NULL)
Packit 032894
    while (cu->last_abbrev_offset != (size_t) -1l)
Packit 032894
      {
Packit 032894
	size_t length;
Packit 032894
Packit 032894
	/* Find the next entry.  It gets automatically added to the
Packit 032894
	   hash table.  */
Packit 032894
	abb = __libdw_getabbrev (cu->dbg, cu, cu->last_abbrev_offset, &length,
Packit 032894
				 NULL);
Packit 032894
	if (abb == NULL || abb == DWARF_END_ABBREV)
Packit 032894
	  {
Packit 032894
	    /* Make sure we do not try to search for it again.  */
Packit 032894
	    cu->last_abbrev_offset = (size_t) -1l;
Packit 032894
	    return DWARF_END_ABBREV;
Packit 032894
	  }
Packit 032894
Packit 032894
	cu->last_abbrev_offset += length;
Packit 032894
Packit 032894
	/* Is this the code we are looking for?  */
Packit 032894
	if (abb->code == code)
Packit 032894
	  break;
Packit 032894
      }
Packit 032894
Packit 032894
  /* This is our second (or third, etc.) call to __libdw_findabbrev
Packit 032894
     and the code is invalid.  */
Packit 032894
  if (unlikely (abb == NULL))
Packit 032894
    abb = DWARF_END_ABBREV;
Packit 032894
Packit 032894
  return abb;
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
int
Packit 032894
dwarf_tag (Dwarf_Die *die)
Packit 032894
{
Packit 032894
  /* Find the abbreviation entry.  */
Packit 032894
  Dwarf_Abbrev *abbrevp = __libdw_dieabbrev (die, NULL);
Packit 032894
  if (unlikely (abbrevp == DWARF_END_ABBREV))
Packit 032894
    {
Packit 032894
      __libdw_seterrno (DWARF_E_INVALID_DWARF);
Packit 032894
      return DW_TAG_invalid;
Packit 032894
    }
Packit 032894
Packit 032894
  return abbrevp->tag;
Packit 032894
}
Packit 032894
INTDEF(dwarf_tag)