LCOV - code coverage report
Current view: top level - libdwfl - dwfl_module_build_id.c (source / functions) Coverage Total Hit
Test: elfutils-0.192 Lines: 93.9 % 33 31
Test Date: 2024-10-18 15:14:37 Functions: 100.0 % 3 3
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 75.0 % 24 18

             Branch data     Line data    Source code
       1                 :             : /* Return build ID information for a module.
       2                 :             :    Copyright (C) 2007-2010, 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 "libdwflP.h"
      34                 :             : 
      35                 :             : static int
      36                 :         308 : found_build_id (Dwfl_Module *mod, bool set,
      37                 :             :                 const void *bits, int len, GElf_Addr vaddr)
      38                 :             : {
      39         [ +  + ]:         308 :   if (!set)
      40                 :             :     /* When checking bits, we do not compare VADDR because the
      41                 :             :        address found in a debuginfo file may not match the main
      42                 :             :        file as modified by prelink.  */
      43                 :          66 :     return 1 + (mod->build_id_len == len
      44   [ +  -  -  + ]:          66 :                 && !memcmp (bits, mod->build_id_bits, len));
      45                 :             : 
      46                 :         242 :   void *copy = malloc (len);
      47         [ -  + ]:         242 :   if (unlikely (copy == NULL))
      48                 :             :     {
      49                 :           0 :       __libdwfl_seterrno (DWFL_E_NOMEM);
      50                 :           0 :       return -1;
      51                 :             :     }
      52                 :             : 
      53                 :         242 :   mod->build_id_bits = memcpy (copy, bits, len);
      54                 :         242 :   mod->build_id_vaddr = vaddr;
      55                 :         242 :   mod->build_id_len = len;
      56                 :         242 :   return len;
      57                 :             : }
      58                 :             : 
      59                 :             : int
      60                 :             : internal_function
      61                 :         330 : __libdwfl_find_build_id (Dwfl_Module *mod, bool set, Elf *elf)
      62                 :             : {
      63                 :         330 :   const void *build_id_bits;
      64                 :         330 :   GElf_Addr build_id_elfaddr;
      65                 :         330 :   int build_id_len;
      66                 :             : 
      67                 :             :   /* For mod == NULL use dwelf_elf_gnu_build_id directly.  */
      68         [ -  + ]:         330 :   assert (mod != NULL);
      69                 :             : 
      70                 :         330 :   int result = __libdwfl_find_elf_build_id (mod, elf, &build_id_bits,
      71                 :             :                                             &build_id_elfaddr, &build_id_len);
      72         [ +  + ]:         330 :   if (result <= 0)
      73                 :             :     return result;
      74                 :             : 
      75                 :         616 :   GElf_Addr build_id_vaddr = build_id_elfaddr + (build_id_elfaddr != 0
      76         [ +  - ]:         308 :                                                  ? mod->main_bias : 0);
      77                 :         308 :   return found_build_id (mod, set, build_id_bits, build_id_len, build_id_vaddr);
      78                 :             : }
      79                 :             : 
      80                 :             : NEW_VERSION (dwfl_module_build_id, ELFUTILS_0.138)
      81                 :             : int
      82                 :        6052 : dwfl_module_build_id (Dwfl_Module *mod,
      83                 :             :                       const unsigned char **bits, GElf_Addr *vaddr)
      84                 :             : {
      85         [ +  - ]:        6052 :   if (mod == NULL)
      86                 :             :     return -1;
      87                 :             : 
      88   [ +  +  +  + ]:        6052 :   if (mod->build_id_len == 0 && mod->main.elf != NULL)
      89                 :             :     {
      90                 :             :       /* We have the file, but have not examined it yet.  */
      91                 :         264 :       int result = __libdwfl_find_build_id (mod, true, mod->main.elf);
      92         [ +  + ]:         264 :       if (result <= 0)
      93                 :             :         {
      94                 :          22 :           mod->build_id_len = -1;    /* Cache negative result.  */
      95                 :          22 :           return result;
      96                 :             :         }
      97                 :             :     }
      98                 :             : 
      99         [ +  + ]:        6030 :   if (mod->build_id_len <= 0)
     100                 :             :     return 0;
     101                 :             : 
     102                 :        6022 :   *bits = mod->build_id_bits;
     103                 :        6022 :   *vaddr = mod->build_id_vaddr;
     104                 :        6022 :   return mod->build_id_len;
     105                 :             : }
     106                 :             : NEW_INTDEF (dwfl_module_build_id)
     107                 :             : 
     108                 :             : #ifdef SYMBOL_VERSIONING
     109                 :             : COMPAT_VERSION (dwfl_module_build_id, ELFUTILS_0.130, vaddr_at_end)
     110                 :             : 
     111                 :             : int
     112                 :             : _compat_vaddr_at_end_dwfl_module_build_id (Dwfl_Module *mod,
     113                 :             :                                            const unsigned char **bits,
     114                 :             :                                            GElf_Addr *vaddr)
     115                 :             : {
     116                 :             :   int result = INTUSE(dwfl_module_build_id) (mod, bits, vaddr);
     117                 :             :   if (result > 0)
     118                 :             :     *vaddr += (result + 3) & -4;
     119                 :             :   return result;
     120                 :             : }
     121                 :             : #endif
        

Generated by: LCOV version 2.0-1