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

When attaching with --pid=, shared libraries are not covered #109

Open VincentGibert opened 9 years ago

VincentGibert commented 9 years ago

Hi (again),

When I use kcov with the --pid flag, I don't manage to get coverage results.

Environment

What does it mean ? Maybe some debug information are missing on my system ?

SimonKagstrom commented 9 years ago

Sorry, I've completely missed this bug report.

It might have something to do with shared library support I think, which perhaps isn't working well together with the --pid= option. Shared libraries are handled via a LD_PRELOAD override, but for an already started process, the LD_PRELOAD wasn't set at startup time. Therefore kcov doesn't detect the loaded libraries when it starts.

You should still get hits from snmpd itself, but not from the other libraries loaded by it.

VincentGibert commented 9 years ago

It makes sense, I will try with a static binary to confirm your analysis.

VincentGibert commented 9 years ago

I just tested with a static version of busybox and it worked well so it seems you guessed right.

SimonKagstrom commented 9 years ago

Great, thanks for testing!

I think I'll resolve this issue by adding a few lines to the documentation - I don't think it will be very easy to fix the core issue.

VincentGibert commented 9 years ago

You may probably retrieve the list of loaded shared libraries by the process through /proc//maps (sadly it is Linux specific) but I don't know if it is sufficient to trace them.

SimonKagstrom commented 9 years ago

Yes, maybe that's a possibility. I'll keep the bug report open for further investigation.

SimonKagstrom commented 8 years ago

I took a look at this bug again, and I believe it should be doable to parse /proc//maps for the shared library-when-tracing-via-pid case.

It will still not cover all cases since it will be difficult to detect dlopen():ing shared libraries this way (which is done via the LD_PRELOAD stuff above as well).

Anyway, it will be Linux-only, but the shared library handling depends on dl_iterate_phdr() as it is today, so it's already Linux-specific.