-
Notifications
You must be signed in to change notification settings - Fork 13
/
vr_error.c
294 lines (238 loc) · 7.69 KB
/
vr_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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/*--------------------------------------------------------------------*/
/*--- Verrou: a FPU instrumentation tool. ---*/
/*--- This file contains code related errors handling. ---*/
/*--- vr_error.c ---*/
/*--------------------------------------------------------------------*/
/*
This file is part of Verrou, a FPU instrumentation tool.
Copyright (C) 2014-2021 EDF
F. Févotte <[email protected]>
B. Lathuilière <[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 2 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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307, USA.
The GNU General Public License is contained in the file COPYING.
*/
#include "vr_main.h"
//#include "coregrind/pub_core_debuginfo.h"
#include "pub_tool_debuginfo.h"
extern Bool VG_(get_fnname_raw) ( DiEpoch ep, Addr a, const HChar** buf );
typedef struct Vr_InstrError_ Vr_InstrError;
struct Vr_InstrError_ {
IROp op;
};
typedef union Vr_Error_ Vr_Error;
union Vr_Error_ {
Vr_InstrError instr;
};
static const HChar* vr_error_name (Vr_ErrorKind kind) {
switch (kind) {
case VR_ERROR_UNCOUNTED:
return "Uncounted operation";
case VR_ERROR_SCALAR:
return "Scalar instruction";
case VR_ERROR_NAN:
return "NaN";
case VR_ERROR_INF:
return "+/-Inf";
case VR_ERROR_CC:
return "Cancellation";
case VR_ERROR_CD:
return "Denorm";
case VR_ERROR_FLT_MAX:
return "FLT_MAX";
default:
return NULL;
}
}
// * Errors at the instruction level
void vr_maybe_record_ErrorOp (Vr_ErrorKind kind, IROp op) {
ThreadId tid = VG_(get_running_tid)();
Addr addr;
VG_(get_StackTrace)(tid, &addr, 1, NULL, NULL, 0);
HChar string[10];
VG_(snprintf)(string, 10, "%u", op);
Vr_Error extra;
extra.instr.op = op;
VG_(maybe_record_error)(tid,
kind,
addr,
string,
&extra);
}
static void vr_pp_ErrorOp (const Error* err) {
Vr_Error *extra = VG_(get_error_extra)(err);
VG_(umsg)("%s: ", vr_get_error_name(err));
VG_(message_flush)();
ppIROp (extra->instr.op);
VG_(printf)(" (%s)", VG_(get_error_string)(err));
VG_(umsg)("\n");
VG_(pp_ExeContext)(VG_(get_error_where)(err));
}
// * Errors happening at run time
void vr_maybe_record_ErrorRt (Vr_ErrorKind kind) {
ThreadId tid = VG_(get_running_tid)();
Addr addr;
VG_(get_StackTrace)(tid, &addr, 1, NULL, NULL, 0);
HChar string[1];
string[0] = 0;
VG_(maybe_record_error)(tid,
kind,
addr,
string,
NULL);
}
void vr_handle_NaN () {
if(vr.checknan){
vr_maybe_record_ErrorRt(VR_ERROR_NAN);
}
}
void vr_handle_Inf () {
if(vr.checkinf){
vr_maybe_record_ErrorRt(VR_ERROR_INF);
}
}
void vr_handle_FLT_MAX () {
if(vr.checkFloatMax){
vr_maybe_record_ErrorRt(VR_ERROR_FLT_MAX);
}
}
void vr_handle_CC (int unused) {
ThreadId tid = VG_(get_running_tid)();
Addr addr;
VG_(get_StackTrace)(tid, &addr, 1, NULL, NULL, 0);
if(vr.dumpCancellation){
DiEpoch di=VG_(current_DiEpoch)();
const HChar* fileName;
const HChar* dirName;
const HChar* symName;
UInt lineNum;
//UInt errorName=
VG_(get_filename_linenum)(di,addr,
&fileName,
&dirName,
&lineNum );
VG_(get_fnname_raw)(di, addr, &symName);
// VG_(umsg)("test ? %s - %s : %u --> %u \n", symName,fileName, lineNum,errorName);
vr_includeSource_generate (&vr.cancellationSource , symName, fileName, lineNum);
}
if(vr.checkCancellation){
HChar string[1];
string[0] = 0;
VG_(maybe_record_error)(tid,
VR_ERROR_CC,
addr,
string,
NULL);
}
}
void vr_handle_CD () {
ThreadId tid = VG_(get_running_tid)();
Addr addr;
VG_(get_StackTrace)(tid, &addr, 1, NULL, NULL, 0);
if(vr.dumpDenorm){
DiEpoch di=VG_(current_DiEpoch)();
const HChar* fileName;
const HChar* dirName;
const HChar* symName;
UInt lineNum;
//UInt errorName=
VG_(get_filename_linenum)(di,addr,
&fileName,
&dirName,
&lineNum );
VG_(get_fnname_raw)(di, addr, &symName);
// VG_(umsg)("test ? %s - %s : %u --> %u \n", symName,fileName, lineNum,errorName);
vr_includeSource_generate (&vr.denormSource , symName, fileName, lineNum);
}
if(vr.checkDenorm){
HChar string[1];
string[0] = 0;
VG_(maybe_record_error)(tid,
VR_ERROR_CD,
addr,
string,
NULL);
}
}
static void vr_pp_ErrorRt (const Error* err) {
VG_(umsg)("%s: ", vr_get_error_name(err));
VG_(message_flush)();
VG_(umsg)("\n");
VG_(pp_ExeContext)(VG_(get_error_where)(err));
}
// * Standard tools interface
const HChar* vr_get_error_name (const Error* err) {
return vr_error_name (VG_(get_error_kind)(err));
}
Bool vr_recognised_suppression (const HChar* name, Supp* su) {
Vr_ErrorKind kind;
for (kind = 0 ; kind < VR_ERROR ; ++kind) {
const HChar* errorName = vr_error_name(kind);
if (errorName && VG_(strcmp)(name, errorName) == 0)
break;
}
if (kind == VR_ERROR) {
return False;
} else {
VG_(set_supp_kind)(su, 0);
return True;
}
}
void vr_before_pp_Error (const Error* err) {}
void vr_pp_Error (const Error* err) {
switch (VG_(get_error_kind)(err)) {
case VR_ERROR_UNCOUNTED:
case VR_ERROR_SCALAR:
vr_pp_ErrorOp (err);
break;
case VR_ERROR_NAN:
case VR_ERROR_INF:
case VR_ERROR_CC:
case VR_ERROR_CD:
case VR_ERROR_FLT_MAX:
vr_pp_ErrorRt (err);
break;
}
}
Bool vr_eq_Error (VgRes res, const Error* e1, const Error* e2) {
return VG_(get_error_address)(e1) == VG_(get_error_address)(e2);
}
UInt vr_update_extra (const Error* err) {
return sizeof(Vr_Error);
}
Bool vr_error_matches_suppression (const Error* err, const Supp* su) {
if (VG_(get_error_kind)(err) != VG_(get_supp_kind)(su)) {
return False;
}
if (VG_(strcmp)(VG_(get_error_string)(err), VG_(get_supp_string)(su)) != 0) {
return False;
}
return True;
}
Bool vr_read_extra_suppression_info (Int fd, HChar** bufpp, SizeT* nBufp,
Int* lineno, Supp* su) {
VG_(get_line)(fd, bufpp, nBufp, lineno);
VG_(set_supp_string)(su, VG_(strdup)("vr.resi.1", *bufpp));
return True;
}
SizeT vr_print_extra_suppression_info (const Error* err,
/*OUT*/HChar* buf, Int nBuf) {
HChar* res=VG_(strncpy)(buf, VG_(get_error_string)(err), nBuf);
SizeT len=VG_(strlen)(res);
return len ;
}
SizeT vr_print_extra_suppression_use (const Supp* su,
/*OUT*/HChar* buf, Int nBuf) {
return (SizeT)0; //False
}
void vr_update_extra_suppression_use (const Error* err, const Supp* su) {}