summaryrefslogtreecommitdiff
path: root/source/Interpreter/OptionValuePathMappings.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2016-07-23 20:50:09 +0000
committerDimitry Andric <dim@FreeBSD.org>2016-07-23 20:50:09 +0000
commitf3fbd1c0586ff6ec7895991e6c28f61a503c36a8 (patch)
tree48d008fd3df8c0e73271a4b18474e0aac6dbfe33 /source/Interpreter/OptionValuePathMappings.cpp
parent2fc5d2d1dfaf623ce4e24cd8590565902f8c557c (diff)
Notes
Diffstat (limited to 'source/Interpreter/OptionValuePathMappings.cpp')
-rw-r--r--source/Interpreter/OptionValuePathMappings.cpp81
1 files changed, 67 insertions, 14 deletions
diff --git a/source/Interpreter/OptionValuePathMappings.cpp b/source/Interpreter/OptionValuePathMappings.cpp
index 722d6a144279e..f3f146f1f8c62 100644
--- a/source/Interpreter/OptionValuePathMappings.cpp
+++ b/source/Interpreter/OptionValuePathMappings.cpp
@@ -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::SetValueFromString (llvm::StringRef value, VarSetOperat
}
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
@@ -85,6 +111,7 @@ OptionValuePathMappings::SetValueFromString (llvm::StringRef value, VarSetOperat
}
m_path_mappings.Clear(m_notify_changes);
// Fall through to append case
+ LLVM_FALLTHROUGH;
case eVarSetOperationAppend:
if (argc < 2 || (argc & 1))
{
@@ -93,14 +120,27 @@ OptionValuePathMappings::SetValueFromString (llvm::StringRef value, VarSetOperat
}
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;
@@ -117,15 +157,28 @@ OptionValuePathMappings::SetValueFromString (llvm::StringRef value, VarSetOperat
}
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