forked from authorNari/objgrind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathog_error.c
158 lines (140 loc) · 4.4 KB
/
og_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "pub_tool_basics.h"
#include "pub_tool_gdbserver.h"
#include "pub_tool_poolalloc.h" // For mc_include.h
#include "pub_tool_hashtable.h" // For mc_include.h
#include "pub_tool_libcbase.h"
#include "pub_tool_libcassert.h"
#include "pub_tool_libcprint.h"
#include "pub_tool_machine.h"
#include "pub_tool_mallocfree.h"
#include "pub_tool_options.h"
#include "pub_tool_replacemalloc.h"
#include "pub_tool_tooliface.h"
#include "pub_tool_threadstate.h"
#include "pub_tool_debuginfo.h" // VG_(get_dataname_and_offset)
#include "pub_tool_xarray.h"
#include "og_error.h"
static Bool og_compare_error_contexts(VgRes res, Error* e1, Error* e2)
{
/* Guaranteed by calling function */
tl_assert(VG_(get_error_kind)(e1) == VG_(get_error_kind)(e2));
switch (VG_(get_error_kind)(e1)) {
case UnwritableErr:
case UnreferableErr:
return (VG_(get_error_address)(e1) == VG_(get_error_address)(e2) ? True : False);
default:
VG_(printf)("Error:\n unknown error code %d\n",
VG_(get_error_kind)(e1));
VG_(tool_panic)("unknown error code in og_compare_error_contexts");
}
return False;
}
/* Do a printf-style operation on either the XML or normal output
channel, depending on the setting of VG_(clo_xml).
*/
static void emit_WRK ( const HChar* format, va_list vargs )
{
if (VG_(clo_xml)) {
VG_(vprintf_xml)(format, vargs);
} else {
VG_(vmessage)(Vg_UserMsg, format, vargs);
}
}
static void emit ( const HChar* format, ... ) PRINTF_CHECK(1, 2);
static void emit ( const HChar* format, ... )
{
va_list vargs;
va_start(vargs, format);
emit_WRK(format, vargs);
va_end(vargs);
}
static void og_tool_error_before_pp (Error* err) {
/* Noop */
}
static void og_tool_error_pp (Error* err) {
const Bool xml = VG_(clo_xml); /* a shorthand */
switch (VG_(get_error_kind)(err)) {
case UnwritableErr:
if (xml) {
emit("<kind>%s</kind>", STR_UnwritableError);
VG_(pp_ExeContext)( VG_(get_error_where)(err) );
}
else {
emit(STR_UnwritableError);
VG_(pp_ExeContext)( VG_(get_error_where)(err) );
}
break;
case UnreferableErr:
if (xml) {
emit("<kind>%s</kind>", STR_UnreferableError);
VG_(pp_ExeContext)( VG_(get_error_where)(err) );
}
else {
emit(STR_UnreferableError);
VG_(pp_ExeContext)( VG_(get_error_where)(err) );
}
break;
default:
VG_(printf)("Error:\n unknown Objgrind error code %d\n",
VG_(get_error_kind)(err));
VG_(tool_panic)("unknown error code in og_tool_error_pp)");
}
}
static UInt og_tool_error_update_extra(Error* e)
{
/* TODO: add extra error for each kind */
return 0;
}
static Bool og_is_recognized_suppression(const HChar* const name,
Supp* const supp)
{
OgErrorKind skind = 0;
if (VG_(strcmp)(name, STR_UnwritableError) == 0)
skind = UnwritableErr;
else if (VG_(strcmp)(name, STR_UnreferableError) == 0)
skind = UnreferableErr;
else
return False;
VG_(set_supp_kind)(supp, skind);
return True;
}
static Bool og_error_matches_suppression(Error* const e, Supp* const supp)
{
return VG_(get_supp_kind)(supp) == VG_(get_error_kind)(e);
}
static
Bool og_read_extra_suppression_info(Int fd, HChar** bufpp,
SizeT* nBufp, Supp* supp)
{
return True;
}
static const HChar* og_get_error_name(Error* e)
{
switch (VG_(get_error_kind)(e))
{
case UnwritableErr: return VGAPPEND(STR_, UnwritableError);
case UnreferableErr: return VGAPPEND(STR_, UnreferableError);
default:
tl_assert(0);
}
return 0;
}
static
Bool og_get_extra_suppression_info(Error* e,
/*OUT*/HChar* buf, Int nBuf)
{
return False;
}
void OG_(register_error_handlers)(void)
{
VG_(needs_tool_errors)(og_compare_error_contexts,
og_tool_error_before_pp,
og_tool_error_pp,
True,
og_tool_error_update_extra,
og_is_recognized_suppression,
og_read_extra_suppression_info,
og_error_matches_suppression,
og_get_error_name,
og_get_extra_suppression_info);
}