Support loading files even when incorrect file name specified by the linker

"Incorrect" file name seen on Android whene the main executable is
called "app_process32" (or 64) but the linker specifies the package
name (e.g. com.android.calculator2). Additionally it can be present
in case of some linker bugs.

This CL adds logic to try to fetch the correct file name from the proc
file system based on the base address sepcified by the linker in case
we are failed to load the module by name.

Differential revision: http://reviews.llvm.org/D22219

llvm-svn: 276411
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index ae32a77..6d822ce 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -1678,6 +1678,20 @@
     else
         return Error ("unexpected /proc/{pid}/maps exec permission char");
 
+    line_extractor.GetChar();              // Read the private bit
+    line_extractor.SkipSpaces();           // Skip the separator
+    line_extractor.GetHexMaxU64(false, 0); // Read the offset
+    line_extractor.GetHexMaxU64(false, 0); // Read the major device number
+    line_extractor.GetChar();              // Read the device id separator
+    line_extractor.GetHexMaxU64(false, 0); // Read the major device number
+    line_extractor.SkipSpaces();           // Skip the separator
+    line_extractor.GetU64(0, 10);          // Read the inode number
+
+    line_extractor.SkipSpaces();
+    const char* name = line_extractor.Peek();
+    if (name)
+        memory_region_info.SetName(name);
+
     return Error ();
 }
 
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index ac76889..ba018be 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -2458,6 +2458,13 @@
                         region_info.SetMapped(MemoryRegionInfo::eNo);
                     }
                 }
+                else if (name.compare ("name") == 0)
+                {
+                    StringExtractorGDBRemote name_extractor;
+                    name_extractor.GetStringRef().swap(value);
+                    name_extractor.GetHexByteString(value);
+                    region_info.SetName(value.c_str());
+                }
                 else if (name.compare ("error") == 0)
                 {
                     StringExtractorGDBRemote name_extractor;
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index ede6976..4721e23 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -2221,6 +2221,15 @@
 
             response.PutChar (';');
         }
+
+        // Name
+        ConstString name = region_info.GetName();
+        if (name)
+        {
+            response.PutCString("name:");
+            response.PutCStringAsRawHex8(name.AsCString());
+            response.PutChar(';');
+        }
     }
 
     return SendPacketNoLock(response.GetData(), response.GetSize());