Train LLDB to deal with bad linker N_SO entries that point to our source files for debug map + DWARF in .o file debugging.



git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@163417 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 898f581..f44f185 100644
--- a/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1822,6 +1822,24 @@
                                                                 if (so_path && so_path[0])
                                                                 {
                                                                     std::string full_so_path (so_path);
+                                                                    const size_t double_slash_pos = full_so_path.find("//");
+                                                                    if (double_slash_pos != std::string::npos)
+                                                                    {
+                                                                        // The linker has been generating bad N_SO entries with doubled up paths
+                                                                        // in the format "%s%s" where the first stirng in the DW_AT_comp_dir,
+                                                                        // and the second is the directory for the source file so you end up with
+                                                                        // a path that looks like "/tmp/src//tmp/src/"
+                                                                        FileSpec so_dir(so_path, false);
+                                                                        if (!so_dir.Exists())
+                                                                        {
+                                                                            so_dir.SetFile(&full_so_path[double_slash_pos + 1], false);
+                                                                            if (so_dir.Exists())
+                                                                            {
+                                                                                // Trim off the incorrect path
+                                                                                full_so_path.erase(0, double_slash_pos + 1);
+                                                                            }
+                                                                        }
+                                                                    }
                                                                     if (*full_so_path.rbegin() != '/')
                                                                         full_so_path += '/';
                                                                     full_so_path += symbol_name;
@@ -2545,6 +2563,24 @@
                             if (so_path && so_path[0])
                             {
                                 std::string full_so_path (so_path);
+                                const size_t double_slash_pos = full_so_path.find("//");
+                                if (double_slash_pos != std::string::npos)
+                                {
+                                    // The linker has been generating bad N_SO entries with doubled up paths
+                                    // in the format "%s%s" where the first stirng in the DW_AT_comp_dir,
+                                    // and the second is the directory for the source file so you end up with
+                                    // a path that looks like "/tmp/src//tmp/src/"
+                                    FileSpec so_dir(so_path, false);
+                                    if (!so_dir.Exists())
+                                    {
+                                        so_dir.SetFile(&full_so_path[double_slash_pos + 1], false);
+                                        if (so_dir.Exists())
+                                        {
+                                            // Trim off the incorrect path
+                                            full_so_path.erase(0, double_slash_pos + 1);
+                                        }
+                                    }
+                                }
                                 if (*full_so_path.rbegin() != '/')
                                     full_so_path += '/';
                                 full_so_path += symbol_name;