[Lldb-commits] [lldb] r274948 - When calling "settings set target.source-map <old-path> <new-path>", make sure that <new-path> exists before accepting it as a remapping.
Greg Clayton via lldb-commits
lldb-commits at lists.llvm.org
Fri Jul 8 16:06:38 PDT 2016
Author: gclayton
Date: Fri Jul 8 18:06:38 2016
New Revision: 274948
URL: http://llvm.org/viewvc/llvm-project?rev=274948&view=rev
Log:
When calling "settings set target.source-map <old-path> <new-path>", make sure that <new-path> exists before accepting it as a remapping.
We had some clients that had added old source paths remappings to their .lldbinit files and they were causing trouble at a later date. This fix should help mitigate these issues.
<rdar://problem/26358860>
Modified:
lldb/trunk/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py
lldb/trunk/source/Interpreter/OptionValuePathMappings.cpp
Modified: lldb/trunk/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py?rev=274948&r1=274947&r2=274948&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py Fri Jul 8 18:06:38 2016
@@ -88,6 +88,10 @@ class SourceManagerTestCase(TestBase):
system([["ls"]])
system([["ls", "hidden"]])
+ # Set source remapping with invalid replace path and verify we get an error
+ self.expect("settings set target.source-map /a/b/c/d/e /q/r/s/t/u", error=True,
+ substrs = ['''error: the replacement path doesn't exist: "/q/r/s/t/u"'''])
+
# 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.
Modified: lldb/trunk/source/Interpreter/OptionValuePathMappings.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValuePathMappings.cpp?rev=274948&r1=274947&r2=274948&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValuePathMappings.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionValuePathMappings.cpp Fri Jul 8 18:06:38 2016
@@ -14,11 +14,24 @@
// Other libraries and framework includes
// Project includes
#include "lldb/Core/Stream.h"
+#include "lldb/Host/FileSpec.h"
#include "lldb/Host/StringConvert.h"
#include "lldb/Interpreter/Args.h"
using namespace lldb;
using namespace lldb_private;
+namespace
+{
+ static bool
+ VerifyPathExists(const char *path)
+ {
+ if (path && path[0])
+ return FileSpec(path, false).Exists();
+ else
+ return false;
+ }
+}
+
void
OptionValuePathMappings::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
@@ -59,14 +72,27 @@ OptionValuePathMappings::SetValueFromStr
}
else
{
+ bool changed = false;
for (size_t i=1; i<argc; i += 2, ++idx)
{
- ConstString a(args.GetArgumentAtIndex(i));
- ConstString b(args.GetArgumentAtIndex(i+1));
- if (!m_path_mappings.Replace (a, b, idx, m_notify_changes))
- m_path_mappings.Append(a, b, m_notify_changes);
+ const char *orginal_path = args.GetArgumentAtIndex(i);
+ const char *replace_path = args.GetArgumentAtIndex(i+1);
+ if (VerifyPathExists(replace_path))
+ {
+ ConstString a(orginal_path);
+ ConstString b(replace_path);
+ if (!m_path_mappings.Replace (a, b, idx, m_notify_changes))
+ m_path_mappings.Append(a, b, m_notify_changes);
+ changed = true;
+ }
+ else
+ {
+ error.SetErrorStringWithFormat("the replacement path doesn't exist: \"%s\"", replace_path);
+ break;
+ }
}
- NotifyValueChanged();
+ if (changed)
+ NotifyValueChanged();
}
}
else
@@ -94,14 +120,27 @@ OptionValuePathMappings::SetValueFromStr
}
else
{
+ bool changed = false;
for (size_t i=0; i<argc; i += 2)
{
- ConstString a(args.GetArgumentAtIndex(i));
- ConstString b(args.GetArgumentAtIndex(i+1));
- m_path_mappings.Append(a, b, m_notify_changes);
- m_value_was_set = true;
+ const char *orginal_path = args.GetArgumentAtIndex(i);
+ const char *replace_path = args.GetArgumentAtIndex(i+1);
+ if (VerifyPathExists(replace_path))
+ {
+ ConstString a(orginal_path);
+ ConstString b(replace_path);
+ m_path_mappings.Append(a, b, m_notify_changes);
+ m_value_was_set = true;
+ changed = true;
+ }
+ else
+ {
+ error.SetErrorStringWithFormat("the replacement path doesn't exist: \"%s\"", replace_path);
+ break;
+ }
}
- NotifyValueChanged();
+ if (changed)
+ NotifyValueChanged();
}
break;
@@ -118,15 +157,28 @@ OptionValuePathMappings::SetValueFromStr
}
else
{
+ bool changed = false;
if (op == eVarSetOperationInsertAfter)
++idx;
for (size_t i=1; i<argc; i += 2, ++idx)
{
- ConstString a(args.GetArgumentAtIndex(i));
- ConstString b(args.GetArgumentAtIndex(i+1));
- m_path_mappings.Insert (a, b, idx, m_notify_changes);
+ const char *orginal_path = args.GetArgumentAtIndex(i);
+ const char *replace_path = args.GetArgumentAtIndex(i+1);
+ if (VerifyPathExists(replace_path))
+ {
+ ConstString a(orginal_path);
+ ConstString b(replace_path);
+ m_path_mappings.Insert (a, b, idx, m_notify_changes);
+ changed = true;
+ }
+ else
+ {
+ error.SetErrorStringWithFormat("the replacement path doesn't exist: \"%s\"", replace_path);
+ break;
+ }
}
- NotifyValueChanged();
+ if (changed)
+ NotifyValueChanged();
}
}
else
More information about the lldb-commits
mailing list