LCOV - code coverage report
Current view: top level - libebl - eblsectionname.c (source / functions) Hit Total Coverage
Test: elfutils-0.189 Lines: 17 26 65.4 %
Date: 2023-08-02 17:40:45 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 15 30 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* Return section name.
       2                 :            :    Copyright (C) 2001, 2002, 2004 Red Hat, Inc.
       3                 :            :    This file is part of elfutils.
       4                 :            :    Written by Ulrich Drepper <drepper@redhat.com>, 2001.
       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 <stdio.h>
      35                 :            : #include <libeblP.h>
      36                 :            : 
      37                 :            : 
      38                 :            : const char *
      39                 :      71114 : ebl_section_name (Ebl *ebl, int section, int xsection, char *buf, size_t len,
      40                 :            :                   const char *scnnames[], size_t shnum)
      41                 :            : {
      42                 :      71114 :   const char *res = ebl != NULL ? ebl->section_name (section, xsection,
      43         [ +  - ]:      71114 :                                                      buf, len) : NULL;
      44                 :            : 
      45         [ +  - ]:      71114 :   if (res == NULL)
      46                 :            :     {
      47         [ +  + ]:      71114 :       if (section == SHN_UNDEF)
      48                 :            :         res = "UNDEF";
      49         [ +  + ]:      65674 :       else if (section == SHN_ABS)
      50                 :            :         res = "ABS";
      51         [ +  + ]:      63189 :       else if (section == SHN_COMMON)
      52                 :            :         res = "COMMON";
      53         [ +  - ]:      63187 :       else if (section == SHN_BEFORE)
      54                 :            :         res = "BEFORE";
      55         [ +  - ]:      63187 :       else if (section == SHN_AFTER)
      56                 :            :         res = "AFTER";
      57         [ +  - ]:      63187 :       else if ((section < SHN_LORESERVE || section == SHN_XINDEX)
      58         [ +  - ]:      63187 :                && (size_t) section < shnum)
      59                 :            :         {
      60         [ -  + ]:      63187 :           int idx = section != SHN_XINDEX ? section : xsection;
      61                 :            : 
      62         [ +  + ]:      63187 :           if (scnnames != NULL)
      63                 :      31202 :             res = scnnames[idx];
      64                 :            :           else
      65                 :            :             {
      66                 :      31985 :               snprintf (buf, len, "%d", idx);
      67                 :      31985 :               res = buf;
      68                 :            :             }
      69                 :            :         }
      70                 :            :       else
      71                 :            :         {
      72                 :            :           /* Handle OS-specific section names.  */
      73         [ #  # ]:          0 :           if (section == SHN_XINDEX)
      74                 :          0 :             snprintf (buf, len, "%s: %d", "XINDEX", xsection);
      75         [ #  # ]:          0 :           else if (section >= SHN_LOOS && section <= SHN_HIOS)
      76                 :          0 :             snprintf (buf, len, "LOOS+%x", section - SHN_LOOS);
      77                 :            :           /* Handle processor-specific section names.  */
      78         [ #  # ]:          0 :           else if (section >= SHN_LOPROC && section <= SHN_HIPROC)
      79                 :          0 :             snprintf (buf, len, "LOPROC+%x", section - SHN_LOPROC);
      80         [ #  # ]:          0 :           else if (section >= SHN_LORESERVE && section <= SHN_HIRESERVE)
      81                 :          0 :             snprintf (buf, len, "LORESERVE+%x", section - SHN_LORESERVE);
      82                 :            :           else
      83                 :          0 :             snprintf (buf, len, "%s: %d", _("<unknown>"), section);
      84                 :            : 
      85                 :            :           res = buf;
      86                 :            :         }
      87                 :            :     }
      88                 :            : 
      89                 :      71114 :   return res;
      90                 :            : }

Generated by: LCOV version 1.16