Blame libdw/dwarf_macro_getsrcfiles.c

Packit 032894
/* Find line information for a given macro.
Packit 032894
   Copyright (C) 2014 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 "libdwP.h"
Packit 032894
Packit 032894
int
Packit 032894
dwarf_macro_getsrcfiles (Dwarf *dbg, Dwarf_Macro *macro,
Packit 032894
			 Dwarf_Files **files, size_t *nfiles)
Packit 032894
{
Packit 032894
  /* macro is declared NN */
Packit 032894
  Dwarf_Macro_Op_Table *const table = macro->table;
Packit 032894
  if (table->files == NULL)
Packit 032894
    {
Packit 032894
      Dwarf_Off line_offset = table->line_offset;
Packit 032894
      if (line_offset == (Dwarf_Off) -1)
Packit 032894
	{
Packit 032894
	  *files = NULL;
Packit 032894
	  *nfiles = 0;
Packit 032894
	  return 0;
Packit 032894
	}
Packit 032894
Packit 032894
      /* If TABLE->comp_dir is NULL that could mean any of the
Packit 032894
	 following:
Packit 032894
Packit 032894
	 - The macro unit is not bound to a CU.  It's an auxiliary
Packit 032894
           unit used purely for import from other units.  In that case
Packit 032894
           there's actually no COMP_DIR value that we could use.
Packit 032894
Packit 032894
	 - The macro unit is bound to a CU, but there's no
Packit 032894
           DW_AT_comp_dir attribute at the CU DIE.
Packit 032894
Packit 032894
	 - The macro unit is bound to a CU, but we don't know that,
Packit 032894
           likely because its iteration was requested through
Packit 032894
           dwarf_getmacros_off interface.  This might be legitimate if
Packit 032894
           one macro unit imports another CU's macro unit, but that is
Packit 032894
           unlikely to happen in practice.  Most probably this is not
Packit 032894
           legitimate use of the interfaces.
Packit 032894
Packit 032894
	 So when the interfaces are used correctly, COMP_DIR value is
Packit 032894
	 always right.  That means that we can cache the parsed
Packit 032894
	 .debug_line unit without fear that later on someone requests
Packit 032894
	 the same unit through dwarf_getsrcfiles, and the file names
Packit 032894
	 will be broken.  */
Packit 032894
Packit 032894
      if (__libdw_getsrclines (dbg, line_offset, table->comp_dir,
Packit 032894
			       table->is_64bit ? 8 : 4,
Packit 032894
			       NULL, &table->files) < 0)
Packit 032894
	table->files = (void *) -1;
Packit 032894
    }
Packit 032894
Packit 032894
  if (table->files == (void *) -1)
Packit 032894
    return -1;
Packit 032894
Packit 032894
  *files = table->files;
Packit 032894
  *nfiles = table->files->nfiles;
Packit 032894
  return 0;
Packit 032894
}