{"id":7826,"date":"2022-04-18T17:54:10","date_gmt":"2022-04-19T00:54:10","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=7826"},"modified":"2022-04-18T17:54:10","modified_gmt":"2022-04-19T00:54:10","slug":"resolving-invalid-source-paths-from-gdb","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/documentation\/missingsources\/","title":{"rendered":"Resolving Invalid Source Paths from GDB"},"content":{"rendered":"<p>This page explains how to resolve invalid source paths sometimes reported by gdb, that would prevent VisualGDB from showing the relevant source code while stepping through the program.<\/p>\n<p>When the application you are debugging with VisualGDB raises an event (e.g. a breakpoint), or when you use the <strong>Debug-&gt;Break All<\/strong> command, VisualGDB asks the underlying <strong>gdb<\/strong> debugger for the path of the source file that corresponds to the currently running code. Normally, it would work out-of-the-box, and you would just see the relevant source code in Visual Studio:<\/p>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/04\/location.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7827\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/04\/location.png\" alt=\"\" width=\"764\" height=\"122\" \/><\/a>However, sometimes the path reported by <strong>gdb<\/strong> would be invalid. Typically, it is caused by one of the following:<\/p>\n<ul>\n<li>The project was built in a different directory (or on a different machine) and then moved<\/li>\n<li>The build tools would wrap the paths on different levels, resulting in artifacts like <strong>\/\/c:\/dir\/file.cpp <\/strong>instead of just <strong>c:\/dir\/file.cpp<\/strong><\/li>\n<\/ul>\n<p>Note that these paths are coming directly from the debugged executable (i.e. ELF file) and are not affected by the contents of Solution Explorer, IntelliSense settings, etc.<\/p>\n<p>When VisualGDB detects an invalid path reported by <strong>gdb<\/strong>, it shows a window that allows conveniently locating the missing files:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/04\/03-map-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7830\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/04\/03-map-2.png\" alt=\"\" width=\"1066\" height=\"728\" \/><\/a><\/p>\n<p>The window displays the path of the currently debugged executable <strong>(1)<\/strong>, and the exact path reported by gdb <strong>(2) <\/strong>and allows recursively searching an arbitrary directory <strong>(3)<\/strong> for the files with the matching name.<\/p>\n<p>Once you start the search <strong>(4)<\/strong> and select a matching file from the list <strong>(5)<\/strong>, VisualGDB can create a generic path mapping to automatically cover other similar files. The mapping will cover all paths that begin with the selected prefix, so you can select <strong>(6)<\/strong> the most generic one that covers your scenario.<\/p>\n<p>The mappings configured via this window will be saved in the project settings and editable via <strong>VisualGDB Project Properties -&gt; Path mapping<\/strong>:<\/p>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/04\/04-settings.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7831\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/04\/04-settings.png\" alt=\"\" width=\"1188\" height=\"445\" \/><\/a>You can disable the <strong>Missing Source File<\/strong> popup via <strong><span id=\"FullSettingPath\">Tools-&gt;Options-&gt;VisualGDB-&gt;General-&gt;Debug-&gt;Locate Missing Source Files<\/span><\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This page explains how to resolve invalid source paths sometimes reported by gdb, that would prevent VisualGDB from showing the<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[202],"tags":[],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7826"}],"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=7826"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7826\/revisions"}],"predecessor-version":[{"id":7832,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7826\/revisions\/7832"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=7826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=7826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=7826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}