Blame libdw/dwarf_getabbrevattr.c

Packit 032894
/* Get specific attribute of abbreviation.
Packit 032894
   Copyright (C) 2003, 2004, 2005, 2014, 2017 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 <assert.h>
Packit 032894
#include <dwarf.h>
Packit 032894
#include "libdwP.h"
Packit 032894
Packit 032894
Packit 032894
int
Packit 032894
dwarf_getabbrevattr_data (Dwarf_Abbrev *abbrev, size_t idx,
Packit 032894
			  unsigned int *namep, unsigned int *formp,
Packit 032894
			  Dwarf_Sword *datap, Dwarf_Off *offsetp)
Packit 032894
{
Packit 032894
  if (abbrev == NULL)
Packit 032894
    return -1;
Packit 032894
Packit 032894
  size_t cnt = 0;
Packit 032894
  const unsigned char *attrp = abbrev->attrp;
Packit 032894
  const unsigned char *start_attrp;
Packit 032894
  unsigned int name;
Packit 032894
  unsigned int form;
Packit 032894
  Dwarf_Word data;
Packit 032894
Packit 032894
  do
Packit 032894
    {
Packit 032894
      start_attrp = attrp;
Packit 032894
Packit 032894
      /* Attribute code and form are encoded as ULEB128 values.
Packit 032894
         Already checked when Dwarf_Abbrev was created, read unchecked.  */
Packit 032894
      get_uleb128_unchecked (name, attrp);
Packit 032894
      get_uleb128_unchecked (form, attrp);
Packit 032894
Packit 032894
      if (form == DW_FORM_implicit_const)
Packit 032894
	get_sleb128_unchecked (data, attrp);
Packit 032894
      else
Packit 032894
	data = 0;
Packit 032894
Packit 032894
      /* If both values are zero the index is out of range.  */
Packit 032894
      if (name == 0 && form == 0)
Packit 032894
	return -1;
Packit 032894
    }
Packit 032894
  while (cnt++ < idx);
Packit 032894
Packit 032894
  /* Store the result if requested.  */
Packit 032894
  if (namep != NULL)
Packit 032894
    *namep = name;
Packit 032894
  if (formp != NULL)
Packit 032894
    *formp = form;
Packit 032894
  if (datap != NULL)
Packit 032894
    *datap = data;
Packit 032894
  if (offsetp != NULL)
Packit 032894
    *offsetp = (start_attrp - abbrev->attrp) + abbrev->offset;
Packit 032894
Packit 032894
  return 0;
Packit 032894
}
Packit 032894
INTDEF(dwarf_getabbrevattr_data)
Packit 032894
Packit 032894
int
Packit 032894
dwarf_getabbrevattr (Dwarf_Abbrev *abbrev, size_t idx, unsigned int *namep,
Packit 032894
		     unsigned int *formp, Dwarf_Off *offsetp)
Packit 032894
{
Packit 032894
  return INTUSE(dwarf_getabbrevattr_data) (abbrev, idx, namep, formp,
Packit 032894
					   NULL, offsetp);
Packit 032894
}