{"id":7364,"date":"2021-07-01T12:51:00","date_gmt":"2021-07-01T19:51:00","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=7364"},"modified":"2021-07-01T13:16:10","modified_gmt":"2021-07-01T20:16:10","slug":"embedded-live-code-coverage","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/documentation\/embedded\/coverage\/","title":{"rendered":"Embedded\/Live Code Coverage"},"content":{"rendered":"<p>This page describes the Code Coverage support for embedded projects.<\/p>\n<h1>Contents<\/h1>\n<p><a href=\"#overview\">Overview<\/a><br \/>\n<a href=\"#implementation\">Implementation<\/a><br \/>\n<a href=\"#reports\">Code Coverage Reports<\/a><br \/>\n<a href=\"#live\">Live Coverage<\/a><br \/>\n<a href=\"#differential\">Differential Coverage<\/a><br \/>\n<a href=\"#cmake\">CMake\u00a0 Projects<\/a><br \/>\n<a href=\"#msbuild\">MSBuild Projects<\/a><br \/>\n<a href=\"#make\">GNU Make Projects<\/a><br \/>\n<a href=\"#nordic\">Nordic nRF5x Devices<\/a><br \/>\n<a href=\"#limitations\">Limitations<\/a><\/p>\n<h1><a id=\"overview\"><\/a>Overview<\/h1>\n<p>Embedded Code Coverage allows viewing the paths of the code that were executed during a debug session. E.g. the example below shows how the code managed to successfully initialize and start the USB device, but the <strong>VCP_read()<\/strong> function never returned 1 and the subsequent <strong>VCP_write()<\/strong> calls were never executed: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/intro-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7367\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/intro-1.png\" alt=\"\" width=\"592\" height=\"325\" \/><\/a>Code coverage is typically used in unit tests to see what code paths were covered by the test, however for embedded projects it has two additional uses:<\/p>\n<ul>\n<li>Observing what parts of the program are running right now without stopping it in the debugger (<a href=\"#live\">Live Coverage<\/a>)<\/li>\n<li>Quickly checking the path taken by a long function, or an interrupt handler without stepping through it (<a href=\"#differential\">Differential coverage<\/a>)<\/li>\n<\/ul>\n<p>Code Coverage is supported by VisualGDB Custom Edition or higher and can be enabled via the Code Coverage page of VisualGDB Project Properties:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/settings-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7369\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/settings-1.png\" alt=\"\" width=\"1059\" height=\"220\" \/><\/a>Note that code coverage reports <strong>(1)<\/strong> can be enabled separately from Live Coverage <strong>(2)<\/strong>.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>WARNING<\/strong><\/span>: After you enable code coverage via VisualGDB Project Properties, the project settings will be changed to instrument the code for coverage. Disabling code coverage here will keep the instrumentation enabled. See the project-specific sections of <a href=\"#cmake\">CMake<\/a>, <a href=\"#msbuild\">MSBuild<\/a> or <a href=\"#make\">GNU Make<\/a> for details on disabling it.<\/p>\n<p>Embedded Code Coverage is supported by CMake, MSBuild and GNU Make-based projects, as well as mbed projects. It is only supported when using the GCC compiler (not Keil or IAR) and it is not supported for ESP-IDF projects, Arduino projects or other projects where VisualGDB does not fully control the build process.<\/p>\n<h1><a id=\"implementation\"><\/a>Implementation<\/h1>\n<p>The code coverage for Embedded projects does not require any tracing hardware (<a href=\"https:\/\/visualgdb.com\/tutorials\/arm\/tracing\/traceback\/\">live tracing with Segger J-Trace<\/a> works separately from Live Coverage). It works by instrumenting the code to keep track of every taken branch, resulting in performance overhead and a considerable memory overhead. You can assess the overhead by comparing the instrumented and non-instrumented build of your project in <a href=\"https:\/\/visualgdb.com\/documentation\/embedded\/memoryexplorer\/\">Embedded Memory Explorer<\/a>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/memexp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7370\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/memexp.png\" alt=\"\" width=\"954\" height=\"371\" \/><\/a>You can reduce the overhead by limiting the instrumentation to a select set of files. See the project-specific sections of <a href=\"#cmake\">CMake<\/a>, <a href=\"#msbuild\">MSBuild<\/a> or <a href=\"#make\">GNU Make<\/a> for details.<\/p>\n<p>Live Coverage is implemented by continuously reading the branch counters while the program is running, so it requires the target to support background memory reads. Most ARM Cortex devices and RISC-V devices support this functionality.<\/p>\n<h1><a id=\"reports\"><\/a>Code Coverage Reports<\/h1>\n<p>You can enable the generation of code coverage reports via <strong>VisualGDB Project Properties -&gt; Code Coverage<\/strong>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/reports.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7372\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/reports.png\" alt=\"\" width=\"820\" height=\"75\" \/><\/a>If the report generation is enabled, each time a debug session is ended, VisualGDB will save the code coverage results in a <strong>.scovreport<\/strong> file in the specified directory. Normally, VisualGDB will only keep the 5 most recent coverage reports for each projects, deleting the older ones automatically. You can change this setting via <strong><span id=\"FullSettingPath\">Tools-&gt;Options-&gt;VisualGDB-&gt;General-&gt;Profiling-&gt;Max. coverage reports per project<\/span><\/strong>.<\/p>\n<p>You can also configure VisualGDB to keep the original <strong>.gcda<\/strong> files produced by <strong>GCOV via the <span id=\"FullSettingPath\">Tools-&gt;Options-&gt;VisualGDB-&gt;General-&gt;Profiling-&gt;Keep raw coverage reports<\/span><\/strong> setting.<\/p>\n<p>Coverage reports can be viewed via <strong>Test-&gt;VisualGDB Code Coverage Reports<\/strong>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/report2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7373\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/report2.png\" alt=\"\" width=\"1116\" height=\"370\" \/><\/a>Below is the summary of the controls in the Code Coverage window:<\/p>\n<ul>\n<li>Normally, the code coverage window will show the report for the last debugged project. If the solution contains multiple projects, you can select a specific one via the project selector <strong>(1)<\/strong>.<\/li>\n<li>You can switch between the recent coverage reports via the report selector <strong>(2)<\/strong>.<\/li>\n<li>You can delete old reports via the &#8216;delete&#8217; button in the drop-down list <strong>(3)<\/strong>. VisualGDB will also delete the old reports automatically according to the <strong><span id=\"FullSettingPath\">Tools-&gt;Options-&gt;VisualGDB-&gt;General-&gt;Profiling-&gt;Max. coverage reports per project<\/span><\/strong> setting.<\/li>\n<li>The refresh button <strong>(4)<\/strong> allows updating the list of reports for a project, in case one was produced outside Visual Studio.<\/li>\n<li>The coverage highlight button <strong>(5)<\/strong> enables highlighting of source code lines based on whether they were covered or not. This only works when using Clang IntelliSense.<\/li>\n<li>System Symbol Filter <strong>(6) <\/strong>allows hiding irrelevant symbols from system directories. You can right-click on any symbol in the Code Coverage window to mark its location as a system directory, and hide any other symbols from that directory as well. System directories are stored in the <strong>SystemDirectoryPrefixes<\/strong> element inside the <strong>.vgdbsettings<\/strong> file.<\/li>\n<li>You can sort the functions in the Code Coverage view by name, declaring file, number of invocations and coverage by clicking on the corresponding headers in the list view <strong>(7)<\/strong>.<\/li>\n<\/ul>\n<p>You can read the coverage reports programmatically by referencing the <strong>VisualGDBCore.dll<\/strong> assembly from the VisualGDB directory and using the <strong>CoverageReportReader<\/strong> class. See <a href=\"https:\/\/github.com\/sysprogs\/VisualGDBExtensibilityExamples\/blob\/master\/CoverageReportReader\/Program.cs\">this file<\/a> for a brief example of reading <strong>.scovreport<\/strong> files.<\/p>\n<h1><a id=\"live\"><\/a>Live Coverage<\/h1>\n<p>Live Coverage can display the branches of code taken in real time. It can be enabled via <strong>VisualGDB Project Properties -&gt; Code Coverage<\/strong> and works independently from the coverage reports:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/live.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7375\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/live.png\" alt=\"\" width=\"819\" height=\"79\" \/><\/a>Enabling Live Coverage also enables the Differential Coverage (Recent Lines).<\/p>\n<p>Once Live Coverage is enabled, you can view it via the <strong>Debug-&gt;Windows-&gt;Live Tracing\/Coverage<\/strong> command while the project is running:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/live2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7376\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/live2.png\" alt=\"\" width=\"817\" height=\"405\" \/><\/a>Below is the summary of the Live Coverage controls:<\/p>\n<ul>\n<li>The View switch allows selecting the Live Coverage view <strong>(1)<\/strong>, differential coverage (Recent Lines) and Statistics view.<\/li>\n<li>The Highlight Mode switch allows either showing whether a particular line is covered <strong>(2)<\/strong>, or showing how recent a line was executed <strong>(3).<\/strong><\/li>\n<li>If continuously sampling the branch counters interferes with other debugging functionality (e.g. makes Live Watch slower), you can suspend it using the suspend button <strong>(4)<\/strong>.<\/li>\n<li>You can sort the contents of the Live Coverage window by function name, number of runs, or the last time it ran by clicking on the corresponding headers <strong>(5)<\/strong>.<\/li>\n<\/ul>\n<p>Highlighting the recently executed lines allows observing the code running in real time without actually stopping it in the debugger. The functions executed within the specified interval will be shown with a more intense color:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/recent.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7377\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/recent.png\" alt=\"\" width=\"575\" height=\"328\" \/><\/a><\/p>\n<h1><a id=\"differential\"><\/a>Differential Coverage<\/h1>\n<p>Differential Coverage is a special type of Live Coverage. It works by comparing the coverage snapshots before and after a step (or between 2 breakpoints):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/differential.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7378\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/differential.png\" alt=\"\" width=\"1195\" height=\"565\" \/><\/a>It is enabled by switching the Live Coverage view to Recent Lines <strong>(1)<\/strong> and either stepping over a function call, or resuming and waiting for another breakpoint to hit. VisualGDB will then display all lines that changed their run counts since the last event. You can further group them by symbol or file <strong>(2)<\/strong>.<\/p>\n<p>Differential coverage is useful if stepping through a large failing function is impractical (e.g. due to high stepping latency) and gives a good overview of what happened since the last debug event.<\/p>\n<h1><a id=\"cmake\"><\/a>Instrumentation &#8211; CMake Projects<\/h1>\n<p>CMake projects offer the best GUI for controlling which files should be instrumented for live coverage.<\/p>\n<p>In order to instrument a project for coverage, you first need to enable the instrumentation of the corresponding BSP <strong>(1)<\/strong> by opening its properties on the Code Coverage page <strong>(2)<\/strong>.<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/cmake1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7380\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/cmake1.png\" alt=\"\" width=\"1627\" height=\"513\" \/><\/a>Once the instrumentation is enabled, VisualGDB will show the &#8220;coverage&#8221; overlay on top of the file icon for the instrumented files <strong>(3)<\/strong>. Non-instrumented files will retain the regular icon <strong>(4)<\/strong>. You can enable or disable coverage for individual files or frameworks via a context menu in Solution Explorer <strong>(5)<\/strong>.<\/p>\n<p>Changing any of the instrumentation settings will insert\/update the <a href=\"https:\/\/visualgdb.com\/reference\/cmake\/bsp_configure_code_coverage\"><strong>bsp_configure_code_coverage()<\/strong><\/a> statement in your CMakeLists.txt. E.g.:<\/p>\n<pre class=\"\">bsp_configure_code_coverage(ENABLED 1\r\n    EXCLUDE_TARGETS BSP_com.sysprogs.arm.stm32.hal\r\n    EXCLUDE_FILES ${BSP_ROOT}\/STM32F4xxxx\/STM32_USB_Device_Library\/Core\/Src\/usbd_ctlreq.c)<\/pre>\n<p><span style=\"text-decoration: underline;\"><strong>WARNING<\/strong><\/span><strong>: <\/strong>Enabling code coverage via VisualGDB Project Properties will automatically enable code instrumentation, however disabling it will keep the code instrumentation settings unchanged. In order to disable instrumentation, simply\u00a0 comment out the <strong>bsp_configure_code_coverage()<\/strong> statement in CMakeLists.txt.<\/p>\n<p>If you would like to quickly switch between instrumented and non-instrumented variants of the project, consider using the <strong>if()<\/strong> statement together with the <a href=\"https:\/\/visualgdb.com\/documentation\/embedded\/cmake\/#platforms\">configuration\/platform GUI<\/a> to create special configurations or platforms for instrumenting the code for code coverage.<\/p>\n<h1><a id=\"msbuild\"><\/a>Instrumentation &#8211; MSBuild Projects<\/h1>\n<p>MSBuild projects rely on the regular Visual Studio property system, so controlling the instrumentation is slightly less straight-forward than for CMake projects. First of all, the instrumentation <strong>always<\/strong> needs to be enabled for the project globally via <strong>Configuration properties -&gt; Embedded Project -&gt; Instrument Code for Code Coverage<\/strong>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/msbuild1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7381\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/msbuild1.png\" alt=\"\" width=\"786\" height=\"544\" \/><\/a>Note that this setting is stored separately for each configuration\/platform. Always double-check that the edited configuration platform matches the one you intend to edit, as Visual Studio sometimes displays settings for an unexpected configuration.<\/p>\n<p>Once you have enabled the instrumentation globally, it will be automatically enabled on the compiler level (<strong>C\/C++ -&gt; Instrumentation -&gt; Generate Code Coverage Reports<\/strong>):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/msbuild2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7382\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/msbuild2.png\" alt=\"\" width=\"786\" height=\"544\" \/><\/a>Normally, you do not need to change the setting under <strong>C\/C++-&gt;Instrumentation<\/strong>, as its default value depends on the global setting. However, you can explicitly set it <strong>No<\/strong> for individual files that you do not wish to be instrumented (select these files in Solution Explorer and open Properties in context menu to edit file-specific properties).<\/p>\n<p>The table below summarizes the relation between the 2 settings:<\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 25%;\">Embedded Project-&gt;Instrumentation<\/td>\n<td style=\"width: 25%;\">C\/C++ -&gt; Instrumentation<\/td>\n<td style=\"width: 25%;\">Intended use<\/td>\n<td style=\"width: 25%;\">Effects<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%;\">No<\/td>\n<td style=\"width: 25%;\">Default (No)<\/td>\n<td style=\"width: 25%;\">Not instrumenting code<\/td>\n<td style=\"width: 25%;\">Code coverage completely disabled<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%;\">No<\/td>\n<td style=\"width: 25%;\">Yes<\/td>\n<td style=\"width: 25%;\"><strong>Do not use<\/strong><\/td>\n<td style=\"width: 25%;\">Files will be instrumented by GCC, but not optimized for embedded projects by VisualGDB. The project will likely not link.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%;\">Yes<\/td>\n<td style=\"width: 25%;\">Default (Yes)<\/td>\n<td style=\"width: 25%;\">Instrumenting code<\/td>\n<td style=\"width: 25%;\">Code coverage working as intended<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%;\">Yes<\/td>\n<td style=\"width: 25%;\">&#8220;Default (Yes)&#8221; for project.<br \/>\n&#8220;No&#8221; for specific files.<\/td>\n<td style=\"width: 25%;\">Excluding specific files<\/td>\n<td style=\"width: 25%;\">The files overriding the option will not be instrumented. The rest of the project will be.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%;\">Yes<\/td>\n<td style=\"width: 25%;\">&#8220;No&#8221; for project.<br \/>\n&#8220;Yes&#8221; for specific files.<\/td>\n<td style=\"width: 25%;\">Only instrumenting specific files<\/td>\n<td style=\"width: 25%;\">The files overriding the option will be instrumented. The rest of the project will not be.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%;\">Yes<\/td>\n<td style=\"width: 25%;\">No<\/td>\n<td style=\"width: 25%;\">Do not use<\/td>\n<td style=\"width: 25%;\">Will have the same effect as disabling the other setting, although could be confusing as the other setting will be set to &#8220;Yes&#8221;.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Note that setting per-file settings works on the translation unit level (e.g. affects a <strong>.c\/.cpp<\/strong> file and all header files used by it). If you would like to control instrumentation for individual header files, you can use the &#8220;Skip instrumenting function in files&#8221; and &#8220;Only instrument functions in files&#8221; options. They correspond to the and <strong>-fprofile-exclude-files<\/strong> and <strong>-fprofile-filter-files<\/strong> GCC switches respectively.<\/p>\n<p><strong>WARNING<\/strong><strong>: <\/strong>Enabling code coverage via VisualGDB Project Properties will automatically enable code instrumentation, however disabling it will keep the code instrumentation settings unchanged. In order to disable instrumentation, simply set the <strong>Embedded Project -&gt; Instrument Code for Code Coverage <\/strong>option to <strong>No<\/strong>.<\/p>\n<p>If you would like to quickly switch between instrumented and non-instrumented variants of the project, consider creating separate MSBuild configurations for instrumented and non-instrumented builds.<\/p>\n<h1><a id=\"make\"><\/a>Instrumentation &#8211; GNU Make Projects<\/h1>\n<p>We do not recommend creating new projects using GNU Make, since it is extremely limited in comparison to Advanced CMake and MSBuild. If you absolutely have to use embedded code coverage with GNU Make, you need to explicitly enable it by adding &#8220;&#8211;coverage&#8221; to <strong>VisualGDB Project Properties -&gt; Makefile Settings -&gt; Common flags:<\/strong><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/make1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7390\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/make1.png\" alt=\"\" width=\"1188\" height=\"754\" \/><\/a>The configuration-specific Makefile (e.g. <strong>debug.mak<\/strong>) should also set the <strong>DETACH_CODE_COVERAGE<\/strong> variable to 1, e.g.:<\/p>\n<pre class=\"\">COMMONFLAGS := --coverage\r\nDETACH_CODE_COVERAGE :=1<\/pre>\n<p>If you would like to disable code coverage later, simply remove &#8220;&#8211;coverage&#8221; from COMMONFLAGS. You can keep the <strong>DETACH_CODE_COVERAGE <\/strong>line, as it will have no effect if no files are actually instrumented.<\/p>\n<h1><a id=\"nrf5x\"><\/a>Nordic NRF5x Devices<\/h1>\n<p>The Nordic nRF5x projects include a softdevice that is controlled by the main firmware via system calls. Instrumenting the entire nRF5x project for coverage breaks this mechanism and results in a hard-to-trace crash:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/nrf1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7384\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/nrf1.png\" alt=\"\" width=\"1229\" height=\"798\" \/><\/a>Although the call stack in this case is not very informative, checking the information about the covered lines just before the crash quickly allows pinpoint the root cause:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/nrf2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7385\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/nrf2.png\" alt=\"\" width=\"1357\" height=\"294\" \/><\/a>The problem is caused by instrumenting the syscall wrappers generated by the <strong>SVCALL()<\/strong> macro. In order to get coverage working, you would need to disable instrumentation for all files using the <strong>SVCALL()<\/strong> macro. Use the <strong>Find All References<\/strong> command (Shift+F12) to obtain a specific list of files:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/nrf3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7386\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/nrf3.png\" alt=\"\" width=\"771\" height=\"372\" \/><\/a>As of SDK <strong>v17.0<\/strong>, these files are located under the <strong>softdevice<\/strong> directory, so the easiest way to exclude them is to add &#8220;<strong>softdevice.*\\.h<\/strong>&#8221; to the &#8220;Skip instrumenting functions in files&#8221; setting:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/nrf4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7387\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/nrf4.png\" alt=\"\" width=\"786\" height=\"544\" \/><\/a>Now you can rebuild the project and confirm that it&#8217;s successfully running the idle loop by highlighting the recently executed lines:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/nrf5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7388\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/nrf5.png\" alt=\"\" width=\"1229\" height=\"798\" \/><\/a><\/p>\n<h1><a id=\"limitations\"><\/a>Limitations<\/h1>\n<p>Embedded Code Coverage relies on the gcc compiler to instrument the code and on the gcov tool to compute invocation counts for each line and function. This works well for the code that has finished executing, however it can produce inaccurate results for the functions that are running, or are on the call stack at the time of sampling. E.g. stopping the code on the &#8220;if()&#8221; line <strong>(A)<\/strong> can incorrectly mark the rest of the function as covered, while stepping over it into the &#8220;return&#8221; statement <strong>(B)<\/strong> will show that it never got a chance to run:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/limit-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7393\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2021\/07\/limit-2.png\" alt=\"\" width=\"1166\" height=\"350\" \/><\/a><\/p>\n<p>This happens because GCC tries to minimize the amount of branch counters it creates.\u00a0 E.g. in the left example, the function was called <em><strong>X<\/strong><\/em> times, the branch leading to line B was taken <em><strong>X-1<\/strong><\/em> times, and the branch leading to line <strong>C<\/strong> was never taken. Under normal circumstances, this would mean that the function has reached at least line <strong>D<\/strong>. However, in practice, the code is stopped in debugger at line A.<\/p>\n<p>This only affects the functions that are currently running, does not affect the function invocation counters, and gets resolved once the CPU leaves the function (and hence all branch counters will make sense again).<\/p>\n<p>In practice, unless a specific function is running most of the time (e.g. looping while waiting for an interrupt), most of the live coverage samples will be taken while the function is not executing, so the results will be accurate. Inaccurate results computed while the function was running will be rectified next time the live coverage is updated.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This page describes the Code Coverage support for embedded projects. Contents Overview Implementation Code Coverage Reports Live Coverage Differential Coverage<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[197],"tags":[],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7364"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=7364"}],"version-history":[{"count":11,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7364\/revisions"}],"predecessor-version":[{"id":7398,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7364\/revisions\/7398"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=7364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=7364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=7364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}