diff options
Diffstat (limited to 'source/Interpreter/Args.cpp')
-rw-r--r-- | source/Interpreter/Args.cpp | 96 |
1 files changed, 11 insertions, 85 deletions
diff --git a/source/Interpreter/Args.cpp b/source/Interpreter/Args.cpp index 9393380..4f0219f 100644 --- a/source/Interpreter/Args.cpp +++ b/source/Interpreter/Args.cpp @@ -19,14 +19,13 @@ #include "lldb/Core/StreamFile.h" #include "lldb/Core/StreamString.h" #include "lldb/DataFormatters/FormatManager.h" +#include "lldb/Host/StringConvert.h" #include "lldb/Interpreter/Options.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Target/Process.h" -//#include "lldb/Target/RegisterContext.h" #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" -//#include "lldb/Target/Thread.h" using namespace lldb; using namespace lldb_private; @@ -166,7 +165,7 @@ Args::SetCommandString (const char *command) if (command && command[0]) { static const char *k_space_separators = " \t"; - static const char *k_space_separators_with_slash_and_quotes = " \t \\'\""; + static const char *k_escapable_characters = " \t\\'\""; const char *arg_end = nullptr; const char *arg_pos; for (arg_pos = command; @@ -202,7 +201,7 @@ Args::SetCommandString (const char *command) do { - arg_end = ::strcspn (arg_pos, k_space_separators_with_slash_and_quotes) + arg_pos; + arg_end = ::strcspn (arg_pos, k_escapable_characters) + arg_pos; switch (arg_end[0]) { @@ -216,7 +215,6 @@ Args::SetCommandString (const char *command) arg.append (arg_piece_start); arg_complete = true; break; - case '\\': // Backslash character switch (arg_end[1]) @@ -228,22 +226,21 @@ Args::SetCommandString (const char *command) break; default: - if (quote_char == '\0') + // Only consider this two-character sequence an escape sequence if we're unquoted and + // the character after the backslash is a whitelisted escapable character. Otherwise + // leave the character sequence untouched. + if (quote_char == '\0' && (nullptr != strchr(k_escapable_characters, arg_end[1]))) { arg.append (arg_piece_start, arg_end - arg_piece_start); - if (arg_end[1] != '\0') - { - arg.append (arg_end + 1, 1); - arg_pos = arg_end + 2; - arg_piece_start = arg_pos; - } + arg.append (arg_end + 1, 1); + arg_pos = arg_end + 2; + arg_piece_start = arg_pos; } else arg_pos = arg_end + 2; break; } break; - case '"': case '\'': case '`': @@ -722,77 +719,6 @@ Args::Clear () m_args_quote_char.clear(); } -int32_t -Args::StringToSInt32 (const char *s, int32_t fail_value, int base, bool *success_ptr) -{ - if (s && s[0]) - { - char *end = nullptr; - const long sval = ::strtol (s, &end, base); - if (*end == '\0') - { - if (success_ptr) - *success_ptr = ((sval <= INT32_MAX) && (sval >= INT32_MIN)); - return (int32_t)sval; // All characters were used, return the result - } - } - if (success_ptr) *success_ptr = false; - return fail_value; -} - -uint32_t -Args::StringToUInt32 (const char *s, uint32_t fail_value, int base, bool *success_ptr) -{ - if (s && s[0]) - { - char *end = nullptr; - const unsigned long uval = ::strtoul (s, &end, base); - if (*end == '\0') - { - if (success_ptr) - *success_ptr = (uval <= UINT32_MAX); - return (uint32_t)uval; // All characters were used, return the result - } - } - if (success_ptr) *success_ptr = false; - return fail_value; -} - - -int64_t -Args::StringToSInt64 (const char *s, int64_t fail_value, int base, bool *success_ptr) -{ - if (s && s[0]) - { - char *end = nullptr; - int64_t uval = ::strtoll (s, &end, base); - if (*end == '\0') - { - if (success_ptr) *success_ptr = true; - return uval; // All characters were used, return the result - } - } - if (success_ptr) *success_ptr = false; - return fail_value; -} - -uint64_t -Args::StringToUInt64 (const char *s, uint64_t fail_value, int base, bool *success_ptr) -{ - if (s && s[0]) - { - char *end = nullptr; - uint64_t uval = ::strtoull (s, &end, base); - if (*end == '\0') - { - if (success_ptr) *success_ptr = true; - return uval; // All characters were used, return the result - } - } - if (success_ptr) *success_ptr = false; - return fail_value; -} - lldb::addr_t Args::StringToAddress (const ExecutionContext *exe_ctx, const char *s, lldb::addr_t fail_value, Error *error_ptr) { @@ -878,7 +804,7 @@ Args::StringToAddress (const ExecutionContext *exe_ctx, const char *s, lldb::add if (regex_match.GetMatchAtIndex(s, 3, str)) { - offset = Args::StringToUInt64(str.c_str(), 0, 0, &success); + offset = StringConvert::ToUInt64(str.c_str(), 0, 0, &success); if (success) { |