{"id":20803,"date":"2018-04-26T07:08:55","date_gmt":"2018-04-26T06:08:55","guid":{"rendered":"https:\/\/sysprogs.com\/w\/?p=20803"},"modified":"2020-04-21T19:29:06","modified_gmt":"2020-04-21T18:29:06","slug":"announcing-visualgdb-5-4-preview-3-with-j-trace-support","status":"publish","type":"post","link":"https:\/\/sysprogs.com\/w\/announcing-visualgdb-5-4-preview-3-with-j-trace-support\/","title":{"rendered":"Announcing VisualGDB 5.4 Preview 3 with Segger J-Trace support"},"content":{"rendered":"<p>Today we are excited to announce the release of VisualGDB 5.4 Preview 3 that adds support for tracing ARM devices with Segger J-Trace. Tracing is a powerful debugging technique that lets you track each and every instruction executed by the target CPU without ever stopping it, or instrumenting any code.<\/p>\n<p>In this post I will show you how to use tracing to step back in time, reconstructing the code path leading to an otherwise untraceable crash and how to see the code coverage for your embedded projects in real time and without any instrumentation overhead.<\/p>\n<p><!--more--><\/p>\n<p>Tracing requires using special a hardware probe &#8211; <a href=\"https:\/\/www.segger.com\/products\/debug-probes\/j-trace\/\">Segger J-Trace Pro<\/a>. It combines a regular JTAG\/SWD debugger with a special interface that can read the tracing data directly from your microcontroller. Once the trace mode is enabled, your device will output a special compressed log via the TRACEDATA and TRACECLK pins, allowing the debug software to reconstruct each instruction that was executed by the MCU. Unlike software instrumentation, this does not incur a major slowdown, although it requires the J-Trace probe in order to capture and interpret the tracing data.<\/p>\n<p>In order to try ARM tracing with VisualGDB, install Segger Software Pack v6.32 or later, VisualGDB 5.4 Preview 3 or later and update your Segger Debug plugin via VisualGDB Package Manager. Once you do that, go to the Embedded Debug Tweaking page of VisualGDB Project Properties and enable real-time tracing there:<a href=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/traceenable.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-20804\" src=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/traceenable.png\" alt=\"traceenable\" width=\"1175\" height=\"753\" srcset=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/traceenable.png 1175w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/traceenable-300x192.png 300w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/traceenable-768x492.png 768w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/traceenable-1024x656.png 1024w\" sizes=\"(max-width: 1175px) 100vw, 1175px\" \/><\/a>This will activate the Live Tracing mode next time you are debugging. It will show detailed statistics on the executed functions and will also compute code coverage for them:<a href=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/livetrace-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-20806\" src=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/livetrace-1.png\" alt=\"livetrace\" width=\"705\" height=\"288\" srcset=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/livetrace-1.png 705w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/livetrace-1-300x123.png 300w\" sizes=\"(max-width: 705px) 100vw, 705px\" \/><\/a>If you are using Visual Studio 2013 or later and have the Clang IntelliSense enabled, you can enable the dynamic highlighting of the currently executed code. Unlike periodic probing of the $pc register, this will highlight every line that was physically executed in the last few seconds:<a href=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/highlight.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-20807\" src=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/highlight.png\" alt=\"highlight\" width=\"1187\" height=\"724\" srcset=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/highlight.png 1187w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/highlight-300x183.png 300w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/highlight-768x468.png 768w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/highlight-1024x625.png 1024w\" sizes=\"(max-width: 1187px) 100vw, 1187px\" \/><\/a>Alternatively you can just highlight the lines based on whether they were executed in this debugging session, letting you easily spot dead code:<a href=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/deadcode.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-20808\" src=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/deadcode.png\" alt=\"deadcode\" width=\"1187\" height=\"724\" srcset=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/deadcode.png 1187w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/deadcode-300x183.png 300w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/deadcode-768x468.png 768w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/deadcode-1024x625.png 1024w\" sizes=\"(max-width: 1187px) 100vw, 1187px\" \/><\/a><\/p>\n<h2>Diagnosing Tough Crashes<\/h2>\n<p>Another great use for tracing is diagnosing tough crashes where the stack\/register corruption makes it hard to pinpoint the culprit. Consider this code:<\/p>\n<pre class=\"\">void badfunc()\r\n{\r\n\u00a0\u00a0\u00a0 register void **sp asm(\"sp\");\r\n\u00a0\u00a0\u00a0 register void *lr asm(\"lr\");\r\n\u00a0\u00a0\u00a0 extern void *_estack;\r\n\u00a0\u00a0\u00a0 for (int i = 0; i &lt; 32 &amp;&amp; sp &lt; &amp;_estack; i++)\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 asm(\"nop\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 *sp++ = (void *)0;\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 lr = (void *)0xFFFFFFFF;\r\n}<\/pre>\n<p>Once the badfunc() erases the stack contents, replaces the $lr register and returns, the program will stop at an exception handler with a pretty useless call stack:<a href=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/stack-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-20810\" src=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/stack-1.png\" alt=\"stack\" width=\"397\" height=\"296\" srcset=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/stack-1.png 397w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/stack-1-300x224.png 300w\" sizes=\"(max-width: 397px) 100vw, 397px\" \/><\/a><\/p>\n<p>The conventional way of tracking this type of problem would involve commenting out parts of your code in hope to pinpoint the part triggering the crash, but tracing simply lets you step back in time, recovering the events before the crash line-by-line:<a href=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/scrollback.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-20811\" src=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/scrollback.png\" alt=\"scrollback\" width=\"1187\" height=\"724\" srcset=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/scrollback.png 1187w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/scrollback-300x183.png 300w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/scrollback-768x468.png 768w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2018\/04\/scrollback-1024x625.png 1024w\" sizes=\"(max-width: 1187px) 100vw, 1187px\" \/><\/a><\/p>\n<p>You can also choose to track individual instructions or functions if the line view is not informative enough.<\/p>\n<h2>Stay Tuned<\/h2>\n<p>We are working with Segger on bringing the J-Trace integration even further, supporting profiling, bottleneck analysis and a zero overhead version of the Real-Time Watch. Follow us on <a href=\"https:\/\/twitter.com\/sysprogs\">Twitter<\/a> to stay tuned. And as always, we would love to hear your feedback, so if you have any suggestions or bugs to report, do not hesitate to contact us via the <a href=\"https:\/\/sysprogs.com\/support\/\">support form<\/a> or <a href=\"https:\/\/sysprogs.com\/w\/forums\/forum\/visualgdb\/\">forum<\/a>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we are excited to announce the release of VisualGDB 5.4 Preview 3 that adds support for tracing ARM devices with Segger J-Trace. Tracing is a powerful debugging technique that lets you track each and every instruction executed by the target CPU without ever stopping it, or instrumenting any code. In this post I will &hellip; <a href=\"https:\/\/sysprogs.com\/w\/announcing-visualgdb-5-4-preview-3-with-j-trace-support\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Announcing VisualGDB 5.4 Preview 3 with Segger J-Trace support<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/posts\/20803"}],"collection":[{"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/comments?post=20803"}],"version-history":[{"count":3,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/posts\/20803\/revisions"}],"predecessor-version":[{"id":20814,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/posts\/20803\/revisions\/20814"}],"wp:attachment":[{"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/media?parent=20803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/categories?post=20803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/tags?post=20803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}