LCOV - code coverage report
Current view: top level - libebl - eblsectionname.c (source / functions) Hit Total Coverage
Test: elfutils- Lines: 17 26 65.4 %
Date: 2020-06-11 18:20:19 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          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       57184 : ebl_section_name (Ebl *ebl, int section, int xsection, char *buf, size_t len,
      40             :                   const char *scnnames[], size_t shnum)
      41             : {
      42       57184 :   const char *res = ebl != NULL ? ebl->section_name (section, xsection,
      43       57184 :                                                      buf, len) : NULL;
      44             : 
      45       57184 :   if (res == NULL)
      46             :     {
      47       57184 :       if (section == SHN_UNDEF)
      48             :         res = "UNDEF";
      49       52307 :       else if (section == SHN_ABS)
      50             :         res = "ABS";
      51       50589 :       else if (section == SHN_COMMON)
      52             :         res = "COMMON";
      53       50587 :       else if (section == SHN_BEFORE)
      54             :         res = "BEFORE";
      55       50587 :       else if (section == SHN_AFTER)
      56             :         res = "AFTER";
      57       50587 :       else if ((section < SHN_LORESERVE || section == SHN_XINDEX)
      58       50587 :                && (size_t) section < shnum)
      59             :         {
      60       50587 :           int idx = section != SHN_XINDEX ? section : xsection;
      61             : 
      62       50587 :           if (scnnames != NULL)
      63       29255 :             res = scnnames[idx];
      64             :           else
      65             :             {
      66       21332 :               snprintf (buf, len, "%d", idx);
      67       21332 :               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", gettext ("<unknown>"), section);
      84             : 
      85             :           res = buf;
      86             :         }
      87             :     }
      88             : 
      89       57184 :   return res;
      90             : }

Generated by: LCOV version 1.13