LCOV - code coverage report
Current view: top level - libdw - dwarf_getsrcfiles.c (source / functions) Hit Total Coverage
Test: elfutils-0.191 Lines: 27 35 77.1 %
Date: 2024-07-24 22:43:53 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 24 58.3 %

           Branch data     Line data    Source code
       1                 :            : /* Return source file information of CU.
       2                 :            :    Copyright (C) 2004, 2005, 2013, 2015, 2018 Red Hat, Inc.
       3                 :            :    This file is part of elfutils.
       4                 :            : 
       5                 :            :    This file is free software; you can redistribute it and/or modify
       6                 :            :    it under the terms of either
       7                 :            : 
       8                 :            :      * the GNU Lesser General Public License as published by the Free
       9                 :            :        Software Foundation; either version 3 of the License, or (at
      10                 :            :        your option) any later version
      11                 :            : 
      12                 :            :    or
      13                 :            : 
      14                 :            :      * the GNU General Public License as published by the Free
      15                 :            :        Software Foundation; either version 2 of the License, or (at
      16                 :            :        your option) any later version
      17                 :            : 
      18                 :            :    or both in parallel, as here.
      19                 :            : 
      20                 :            :    elfutils is distributed in the hope that it will be useful, but
      21                 :            :    WITHOUT ANY WARRANTY; without even the implied warranty of
      22                 :            :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      23                 :            :    General Public License for more details.
      24                 :            : 
      25                 :            :    You should have received copies of the GNU General Public License and
      26                 :            :    the GNU Lesser General Public License along with this program.  If
      27                 :            :    not, see <http://www.gnu.org/licenses/>.  */
      28                 :            : 
      29                 :            : #ifdef HAVE_CONFIG_H
      30                 :            : # include <config.h>
      31                 :            : #endif
      32                 :            : 
      33                 :            : #include <assert.h>
      34                 :            : #include <dwarf.h>
      35                 :            : #include "libdwP.h"
      36                 :            : 
      37                 :            : 
      38                 :            : int
      39                 :     992010 : dwarf_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files, size_t *nfiles)
      40                 :            : {
      41         [ -  + ]:     992010 :   if (cudie == NULL)
      42                 :            :     return -1;
      43         [ -  + ]:     992010 :   if (! is_cudie (cudie))
      44                 :            :     {
      45                 :          0 :       __libdw_seterrno (DWARF_E_NOT_CUDIE);
      46                 :          0 :       return -1;
      47                 :            :     }
      48                 :            : 
      49                 :     992010 :   int res = -1;
      50                 :            : 
      51                 :            :   /* Get the information if it is not already known.  */
      52                 :     992010 :   struct Dwarf_CU *const cu = cudie->cu;
      53         [ +  + ]:     992010 :   if (cu->files == NULL)
      54                 :            :     {
      55                 :            :       /* For split units there might be a simple file table (without lines).
      56                 :            :          If not, use the one from the skeleton.  */
      57                 :      39074 :       if (cu->unit_type == DW_UT_split_compile
      58         [ +  + ]:      39074 :           || cu->unit_type == DW_UT_split_type)
      59                 :            :         {
      60                 :            :           /* We tried, assume we fail...  */
      61                 :         48 :           cu->files = (void *) -1;
      62                 :            : 
      63                 :            :           /* See if there is a .debug_line section, for split CUs
      64                 :            :              the table is at offset zero.  */
      65         [ +  - ]:         48 :           if (cu->dbg->sectiondata[IDX_debug_line] != NULL)
      66                 :            :             {
      67                 :         48 :               Dwarf_Off dwp_off;
      68         [ +  - ]:         48 :               if (INTUSE(dwarf_cu_dwp_section_info) (cu, DW_SECT_LINE,
      69                 :            :                                                      &dwp_off, NULL) == 0)
      70                 :            :                 {
      71                 :            :                   /* We are only interested in the files, the lines will
      72                 :            :                      always come from the skeleton.  */
      73                 :         48 :                   res = __libdw_getsrcfiles (cu->dbg, dwp_off,
      74                 :            :                                              __libdw_getcompdir (cudie),
      75                 :         48 :                                              cu->address_size, &cu->files);
      76                 :            :                 }
      77                 :            :             }
      78                 :            :           else
      79                 :            :             {
      80                 :          0 :               Dwarf_CU *skel = __libdw_find_split_unit (cu);
      81         [ #  # ]:          0 :               if (skel != NULL)
      82                 :            :                 {
      83                 :          0 :                   Dwarf_Die skeldie = CUDIE (skel);
      84                 :          0 :                   res = INTUSE(dwarf_getsrcfiles) (&skeldie, files, nfiles);
      85                 :          0 :                   cu->files = skel->files;
      86                 :            :                 }
      87                 :            :             }
      88                 :            :         }
      89                 :            :       else
      90                 :            :         {
      91                 :            :           /* The die must have a statement list associated.  */
      92                 :      39026 :           Dwarf_Attribute stmt_list_mem;
      93                 :      39026 :           Dwarf_Attribute *stmt_list = INTUSE(dwarf_attr) (cudie, DW_AT_stmt_list,
      94                 :            :                                                            &stmt_list_mem);
      95                 :            : 
      96                 :      39026 :           Dwarf_Off debug_line_offset;
      97         [ -  + ]:      39026 :           if (__libdw_formptr (stmt_list, IDX_debug_line, DWARF_E_NO_DEBUG_LINE,
      98                 :            :                                NULL, &debug_line_offset) == NULL)
      99                 :          0 :             return -1;
     100                 :            : 
     101                 :      39026 :           res = __libdw_getsrcfiles (cu->dbg, debug_line_offset,
     102                 :            :                                      __libdw_getcompdir (cudie),
     103                 :      39026 :                                      cu->address_size, &cu->files);
     104                 :            :         }
     105                 :            :     }
     106         [ -  + ]:     952936 :   else if (cu->files != (void *) -1l)
     107                 :            :     /* We already have the information.  */
     108                 :     992010 :     res = 0;
     109                 :            : 
     110         [ +  - ]:     992010 :   if (likely (res == 0))
     111                 :            :     {
     112         [ -  + ]:     992010 :       assert (cu->files != NULL && cu->files != (void *) -1l);
     113                 :     992010 :       *files = cu->files;
     114         [ +  + ]:     992010 :       if (nfiles != NULL)
     115                 :     991726 :         *nfiles = cu->files->nfiles;
     116                 :            :     }
     117                 :            : 
     118                 :            :   // XXX Eventually: unlocking here.
     119                 :            : 
     120                 :            :   return res;
     121                 :            : }
     122                 :            : INTDEF (dwarf_getsrcfiles)

Generated by: LCOV version 1.16