diff options
author | Greg Clayton <gclayton@apple.com> | 2016-07-08 23:06:38 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2016-07-08 23:06:38 +0000 |
commit | 6a3116415b04f040e2034ae578667e11418081b0 (patch) | |
tree | 4b3adc9b2e75ef3816c7222530391788b40d3b32 /lldb/source/Interpreter/OptionValuePathMappings.cpp | |
parent | 3b77612839390d0dc6ebe3c8cb570dddae124fcf (diff) | |
download | bcm5719-llvm-6a3116415b04f040e2034ae578667e11418081b0.tar.gz bcm5719-llvm-6a3116415b04f040e2034ae578667e11418081b0.zip |
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>
llvm-svn: 274948
Diffstat (limited to 'lldb/source/Interpreter/OptionValuePathMappings.cpp')
-rw-r--r-- | lldb/source/Interpreter/OptionValuePathMappings.cpp | 80 |
1 files changed, 66 insertions, 14 deletions
diff --git a/lldb/source/Interpreter/OptionValuePathMappings.cpp b/lldb/source/Interpreter/OptionValuePathMappings.cpp index b0d460a8ca2..f3f146f1f8c 100644 --- a/lldb/source/Interpreter/OptionValuePathMappings.cpp +++ b/lldb/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 @@ -94,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; @@ -118,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 |