wilzbach / tools-test

1 stars 0 forks source link

RDMD masks out segmentation faults #98

Closed wilzbach closed 10 years ago

wilzbach commented 10 years ago

Note: the issue was created automatically migrated from https://issues.dlang.org

Original bug ID: BZ#11983 From: Puneet Goel <puneet@coverify.org> Reported version: D2 CC: @andralex, bugzilla@digitalmars.com, bugzilla@kyllingen.net, dlang-bugzilla@thecybershadow.net

wilzbach commented 10 years ago

Comment author: Puneet Goel <puneet@coverify.org>

When executed with RDMD (github HEAD), the following code does not report segmentation fault. RDMD is returning exit code 245 instead of 139 on my ubuntu box. RDMD 2.064.2 does report segmentation fault.

void main() { int foo; foo = 4; }

wilzbach commented 10 years ago

Comment author: Walter Bright <bugzilla@digitalmars.com>

I don't really understand this report. Neither exit code 245 nor 139 have any specific purpose:

http://tldp.org/LDP/abs/html/exitcodes.html#EXITCODESREF

and all rdmd does is return the exit code of the program it runs.

wilzbach commented 10 years ago

Comment author: Puneet Goel <puneet@coverify.org>

I don't really understand this report. Neither exit code 245 nor 139 have any specific purpose:

http://tldp.org/LDP/abs/html/exitcodes.html#EXITCODESREF

and all rdmd does is return the exit code of the program it runs.

I am not sure of the purpose of the exit codes. I know these because I have been using these in my dustmite scripts.

Apart from the exit codes, rdmd is not even printing the usual "Segmentation fault (core dumped)" on my ubuntu 13.10 box. Previous versions of rdmd do that.

$ rdmd /tmp/test.d # no output on screen $ ~/local/dmd-2.064/dmd2/linux/bin64/rdmd /tmp/test.d Segmentation fault (core dumped)

I am using the latest version of the tools directory: $ git show commit 49cdc64116ba109352b661a3b3a5968d4c1afef9 Merge: 3a4b295 2ac7c99 Author: Martin Nowak <code@ dawg.eu> Date: Mon Jan 27 14:50:47 2014 -0800

wilzbach commented 10 years ago

Comment author: Puneet Goel <puneet@coverify.org>

Ok, I could confirm this on another ubuntu 13.10 (32 bit) machine as well.

root@ amstredam:/tmp# rdmd test.d # exits silently root@ amstredam:/tmp# echo $? 245 root@ amstredam:/tmp# rdmd --build-only test.d root@ amstredam:/tmp# ./test Segmentation fault (core dumped) root@ amstredam:/tmp# echo $? 139 root@ amstredam:/tmp# cat test.d void main() { int foo; foo = 4; }

wilzbach commented 10 years ago

Comment author: Walter Bright <bugzilla@digitalmars.com>

I did find something interesting (running on Ubuntu):


rdmd> ./rdmd foo.d rdmd> rdmd> echo $? 245 rdmd> dmd foo.d rdmd> ./foo hello Segmentation fault rdmd> echo $? 139

There's the 139 and 245 you were talking about. Looking at the source to rdmd:

private int run(string[] args, string output = null) { import std.conv; yap(args.text); if (dryRun) return 0;

File outputFile;
if (output)
    outputFile = File(output, "wb");
else
    outputFile = stdout;
auto process = spawnProcess(args, stdin, outputFile);
return process.wait();

}

so it must have something to do with spawnProcess() and wait().

wilzbach commented 10 years ago

Comment author: Lars T. Kyllingstad <bugzilla@kyllingen.net>

When the child process is terminated by a signal, wait() returns a negative number whose absolute value is the sigmal number. In this case, the signal is SIGSEGV, or 11, so wait() returns -11. Rdmd apparently uses this directly as its exit code, and since POSIX exit codes are restricted to the range 0-255, it wraps around to 245.

In other words, rdmd should probably check the value of wait(), and print something like "Terminated by signal X" if it is negative.

The 139 is set by the shell. Explanation here: https://stackoverflow.com/questions/1101957/are-there-any-standard-exit-status-codes-in-linux

Since this is an RDMD bug (if that), I'm changing "Component" from "DMD2" to "tools".

wilzbach commented 10 years ago

Comment author: Walter Bright <bugzilla@digitalmars.com>

https://github.com/D-Programming-Language/tools/pull/111

wilzbach commented 10 years ago

Comment author: @andralex

Relevant info from Walter for the record: https://stackoverflow.com/questions/1101957/are-there-any-standard-exit-status-codes-in-linux

wilzbach commented 10 years ago

Comment author: Vladimir Panteleev <dlang-bugzilla@thecybershadow.net>

Reposting this here, pull which fixes regression by restoring old behavior:

https://github.com/D-Programming-Language/tools/pull/112

wilzbach commented 10 years ago

Comment author: github-bugzilla@puremagic.com

Commits pushed to master at https://github.com/D-Programming-Language/tools

https://github.com/D-Programming-Language/tools/commit/524a76ecc5f654f13eb3854cd4a2bc757eca3b19 rdmd_test: Add test for issue 11983

https://github.com/D-Programming-Language/tools/commit/ef71a52ddf5f59fb31a7dcd9d1fa4c025f1b919d Merge pull request BZ#113 from CyberShadow/rdmd-20140202

rdmd: Fix --dry-run, add test for issue 11983