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
720 stars 110 forks source link

How to know that the parser for kcov and that for executables are different #288

Closed kimkim19642004 closed 5 years ago

kimkim19642004 commented 5 years ago

Dear Mr.Simon Kagstrom,

I created a shell script containing the shebang '#!/usr/bin/env bash' and tested it with kcov.

The test environment: Mac OS X on Travis CI

The kcov option: --bash-parser="$(which bash)" (default: /bin/bash)

The core of my question: Does 'kcov' check Bash's version described at the shebang in the shell script, and reports errors if there are any problems? If so, how to use 'kcov' will be easier...

Thank you

SimonKagstrom commented 5 years ago

Not really, unfortunately. The shebang is ignored, and only the selected bash parser (or the default bash in the path) is used. The version of the used bash is checked though, to know if it's possible to use the "BASH_XTRACEFD" instead of parsing stderr.

Often, the shebang is set to #!/bin/sh, which can be e.g., dash or similar on some systems. These can't use the debugging features kcov needs, so it will always run bash even if the shebang says the script should be parsed by something else.

A special place where the shebang is parsed is in a dynamically loaded shared library:

https://github.com/SimonKagstrom/kcov/blob/master/src/engines/bash-execve-redirector.c

this is used to detect when another script is started from the covered script, to run coverage on that too. This particular one would fail with your shebang, so that might be a place to improve.

kimkim19642004 commented 5 years ago

Thank you for your reply.

The problem was solved by examining the value of the shell variable BASH_VERSINFO.

I should have checked the parser in my shell scripts.