-
Notifications
You must be signed in to change notification settings - Fork 2
/
refl-error.c
103 lines (90 loc) · 2.35 KB
/
refl-error.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Copyright (C) 2011, 2013 Petr Machata <[email protected]>
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include "reflP.h"
static __thread struct refl_error global_error;
void
__refl_seterr_2 (enum __refl_major_errcode major, int minor)
{
global_error.major = major;
global_error.minor = minor;
}
void
__refl_seterr (enum __refl_major_errcode major)
{
switch (major)
{
case REFL_E_NOERROR:
__refl_seterr_2 (major, 0);
return;
case REFL_E_SYSTEM:
__refl_seterr_2 (major, errno);
return;
case REFL_E_DWFL:
__refl_seterr_2 (major, dwfl_errno ());
return;
case REFL_E_DWARF:
__refl_seterr_2 (major, dwarf_errno ());
return;
case REFL_E_REFL:
/* Refl-owned error codes are set manually as well. */
assert (major != REFL_E_REFL);
abort ();
};
assert (!"unhandled major error code!");
}
void
__refl_error (enum __refl_minor_errcode minor)
{
__refl_seterr_2 (REFL_E_REFL, minor);
}
struct refl_error
refl_error (void)
{
struct refl_error result = global_error;
memset (&global_error, 0, sizeof (global_error));
return result;
}
char const *
refl_errmsg (struct refl_error error)
{
switch (error.major)
{
case REFL_E_NOERROR:
return "no error";
case REFL_E_SYSTEM:
return strerror (error.minor);
case REFL_E_DWFL:
return dwfl_errmsg (error.minor);
case REFL_E_DWARF:
return dwarf_errmsg (error.minor);
case REFL_E_REFL:
switch ((enum __refl_minor_errcode)error.minor)
{
case REFL_ME_DWARF:
return "invalid dwarf";
case REFL_ME_MISMATCH:
return "mismatch";
case REFL_ME_NOT_FOUND:
return "entity not found";
}
}
abort ();
}