LCOV - code coverage report
Current view: top level - elfutils/libdw - dwarf_error.c (source / functions) Hit Total Coverage
Test: lcov.out Lines: 8 15 53.3 %
Date: 2012-10-31 Functions: 2 3 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 10 10.0 %

           Branch data     Line data    Source code
       1                 :            : /* Retrieve ELF descriptor used for DWARF access.
       2                 :            :    Copyright (C) 2002, 2003, 2004, 2005, 2009 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 <assert.h>
      35                 :            : #include <stddef.h>
      36                 :            : 
      37                 :            : #include "libdwP.h"
      38                 :            : 
      39                 :            : 
      40                 :            : /* The error number.  */
      41                 :            : static __thread int global_error;
      42                 :            : 
      43                 :            : 
      44                 :            : int
      45                 :         56 : dwarf_errno (void)
      46                 :            : {
      47                 :         56 :   int result = global_error;
      48                 :         56 :   global_error = DWARF_E_NOERROR;
      49                 :         56 :   return result;
      50                 :            : }
      51                 :            : INTDEF(dwarf_errno)
      52                 :            : 
      53                 :            : 
      54                 :            : /* XXX For now we use string pointers.  Once the table stablelizes
      55                 :            :    make it more DSO-friendly.  */
      56                 :            : static const char *errmsgs[] =
      57                 :            :   {
      58                 :            :     [DWARF_E_NOERROR] = N_("no error"),
      59                 :            :     [DWARF_E_UNKNOWN_ERROR] = N_("unknown error"),
      60                 :            :     [DWARF_E_INVALID_ACCESS] = N_("invalid access"),
      61                 :            :     [DWARF_E_NO_REGFILE] = N_("no regular file"),
      62                 :            :     [DWARF_E_IO_ERROR] = N_("I/O error"),
      63                 :            :     [DWARF_E_INVALID_ELF] = N_("invalid ELF file"),
      64                 :            :     [DWARF_E_NO_DWARF] = N_("no DWARF information"),
      65                 :            :     [DWARF_E_NOELF] = N_("no ELF file"),
      66                 :            :     [DWARF_E_GETEHDR_ERROR] = N_("cannot get ELF header"),
      67                 :            :     [DWARF_E_NOMEM] = N_("out of memory"),
      68                 :            :     [DWARF_E_UNIMPL] = N_("not implemented"),
      69                 :            :     [DWARF_E_INVALID_CMD] = N_("invalid command"),
      70                 :            :     [DWARF_E_INVALID_VERSION] = N_("invalid version"),
      71                 :            :     [DWARF_E_INVALID_FILE] = N_("invalid file"),
      72                 :            :     [DWARF_E_NO_ENTRY] = N_("no entries found"),
      73                 :            :     [DWARF_E_INVALID_DWARF] = N_("invalid DWARF"),
      74                 :            :     [DWARF_E_NO_STRING] = N_("no string data"),
      75                 :            :     [DWARF_E_NO_ADDR] = N_("no address value"),
      76                 :            :     [DWARF_E_NO_CONSTANT] = N_("no constant value"),
      77                 :            :     [DWARF_E_NO_REFERENCE] = N_("no reference value"),
      78                 :            :     [DWARF_E_INVALID_REFERENCE] = N_("invalid reference value"),
      79                 :            :     [DWARF_E_NO_DEBUG_LINE] = N_(".debug_line section missing"),
      80                 :            :     [DWARF_E_INVALID_DEBUG_LINE] = N_("invalid .debug_line section"),
      81                 :            :     [DWARF_E_TOO_BIG] = N_("debug information too big"),
      82                 :            :     [DWARF_E_VERSION] = N_("invalid DWARF version"),
      83                 :            :     [DWARF_E_INVALID_DIR_IDX] = N_("invalid directory index"),
      84                 :            :     [DWARF_E_ADDR_OUTOFRANGE] = N_("address out of range"),
      85                 :            :     [DWARF_E_NO_LOCLIST] = N_("no location list value"),
      86                 :            :     [DWARF_E_NO_BLOCK] = N_("no block data"),
      87                 :            :     [DWARF_E_INVALID_LINE_IDX] = N_("invalid line index"),
      88                 :            :     [DWARF_E_INVALID_ARANGE_IDX] = N_("invalid address range index"),
      89                 :            :     [DWARF_E_NO_MATCH] = N_("no matching address range"),
      90                 :            :     [DWARF_E_NO_FLAG] = N_("no flag value"),
      91                 :            :     [DWARF_E_INVALID_OFFSET] = N_("invalid offset"),
      92                 :            :     [DWARF_E_NO_DEBUG_RANGES] = N_(".debug_ranges section missing"),
      93                 :            :     [DWARF_E_INVALID_CFI] = N_("invalid CFI section"),
      94                 :            :     [DWARF_E_NO_ALT_DEBUGLINK] = N_("no alternative debug link found"),
      95                 :            :   };
      96                 :            : #define nerrmsgs (sizeof (errmsgs) / sizeof (errmsgs[0]))
      97                 :            : 
      98                 :            : 
      99                 :            : void
     100                 :         82 : __libdw_seterrno (value)
     101                 :            :      int value;
     102                 :            : {
     103                 :        164 :   global_error = (value >= 0 && value < (int) nerrmsgs
     104         [ +  - ]:         82 :                   ? value : DWARF_E_UNKNOWN_ERROR);
     105                 :         82 : }
     106                 :            : 
     107                 :            : 
     108                 :            : const char *
     109                 :          0 : dwarf_errmsg (error)
     110                 :            :      int error;
     111                 :            : {
     112                 :          0 :   int last_error = global_error;
     113                 :            : 
     114         [ #  # ]:          0 :   if (error == 0)
     115         [ #  # ]:          0 :     return last_error != 0 ? _(errmsgs[last_error]) : NULL;
     116         [ #  # ]:          0 :   else if (error < -1 || error >= (int) nerrmsgs)
     117                 :          0 :     return _(errmsgs[DWARF_E_UNKNOWN_ERROR]);
     118                 :            : 
     119         [ #  # ]:          0 :   return _(errmsgs[error == -1 ? last_error : error]);
     120                 :            : }
     121                 :            : INTDEF(dwarf_errmsg)

Generated by: LCOV version 1.9