LCOV - code coverage report
Current view: top level - libebl - eblobjnotetypename.c (source / functions) Hit Total Coverage
Test: elfutils-0.191 Lines: 26 34 76.5 %
Date: 2024-09-06 23:49:26 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 18 34 52.9 %

           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                 :       4496 : 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                 :       4496 :   const char *res = ebl->object_note_type_name (name, type, buf, len);
      48                 :            : 
      49         [ +  - ]:       4496 :   if (res == NULL)
      50                 :            :     {
      51         [ -  + ]:       4496 :       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                 :       4496 :       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         [ -  + ]:       4496 :       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         [ +  + ]:       4496 :       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                 :       4044 :           char *t = buf;
      90                 :       4044 :           const char *gba = "GNU Build Attribute";
      91         [ +  + ]:       4044 :           int w = snprintf (t, len, "%s ", gba);
      92                 :       4044 :           t += w;
      93                 :       4044 :           len -= w;
      94         [ +  + ]:       4044 :           if (type == NT_GNU_BUILD_ATTRIBUTE_OPEN)
      95                 :       3764 :             snprintf (t, len, "OPEN");
      96         [ +  - ]:        280 :           else if (type == NT_GNU_BUILD_ATTRIBUTE_FUNC)
      97                 :        280 :             snprintf (t, len, "FUNC");
      98                 :            :           else
      99                 :          0 :             snprintf (t, len, "%x", type);
     100                 :            : 
     101                 :       4044 :           return buf;
     102                 :            :         }
     103                 :            : 
     104   [ -  +  -  - ]:        452 :       if (strcmp (name, "FDO") == 0 && type == NT_FDO_PACKAGING_METADATA)
     105                 :            :         return "FDO_PACKAGING_METADATA";
     106                 :            : 
     107   [ -  +  -  - ]:        452 :       if (strcmp (name, "FDO") == 0 && type == NT_FDO_DLOPEN_METADATA)
     108                 :            :         return "FDO_DLOPEN_METADATA";
     109                 :            : 
     110         [ +  + ]:        452 :       if (strcmp (name, "GNU") != 0)
     111                 :            :         {
     112                 :            :           /* NT_VERSION is special, all data is in the name.  */
     113         [ +  + ]:         12 :           if (descsz == 0 && type == NT_VERSION)
     114                 :            :             return "VERSION";
     115                 :            : 
     116                 :          2 :           snprintf (buf, len, "%s: %" PRIu32, _("<unknown>"), type);
     117                 :          2 :           return buf;
     118                 :            :         }
     119                 :            : 
     120                 :            :       /* And finally all the "GNU" note types.  */
     121                 :        440 :       static const char *knowntypes[] =
     122                 :            :         {
     123                 :            : #define KNOWNSTYPE(name) [NT_##name] = #name
     124                 :            :           KNOWNSTYPE (GNU_ABI_TAG),
     125                 :            :           KNOWNSTYPE (GNU_HWCAP),
     126                 :            :           KNOWNSTYPE (GNU_BUILD_ID),
     127                 :            :           KNOWNSTYPE (GNU_GOLD_VERSION),
     128                 :            :           KNOWNSTYPE (GNU_PROPERTY_TYPE_0),
     129                 :            :         };
     130                 :            : 
     131                 :            :       /* Handle standard names.  */
     132         [ +  - ]:        440 :       if (type < sizeof (knowntypes) / sizeof (knowntypes[0])
     133         [ -  + ]:        440 :           && knowntypes[type] != NULL)
     134                 :            :         res = knowntypes[type];
     135                 :            :       else
     136                 :            :         {
     137                 :          0 :           snprintf (buf, len, "%s: %" PRIu32, _("<unknown>"), type);
     138                 :            : 
     139                 :          0 :           res = buf;
     140                 :            :         }
     141                 :            :     }
     142                 :            : 
     143                 :            :   return res;
     144                 :            : }

Generated by: LCOV version 1.16