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

stdout is not shown when using kcov on Ubuntu 20.04 #362

Closed alalazo closed 2 years ago

alalazo commented 3 years ago

This is similar to #61. Given this simple script:

$ cat run_it.sh
#!/bin/bash
echo "Hello"

I see the following:

$ ls -l run_it.sh
-rwxrw-r-- 1 culpo culpo 26 Aug 13 15:56 run_it.sh
$ ./run_it.sh 
Hello
$ kcov $PWD/coverage run_it.sh
$

i.e. nothing gets printed to stdout when running under kcov. Using one of the workaround suggested in #61 changes the behavior:

$ kcov --debug-force-bash-stderr $PWD/coverage run_it.sh
Hello

It's possibly done on purpose, but the --debug-force-bash-stderr is not shown from kcov help message. If it matters I am working on:

$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
SimonKagstrom commented 3 years ago

Hmm.. I don't see that issue here (on OSX though):

Simons-iMac:kcov ska$ kcov --bash-dont-parse-binary-dir /tmp/kcov /tmp/a.sh
Hello

Is this with the latest from git?

alalazo commented 3 years ago

Is this with the latest from git?

No, it's with kcov v38 packaged in the Ubuntu repository

SimonKagstrom commented 3 years ago

I tried re-builing on v38 and it works for me there as well. Not sure if it can affect it, but my bash version is

GNU bash, version 5.1.4(1)-release (x86_64-apple-darwin17.7.0)

alalazo commented 3 years ago

Ok, I have a different bash version:

$ bash --version
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
alalazo commented 3 years ago

I think you can probably reproduce starting from a vanilla ubuntu:20.04 docker image.

alalazo commented 3 years ago

It should be reproducible if you run in this image:

FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get -y update && apt-get -y upgrade && \
    apt-get install -y coreutils curl patchelf kcov emacs

RUN useradd -m bob
USER bob
WORKDIR /home/bob
SimonKagstrom commented 2 years ago

I tried your docker image now, and I can reproduce it there. It seems to be caused by the xtrace FD support. A workaround is to use --debug-force-bash-stderr, which disables it altogether. Then I see the stdout output when using kcov as well.

SimonKagstrom commented 2 years ago

Actually, this is only a problem with v38 (and presumably earlier). I've tested the latest git HEAD on ubuntu 20.04, and that works while v38 fails, so closing.