{"id":3526,"date":"2017-11-14T10:58:20","date_gmt":"2017-11-14T18:58:20","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=3526"},"modified":"2017-11-14T10:58:20","modified_gmt":"2017-11-14T18:58:20","slug":"speeding-up-raspberry-pi-debugging-by-running-gdb-locally","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/raspberry\/crossgdb\/","title":{"rendered":"Speeding Up Raspberry Pi Debugging by Running GDB Locally"},"content":{"rendered":"<p>This tutorial shows how to improve debugging performance for projects built directly on your Raspberry Pi by running the gdb debugger on the Windows machine. We will start with creating a regular remotely built project and will show how to modify it to run gdb locally, explaining why this results in a performance boost. Before you begin, install VisualGDB 5.3 or later.<\/p>\n<ol>\n<li>Start Visual Studio and open the VisualGDB Linux Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/01-prjname1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3527\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/01-prjname1.png\" alt=\"01-prjname\" width=\"853\" height=\"524\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/01-prjname1.png 853w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/01-prjname1-300x184.png 300w\" sizes=\"(max-width: 853px) 100vw, 853px\" \/><\/a><\/li>\n<li>Select &#8220;Create a new project -&gt; Application -&gt; MSBuild&#8221;. Note that the techniques shown in this tutorial will also work for other project types:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/02-msbuild1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3528\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/02-msbuild1.png\" alt=\"02-msbuild\" width=\"822\" height=\"662\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/02-msbuild1.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/02-msbuild1-300x242.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>Select &#8220;Build the project under Linux over network&#8221; and select your Raspberry Pi as the remote computer:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/03-rasp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3529\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/03-rasp.png\" alt=\"03-rasp\" width=\"822\" height=\"662\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/03-rasp.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/03-rasp-300x242.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>Proceed with the default source location settings (store locally, upload during build):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/04-store.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3530\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/04-store.png\" alt=\"04-store\" width=\"822\" height=\"662\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/04-store.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/04-store-300x242.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; to generate a basic project:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/05-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3531\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/05-build.png\" alt=\"05-build\" width=\"1123\" height=\"739\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/05-build.png 1123w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/05-build-300x197.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/05-build-1024x674.png 1024w\" sizes=\"(max-width: 1123px) 100vw, 1123px\" \/><\/a><\/li>\n<li>Replace the contents of the main source file with the following code:\n<pre class=\"\">#include &lt;iostream&gt;\r\n#include &lt;list&gt;\r\n#include &lt;string&gt;\r\n\r\nusing namespace std;\r\n\r\nint main(int argc, char *argv[])\r\n{\r\n\u00a0\u00a0\u00a0 std::list&lt;std::string&gt; list;\r\n\u00a0\u00a0\u00a0 for (int i = 0; i &lt; 10; i++)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.push_back(\"test\");\r\n\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0char sz[] = \"Hello, World!\";\u00a0\u00a0 \u00a0\/\/Hover mouse over \"sz\" while debugging to see its contents\r\n\u00a0\u00a0 \u00a0cout &lt;&lt; sz &lt;&lt; endl;\u00a0\u00a0 \u00a0\/\/&lt;================= Put a breakpoint here\r\n\u00a0\u00a0 \u00a0return 0;\r\n}<\/pre>\n<\/li>\n<li>Evaluating a list of STL strings involves non-trivial computations on the gdb side, so doing them on the Raspberry Pi would cause noticeable delays. Step into the main() function and hover the mouse over <strong>list<\/strong> to see the values:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/06-values.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3532\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/06-values.png\" alt=\"06-values\" width=\"1123\" height=\"739\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/06-values.png 1123w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/06-values-300x197.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/06-values-1024x674.png 1024w\" sizes=\"(max-width: 1123px) 100vw, 1123px\" \/><\/a><\/li>\n<li>Now we will change the project setup to run gdb on Windows so all the expression parsing and symbol handling is done on your development machine. Open VisualGDB Project Properties and set the &#8220;Allow choosing build\/clean\/debug command hosts independently&#8221; checkbox (requires Custom edition or higher):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/07-indep.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3533\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/07-indep.png\" alt=\"07-indep\" width=\"786\" height=\"594\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/07-indep.png 786w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/07-indep-300x227.png 300w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/a><\/li>\n<li>Go to the Debug Settings page, select &#8220;ust a custom GDB executable&#8221; and click &#8220;Customize&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/08-gdb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3534\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/08-gdb.png\" alt=\"08-gdb\" width=\"1123\" height=\"739\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/08-gdb.png 1123w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/08-gdb-300x197.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/08-gdb-1024x674.png 1024w\" sizes=\"(max-width: 1123px) 100vw, 1123px\" \/><\/a><\/li>\n<li>Ensure you have a <a href=\"http:\/\/gnutoolchains.com\/raspberry\/\">Raspberry Pi toolchain<\/a> compatible with the target image installed. Then select &#8220;Computer containing GDB: (local computer)&#8221; and locate the gdb executable:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/09-gdbpath.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3535\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/09-gdbpath.png\" alt=\"09-gdbpath\" width=\"559\" height=\"160\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/09-gdbpath.png 559w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/09-gdbpath-300x86.png 300w\" sizes=\"(max-width: 559px) 100vw, 559px\" \/><\/a><\/li>\n<li>As the executable is built on the Raspberry Pi, we would need to download it to the Windows machine and configure gdb to use it. Enter &#8220;$(ProjectDir)\/$(TargetFileName)&#8221; in the &#8220;Debugged executable&#8221; field:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/10-targetfn.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3536\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/10-targetfn.png\" alt=\"10-targetfn\" width=\"786\" height=\"594\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/10-targetfn.png 786w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/10-targetfn-300x227.png 300w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/a><\/li>\n<li>Now we will configure VisualGDB to download the executable before debugging. Go to the Custom Debug Steps page, click &#8220;Before launching GDB -&gt; Edit&#8221; and add a custom action to download $(TargetPath) to $(ProjectDir)\/$(TargetFileName):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/11-import.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3537\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/11-import.png\" alt=\"11-import\" width=\"1123\" height=\"739\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/11-import.png 1123w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/11-import-300x197.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/11-import-1024x674.png 1024w\" sizes=\"(max-width: 1123px) 100vw, 1123px\" \/><\/a><\/li>\n<li>Start debugging again. VisualGDB will automatically launch gdbserver on the remote machine and connect gdb to it:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/12-run1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3538\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/12-run1.png\" alt=\"12-run\" width=\"1123\" height=\"739\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/12-run1.png 1123w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/12-run1-300x197.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/12-run1-1024x674.png 1024w\" sizes=\"(max-width: 1123px) 100vw, 1123px\" \/><\/a><\/li>\n<li>Observe how evaluating the complex expressions is now faster because most of the computations are done on the Windows computer:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/13-view.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3539\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/13-view.png\" alt=\"13-view\" width=\"1123\" height=\"739\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/13-view.png 1123w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/13-view-300x197.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/13-view-1024x674.png 1024w\" sizes=\"(max-width: 1123px) 100vw, 1123px\" \/><\/a><\/li>\n<li>If you are running gdb locally, you need to keep up-to-date local copies of your Raspberry Pi libraries so that gdb can load symbols from them. Alternatively you can configure it to automatically fetch the libraries from the remote machine by adding &#8220;set sysroot remote:\/&#8221; to the startup command list:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/14-sysroot.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3540\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/14-sysroot.png\" alt=\"14-sysroot\" width=\"786\" height=\"594\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/14-sysroot.png 786w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/14-sysroot-300x227.png 300w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/a><\/li>\n<li>You can get a quick idea about the simplification done by gdb on the Windows side by running the &#8220;set debug remote 1&#8221; command in the GDB Session window and then observing the packets sent by GDB to gdbserver. See how gdb translates complex expressions to simple commands like &#8220;read 4 bytes at address XXX&#8221; that are then quickly handled by gdbserver running on your Raspberry Pi:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/15-eval.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3542\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/15-eval.png\" alt=\"15-eval\" width=\"1123\" height=\"739\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/15-eval.png 1123w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/15-eval-300x197.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/11\/15-eval-1024x674.png 1024w\" sizes=\"(max-width: 1123px) 100vw, 1123px\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to improve debugging performance for projects built directly on your Raspberry Pi by running the gdb<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[43],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/3526"}],"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=3526"}],"version-history":[{"count":3,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/3526\/revisions"}],"predecessor-version":[{"id":3561,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/3526\/revisions\/3561"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=3526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=3526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=3526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}