{"id":118,"date":"2018-02-05T15:34:22","date_gmt":"2018-02-05T23:34:22","guid":{"rendered":"https:\/\/sysprogs.com\/tutorials\/?p=118"},"modified":"2018-02-06T18:53:00","modified_gmt":"2018-02-07T02:53:00","slug":"debugging-raspberry-pi-kernel-with-visualkernel","status":"publish","type":"post","link":"https:\/\/sysprogs.com\/VisualKernel\/tutorials\/raspberry\/debugkernel\/","title":{"rendered":"Debugging Raspberry PI Kernel with VisualKernel"},"content":{"rendered":"<p>This tutorial shows how to debug a the Linux Kernel on Raspberry PI over JTAG using Visual Studio. Before you begin, follow the\u00a0<a href=\"http:\/\/sysprogs.com\/VisualKernel\/tutorials\/raspberry\/basicmodule\/\">basic Raspberry PI Kernel Module tutorial<\/a>\u00a0to ensure that your debugging setup works.<\/p>\n<ol>\n<li>Start Visual Studio. Select File-&gt;New-&gt;Project-&gt;VisualKernel-&gt;Custom Linux Kernel Wizard:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-220\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/01-prjname.png\" alt=\"\" width=\"941\" height=\"653\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/01-prjname.png 941w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/01-prjname-300x208.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/01-prjname-768x533.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/01-prjname-392x272.png 392w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/01-prjname-130x90.png 130w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/li>\n<li>Specify the same target settings you used in the\u00a0<a href=\"http:\/\/sysprogs.com\/VisualKernel\/tutorials\/raspberry\/basicmodule\/\">Kernel Module tutorial<\/a>:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-221\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/02-anothermach.png\" alt=\"\" width=\"822\" height=\"642\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/02-anothermach.png 822w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/02-anothermach-300x234.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/02-anothermach-768x600.png 768w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/li>\n<li>Select &#8220;Automatically download sources&#8221; and click &#8220;Next&#8221;:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-223\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/03-autokernel.png\" alt=\"\" width=\"822\" height=\"642\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/03-autokernel.png 822w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/03-autokernel-300x234.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/03-autokernel-768x600.png 768w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/li>\n<li>VisualKernel will automatically download the Raspberry Pi cross-toolchain and the kernel sources\u00a0to the machine selected for building:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-225\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/04-tools.png\" alt=\"\" width=\"736\" height=\"553\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/04-tools.png 736w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/04-tools-300x225.png 300w\" sizes=\"(max-width: 736px) 100vw, 736px\" \/><\/li>\n<li>On the next page of the wizard select\u00a0the method to access the source code on the build machine. For most scenarios we recommend using direct SSH access. If you want to keep a local copy of the sources,\u00a0select &#8220;Copy sources locally and upload modified files&#8221; instead:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-224\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/05-source.png\" alt=\"\" width=\"822\" height=\"642\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/05-source.png 822w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/05-source-300x234.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/05-source-768x600.png 768w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/li>\n<li>Enter the same debug settings that you used when\u00a0testing the kernel module. Use the &#8220;test&#8221; button to validate them:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-226\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/06-debug.png\" alt=\"\" width=\"859\" height=\"642\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/06-debug.png 859w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/06-debug-300x224.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/06-debug-768x574.png 768w\" sizes=\"(max-width: 859px) 100vw, 859px\" \/><\/li>\n<li>Press Finish to generate the project. VisualKernel will create an advanced kernel project and will begin\u00a0querying its structure from KBuild:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-227\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/07-loading.png\" alt=\"\" width=\"997\" height=\"652\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/07-loading.png 997w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/07-loading-300x196.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/07-loading-768x502.png 768w\" sizes=\"(max-width: 997px) 100vw, 997px\" \/><\/li>\n<li>Once the structure is queried, press Ctrl-Shift-B to build the kernel.\u00a0The build may stop on an internal compiler error in\u00a0<strong>dwarf2out_frame_debug_adjust_cfa()<\/strong>:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-228\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/08-errors.png\" alt=\"\" width=\"1169\" height=\"710\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/08-errors.png 1169w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/08-errors-300x182.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/08-errors-768x466.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/08-errors-1024x622.png 1024w\" sizes=\"(max-width: 1169px) 100vw, 1169px\" \/><\/li>\n<li>To work around this, open both failing files and insert the following code at the beginning of them:\n<pre class=\"\">#pragma GCC optimize(\"-g0\")<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-229\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/09-optimize-g0.png\" alt=\"\" width=\"1169\" height=\"710\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/09-optimize-g0.png 1169w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/09-optimize-g0-300x182.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/09-optimize-g0-768x466.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/09-optimize-g0-1024x622.png 1024w\" sizes=\"(max-width: 1169px) 100vw, 1169px\" \/><\/li>\n<li>Then build the\u00a0project again. The build will now succeed and VisualKernel will\u00a0remind you to\u00a0install the kernel on\u00a0Raspberry Pi:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-230\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/10-built-1.png\" alt=\"\" width=\"1169\" height=\"710\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/10-built-1.png 1169w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/10-built-1-300x182.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/10-built-1-768x466.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/10-built-1-1024x622.png 1024w\" sizes=\"(max-width: 1169px) 100vw, 1169px\" \/><\/li>\n<li>Open VisualKernel Project Properties on the Kernel build settings page and click &#8220;Install embedded kernel&#8221;:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-231\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/11-install-1.png\" alt=\"\" width=\"1099\" height=\"594\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/11-install-1.png 1099w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/11-install-1-300x162.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/11-install-1-768x415.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/11-install-1-1024x553.png 1024w\" sizes=\"(max-width: 1099px) 100vw, 1099px\" \/><\/li>\n<li>VisualKernel will automatically export the built kernel, transfer it to Raspberry Pi and install it there, including the related modules:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-232\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/12-installing.png\" alt=\"\" width=\"1169\" height=\"710\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/12-installing.png 1169w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/12-installing-300x182.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/12-installing-768x466.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/12-installing-1024x622.png 1024w\" sizes=\"(max-width: 1169px) 100vw, 1169px\" \/><\/li>\n<li>Once the installation is complete, restart\u00a0Raspberry Pi and ensure the new kernel starts:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-233\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/13-installed.png\" alt=\"\" width=\"1169\" height=\"710\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/13-installed.png 1169w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/13-installed-300x182.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/13-installed-768x466.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/13-installed-1024x622.png 1024w\" sizes=\"(max-width: 1169px) 100vw, 1169px\" \/><\/li>\n<li>Press F5 to start debugging the kernel. VisualKernel will begin analyzing the kernel image and once it is done, the debugging session will automatically start:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-234\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/14-load.png\" alt=\"\" width=\"1169\" height=\"710\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/14-load.png 1169w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/14-load-300x182.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/14-load-768x466.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/14-load-1024x622.png 1024w\" sizes=\"(max-width: 1169px) 100vw, 1169px\" \/><\/li>\n<li>Set a breakpoint in the <strong>sys_open()<\/strong> function via the Breakpoints window:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-235\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/15-bp.png\" alt=\"\" width=\"1169\" height=\"710\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/15-bp.png 1169w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/15-bp-300x182.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/15-bp-768x466.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/15-bp-1024x622.png 1024w\" sizes=\"(max-width: 1169px) 100vw, 1169px\" \/><\/li>\n<li>The breakpoint will soon hit:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-236\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/16-break.png\" alt=\"\" width=\"1169\" height=\"710\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/16-break.png 1169w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/16-break-300x182.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/16-break-768x466.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/16-break-1024x622.png 1024w\" sizes=\"(max-width: 1169px) 100vw, 1169px\" \/>If it doesn&#8217;t get triggered, try\u00a0reading any file on your Raspberry Pi using the &#8216;cat&#8217; command.<\/li>\n<li>Press F11 until you step into do_sys_open(). Hover the mouse around various variables to see their values:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-237\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/17-args.png\" alt=\"\" width=\"1169\" height=\"710\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/17-args.png 1169w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/17-args-300x182.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/17-args-768x466.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/17-args-1024x622.png 1024w\" sizes=\"(max-width: 1169px) 100vw, 1169px\" \/><\/li>\n<li>If stepping through the kernel is too slow due to multiple printk() messages, you can disable printk() hooking via VisualKernel Project Properties:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-238\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/noprintk.png\" alt=\"\" width=\"1099\" height=\"594\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/noprintk.png 1099w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/noprintk-300x162.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/noprintk-768x415.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/noprintk-1024x553.png 1024w\" sizes=\"(max-width: 1099px) 100vw, 1099px\" \/><\/li>\n<li>You can edit the kernel configuration by right-clicking on the kernel project and selecting &#8220;Configure Kernel Project&#8221;:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-239\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/config.png\" alt=\"\" width=\"1169\" height=\"710\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/config.png 1169w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/config-300x182.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/config-768x466.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/config-1024x622.png 1024w\" sizes=\"(max-width: 1169px) 100vw, 1169px\" \/><\/li>\n<li>This will launch the xconfig\u00a0tool, letting you configure various kernel parameters directly from your Windows machine:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-240\" src=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/xconfig.png\" alt=\"\" width=\"1169\" height=\"710\" srcset=\"https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/xconfig.png 1169w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/xconfig-300x182.png 300w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/xconfig-768x466.png 768w, https:\/\/sysprogs.com\/tutorials\/wp-content\/uploads\/2018\/02\/xconfig-1024x622.png 1024w\" sizes=\"(max-width: 1169px) 100vw, 1169px\" \/><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to debug a the Linux Kernel on Raspberry PI over JTAG using Visual Studio. Before you<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[34,37],"_links":{"self":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/118"}],"collection":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/comments?post=118"}],"version-history":[{"count":3,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/118\/revisions"}],"predecessor-version":[{"id":241,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/posts\/118\/revisions\/241"}],"wp:attachment":[{"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/media?parent=118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/categories?post=118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sysprogs.com\/tutorials\/wp-json\/wp\/v2\/tags?post=118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}