LCOV - code coverage report
Current view: top level - libdw - dwarf_getsrcfiles.c (source / functions) Coverage Total Hit
Test: elfutils-0.193 Lines: 76.3 % 38 29
Test Date: 2025-08-30 14:31:09 Functions: 100.0 % 1 1
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 58.3 % 24 14

             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                 :     1038718 : dwarf_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files, size_t *nfiles)
      40                 :             : {
      41         [ -  + ]:     1038718 :   if (cudie == NULL)
      42                 :             :     return -1;
      43         [ -  + ]:     1038718 :   if (! is_cudie (cudie))
      44                 :             :     {
      45                 :           0 :       __libdw_seterrno (DWARF_E_NOT_CUDIE);
      46                 :           0 :       return -1;
      47                 :             :     }
      48                 :             : 
      49                 :     1038718 :   int res = -1;
      50                 :     1038718 :   struct Dwarf_CU *const cu = cudie->cu;
      51                 :     1038718 :   mutex_lock (cudie->cu->src_lock);
      52                 :             : 
      53                 :             :   /* Get the information if it is not already known.  */
      54         [ +  + ]:     1038718 :   if (cu->files == NULL)
      55                 :             :     {
      56                 :             :       /* For split units there might be a simple file table (without lines).
      57                 :             :          If not, use the one from the skeleton.  */
      58                 :       50694 :       if (cu->unit_type == DW_UT_split_compile
      59         [ +  + ]:       50694 :           || cu->unit_type == DW_UT_split_type)
      60                 :             :         {
      61                 :             :           /* We tried, assume we fail...  */
      62                 :          48 :           cu->files = (void *) -1;
      63                 :             : 
      64                 :             :           /* See if there is a .debug_line section, for split CUs
      65                 :             :              the table is at offset zero.  */
      66         [ +  - ]:          48 :           if (cu->dbg->sectiondata[IDX_debug_line] != NULL)
      67                 :             :             {
      68                 :          48 :               Dwarf_Off dwp_off;
      69         [ -  + ]:          48 :               if (INTUSE(dwarf_cu_dwp_section_info) (cu, DW_SECT_LINE,
      70                 :             :                                                      &dwp_off, NULL) == 0)
      71                 :             :                 {
      72                 :             :                   /* We are only interested in the files, the lines will
      73                 :             :                      always come from the skeleton.  */
      74                 :          48 :                   res = __libdw_getsrcfiles (cu->dbg, dwp_off,
      75                 :             :                                              __libdw_getcompdir (cudie),
      76                 :          48 :                                              cu->address_size, &cu->files);
      77                 :             :                 }
      78                 :             :             }
      79                 :             :           else
      80                 :             :             {
      81                 :           0 :               Dwarf_CU *skel = __libdw_find_split_unit (cu);
      82         [ #  # ]:           0 :               if (skel != NULL)
      83                 :             :                 {
      84                 :           0 :                   Dwarf_Die skeldie = CUDIE (skel);
      85                 :           0 :                   res = INTUSE(dwarf_getsrcfiles) (&skeldie, files, nfiles);
      86                 :           0 :                   cu->files = skel->files;
      87                 :             :                 }
      88                 :             :             }
      89                 :             :         }
      90                 :             :       else
      91                 :             :         {
      92                 :             :           /* The die must have a statement list associated.  */
      93                 :       50646 :           Dwarf_Attribute stmt_list_mem;
      94                 :       50646 :           Dwarf_Attribute *stmt_list = INTUSE(dwarf_attr) (cudie, DW_AT_stmt_list,
      95                 :             :                                                            &stmt_list_mem);
      96                 :             : 
      97                 :       50646 :           Dwarf_Off debug_line_offset;
      98         [ -  + ]:       50646 :           if (__libdw_formptr (stmt_list, IDX_debug_line, DWARF_E_NO_DEBUG_LINE,
      99                 :             :                                NULL, &debug_line_offset) == NULL)
     100                 :             :             {
     101                 :           0 :               mutex_unlock (cudie->cu->src_lock);
     102                 :           0 :               return -1;
     103                 :             :             }
     104                 :             : 
     105                 :       50646 :           res = __libdw_getsrcfiles (cu->dbg, debug_line_offset,
     106                 :             :                                      __libdw_getcompdir (cudie),
     107                 :       50646 :                                      cu->address_size, &cu->files);
     108                 :             :         }
     109                 :             :     }
     110         [ +  - ]:      988024 :   else if (cu->files != (void *) -1l)
     111                 :             :     /* We already have the information.  */
     112                 :             :     res = 0;
     113                 :             : 
     114         [ +  - ]:       50694 :   if (likely (res == 0))
     115                 :             :     {
     116         [ -  + ]:     1038718 :       assert (cu->files != NULL && cu->files != (void *) -1l);
     117                 :     1038718 :       *files = cu->files;
     118         [ +  + ]:     1038718 :       if (nfiles != NULL)
     119                 :     1038434 :         *nfiles = cu->files->nfiles;
     120                 :             :     }
     121                 :             : 
     122                 :     1038718 :   mutex_unlock (cudie->cu->src_lock);
     123                 :     1038718 :   return res;
     124                 :             : }
     125                 :             : INTDEF (dwarf_getsrcfiles)
        

Generated by: LCOV version 2.0-1