{"id":145,"date":"2014-02-04T17:39:31","date_gmt":"2014-02-04T17:39:31","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=145"},"modified":"2014-02-04T17:39:31","modified_gmt":"2014-02-04T17:39:31","slug":"linux-bp-diag","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/linux\/bp-diag\/","title":{"rendered":"Diagnosing breakpoint problems on Linux"},"content":{"rendered":"\n<p>This tutorial explains how to solve breakpoint problems using VisualGDB&#8217;s breakpoint diagnostics feature.<\/p>\n<p>Before you begin, please install <a href=\"\/download\"> VisualGDB 2.8<\/a> or later.<\/p>\n<ol>\n<li>We begin with making a new Linux project. Hence in Visual Studio go to File-&gt;New Project. There specify the name and location of the project and press &#8216;OK&#8217;. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/01-newproject.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/01-newproject.png\" alt=\"01-newproject\" width=\"700\" height=\"394\" \/><\/a><\/li>\n<li>Choose &#8216;A remote Linux application&#8217;. Press &#8216;Next&#8217;. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/02-linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/02-linux.png\" alt=\"02-linux\" width=\"700\" height=\"591\" \/><\/a><\/li>\n<li>Choose &#8216;Create a new project&#8217;. Press &#8216;Next&#8217;.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/03-new.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/03-new.png\" alt=\"03-new\" width=\"700\" height=\"591\" \/><\/a><\/li>\n<li>Choose the Linux machine used for building and debugging. Press on &#8216;Select&#8217;.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/04-remote.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/04-remote.png\" alt=\"04-remote\" width=\"700\" height=\"591\" \/><\/a><\/li>\n<li>Choose from list or enter the ip address of the Linux machine. Press &#8216;OK&#8217;.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/05-remotemachine.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/05-remotemachine.png\" alt=\"05-remotemachine\" width=\"600\" height=\"277\" \/><\/a><\/li>\n<li>As we want to use just the default toolchain on the Linux machine, we do not need to change any of the tools. Press &#8216;Next&#8217; and the toolchain will be tested.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/06-toolchain.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/06-toolchain.png\" alt=\"06-toolchain\" width=\"700\" height=\"591\" \/><\/a><\/li>\n<li>Make a note of the directory in tmp where the project files will be automatically copied to. We do not need to make any changes on this page, so press &#8216;Next&#8217;.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/07-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/07-build.png\" alt=\"07-build\" width=\"700\" height=\"591\" \/><\/a><\/li>\n<li>We do not need to change any debug settings, so press &#8216;Next&#8217;.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/08-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/08-debug.png\" alt=\"08-debug\" width=\"700\" height=\"591\" \/><\/a><\/li>\n<li>We are currently not going to add any file mappings, press &#8216;Next&#8217;.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/09-filemapping.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/09-filemapping.png\" alt=\"09-filemapping\" width=\"700\" height=\"591\" \/><\/a><\/li>\n<li>Import the system includes to the IntelliSense. Click on the link to import the includes automatically. Press &#8216;OK&#8217; and in the wizard press &#8216;OK&#8217;.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/10-importintellisense.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-10\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/10-importintellisense.png\" alt=\"10-importintellisense\" width=\"700\" height=\"322\" \/><\/a><a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/11-intellisense.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/11-intellisense.png\" alt=\"11-intellisense\" width=\"700\" height=\"591\" \/><\/a><\/li>\n<li>Build the solution in Visual Studio at Build-&gt;Build Solution.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/12-buildsoln.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-12\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/12-buildsoln.png\" alt=\"12-buildsoln\" width=\"700\" height=\"501\" \/><\/a><\/li>\n<li>Set a breakpoint in the main function and start debugging.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/13-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-13\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/13-debug.png\" alt=\"13-debug\" width=\"700\" height=\"501\" \/><\/a><\/li>\n<li>Note that the program stops at the breakpoint. Hence currently the project is correctly set up.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/15-debugging.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-14\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/15-debugging.png\" alt=\"15-debugging\" width=\"699\" height=\"500\" \/><\/a><\/li>\n<li>Now we make some changes to the project to introduce a breakpoint problem. First create a new header file somewhere on the Linux machine, but not in the same folder the rest of the project is in tmp. In this example we create an header file called <strong>func.h<\/strong> in <strong>\/tmp<\/strong> with the following content.\n<pre>int func()\r\n{\r\n    return 42;\r\n}<\/pre>\n<\/li>\n<li>Then go back to the Visual Studio solution and add the inclusion and usage of this new <strong>func<\/strong> function. So, the main cpp file looks something as follows.\n<pre>#include &lt;stdio.h&gt;\r\n#include \"..\/..\/..\/..\/..\/func.h\"\r\n\r\nint main()\r\n{\r\n    int i = func();\r\n    char sz[] = \"Hello, World!\\n\";\r\n    printf(\"%s\", sz);\r\n    return 0;\r\n}<\/pre>\n<\/li>\n<li>Now copy the func.h file to some directory outside the project directory on the Windows machine. We copy it to <strong>C:\\Temp\\func.h<\/strong>.<\/li>\n<li>Next we add this file to the project by right clicking on the &#8216;Header files&#8217; folder of the project and selecting Add-&gt;Existing Item.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/17-addexisting.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/17-addexisting.png\" alt=\"17-addexisting\" width=\"625\" height=\"434\" \/><\/a><\/li>\n<li>Open <strong>func.h<\/strong> and set a breakpoint inside the <strong>func<\/strong> function.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/17-openfile.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-16\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/17-openfile.png\" alt=\"17-openfile\" width=\"699\" height=\"500\" \/><\/a><\/li>\n<li>Build the solution and start debugging. Note that debugging does not stop at the breakpoint in the new func function, as VisualGDB does not that you have copied <strong> \/tmp\/func.h<\/strong> to c<strong>:\\temp<\/strong>.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/19-unresolvedbp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-17\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/19-unresolvedbp.png\" alt=\"19-unresolvedbp\" width=\"699\" height=\"500\" \/><\/a><\/li>\n<li>Open the breakpoints diagnostics window from the &#8216;GDB session&#8217; tool window.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/20-bpdiag.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-18\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/20-bpdiag.png\" alt=\"20-bpdiag\" width=\"699\" height=\"500\" \/><\/a><\/li>\n<li>Select the source file in the list. As you can see, VisualGDB does not know how to translate it into a valid path on the Linux machine, so it tries <strong>c:\/temp\/func.h<\/strong> as the last resort, that is wrong in this case.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/21-localbp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-19\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/21-localbp.png\" alt=\"21-localbp\" width=\"600\" height=\"382\" \/><\/a><\/li>\n<li>Select a corrected file path from the suggestion list. The list is built based on the debugging symbols that contain file paths on the Linux machine, so it will actually contain the correct path.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/22-selectpath.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-20\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/22-selectpath.png\" alt=\"22-selectpath\" width=\"600\" height=\"480\" \/><\/a><\/li>\n<li>VisualGDB will help you create a path mapping rule to resolve problems in further files copied from the same directory. Select an appropriate mapping from the suggestion list and press&nbsp; &#8216;Add&#8217;.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/22-pathmapping.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-21\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/22-pathmapping.png\" alt=\"22-pathmapping\" width=\"600\" height=\"165\" \/><\/a><a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/23-addrule.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-22\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/23-addrule.png\" alt=\"23-addrule\" width=\"600\" height=\"165\" \/><\/a><\/li>\n<li>Notice how both in Visual Studio and the diagnostics window the breakpoint is marked as fixed. Close the diagnostics window. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/24-solved.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-23\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/24-solved.png\" alt=\"24-solved\" width=\"700\" height=\"501\" \/><\/a><\/li>\n<li>Restart debugging. Notice how the breakpoint now works due to the added rule. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/25-bpworks.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-24\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/25-bpworks.png\" alt=\"25-bpworks\" width=\"699\" height=\"500\" \/><\/a><\/li>\n<li>Open the file mappings window from the &#8216;GDB Session&#8217; tool window. This window lists all the file mappings used for debugging. Note that many of them are added by default, such as the project directory and the system includes. Due to our added rule, the extra file added to the project is now also in the list. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/26-filemappings.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-25\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/linux\/bp-diag\/26-filemappings.png\" alt=\"26-filemappings\" width=\"670\" height=\"409\" \/><\/a><\/li>\n<\/ol>\n<p><\/root><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial explains how to solve breakpoint problems using VisualGDB&#8217;s breakpoint diagnostics feature. Before you begin, please install VisualGDB 2.8<\/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":[75,33],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/145"}],"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=145"}],"version-history":[{"count":0,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/145\/revisions"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}