Home | History | Annotate | Download | only in libdw
      1 /* Return source file information of CU.
      2    Copyright (C) 2004 Red Hat, Inc.
      3    Written by Ulrich Drepper <drepper (at) redhat.com>, 2004.
      4 
      5    This program is Open Source software; you can redistribute it and/or
      6    modify it under the terms of the Open Software License version 1.0 as
      7    published by the Open Source Initiative.
      8 
      9    You should have received a copy of the Open Software License along
     10    with this program; if not, you may obtain a copy of the Open Software
     11    License version 1.0 from http://www.opensource.org/licenses/osl.php or
     12    by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
     13    3001 King Ranch Road, Ukiah, CA 95482.   */
     14 
     15 #ifdef HAVE_CONFIG_H
     16 # include <config.h>
     17 #endif
     18 
     19 #include <assert.h>
     20 #include <dwarf.h>
     21 #include "libdwP.h"
     22 
     23 
     24 int
     25 dwarf_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files, size_t *nfiles)
     26 {
     27   if (unlikely (cudie == NULL || dwarf_tag (cudie) != DW_TAG_compile_unit))
     28     return -1;
     29 
     30   int res = -1;
     31 
     32   /* Get the information if it is not already known.  */
     33   struct Dwarf_CU *const cu = cudie->cu;
     34   if (cu->lines == NULL)
     35     {
     36       Dwarf_Lines *lines;
     37       size_t nlines;
     38 
     39       /* Let the more generic function do the work.  It'll create more
     40 	 data but that will be needed in an real program anyway.  */
     41       res = dwarf_getsrclines (cudie, &lines, &nlines);
     42     }
     43   else if (cu->files != (void *) -1l)
     44     /* We already have the information.  */
     45     res = 0;
     46 
     47   if (likely (res == 0))
     48     {
     49       assert (cu->files != NULL && cu->files != (void *) -1l);
     50       *files = cu->files;
     51       if (nfiles != NULL)
     52 	*nfiles = cu->files->nfiles;
     53     }
     54 
     55   // XXX Eventually: unlocking here.
     56 
     57   return res;
     58 }
     59