-
Notifications
You must be signed in to change notification settings - Fork 13
/
vr_include_trace.c
130 lines (105 loc) · 3.92 KB
/
vr_include_trace.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
/*--------------------------------------------------------------------*/
/*--- Verrou: a FPU instrumentation tool. ---*/
/*--- This file contains code allowing to include some symbols ---*/
/*--- for the trace instrumentation. ---*/
/*--- vr_include_trace.c ---*/
/*--------------------------------------------------------------------*/
/* The code is a fork of vr_exclude.c*/
/*
This file is part of Verrou, a FPU instrumentation tool.
Copyright (C) 2014-2021 EDF
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 "vr_include_trace.h"
#define LINE_SIZEMAX VR_FNNAME_BUFSIZE
static Vr_Include_Trace* vr_addIncludeTrace (Vr_Include_Trace* list, const HChar * fnname, const HChar * objname) {
Vr_Include_Trace * cell = VG_(malloc)("vr.addIncludeTrace.1", sizeof(Vr_Include_Trace));
cell->fnname = VG_(strdup)("vr.addIncludeTrace.2", fnname);
cell->objname = VG_(strdup)("vr.addIncludeTrace.3", objname);
cell->next = list;
return cell;
}
static Vr_Include_Trace * vr_findIncludeTrace (Vr_Include_Trace* list, const HChar * fnname, const HChar * objname) {
Vr_Include_Trace * include;
for (include = list ; include != NULL ; include = include->next) {
if (include->fnname[0] != '*'
&& VG_(strcmp)(include->fnname, fnname) != 0)
continue;
if (include->objname[0] != '*'
&& VG_(strcmp)(include->objname, objname) != 0)
continue;
return include;
}
return NULL;
}
void vr_freeIncludeTraceList (Vr_Include_Trace* list) {
while (list != NULL) {
Vr_Include_Trace *next = list->next;
VG_(free)(list->fnname);
VG_(free)(list->objname);
VG_(free)(list);
list = next;
}
}
Vr_Include_Trace * vr_loadIncludeTraceList (Vr_Include_Trace * list, const HChar * fname) {
VG_(umsg)("Loading inclusion trace list from `%s'... ", fname);
Int fd = VG_(fd_open)(fname,VKI_O_RDONLY, 0);
if (fd == -1) {
VG_(umsg)("ERROR (open)\n");
return list;
}
SizeT nLine = LINE_SIZEMAX;
HChar *line = VG_(malloc)("vr.loadIncludeTrace.1", nLine*sizeof(HChar));
Int lineno = 0;
while (! VG_(get_line)(fd, &line, &nLine, &lineno)) {
HChar * c;
// Skip non-blank characters
for (c = line;
c<line+LINE_SIZEMAX && *c != 0 && *c != '\t' && *c != ' ';
++c) {}
if (*c == 0 || c>line+LINE_SIZEMAX-1) {
VG_(umsg)("ERROR (parse) :%s \n",line);
return list;
}
*c = 0;
// Skip blank characters
for (++c;
c<line+LINE_SIZEMAX && *c != 0 && (*c == '\t' || *c == ' ');
++c) {}
list = vr_addIncludeTrace (list,
/*fnname=*/ line,
/*objname*/ c);;
}
VG_(free)(line);
VG_(close)(fd);
VG_(umsg)("OK.\n");
return list;
}
Bool vr_includeTraceIRSB (const HChar** fnname, const HChar **objname) {
if (** fnname == 0) {
return False;
}
if (** objname == 0) {
return False;
}
// Never exclude functions / objects unless they are explicitly listed
Vr_Include_Trace *include = vr_findIncludeTrace (vr.includeTrace, *fnname, *objname);
if (include != NULL) {
return True;
}
return False;
}