Coverage Report

Created: 2025-08-29 06:11

/src/elfutils/libdw/dwarf_error.c
Line
Count
Source (jump to first uncovered line)
1
/* Retrieve ELF descriptor used for DWARF access.
2
   Copyright (C) 2002-2005, 2009, 2014, 2015, 2017, 2018 Red Hat, Inc.
3
   This file is part of elfutils.
4
5
   This file is free software; you can redistribute it and/or modify
6
   it under the terms of either
7
8
     * the GNU Lesser General Public License as published by the Free
9
       Software Foundation; either version 3 of the License, or (at
10
       your option) any later version
11
12
   or
13
14
     * the GNU General Public License as published by the Free
15
       Software Foundation; either version 2 of the License, or (at
16
       your option) any later version
17
18
   or both in parallel, as here.
19
20
   elfutils is distributed in the hope that it will be useful, but
21
   WITHOUT ANY WARRANTY; without even the implied warranty of
22
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23
   General Public License for more details.
24
25
   You should have received copies of the GNU General Public License and
26
   the GNU Lesser General Public License along with this program.  If
27
   not, see <http://www.gnu.org/licenses/>.  */
28
29
#ifdef HAVE_CONFIG_H
30
# include <config.h>
31
#endif
32
33
#include <assert.h>
34
#include <stddef.h>
35
36
#include "libdwP.h"
37
38
39
/* The error number.  */
40
static __thread int global_error;
41
42
43
int
44
dwarf_errno (void)
45
23
{
46
23
  int result = global_error;
47
23
  global_error = DWARF_E_NOERROR;
48
23
  return result;
49
23
}
50
INTDEF(dwarf_errno)
51
52
53
/* XXX For now we use string pointers.  Once the table stablelizes
54
   make it more DSO-friendly.  */
55
static const char *errmsgs[] =
56
  {
57
    [DWARF_E_NOERROR] = N_("no error"),
58
    [DWARF_E_UNKNOWN_ERROR] = N_("unknown error"),
59
    [DWARF_E_INVALID_ACCESS] = N_("invalid access"),
60
    [DWARF_E_NO_REGFILE] = N_("no regular file"),
61
    [DWARF_E_IO_ERROR] = N_("I/O error"),
62
    [DWARF_E_INVALID_ELF] = N_("invalid ELF file"),
63
    [DWARF_E_NO_DWARF] = N_("no DWARF information"),
64
    [DWARF_E_COMPRESSED_ERROR] = N_("cannot decompress DWARF"),
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_DEBUG_STR] = N_(".debug_str section missing"),
76
    [DWARF_E_NO_DEBUG_LINE_STR] = N_(".debug_line_str section missing"),
77
    [DWARF_E_NO_STR_OFFSETS] = N_(".debug_str_offsets section missing"),
78
    [DWARF_E_NO_ADDR] = N_("no address value"),
79
    [DWARF_E_NO_CONSTANT] = N_("no constant value"),
80
    [DWARF_E_NO_REFERENCE] = N_("no reference value"),
81
    [DWARF_E_INVALID_REFERENCE] = N_("invalid reference value"),
82
    [DWARF_E_NO_DEBUG_LINE] = N_(".debug_line section missing"),
83
    [DWARF_E_INVALID_DEBUG_LINE] = N_("invalid .debug_line section"),
84
    [DWARF_E_TOO_BIG] = N_("debug information too big"),
85
    [DWARF_E_VERSION] = N_("invalid DWARF version"),
86
    [DWARF_E_INVALID_DIR_IDX] = N_("invalid directory index"),
87
    [DWARF_E_ADDR_OUTOFRANGE] = N_("address out of range"),
88
    [DWARF_E_NO_DEBUG_LOC] = N_(".debug_loc section missing"),
89
    [DWARF_E_NO_DEBUG_LOCLISTS] = N_(".debug_loclists section missing"),
90
    [DWARF_E_NO_LOC_VALUE] = N_("not a location list value"),
91
    [DWARF_E_NO_BLOCK] = N_("no block data"),
92
    [DWARF_E_INVALID_LINE_IDX] = N_("invalid line index"),
93
    [DWARF_E_INVALID_ARANGE_IDX] = N_("invalid address range index"),
94
    [DWARF_E_NO_MATCH] = N_("no matching address range"),
95
    [DWARF_E_NO_FLAG] = N_("no flag value"),
96
    [DWARF_E_INVALID_OFFSET] = N_("invalid offset"),
97
    [DWARF_E_NO_DEBUG_RANGES] = N_(".debug_ranges section missing"),
98
    [DWARF_E_NO_DEBUG_RNGLISTS] = N_(".debug_rnglists section missing"),
99
    [DWARF_E_INVALID_CFI] = N_("invalid CFI section"),
100
    [DWARF_E_NO_ALT_DEBUGLINK] = N_("no alternative debug link found"),
101
    [DWARF_E_INVALID_OPCODE] = N_("invalid opcode"),
102
    [DWARF_E_NOT_CUDIE] = N_("not a CU (unit) DIE"),
103
    [DWARF_E_UNKNOWN_LANGUAGE] = N_("unknown language code"),
104
    [DWARF_E_NO_DEBUG_ADDR] = N_(".debug_addr section missing"),
105
    [DWARF_E_UNKNOWN_SECTION] = N_("unknown section"),
106
  };
107
23
#define nerrmsgs (sizeof (errmsgs) / sizeof (errmsgs[0]))
108
109
110
void
111
internal_function
112
__libdw_seterrno (int value)
113
23
{
114
23
  global_error = (value >= 0 && value < (int) nerrmsgs
115
23
      ? value : DWARF_E_UNKNOWN_ERROR);
116
23
}
117
118
119
const char *
120
dwarf_errmsg (int error)
121
0
{
122
0
  int last_error = global_error;
123
124
0
  if (error == 0)
125
0
    return last_error != 0 ? _(errmsgs[last_error]) : NULL;
126
0
  else if (error < -1 || error >= (int) nerrmsgs)
127
0
    return _(errmsgs[DWARF_E_UNKNOWN_ERROR]);
128
129
0
  return _(errmsgs[error == -1 ? last_error : error]);
130
0
}
131
INTDEF(dwarf_errmsg)