LCOV - code coverage report
Current view: top level - libdw - dwarf_macro_getsrcfiles.c (source / functions) Hit Total Coverage
Test: elfutils-0.189 Lines: 12 16 75.0 %
Date: 2023-10-24 20:27:32 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                 :         26 : 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                 :         26 :   (void)dbg;
      41                 :            : 
      42                 :            :   /* macro is declared NN */
      43                 :         26 :   Dwarf_Macro_Op_Table *const table = macro->table;
      44         [ +  + ]:         26 :   if (table->files == NULL)
      45                 :            :     {
      46                 :          8 :       Dwarf_Off line_offset = table->line_offset;
      47         [ -  + ]:          8 :       if (line_offset == (Dwarf_Off) -1)
      48                 :            :         {
      49                 :          0 :           *files = NULL;
      50                 :          0 :           *nfiles = 0;
      51                 :          0 :           return 0;
      52                 :            :         }
      53                 :            : 
      54                 :            :       /* If TABLE->comp_dir is NULL that could mean any of the
      55                 :            :          following:
      56                 :            : 
      57                 :            :          - The macro unit is not bound to a CU.  It's an auxiliary
      58                 :            :            unit used purely for import from other units.  In that case
      59                 :            :            there's actually no COMP_DIR value that we could use.
      60                 :            : 
      61                 :            :          - The macro unit is bound to a CU, but there's no
      62                 :            :            DW_AT_comp_dir attribute at the CU DIE.
      63                 :            : 
      64                 :            :          - The macro unit is bound to a CU, but we don't know that,
      65                 :            :            likely because its iteration was requested through
      66                 :            :            dwarf_getmacros_off interface.  This might be legitimate if
      67                 :            :            one macro unit imports another CU's macro unit, but that is
      68                 :            :            unlikely to happen in practice.  Most probably this is not
      69                 :            :            legitimate use of the interfaces.
      70                 :            : 
      71                 :            :          So when the interfaces are used correctly, COMP_DIR value is
      72                 :            :          always right.  That means that we can cache the parsed
      73                 :            :          .debug_line unit without fear that later on someone requests
      74                 :            :          the same unit through dwarf_getsrcfiles, and the file names
      75                 :            :          will be broken.  */
      76                 :            : 
      77         [ -  + ]:          8 :       if (__libdw_getsrclines (table->dbg, line_offset, table->comp_dir,
      78                 :          8 :                                table->address_size, NULL, &table->files) < 0)
      79                 :          0 :         table->files = (void *) -1;
      80                 :            :     }
      81                 :            : 
      82         [ +  - ]:         26 :   if (table->files == (void *) -1)
      83                 :            :     return -1;
      84                 :            : 
      85                 :         26 :   *files = table->files;
      86                 :         26 :   *nfiles = table->files->nfiles;
      87                 :         26 :   return 0;
      88                 :            : }

Generated by: LCOV version 1.16