# GCOV for SpiderMonkey

**URL:** <https://discourse.mozilla.org/t/gcov-for-spidermonkey/110257>\
**Category:** SpiderMonkey\
**Created:** [January 22, 2023, 9:04pm UTC](https://discourse.mozilla.org/t/gcov-for-spidermonkey/110257 "2023-01-22T21:04:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![TL119](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@TL119](https://discourse.mozilla.org/u/TL119)\
**Post date:** [January 22, 2023, 9:04pm UTC](https://discourse.mozilla.org/t/gcov-for-spidermonkey/110257/1 "2023-01-22T21:04:17Z")

</div>

I wonder whether there is a way that I can do a coverage test for SpiderMonkey (e.g., using gcov). I see lines in “js/src/shell/js.cpp” to support gcov, but I am not certain how I can enable this opinion when compiling the js executable (i.e., using the make command) and using gcov to do a code coverage. If someone can lead me in the right direction, that would be much appreciated. (FYI. I’m on Ubuntu 20).

---

<div class="post-metadata">

**Author:** ![nbp](https://avatars.discourse-cdn.com/v4/letter/n/eada6e/32.png) [@nbp](https://discourse.mozilla.org/u/nbp)\
**Post date:** [January 23, 2023, 10:32am UTC](https://discourse.mozilla.org/t/gcov-for-spidermonkey/110257/2 "2023-01-23T10:32:13Z")

</div>

I see that Firefox configuration system exposes [`--enable-coverage`](https://searchfox.org/mozilla-central/source/build/moz.configure/toolchain.configure#2461) option. Would this help?

---

<div class="post-metadata">

**Author:** ![mgaudet](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mgaudet/32/76131_2.png) [@mgaudet](https://discourse.mozilla.org/u/mgaudet)\
**Post date:** [January 23, 2023, 4:41pm UTC](https://discourse.mozilla.org/t/gcov-for-spidermonkey/110257/3 "2023-01-23T16:41:04Z")

</div>

Another related question: Are you hoping to get coverage information for JS (which we do support) or the C++ inside SM?

---

<div class="post-metadata">

**Author:** ![TL119](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@TL119](https://discourse.mozilla.org/u/TL119)\
**Post date:** [January 23, 2023, 4:51pm UTC](https://discourse.mozilla.org/t/gcov-for-spidermonkey/110257/4 "2023-01-23T16:51:56Z")

</div>

Thanks for the suggestion. I tried the configuration with the `--enable-coverage` option (`$configure --enable-coverage`) and compiled using `make`. The configuration was successful, but compiling failed with multiple errors mainly with `error: undefined symbol` errors. I believe it has to do with the LLVM symbols. I am not so sure why that is and if you can give some suggestions, that would be very appreciated.

Example errors:

```auto
ld.lld: error: undefined symbol: llvm_gcda_start_file
ld.lld: error: undefined symbol: llvm_gcda_emit_function
ld.lld: error: undefined symbol: llvm_gcda_summary_info

```

---

<div class="post-metadata">

**Author:** ![TL119](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@TL119](https://discourse.mozilla.org/u/TL119)\
**Post date:** [January 23, 2023, 4:53pm UTC](https://discourse.mozilla.org/t/gcov-for-spidermonkey/110257/5 "2023-01-23T16:53:32Z")

</div>

I am specifically interested in the C++ code coverage, i.e., SpiderMonkey’s source code (parser, interpreter, jit compiler, etc.). Thank you for asking.

---

<div class="post-metadata">

**Author:** ![mgaudet](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mgaudet/32/76131_2.png) [@mgaudet](https://discourse.mozilla.org/u/mgaudet)\
**Post date:** [January 23, 2023, 5:02pm UTC](https://discourse.mozilla.org/t/gcov-for-spidermonkey/110257/6 "2023-01-23T17:02:57Z")

</div>

Could you open a bug [here](https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&component=JavaScript+Engine) – something is definitely wonky, and we should look into it, as if we have the `--enable-coverage` option, it should at least work.

---

<div class="post-metadata">

**Author:** ![jandem](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/jandem/32/45226_2.png) [@jandem](https://discourse.mozilla.org/u/jandem)\
**Post date:** [January 24, 2023, 8:35am UTC](https://discourse.mozilla.org/t/gcov-for-spidermonkey/110257/7 "2023-01-24T08:35:25Z")

</div>

In case it helps, you can also browse coverage data for js/src generated by Firefox CI builds here:

[https://coverage.moz.tools/#revision=latest&path=js%2Fsrc&view=directory](https://coverage.moz.tools/#revision=latest&path=js%2Fsrc&view=directory)
