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