Blame libdw/dwarf_getsrcfiles.c

Packit 032894
/* Return source file information of CU.
Packit 032894
   Copyright (C) 2004, 2005, 2013, 2015, 2018 Red Hat, Inc.
Packit 032894
   This file is part of elfutils.
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_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files, size_t *nfiles)
Packit 032894
{
Packit 032894
  if (cudie == NULL)
Packit 032894
    return -1;
Packit 032894
  if (! is_cudie (cudie))
Packit 032894
    {
Packit 032894
      __libdw_seterrno (DWARF_E_NOT_CUDIE);
Packit 032894
      return -1;
Packit 032894
    }
Packit 032894
Packit 032894
  int res = -1;
Packit 032894
Packit 032894
  /* Get the information if it is not already known.  */
Packit 032894
  struct Dwarf_CU *const cu = cudie->cu;
Packit 032894
  if (cu->files == NULL)
Packit 032894
    {
Packit 032894
      /* For split units there might be a simple file table (without lines).
Packit 032894
	 If not, use the one from the skeleton.  */
Packit 032894
      if (cu->unit_type == DW_UT_split_compile
Packit 032894
	  || cu->unit_type == DW_UT_split_type)
Packit 032894
	{
Packit 032894
	  /* We tried, assume we fail...  */
Packit 032894
	  cu->files = (void *) -1;
Packit 032894
Packit 032894
	  /* See if there is a .debug_line section, for split CUs
Packit 032894
	     the table is at offset zero.  */
Packit 032894
	  if (cu->dbg->sectiondata[IDX_debug_line] != NULL)
Packit 032894
	    {
Packit 032894
	      /* We are only interested in the files, the lines will
Packit 032894
		 always come from the skeleton.  */
Packit 032894
	      res = __libdw_getsrclines (cu->dbg, 0,
Packit 032894
					 __libdw_getcompdir (cudie),
Packit 032894
					 cu->address_size, NULL,
Packit 032894
					 &cu->files);
Packit 032894
	    }
Packit 032894
	  else
Packit 032894
	    {
Packit 032894
	      Dwarf_CU *skel = __libdw_find_split_unit (cu);
Packit 032894
	      if (skel != NULL)
Packit 032894
		{
Packit 032894
		  Dwarf_Die skeldie = CUDIE (skel);
Packit 032894
		  res = INTUSE(dwarf_getsrcfiles) (&skeldie, files, nfiles);
Packit 032894
		  cu->files = skel->files;
Packit 032894
		}
Packit 032894
	    }
Packit 032894
	}
Packit 032894
      else
Packit 032894
	{
Packit 032894
	  Dwarf_Lines *lines;
Packit 032894
	  size_t nlines;
Packit 032894
Packit 032894
	  /* Let the more generic function do the work.  It'll create more
Packit 032894
	     data but that will be needed in an real program anyway.  */
Packit 032894
	  res = INTUSE(dwarf_getsrclines) (cudie, &lines, &nlines);
Packit 032894
	}
Packit 032894
    }
Packit 032894
  else if (cu->files != (void *) -1l)
Packit 032894
    /* We already have the information.  */
Packit 032894
    res = 0;
Packit 032894
Packit 032894
  if (likely (res == 0))
Packit 032894
    {
Packit 032894
      assert (cu->files != NULL && cu->files != (void *) -1l);
Packit 032894
      *files = cu->files;
Packit 032894
      if (nfiles != NULL)
Packit 032894
	*nfiles = cu->files->nfiles;
Packit 032894
    }
Packit 032894
Packit 032894
  // XXX Eventually: unlocking here.
Packit 032894
Packit 032894
  return res;
Packit 032894
}
Packit 032894
INTDEF (dwarf_getsrcfiles)