Blame libdw/dwarf_error.c

Packit 032894
/* Retrieve ELF descriptor used for DWARF access.
Packit 032894
   Copyright (C) 2002-2005, 2009, 2014, 2015, 2017, 2018 Red Hat, Inc.
Packit 032894
   This file is part of elfutils.
Packit 032894
Packit 032894
   This file is free software; you can redistribute it and/or modify
Packit 032894
   it under the terms of either
Packit 032894
Packit 032894
     * the GNU Lesser General Public License as published by the Free
Packit 032894
       Software Foundation; either version 3 of the License, or (at
Packit 032894
       your option) any later version
Packit 032894
Packit 032894
   or
Packit 032894
Packit 032894
     * the GNU General Public License as published by the Free
Packit 032894
       Software Foundation; either version 2 of the License, or (at
Packit 032894
       your option) any later version
Packit 032894
Packit 032894
   or both in parallel, as here.
Packit 032894
Packit 032894
   elfutils is distributed in the hope that it will be useful, but
Packit 032894
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 032894
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 032894
   General Public License for more details.
Packit 032894
Packit 032894
   You should have received copies of the GNU General Public License and
Packit 032894
   the GNU Lesser General Public License along with this program.  If
Packit 032894
   not, see <http://www.gnu.org/licenses/>.  */
Packit 032894
Packit 032894
#ifdef HAVE_CONFIG_H
Packit 032894
# include <config.h>
Packit 032894
#endif
Packit 032894
Packit 032894
#include <assert.h>
Packit 032894
#include <stddef.h>
Packit 032894
Packit 032894
#include "libdwP.h"
Packit 032894
Packit 032894
Packit 032894
/* The error number.  */
Packit 032894
static __thread int global_error;
Packit 032894
Packit 032894
Packit 032894
int
Packit 032894
dwarf_errno (void)
Packit 032894
{
Packit 032894
  int result = global_error;
Packit 032894
  global_error = DWARF_E_NOERROR;
Packit 032894
  return result;
Packit 032894
}
Packit 032894
INTDEF(dwarf_errno)
Packit 032894
Packit 032894
Packit 032894
/* XXX For now we use string pointers.  Once the table stablelizes
Packit 032894
   make it more DSO-friendly.  */
Packit 032894
static const char *errmsgs[] =
Packit 032894
  {
Packit 032894
    [DWARF_E_NOERROR] = N_("no error"),
Packit 032894
    [DWARF_E_UNKNOWN_ERROR] = N_("unknown error"),
Packit 032894
    [DWARF_E_INVALID_ACCESS] = N_("invalid access"),
Packit 032894
    [DWARF_E_NO_REGFILE] = N_("no regular file"),
Packit 032894
    [DWARF_E_IO_ERROR] = N_("I/O error"),
Packit 032894
    [DWARF_E_INVALID_ELF] = N_("invalid ELF file"),
Packit 032894
    [DWARF_E_NO_DWARF] = N_("no DWARF information"),
Packit 032894
    [DWARF_E_COMPRESSED_ERROR] = N_("cannot decompress DWARF"),
Packit 032894
    [DWARF_E_NOELF] = N_("no ELF file"),
Packit 032894
    [DWARF_E_GETEHDR_ERROR] = N_("cannot get ELF header"),
Packit 032894
    [DWARF_E_NOMEM] = N_("out of memory"),
Packit 032894
    [DWARF_E_UNIMPL] = N_("not implemented"),
Packit 032894
    [DWARF_E_INVALID_CMD] = N_("invalid command"),
Packit 032894
    [DWARF_E_INVALID_VERSION] = N_("invalid version"),
Packit 032894
    [DWARF_E_INVALID_FILE] = N_("invalid file"),
Packit 032894
    [DWARF_E_NO_ENTRY] = N_("no entries found"),
Packit 032894
    [DWARF_E_INVALID_DWARF] = N_("invalid DWARF"),
Packit 032894
    [DWARF_E_NO_STRING] = N_("no string data"),
Packit 032894
    [DWARF_E_NO_DEBUG_STR] = N_(".debug_str section missing"),
Packit 032894
    [DWARF_E_NO_DEBUG_LINE_STR] = N_(".debug_line_str section missing"),
Packit 032894
    [DWARF_E_NO_STR_OFFSETS] = N_(".debug_str_offsets section missing"),
Packit 032894
    [DWARF_E_NO_ADDR] = N_("no address value"),
Packit 032894
    [DWARF_E_NO_CONSTANT] = N_("no constant value"),
Packit 032894
    [DWARF_E_NO_REFERENCE] = N_("no reference value"),
Packit 032894
    [DWARF_E_INVALID_REFERENCE] = N_("invalid reference value"),
Packit 032894
    [DWARF_E_NO_DEBUG_LINE] = N_(".debug_line section missing"),
Packit 032894
    [DWARF_E_INVALID_DEBUG_LINE] = N_("invalid .debug_line section"),
Packit 032894
    [DWARF_E_TOO_BIG] = N_("debug information too big"),
Packit 032894
    [DWARF_E_VERSION] = N_("invalid DWARF version"),
Packit 032894
    [DWARF_E_INVALID_DIR_IDX] = N_("invalid directory index"),
Packit 032894
    [DWARF_E_ADDR_OUTOFRANGE] = N_("address out of range"),
Packit 032894
    [DWARF_E_NO_DEBUG_LOC] = N_(".debug_loc section missing"),
Packit 032894
    [DWARF_E_NO_DEBUG_LOCLISTS] = N_(".debug_loclists section missing"),
Packit 032894
    [DWARF_E_NO_LOC_VALUE] = N_("not a location list value"),
Packit 032894
    [DWARF_E_NO_BLOCK] = N_("no block data"),
Packit 032894
    [DWARF_E_INVALID_LINE_IDX] = N_("invalid line index"),
Packit 032894
    [DWARF_E_INVALID_ARANGE_IDX] = N_("invalid address range index"),
Packit 032894
    [DWARF_E_NO_MATCH] = N_("no matching address range"),
Packit 032894
    [DWARF_E_NO_FLAG] = N_("no flag value"),
Packit 032894
    [DWARF_E_INVALID_OFFSET] = N_("invalid offset"),
Packit 032894
    [DWARF_E_NO_DEBUG_RANGES] = N_(".debug_ranges section missing"),
Packit 032894
    [DWARF_E_NO_DEBUG_RNGLISTS] = N_(".debug_rnglists section missing"),
Packit 032894
    [DWARF_E_INVALID_CFI] = N_("invalid CFI section"),
Packit 032894
    [DWARF_E_NO_ALT_DEBUGLINK] = N_("no alternative debug link found"),
Packit 032894
    [DWARF_E_INVALID_OPCODE] = N_("invalid opcode"),
Packit 032894
    [DWARF_E_NOT_CUDIE] = N_("not a CU (unit) DIE"),
Packit 032894
    [DWARF_E_UNKNOWN_LANGUAGE] = N_("unknown language code"),
Packit 032894
    [DWARF_E_NO_DEBUG_ADDR] = N_(".debug_addr section missing"),
Packit 032894
  };
Packit 032894
#define nerrmsgs (sizeof (errmsgs) / sizeof (errmsgs[0]))
Packit 032894
Packit 032894
Packit 032894
void
Packit 032894
internal_function
Packit 032894
__libdw_seterrno (int value)
Packit 032894
{
Packit 032894
  global_error = (value >= 0 && value < (int) nerrmsgs
Packit 032894
		  ? value : DWARF_E_UNKNOWN_ERROR);
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
const char *
Packit 032894
dwarf_errmsg (int error)
Packit 032894
{
Packit 032894
  int last_error = global_error;
Packit 032894
Packit 032894
  if (error == 0)
Packit 032894
    return last_error != 0 ? _(errmsgs[last_error]) : NULL;
Packit 032894
  else if (error < -1 || error >= (int) nerrmsgs)
Packit 032894
    return _(errmsgs[DWARF_E_UNKNOWN_ERROR]);
Packit 032894
Packit 032894
  return _(errmsgs[error == -1 ? last_error : error]);
Packit 032894
}
Packit 032894
INTDEF(dwarf_errmsg)