{"id":8377,"date":"2023-09-20T09:13:14","date_gmt":"2023-09-20T16:13:14","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=8377"},"modified":"2023-09-20T09:13:14","modified_gmt":"2023-09-20T16:13:14","slug":"debugging-linux-machines-not-directly-accessible-from-windows","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/linux\/3machine\/indirect\/","title":{"rendered":"Debugging Linux Machines Not Directly Accessible from Windows"},"content":{"rendered":"<p>This tutorial shows how to debug applications build with Linux cross-toolchains where the target machine is not directly accessible from the Windows machine running VisualGDB.<\/p>\n<p>We will demonstrate it based on a simple setup involving 2 Linux VMs: we will build the application on <strong>ubuntu2204vm <\/strong>and will then deploy it to <strong>deployvm<\/strong> that is not directly accessible from the Windows machine.<\/p>\n<ol>\n<li>Start Visual Studio and locate the VisualGDB Linux Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/01-linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8378\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/01-linux.png\" alt=\"\" width=\"890\" height=\"625\" \/><\/a><\/li>\n<li>Enter the name and location for your project, then click &#8220;Create&#8221;: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/02-name.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8379\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/02-name.png\" alt=\"\" width=\"890\" height=\"625\" \/><\/a><\/li>\n<li>On the first page of the VisualGDB Linux Wizard, select &#8220;application&#8221; and choose a build system. For most new projects we recommend using Advanced CMake:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/03-app.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8380\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/03-app.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>The next page of the wizard allows selecting the build and deployment machines. Click &#8220;build the project under Linux&#8221; and select the build machine. If you are using a cross-toolchain, select it in the &#8220;remote toolchain&#8221; field (see <a href=\"https:\/\/visualgdb.com\/tutorials\/linux\/3machine\/\">this tutorial<\/a> for more details). In this tutorial, the deployment machine is not accessible from the Windows side, so it won&#8217;t be listed in the &#8220;deployment computer field&#8221;: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/04-machines.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8381\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/04-machines.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>If we try adding it directly, we would get an error message (e.g. a &#8220;connection attempt failed&#8230; &#8221; or &#8220;no such host is known&#8221;):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/05-error.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8382\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/05-error.png\" alt=\"\" width=\"967\" height=\"737\" \/><\/a><\/li>\n<li>To work around it select the build machine (<strong>ubuntu2204vm<\/strong>) as the deployment machine as well:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/06-same.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8383\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/06-same.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>If you are using a cross-toolchain that targets another CPU type (e.g. x64-&gt;ARM), the binaries produced by the toolchain won&#8217;t run on the build machine and VisualGDB will warn about it. Click &#8220;Ignore&#8221; to proceed: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/ignore.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8396\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/ignore.png\" alt=\"\" width=\"786\" height=\"493\" \/><\/a><\/li>\n<li>Finally, choose how you would like VisualGDB to manage the source files. In this tutorial we will store them on the Windows side and upload the changed files during build: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/07-disp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8384\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/07-disp.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; to create the project and build it via <strong>Build-&gt;Build Solution<\/strong>. Once the build succeeds, open an SSH console on the build machine (you can also use <a href=\"https:\/\/sysprogs.com\/SmarTTY\/\">SmarTTY<\/a> or any other SSH client to do it):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/08-ssh.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8385\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/08-ssh.png\" alt=\"\" width=\"967\" height=\"737\" \/><\/a><\/li>\n<li>Try connecting from the build machine to the deployment machine by running &#8220;<strong>ssh &lt;username&gt;@&lt;deployment machine name&gt; hostname<\/strong>&#8221; on the <strong>build machine<\/strong>. It should connect to the <strong>deployment<\/strong> machine, run &#8220;hostname&#8221; there and display its output. VisualGDB will use this mechanism to launch gdbserver on the target:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/09-hostname.png\"> <img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8386\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/09-hostname.png\" alt=\"\" width=\"967\" height=\"737\" \/><\/a><\/li>\n<li>Note that if running <strong>ssh<\/strong> on the build machine asks for password, automating it with VisualGDB won&#8217;t work. If this is the case, you would need to configure public key-based authentication between the <strong>build<\/strong> and <strong>deployment<\/strong> machines. If the <strong>build<\/strong> machine does not have a private SSH key generated (normally stored in <strong>~\/.ssh\/id_rsa<\/strong>), run &#8220;<strong>ssh-keygen<\/strong>&#8221; on it:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/10-keygen.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8387\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/10-keygen.png\" alt=\"\" width=\"967\" height=\"737\" \/><\/a><\/li>\n<li>Install the public key matching the generated private key on the <strong>deployment<\/strong> machine by running &#8220;<strong>ssh-copy-id &lt;username&gt;@&lt;deployment machine&gt;<\/strong>&#8221; from the build machine: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/11-deploy.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8388\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/11-deploy.png\" alt=\"\" width=\"967\" height=\"737\" \/><\/a><\/li>\n<li>Now running &#8220;<strong>ssh &lt;user name&gt;@&lt;deployment machine&gt;<\/strong>&#8221; from the build machine should work without asking for a password:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/12-hostname.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8389\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/12-hostname.png\" alt=\"\" width=\"967\" height=\"737\" \/><\/a><\/li>\n<li>Once the SSH connections between the build and deployment machines have been configured, we can setup VisualGDB to use them to deploy and debug the built applications. First, check the &#8220;<strong>allow choosing build\/clean\/debug command hosts independently<\/strong>&#8221; checkbox on the <strong>Project Settings<\/strong> page of <strong>VisualGDB Project Properties<\/strong>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/13-hosts-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8397\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/13-hosts-1.png\" alt=\"\" width=\"1188\" height=\"754\" \/><\/a>Note that this option is available on VisualGDB Custom Edition or higher.<\/li>\n<li>Then go to the <strong>Custom Debug Steps<\/strong> page and add the following step to the commands before launching the debugger:<br \/>\n<table style=\"border-collapse: collapse; width: 100%; height: 24px;\" border=\"1\">\n<tbody>\n<tr style=\"height: 24px;\">\n<td style=\"width: 50%; height: 24px;\">Command<\/td>\n<td style=\"width: 50%; height: 24px;\">scp<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\">Arguments<\/td>\n<td style=\"width: 50%;\">$(TargetPath) &lt;user&gt;@&lt;deployment machine&gt;:&lt;deployment path&gt;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/16-copy-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8398\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/16-copy-1.png\" alt=\"\" width=\"1188\" height=\"754\" \/><\/a>This will copy the built application to the deployment machine before VisualGDB attempts to debug it. If you would like to copy the file only when it has changed, consider using <strong>rsync<\/strong> instead of <strong>scp<\/strong>.<\/li>\n<li>Finally, go to the <strong>Debug Settings<\/strong> page and configure VisualGDB to launch gdbserver on the target indirectly and connect to it:<br \/>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 50%;\">Debug mode<\/td>\n<td style=\"width: 50%;\">Fully custom<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\">GDB launch command<\/td>\n<td style=\"width: 50%;\">(default)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\">Use a GDB stub<\/td>\n<td style=\"width: 50%;\">Yes<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\">GDB stub command<\/td>\n<td style=\"width: 50%;\">ssh<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\">GDB stub arguments<\/td>\n<td style=\"width: 50%;\">&lt;user&gt;@&lt;deployment machine&gt; gdbserver:&lt;gdbserver port&gt; &lt;deployment path&gt;<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\">Target selection command<\/td>\n<td style=\"width: 50%;\">target remote &lt;deployment machine&gt; :&lt;gdbserver port&gt;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/14-indirect-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8399\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/14-indirect-1.png\" alt=\"\" width=\"1188\" height=\"754\" \/><\/a><\/li>\n<li>Now you can debug the project as usual by pressing F5:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/17-bkpt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8393\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/17-bkpt.png\" alt=\"\" width=\"1069\" height=\"737\" \/><\/a><\/li>\n<li>You can double-check that the project is being built and deployed by modifying it to call the <strong>hostname()<\/strong> function. Verify that the host name matches the deployment machine name:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/18-hostname.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8394\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2023\/09\/18-hostname.png\" alt=\"\" width=\"1069\" height=\"737\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to debug applications build with Linux cross-toolchains where the target machine is not directly accessible from<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[33],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/8377"}],"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=8377"}],"version-history":[{"count":2,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/8377\/revisions"}],"predecessor-version":[{"id":8400,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/8377\/revisions\/8400"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=8377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=8377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=8377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}