LCOV - code coverage report
Current view: top level - libdw - dwarf_macro_getsrcfiles.c (source / functions) Hit Total Coverage
Test: elfutils-0.192 Lines: 14 19 73.7 %
Date: 2025-04-08 22:00:17 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 8 62.5 %

           Branch data     Line data    Source code
       1                 :            : /* Find line information for a given macro.
       2                 :            :    Copyright (C) 2014 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 "libdwP.h"
      34                 :            : 
      35                 :            : int
      36                 :         62 : dwarf_macro_getsrcfiles (Dwarf *dbg, Dwarf_Macro *macro,
      37                 :            :                          Dwarf_Files **files, size_t *nfiles)
      38                 :            : {
      39                 :            :   /* This was needed before Dwarf_Macro_Op_Table stored the Dwarf handle.  */
      40                 :         62 :   (void)dbg;
      41                 :            : 
      42                 :            :   /* macro is declared NN */
      43                 :         62 :   Dwarf_Macro_Op_Table *const table = macro->table;
      44                 :            : 
      45                 :         62 :   mutex_lock (table->dbg->macro_lock);
      46         [ +  + ]:         62 :   if (table->files == NULL)
      47                 :            :     {
      48                 :         20 :       Dwarf_Off line_offset = table->line_offset;
      49         [ -  + ]:         20 :       if (line_offset == (Dwarf_Off) -1)
      50                 :            :         {
      51                 :          0 :           *files = NULL;
      52                 :          0 :           *nfiles = 0;
      53                 :          0 :           mutex_unlock (table->dbg->macro_lock);
      54                 :          0 :           return 0;
      55                 :            :         }
      56                 :            : 
      57                 :            :       /* If TABLE->comp_dir is NULL that could mean any of the
      58                 :            :          following:
      59                 :            : 
      60                 :            :          - The macro unit is not bound to a CU.  It's an auxiliary
      61                 :            :            unit used purely for import from other units.  In that case
      62                 :            :            there's actually no COMP_DIR value that we could use.
      63                 :            : 
      64                 :            :          - The macro unit is bound to a CU, but there's no
      65                 :            :            DW_AT_comp_dir attribute at the CU DIE.
      66                 :            : 
      67                 :            :          - The macro unit is bound to a CU, but we don't know that,
      68                 :            :            likely because its iteration was requested through
      69                 :            :            dwarf_getmacros_off interface.  This might be legitimate if
      70                 :            :            one macro unit imports another CU's macro unit, but that is
      71                 :            :            unlikely to happen in practice.  Most probably this is not
      72                 :            :            legitimate use of the interfaces.
      73                 :            : 
      74                 :            :          So when the interfaces are used correctly, COMP_DIR value is
      75                 :            :          always right.  That means that we can cache the parsed
      76                 :            :          .debug_line unit without fear that later on someone requests
      77                 :            :          the same unit through dwarf_getsrcfiles, and the file names
      78                 :            :          will be broken.  */
      79                 :            : 
      80         [ -  + ]:         20 :       if (__libdw_getsrcfiles (table->dbg, line_offset, table->comp_dir,
      81                 :         20 :                                table->address_size, &table->files) < 0)
      82                 :          0 :         table->files = (void *) -1;
      83                 :            :     }
      84                 :            : 
      85         [ +  - ]:         62 :   if (table->files == (void *) -1)
      86                 :            :     {
      87                 :            :       mutex_unlock (table->dbg->macro_lock);
      88                 :            :       return -1;
      89                 :            :     }
      90                 :            : 
      91                 :         62 :   *files = table->files;
      92                 :         62 :   *nfiles = table->files->nfiles;
      93                 :            : 
      94                 :         62 :   mutex_unlock (table->dbg->macro_lock);
      95                 :         62 :   return 0;
      96                 :            : }

Generated by: LCOV version 1.16