LCOV - code coverage report
Current view: top level - libebl - eblobjnotetypename.c (source / functions) Hit Total Coverage
Test: elfutils-0.190 Lines: 25 33 75.8 %
Date: 2023-12-21 21:54:50 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 17 30 56.7 %

           Branch data     Line data    Source code
       1                 :            : /* Return note type name.
       2                 :            :    Copyright (C) 2002, 2007, 2009, 2011, 2016, 2018 Red Hat, Inc.
       3                 :            :    This file is part of elfutils.
       4                 :            :    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
       5                 :            : 
       6                 :            :    This file is free software; you can redistribute it and/or modify
       7                 :            :    it under the terms of either
       8                 :            : 
       9                 :            :      * the GNU Lesser General Public License as published by the Free
      10                 :            :        Software Foundation; either version 3 of the License, or (at
      11                 :            :        your option) any later version
      12                 :            : 
      13                 :            :    or
      14                 :            : 
      15                 :            :      * the GNU General Public License as published by the Free
      16                 :            :        Software Foundation; either version 2 of the License, or (at
      17                 :            :        your option) any later version
      18                 :            : 
      19                 :            :    or both in parallel, as here.
      20                 :            : 
      21                 :            :    elfutils is distributed in the hope that it will be useful, but
      22                 :            :    WITHOUT ANY WARRANTY; without even the implied warranty of
      23                 :            :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      24                 :            :    General Public License for more details.
      25                 :            : 
      26                 :            :    You should have received copies of the GNU General Public License and
      27                 :            :    the GNU Lesser General Public License along with this program.  If
      28                 :            :    not, see <http://www.gnu.org/licenses/>.  */
      29                 :            : 
      30                 :            : #ifdef HAVE_CONFIG_H
      31                 :            : # include <config.h>
      32                 :            : #endif
      33                 :            : 
      34                 :            : #include <system.h>
      35                 :            : 
      36                 :            : #include <inttypes.h>
      37                 :            : #include <stdio.h>
      38                 :            : #include <string.h>
      39                 :            : #include <libeblP.h>
      40                 :            : 
      41                 :            : 
      42                 :            : const char *
      43                 :       6392 : ebl_object_note_type_name (Ebl *ebl, const char *name, uint32_t type,
      44                 :            :                            GElf_Word descsz,
      45                 :            :                            char *buf, size_t len)
      46                 :            : {
      47                 :       6392 :   const char *res = ebl->object_note_type_name (name, type, buf, len);
      48                 :            : 
      49         [ +  - ]:       6392 :   if (res == NULL)
      50                 :            :     {
      51         [ -  + ]:       6392 :       if (strcmp (name, "stapsdt") == 0)
      52                 :            :         {
      53                 :          0 :           snprintf (buf, len, "Version: %" PRIu32, type);
      54                 :            :           return buf;
      55                 :            :         }
      56                 :            : 
      57                 :            : #define ELF_NOTE_GOPKGLIST 1
      58                 :            : #define ELF_NOTE_GOABIHASH 2
      59                 :            : #define ELF_NOTE_GODEPS    3
      60                 :            : #define ELF_NOTE_GOBUILDID 4
      61                 :            : 
      62                 :       6392 :       static const char *goknowntypes[] =
      63                 :            :         {
      64                 :            : #define KNOWNSTYPE(name) [ELF_NOTE_GO##name] = #name
      65                 :            :           KNOWNSTYPE (PKGLIST),
      66                 :            :           KNOWNSTYPE (ABIHASH),
      67                 :            :           KNOWNSTYPE (DEPS),
      68                 :            :           KNOWNSTYPE (BUILDID),
      69                 :            : #undef KNOWNSTYPE
      70                 :            :         };
      71                 :            : 
      72         [ -  + ]:       6392 :       if (strcmp (name, "Go") == 0)
      73                 :            :         {
      74         [ #  # ]:          0 :           if (type < sizeof (goknowntypes) / sizeof (goknowntypes[0])
      75         [ #  # ]:          0 :               && goknowntypes[type] != NULL)
      76                 :            :             return goknowntypes[type];
      77                 :            :           else
      78                 :            :             {
      79                 :          0 :               snprintf (buf, len, "%s: %" PRIu32, _("<unknown>"), type);
      80                 :          0 :               return buf;
      81                 :            :             }
      82                 :            :         }
      83                 :            : 
      84         [ +  + ]:       6392 :       if (startswith (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX))
      85                 :            :         {
      86                 :            :           /* GNU Build Attribute notes (ab)use the owner name to store
      87                 :            :              most of their data.  Don't decode everything here.  Just
      88                 :            :              the type.*/
      89                 :       5868 :           char *t = buf;
      90                 :       5868 :           const char *gba = "GNU Build Attribute";
      91         [ +  + ]:       5868 :           int w = snprintf (t, len, "%s ", gba);
      92                 :       5868 :           t += w;
      93                 :       5868 :           len -= w;
      94         [ +  + ]:       5868 :           if (type == NT_GNU_BUILD_ATTRIBUTE_OPEN)
      95                 :       5456 :             snprintf (t, len, "OPEN");
      96         [ +  - ]:        412 :           else if (type == NT_GNU_BUILD_ATTRIBUTE_FUNC)
      97                 :        412 :             snprintf (t, len, "FUNC");
      98                 :            :           else
      99                 :          0 :             snprintf (t, len, "%x", type);
     100                 :            : 
     101                 :       5868 :           return buf;
     102                 :            :         }
     103                 :            : 
     104   [ -  +  -  - ]:        524 :       if (strcmp (name, "FDO") == 0 && type == NT_FDO_PACKAGING_METADATA)
     105                 :            :         return "FDO_PACKAGING_METADATA";
     106                 :            : 
     107         [ +  + ]:        524 :       if (strcmp (name, "GNU") != 0)
     108                 :            :         {
     109                 :            :           /* NT_VERSION is special, all data is in the name.  */
     110         [ +  + ]:         12 :           if (descsz == 0 && type == NT_VERSION)
     111                 :            :             return "VERSION";
     112                 :            : 
     113                 :          2 :           snprintf (buf, len, "%s: %" PRIu32, _("<unknown>"), type);
     114                 :          2 :           return buf;
     115                 :            :         }
     116                 :            : 
     117                 :            :       /* And finally all the "GNU" note types.  */
     118                 :        512 :       static const char *knowntypes[] =
     119                 :            :         {
     120                 :            : #define KNOWNSTYPE(name) [NT_##name] = #name
     121                 :            :           KNOWNSTYPE (GNU_ABI_TAG),
     122                 :            :           KNOWNSTYPE (GNU_HWCAP),
     123                 :            :           KNOWNSTYPE (GNU_BUILD_ID),
     124                 :            :           KNOWNSTYPE (GNU_GOLD_VERSION),
     125                 :            :           KNOWNSTYPE (GNU_PROPERTY_TYPE_0),
     126                 :            :         };
     127                 :            : 
     128                 :            :       /* Handle standard names.  */
     129         [ +  - ]:        512 :       if (type < sizeof (knowntypes) / sizeof (knowntypes[0])
     130         [ -  + ]:        512 :           && knowntypes[type] != NULL)
     131                 :            :         res = knowntypes[type];
     132                 :            :       else
     133                 :            :         {
     134                 :          0 :           snprintf (buf, len, "%s: %" PRIu32, _("<unknown>"), type);
     135                 :            : 
     136                 :          0 :           res = buf;
     137                 :            :         }
     138                 :            :     }
     139                 :            : 
     140                 :            :   return res;
     141                 :            : }

Generated by: LCOV version 1.16