{"id":144,"date":"2014-02-04T17:39:31","date_gmt":"2014-02-04T17:39:31","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=144"},"modified":"2014-02-04T17:39:31","modified_gmt":"2014-02-04T17:39:31","slug":"linux-attach","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/linux\/attach\/","title":{"rendered":"Attaching to remote Linux applications with VisualGDB"},"content":{"rendered":"\n<p>This tutorial shows how to attach to and debug a remote Linux process without creating a project in Visual Studio. We will download the sources of <a href=\"http:\/\/www.gnu.org\/software\/mc\/\">Midnight Commander<\/a> to a Linux machine and build it there.<\/p>\n<ol>\n<li>Please install <a href=\"\/download\">VisualGDB<\/a> 3.0 or newer on your Windows machine.<\/li>\n<li>On your Linux machine get the source code of Midnight Commander by running the following commands from your home directory:\n<pre>sudo apt-get build-dep mc\r\napt-get source mc<\/pre>\n<p><a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/01-getsource.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/01-getsource.png\" alt=\"01-getsource\" width=\"583\" height=\"566\" \/><\/a><\/li>\n<li>When the source code is downloaded, go to the newly created directory and configure Midnight Commander with default settings:\n<pre>cd mc-&lt;VERSION&gt;\r\n.\/configure<\/pre>\n<p><a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/02-configure.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/02-configure.png\" alt=\"02-configure\" width=\"583\" height=\"566\" \/><\/a><\/li>\n<li>Build the program with make.\n<pre>make<\/pre>\n<p><a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/03-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/03-build.png\" alt=\"03-build\" width=\"583\" height=\"505\" \/><\/a><\/li>\n<li>Locate the mc executable and run it.\n<pre>find -name mc\r\n.\/src\/mc<\/pre>\n<p><a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/04-run.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/04-run.png\" alt=\"04-run\" width=\"583\" height=\"505\" \/><\/a><a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/05-running.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/05-running.png\" alt=\"05-running\" width=\"582\" height=\"505\" \/><\/a><\/li>\n<li>Now open Visual Studio and go to&nbsp; Debug-&gt;Attach to<br \/>\n\t\t\t\t\tProcess&#8230; . Change the &#8216;Transport&#8217; to VisualGDB.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/06-attachvgdb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/06-attachvgdb.png\" alt=\"06-attachvgdb\" width=\"700\" height=\"471\" \/><\/a><\/li>\n<li>Then on the &#8216;Qualifier&#8217; line click on the &#8216;Find&#8230;&#8217; button. Choose &#8216;Linux application&#8217;.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/07-remote.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/07-remote.png\" alt=\"07-remote\" width=\"500\" height=\"383\" \/><\/a><\/li>\n<li>Choose a remote host from the list or make a new SSH connection.<\/li>\n<li>Press &#8216;OK&#8217; on the port selection window. Now the processes on that Linux machine are listed.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/09-showprocesses.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/09-showprocesses.png\" alt=\"09-showprocesses\" width=\"500\" height=\"383\" \/><\/a><a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/10-processes.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/10-processes.png\" alt=\"10-processes\" width=\"700\" height=\"471\" \/><\/a><\/li>\n<li>Find mc from the list and click on &#8216;Attach&#8217;.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/11-attach.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-10\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/11-attach.png\" alt=\"11-attach\" width=\"700\" height=\"471\" \/><\/a><\/li>\n<li>VisualGDB attaches to the mc program on the Linux machine and pauses the execution.<br \/><span class=\"warning\">If attaching fails due to different user rights, then start VisualGDBBuildServer on the Linux machine as root.<\/span><a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/12-debugging.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/12-debugging.png\" alt=\"12-debugging\" width=\"697\" height=\"496\" \/><\/a><\/li>\n<li>Continue executing. Go to the Linux machine and trigger some dialog for a directory. Here we just press &#8216;F1&#8217; on some directory. Then go back to Visual Studio and pause execution.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/12b-sometext.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-12\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/12b-sometext.png\" alt=\"12b-sometext\" width=\"583\" height=\"532\" \/><\/a><\/li>\n<li>If prompted by a SIGINT dialog, just press on &#8216;Break&#8217;.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/13-sigint.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-13\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/13-sigint.png\" alt=\"13-sigint\" width=\"559\" height=\"317\" \/><\/a><\/li>\n<li>The execution is now paused. In the call stack double click on &#8216;fg_message()&#8217;. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/14-stopped.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-14\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/14-stopped.png\" alt=\"14-stopped\" width=\"697\" height=\"496\" \/><\/a><\/li>\n<li>Hover over the &#8216;text&#8217;, it show the text that the dialog is showing. Hence we are debugging that particular program. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/15-correcttext.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/15-correcttext.png\" alt=\"15-correcttext\" width=\"697\" height=\"496\" \/><\/a><\/li>\n<li>Additionally you can move between the files by opening them via the &#8216;GDB Session&#8217; tool window. Click there now. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/16-allsources.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-16\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/16-allsources.png\" alt=\"16-allsources\" width=\"697\" height=\"496\" \/><\/a><\/li>\n<li>In this list you can find all the source files gdb knows. You can also open them and they will be auto-downloaded for local viewing. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/17-sources.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-17\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/attach\/17-sources.png\" alt=\"17-sources\" width=\"695\" height=\"395\" \/><\/a><\/li>\n<\/ol>\n<p><\/root><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to attach to and debug a remote Linux process without creating a project in Visual Studio.<\/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":[74,33],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/144"}],"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=144"}],"version-history":[{"count":0,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/144\/revisions"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}