rdar://problem/10227672

There were two problems associated with this radar:
1. "settings show target.source-map" failed to show the source-map after, for example,
   "settings set target.source-map /Volumes/data/lldb/svn/trunk/test/source-manager /Volumes/data/lldb/svn/trunk/test/source-manager/hidden"
   has been executed to set the source-map.
2. "list -n main" failed to display the source of the main() function after we properly set the source-map.

The first was fixed by adding the missing functionality to TargetInstanceSettings::GetInstanceSettingsValue (Target.cpp)
and updating the support files PathMappingList.h/.cpp; the second by modifying SourceManager.cpp to fix several places
with incorrect logic.

Also added a test case test_move_and_then_display_source() to TestSourceManager.py, which moves main.c to hidden/main.c,
sets target.source-map to perform the directory mapping, and then verifies that "list -n main" can still show the main()
function.

llvm-svn: 146422
diff --git a/lldb/test/source-manager/TestSourceManager.py b/lldb/test/source-manager/TestSourceManager.py
index 56b9dd9..f1a4cf2 100644
--- a/lldb/test/source-manager/TestSourceManager.py
+++ b/lldb/test/source-manager/TestSourceManager.py
@@ -22,6 +22,7 @@
         TestBase.setUp(self)
         # Find the line number to break inside main().
         self.line = line_number('main.c', '// Set break point at this line.')
+        lldb.skip_build_and_cleanup = False
 
     @python_api_test
     def test_display_source_python(self):
@@ -29,6 +30,11 @@
         self.buildDefault()
         self.display_source_python()
 
+    def test_move_and_then_display_source(self):
+        """Test that target.source-map settings work by moving main.c to hidden/main.c."""
+        self.buildDefault()
+        self.move_and_then_display_source()
+
     def test_modify_source_file_while_debugging(self):
         """Modify a source file while debugging the executable."""
         self.buildDefault()
@@ -70,6 +76,33 @@
                     exe=False,
             patterns = ['=> %d.*Hello world' % self.line])        
 
+    def move_and_then_display_source(self):
+        """Test that target.source-map settings work by moving main.c to hidden/main.c."""
+        exe = os.path.join(os.getcwd(), "a.out")
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+        # Move main.c to hidden/main.c.
+        main_c = "main.c"
+        main_c_hidden = os.path.join("hidden", main_c)
+        os.rename(main_c, main_c_hidden)
+
+        if self.TraceOn():
+            system(["ls"])
+            system(["ls", "hidden"])
+
+        # Restore main.c after the test.
+        self.addTearDownHook(lambda: os.rename(main_c_hidden, main_c))
+
+        # Set target.source-map settings.
+        self.runCmd("settings set target.source-map %s %s" % (os.getcwd(), os.path.join(os.getcwd(), "hidden")))
+        # And verify that the settings work.
+        self.expect("settings show target.source-map",
+            substrs = [os.getcwd(), os.path.join(os.getcwd(), "hidden")])
+
+        # Display main() and verify that the source mapping has been kicked in.
+        self.expect("list -n main", SOURCE_DISPLAYED_CORRECTLY,
+            substrs = ['Hello world'])
+
     def modify_source_file_while_debugging(self):
         """Modify a source file while debugging the executable."""
         exe = os.path.join(os.getcwd(), "a.out")