Blame libdw/dwarf_decl_file.c

Packit Service 97d2fb
/* Return file name containing definition of the given function.
Packit Service 97d2fb
   Copyright (C) 2005, 2009 Red Hat, Inc.
Packit Service 97d2fb
   This file is part of elfutils.
Packit Service 97d2fb
   Written by Ulrich Drepper <drepper@redhat.com>, 2005.
Packit Service 97d2fb
Packit Service 97d2fb
   This file is free software; you can redistribute it and/or modify
Packit Service 97d2fb
   it under the terms of either
Packit Service 97d2fb
Packit Service 97d2fb
     * the GNU Lesser General Public License as published by the Free
Packit Service 97d2fb
       Software Foundation; either version 3 of the License, or (at
Packit Service 97d2fb
       your option) any later version
Packit Service 97d2fb
Packit Service 97d2fb
   or
Packit Service 97d2fb
Packit Service 97d2fb
     * the GNU General Public License as published by the Free
Packit Service 97d2fb
       Software Foundation; either version 2 of the License, or (at
Packit Service 97d2fb
       your option) any later version
Packit Service 97d2fb
Packit Service 97d2fb
   or both in parallel, as here.
Packit Service 97d2fb
Packit Service 97d2fb
   elfutils is distributed in the hope that it will be useful, but
Packit Service 97d2fb
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 97d2fb
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 97d2fb
   General Public License for more details.
Packit Service 97d2fb
Packit Service 97d2fb
   You should have received copies of the GNU General Public License and
Packit Service 97d2fb
   the GNU Lesser General Public License along with this program.  If
Packit Service 97d2fb
   not, see <http://www.gnu.org/licenses/>.  */
Packit Service 97d2fb
Packit Service 97d2fb
#ifdef HAVE_CONFIG_H
Packit Service 97d2fb
# include <config.h>
Packit Service 97d2fb
#endif
Packit Service 97d2fb
Packit Service 97d2fb
#include <assert.h>
Packit Service 97d2fb
#include <dwarf.h>
Packit Service 97d2fb
#include "libdwP.h"
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
const char *
Packit Service 97d2fb
dwarf_decl_file (Dwarf_Die *die)
Packit Service 97d2fb
{
Packit Service 97d2fb
  Dwarf_Attribute attr_mem;
Packit Service 97d2fb
  Dwarf_Word idx = 0;
Packit Service 97d2fb
Packit Service 97d2fb
  if (INTUSE(dwarf_formudata) (INTUSE(dwarf_attr_integrate)
Packit Service 97d2fb
			       (die, DW_AT_decl_file, &attr_mem),
Packit Service 97d2fb
			       &idx) != 0)
Packit Service 97d2fb
    return NULL;
Packit Service 97d2fb
Packit Service 97d2fb
  /* Zero means no source file information available.  */
Packit Service 97d2fb
  if (idx == 0)
Packit Service 97d2fb
    {
Packit Service 97d2fb
      __libdw_seterrno (DWARF_E_NO_ENTRY);
Packit Service 97d2fb
      return NULL;
Packit Service 97d2fb
    }
Packit Service 97d2fb
Packit Service 97d2fb
  /* Get the array of source files for the CU.  */
Packit Service 97d2fb
  struct Dwarf_CU *cu = attr_mem.cu;
Packit Service 97d2fb
  if (cu->lines == NULL)
Packit Service 97d2fb
    {
Packit Service 97d2fb
      Dwarf_Lines *lines;
Packit Service 97d2fb
      size_t nlines;
Packit Service 97d2fb
Packit Service 97d2fb
      /* Let the more generic function do the work.  It'll create more
Packit Service 97d2fb
	 data but that will be needed in an real program anyway.  */
Packit Service 97d2fb
      (void) INTUSE(dwarf_getsrclines) (&CUDIE (cu), &lines, &nlines);
Packit Service 97d2fb
      assert (cu->lines != NULL);
Packit Service 97d2fb
    }
Packit Service 97d2fb
Packit Service 97d2fb
  if (cu->lines == (void *) -1l)
Packit Service 97d2fb
    {
Packit Service 97d2fb
      /* If the file index is not zero, there must be file information
Packit Service 97d2fb
	 available.  */
Packit Service 97d2fb
      __libdw_seterrno (DWARF_E_INVALID_DWARF);
Packit Service 97d2fb
      return NULL;
Packit Service 97d2fb
    }
Packit Service 97d2fb
Packit Service 97d2fb
  assert (cu->files != NULL && cu->files != (void *) -1l);
Packit Service 97d2fb
Packit Service 97d2fb
  if (idx >= cu->files->nfiles)
Packit Service 97d2fb
    {
Packit Service 97d2fb
      __libdw_seterrno (DWARF_E_INVALID_DWARF);
Packit Service 97d2fb
      return NULL;
Packit Service 97d2fb
    }
Packit Service 97d2fb
Packit Service 97d2fb
  return cu->files->info[idx].name;
Packit Service 97d2fb
}
Packit Service 97d2fb
OLD_VERSION (dwarf_decl_file, ELFUTILS_0.122)
Packit Service 97d2fb
NEW_VERSION (dwarf_decl_file, ELFUTILS_0.143)