-
-
Notifications
You must be signed in to change notification settings - Fork 644
/
Copy pathdwarf.d
executable file
·177 lines (146 loc) · 4.55 KB
/
dwarf.d
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
import dshell;
import std.algorithm;
import std.file;
import std.process;
import std.regex;
import std.conv;
int main()
{
version(DigitalMars) { }
else
{
writeln("Skipping dwarf.d for non-DMD compilers.");
return DISABLED;
}
version(Windows)
{
writeln("Skipping dwarf.d for Windows.");
return DISABLED;
}
version(OSX)
{
writeln("Skipping dwarf.d for MacOS X.");
return DISABLED;
}
version(Windows)
immutable slash = "\\";
else
immutable slash = "/";
// If the Unix system doesn't have objdump, disable the tests
auto sysObjdump = executeShell("objdump --version");
if (sysObjdump.status)
return DISABLED;
double objdumpVersion;
try
{
// output examples :
// GNU objdump 2.15
// GNU objdump 2.17.50 [FreeBSD] 2007-07-03
// GNU objdump (GNU Binutils) 2.36.1
string strVer = sysObjdump.output.split("\n")[0];
writeln("Objdump version of the machine : ", strVer);
auto cap = matchFirst(strVer, `[0-9]+\.[0-9]+`);
assert(cap);
objdumpVersion = cap.hit.to!double;
}
catch (ConvException ce)
{
// The conversion failed
return DISABLED;
}
writeln("Parsed objdump version of the machine : ", objdumpVersion);
// DWARF 3 (and 4) support has been implemented in version 2.20 (2.20.51.0.1)
if(objdumpVersion < 2.20)
return DISABLED;
immutable extra_dwarf_dir = EXTRA_FILES ~ slash ~ "dwarf" ~ slash;
bool failed;
// test them all
foreach (string path; dirEntries(extra_dwarf_dir, SpanMode.shallow))
{
if (!isFile(path) || extension(path) != ".d")
continue;
// retrieve the filename without the extension
auto filename = baseName(stripExtension(path));
string[string] requirements = getRequirements(path);
try
{
if (objdumpVersion < requirements["MIN_OBJDUMP_VERSION"].to!double)
{
writeln("Warning: test " ~ path ~ " skipped.");
continue ;
}
}
catch(Exception e) { }
string exe = OUTPUT_BASE ~ slash ~ filename;
run("$DMD -m$MODEL -of" ~ exe ~ "$EXE -conf= -fPIE -g " ~ requirements["EXTRA_ARGS"]
~ " -I" ~ extra_dwarf_dir ~ " " ~ path);
// Write objdump result to a file
auto objdump = exe ~ ".objdump";
auto objdump_file = File(objdump, "w");
run("objdump -W " ~ exe, objdump_file);
objdump_file.close();
auto llvmDwarfdump = executeShell("llvm-dwarfdump --version");
try {
if (!llvmDwarfdump.status && requirements["DWARF_VERIFY"].to!bool)
run("llvm-dwarfdump --verify " ~ exe);
} catch (ConvException e) { }
// Objdump excepted results
string excepted_results_file = extra_dwarf_dir ~ "excepted_results"
~ slash ~ filename ~ ".txt";
if (!exists(excepted_results_file))
assert(0, "DWARF tests must have a .txt file in the `excepted_results`"
~ " folder which contains the DWARF dump info");
// Read file result as a string
auto result = cast(string)readText(objdump);
string failmsg;
foreach (line; File(excepted_results_file).byLine)
{
if (!canFind(result, line))
{
failmsg ~= filename ~ ": Couln't find `" ~ line
~ "` in the DWARF dump info.\n";
failed = true;
}
}
if (failmsg)
{
// Writes the result into stdout for the CI machines.
writeln(result);
write(failmsg);
}
}
return failed;
}
string[string] getRequirements(string dfile)
{
string[string] result;
// Initialize to an empty string to prevent RangeViolation exceptions.
foreach (req; ["EXTRA_ARGS", "MIN_OBJDUMP_VERSION"])
result[req] = "";
result["DWARF_VERIFY"] = "true";
bool begin;
auto f = File(dfile, "r");
foreach (line; f.byLine)
{
if (line.length < 2)
continue;
if (line.startsWith("/*"))
{
begin = true;
}
if (begin)
{
string[] args = line.split(":").to!(string[]);
if (args.length == 2)
{
result[args[0]] = args[1].strip();
}
if (line.indexOf("*/") != -1)
{
break;
}
}
}
f.close();
return result;
}