SimonKagstrom / kcov

Code coverage tool for compiled programs, Python and Bash which uses debugging information to collect and report data without special compilation options
http://simonkagstrom.github.io/kcov/
GNU General Public License v2.0
710 stars 109 forks source link

shell script STDOUT goes missing #395

Open phil-hands opened 1 year ago

phil-hands commented 1 year ago

Here is a demonstration of running a shell script under kcov, which makes the output go missing:

nimble% cat ./kcov_test/date.sh
#!/bin/sh
[ "$1" ] && exec >&8
date

% ./kcov_test/date.sh
Thu 25 May 09:32:29 CEST 2023

% kcov ./kcov_test/output ./kcov_test/date.sh

% kcov ./kcov_test/output ./kcov_test/date.sh redir_to_8
./kcov_test/date.sh: line 2: 8: Bad file descriptor

% kcov ./kcov_test/output ./kcov_test/date.sh redir_to_8 8>&1
Thu 25 May 09:32:33 CEST 2023

% kcov ./kcov_test/output date
Thu 25 May 09:32:55 CEST 2023

% kcov --version
kcov 38

That was on a Debian GNU/Linux 13 (aka "bookworm" or testing) system, with the packaged version of kcov (ver: 38+dfsg-1).

As you can see, if one redirects STDOUT in the script to FD 8 (chosen at random) and then redirect that back to STDOUT outside kcov, things work as expected. I presume this is unexpected.

I've had a glance at the Debian specific patches, and I don't see how they would produce this effect, so I suspect that it exists upstream, which is why I'm reporting this here.

SimonKagstrom commented 1 year ago

Can you retry it with the latest from git? I tested your script with my build, and it doesn't seem to happen there (on OSX though).

v38 is a few years old, so although I don't know of any specific fix of this, there are many changes since then.