[Lldb-commits] [lldb] r329677 - Move Args::StringTo*** functions to a new OptionArgParser class
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Apr 10 02:04:00 PDT 2018
Author: labath
Date: Tue Apr 10 02:03:59 2018
New Revision: 329677
URL: http://llvm.org/viewvc/llvm-project?rev=329677&view=rev
Log:
Move Args::StringTo*** functions to a new OptionArgParser class
Summary:
The idea behind this is to move the functionality which depend on other lldb
classes into a separate class. This way, the Args class can be turned
into a lightweight arc+argv wrapper and moved into the lower lldb
layers.
Reviewers: jingham, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D44306
Added:
lldb/trunk/include/lldb/Interpreter/OptionArgParser.h
lldb/trunk/source/Interpreter/OptionArgParser.cpp
lldb/trunk/unittests/Interpreter/TestOptionArgParser.cpp
Modified:
lldb/trunk/include/lldb/Interpreter/Args.h
lldb/trunk/include/lldb/Interpreter/Options.h
lldb/trunk/source/API/SBDebugger.cpp
lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp
lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp
lldb/trunk/source/Commands/CommandObjectCommands.cpp
lldb/trunk/source/Commands/CommandObjectDisassemble.cpp
lldb/trunk/source/Commands/CommandObjectExpression.cpp
lldb/trunk/source/Commands/CommandObjectLog.cpp
lldb/trunk/source/Commands/CommandObjectMemory.cpp
lldb/trunk/source/Commands/CommandObjectProcess.cpp
lldb/trunk/source/Commands/CommandObjectSource.cpp
lldb/trunk/source/Commands/CommandObjectTarget.cpp
lldb/trunk/source/Commands/CommandObjectThread.cpp
lldb/trunk/source/Commands/CommandObjectType.cpp
lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp
lldb/trunk/source/Interpreter/Args.cpp
lldb/trunk/source/Interpreter/CMakeLists.txt
lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp
lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp
lldb/trunk/source/Interpreter/OptionValueBoolean.cpp
lldb/trunk/source/Interpreter/OptionValueChar.cpp
lldb/trunk/source/Interpreter/OptionValueFormat.cpp
lldb/trunk/source/Interpreter/Property.cpp
lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
lldb/trunk/source/Target/Process.cpp
lldb/trunk/unittests/Interpreter/CMakeLists.txt
lldb/trunk/unittests/Interpreter/TestArgs.cpp
Modified: lldb/trunk/include/lldb/Interpreter/Args.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/Args.h?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/Args.h (original)
+++ lldb/trunk/include/lldb/Interpreter/Args.h Tue Apr 10 02:03:59 2018
@@ -12,7 +12,6 @@
// C Includes
// C++ Includes
-#include <list>
#include <string>
#include <utility>
#include <vector>
@@ -22,7 +21,6 @@
#include "llvm/ADT/StringRef.h"
// Project includes
#include "lldb/Utility/Environment.h"
-#include "lldb/Utility/Status.h"
#include "lldb/lldb-private-types.h"
#include "lldb/lldb-types.h"
@@ -343,30 +341,6 @@ public:
return min <= sval64 && sval64 <= max;
}
- static lldb::addr_t StringToAddress(const ExecutionContext *exe_ctx,
- llvm::StringRef s,
- lldb::addr_t fail_value, Status *error);
-
- static bool StringToBoolean(llvm::StringRef s, bool fail_value,
- bool *success_ptr);
-
- static char StringToChar(llvm::StringRef s, char fail_value,
- bool *success_ptr);
-
- static int64_t StringToOptionEnum(llvm::StringRef s,
- OptionEnumValueElement *enum_values,
- int32_t fail_value, Status &error);
-
- static lldb::ScriptLanguage
- StringToScriptLanguage(llvm::StringRef s, lldb::ScriptLanguage fail_value,
- bool *success_ptr);
-
- // TODO: Use StringRef
- static Status StringToFormat(const char *s, lldb::Format &format,
- size_t *byte_size_ptr); // If non-NULL, then a
- // byte size can precede
- // the format character
-
static lldb::Encoding
StringToEncoding(llvm::StringRef s,
lldb::Encoding fail_value = lldb::eEncodingInvalid);
Added: lldb/trunk/include/lldb/Interpreter/OptionArgParser.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/OptionArgParser.h?rev=329677&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/OptionArgParser.h (added)
+++ lldb/trunk/include/lldb/Interpreter/OptionArgParser.h Tue Apr 10 02:03:59 2018
@@ -0,0 +1,43 @@
+//===-- OptionArgParser.h ---------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_INTERPRETER_OPTIONARGPARSER_H
+#define LLDB_INTERPRETER_OPTIONARGPARSER_H
+
+#include "lldb/lldb-private-types.h"
+
+namespace lldb_private {
+
+struct OptionArgParser {
+ static lldb::addr_t ToAddress(const ExecutionContext *exe_ctx,
+ llvm::StringRef s, lldb::addr_t fail_value,
+ Status *error);
+
+ static bool ToBoolean(llvm::StringRef s, bool fail_value, bool *success_ptr);
+
+ static char ToChar(llvm::StringRef s, char fail_value, bool *success_ptr);
+
+ static int64_t ToOptionEnum(llvm::StringRef s,
+ OptionEnumValueElement *enum_values,
+ int32_t fail_value, Status &error);
+
+ static lldb::ScriptLanguage ToScriptLanguage(llvm::StringRef s,
+ lldb::ScriptLanguage fail_value,
+ bool *success_ptr);
+
+ // TODO: Use StringRef
+ static Status ToFormat(const char *s, lldb::Format &format,
+ size_t *byte_size_ptr); // If non-NULL, then a
+ // byte size can precede
+ // the format character
+};
+
+} // namespace lldb_private
+
+#endif // LLDB_INTERPRETER_OPTIONARGPARSER_H
Modified: lldb/trunk/include/lldb/Interpreter/Options.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/Options.h?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/Options.h (original)
+++ lldb/trunk/include/lldb/Interpreter/Options.h Tue Apr 10 02:03:59 2018
@@ -18,6 +18,7 @@
// Other libraries and framework includes
// Project includes
#include "lldb/Interpreter/Args.h"
+#include "lldb/Utility/Status.h"
#include "lldb/lldb-defines.h"
#include "lldb/lldb-private.h"
Modified: lldb/trunk/source/API/SBDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/API/SBDebugger.cpp (original)
+++ lldb/trunk/source/API/SBDebugger.cpp Tue Apr 10 02:03:59 2018
@@ -47,6 +47,7 @@
#include "lldb/Initialization/SystemLifetimeManager.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionGroupPlatform.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/TargetList.h"
@@ -480,8 +481,8 @@ bool SBDebugger::SetDefaultArchitecture(
ScriptLanguage
SBDebugger::GetScriptingLanguage(const char *script_language_name) {
if (!script_language_name) return eScriptLanguageDefault;
- return Args::StringToScriptLanguage(llvm::StringRef(script_language_name),
- eScriptLanguageDefault, nullptr);
+ return OptionArgParser::ToScriptLanguage(
+ llvm::StringRef(script_language_name), eScriptLanguageDefault, nullptr);
}
const char *SBDebugger::GetVersionString() {
Modified: lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp Tue Apr 10 02:03:59 2018
@@ -22,6 +22,7 @@
#include "lldb/Interpreter/CommandCompletions.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionValueBoolean.h"
#include "lldb/Interpreter/OptionValueString.h"
#include "lldb/Interpreter/OptionValueUInt64.h"
@@ -100,7 +101,7 @@ public:
break;
case 'G': {
bool value, success;
- value = Args::StringToBoolean(option_arg, false, &success);
+ value = OptionArgParser::ToBoolean(option_arg, false, &success);
if (success) {
m_bp_opts.SetAutoContinue(value);
} else
@@ -121,7 +122,7 @@ public:
break;
case 'o': {
bool value, success;
- value = Args::StringToBoolean(option_arg, false, &success);
+ value = OptionArgParser::ToBoolean(option_arg, false, &success);
if (success) {
m_bp_opts.SetOneShot(value);
} else
@@ -377,8 +378,8 @@ public:
switch (short_option) {
case 'a': {
- m_load_addr = Args::StringToAddress(execution_context, option_arg,
- LLDB_INVALID_ADDRESS, &error);
+ m_load_addr = OptionArgParser::ToAddress(execution_context, option_arg,
+ LLDB_INVALID_ADDRESS, &error);
} break;
case 'A':
@@ -442,7 +443,7 @@ public:
case 'h': {
bool success;
- m_catch_bp = Args::StringToBoolean(option_arg, true, &success);
+ m_catch_bp = OptionArgParser::ToBoolean(option_arg, true, &success);
if (!success)
error.SetErrorStringWithFormat(
"Invalid boolean value for on-catch option: '%s'",
@@ -456,7 +457,7 @@ public:
case 'K': {
bool success;
bool value;
- value = Args::StringToBoolean(option_arg, true, &success);
+ value = OptionArgParser::ToBoolean(option_arg, true, &success);
if (value)
m_skip_prologue = eLazyBoolYes;
else
@@ -485,7 +486,7 @@ public:
case 'm': {
bool success;
bool value;
- value = Args::StringToBoolean(option_arg, true, &success);
+ value = OptionArgParser::ToBoolean(option_arg, true, &success);
if (value)
m_move_to_nearest_code = eLazyBoolYes;
else
@@ -519,8 +520,8 @@ public:
case 'R': {
lldb::addr_t tmp_offset_addr;
- tmp_offset_addr =
- Args::StringToAddress(execution_context, option_arg, 0, &error);
+ tmp_offset_addr = OptionArgParser::ToAddress(execution_context,
+ option_arg, 0, &error);
if (error.Success())
m_offset_addr = tmp_offset_addr;
} break;
@@ -549,7 +550,7 @@ public:
case 'w': {
bool success;
- m_throw_bp = Args::StringToBoolean(option_arg, true, &success);
+ m_throw_bp = OptionArgParser::ToBoolean(option_arg, true, &success);
if (!success)
error.SetErrorStringWithFormat(
"Invalid boolean value for on-throw option: '%s'",
@@ -1783,7 +1784,7 @@ public:
switch (short_option) {
case 'L': {
bool value, success;
- value = Args::StringToBoolean(option_arg, false, &success);
+ value = OptionArgParser::ToBoolean(option_arg, false, &success);
if (success) {
m_permissions.SetAllowList(value);
} else
@@ -1793,7 +1794,7 @@ public:
} break;
case 'A': {
bool value, success;
- value = Args::StringToBoolean(option_arg, false, &success);
+ value = OptionArgParser::ToBoolean(option_arg, false, &success);
if (success) {
m_permissions.SetAllowDisable(value);
} else
@@ -1803,7 +1804,7 @@ public:
} break;
case 'D': {
bool value, success;
- value = Args::StringToBoolean(option_arg, false, &success);
+ value = OptionArgParser::ToBoolean(option_arg, false, &success);
if (success) {
m_permissions.SetAllowDelete(value);
} else
Modified: lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp Tue Apr 10 02:03:59 2018
@@ -22,6 +22,7 @@
#include "lldb/Host/OptionParser.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
@@ -293,7 +294,7 @@ are no syntax errors may indicate that a
break;
case 's':
- m_script_language = (lldb::ScriptLanguage)Args::StringToOptionEnum(
+ m_script_language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
option_arg, g_breakpoint_add_options[option_idx].enum_values,
eScriptLanguageNone, error);
@@ -307,7 +308,8 @@ are no syntax errors may indicate that a
case 'e': {
bool success = false;
- m_stop_on_error = Args::StringToBoolean(option_arg, false, &success);
+ m_stop_on_error =
+ OptionArgParser::ToBoolean(option_arg, false, &success);
if (!success)
error.SetErrorStringWithFormat(
"invalid value for stop-on-error: \"%s\"",
Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Tue Apr 10 02:03:59 2018
@@ -23,6 +23,7 @@
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandObjectRegexCommand.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionValueBoolean.h"
#include "lldb/Interpreter/OptionValueString.h"
#include "lldb/Interpreter/OptionValueUInt64.h"
@@ -1639,7 +1640,7 @@ protected:
break;
case 's':
m_synchronicity =
- (ScriptedCommandSynchronicity)Args::StringToOptionEnum(
+ (ScriptedCommandSynchronicity)OptionArgParser::ToOptionEnum(
option_arg, GetDefinitions()[option_idx].enum_values, 0, error);
if (!error.Success())
error.SetErrorStringWithFormat(
Modified: lldb/trunk/source/Commands/CommandObjectDisassemble.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectDisassemble.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectDisassemble.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectDisassemble.cpp Tue Apr 10 02:03:59 2018
@@ -20,6 +20,7 @@
#include "lldb/Interpreter/CommandCompletions.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/Options.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/Symbol.h"
@@ -101,14 +102,14 @@ Status CommandObjectDisassemble::Command
break;
case 's': {
- start_addr = Args::StringToAddress(execution_context, option_arg,
- LLDB_INVALID_ADDRESS, &error);
+ start_addr = OptionArgParser::ToAddress(execution_context, option_arg,
+ LLDB_INVALID_ADDRESS, &error);
if (start_addr != LLDB_INVALID_ADDRESS)
some_location_specified = true;
} break;
case 'e': {
- end_addr = Args::StringToAddress(execution_context, option_arg,
- LLDB_INVALID_ADDRESS, &error);
+ end_addr = OptionArgParser::ToAddress(execution_context, option_arg,
+ LLDB_INVALID_ADDRESS, &error);
if (end_addr != LLDB_INVALID_ADDRESS)
some_location_specified = true;
} break;
@@ -168,7 +169,7 @@ Status CommandObjectDisassemble::Command
break;
case 'a': {
- symbol_containing_addr = Args::StringToAddress(
+ symbol_containing_addr = OptionArgParser::ToAddress(
execution_context, option_arg, LLDB_INVALID_ADDRESS, &error);
if (symbol_containing_addr != LLDB_INVALID_ADDRESS) {
some_location_specified = true;
Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Tue Apr 10 02:03:59 2018
@@ -27,6 +27,7 @@
#include "lldb/Host/OptionParser.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/Variable.h"
#include "lldb/Target/Language.h"
@@ -88,7 +89,7 @@ Status CommandObjectExpression::CommandO
case 'a': {
bool success;
bool result;
- result = Args::StringToBoolean(option_arg, true, &success);
+ result = OptionArgParser::ToBoolean(option_arg, true, &success);
if (!success)
error.SetErrorStringWithFormat(
"invalid all-threads value setting: \"%s\"",
@@ -99,7 +100,7 @@ Status CommandObjectExpression::CommandO
case 'i': {
bool success;
- bool tmp_value = Args::StringToBoolean(option_arg, true, &success);
+ bool tmp_value = OptionArgParser::ToBoolean(option_arg, true, &success);
if (success)
ignore_breakpoints = tmp_value;
else
@@ -111,7 +112,7 @@ Status CommandObjectExpression::CommandO
case 'j': {
bool success;
- bool tmp_value = Args::StringToBoolean(option_arg, true, &success);
+ bool tmp_value = OptionArgParser::ToBoolean(option_arg, true, &success);
if (success)
allow_jit = tmp_value;
else
@@ -131,7 +132,7 @@ Status CommandObjectExpression::CommandO
case 'u': {
bool success;
- bool tmp_value = Args::StringToBoolean(option_arg, true, &success);
+ bool tmp_value = OptionArgParser::ToBoolean(option_arg, true, &success);
if (success)
unwind_on_error = tmp_value;
else
@@ -146,8 +147,8 @@ Status CommandObjectExpression::CommandO
m_verbosity = eLanguageRuntimeDescriptionDisplayVerbosityFull;
break;
}
- m_verbosity =
- (LanguageRuntimeDescriptionDisplayVerbosity)Args::StringToOptionEnum(
+ m_verbosity = (LanguageRuntimeDescriptionDisplayVerbosity)
+ OptionArgParser::ToOptionEnum(
option_arg, GetDefinitions()[option_idx].enum_values, 0, error);
if (!error.Success())
error.SetErrorStringWithFormat(
@@ -167,7 +168,7 @@ Status CommandObjectExpression::CommandO
case 'X': {
bool success;
- bool tmp_value = Args::StringToBoolean(option_arg, true, &success);
+ bool tmp_value = OptionArgParser::ToBoolean(option_arg, true, &success);
if (success)
auto_apply_fixits = tmp_value ? eLazyBoolYes : eLazyBoolNo;
else
Modified: lldb/trunk/source/Commands/CommandObjectLog.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectLog.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectLog.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectLog.cpp Tue Apr 10 02:03:59 2018
@@ -19,6 +19,7 @@
#include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/Options.h"
#include "lldb/Symbol/LineTable.h"
#include "lldb/Symbol/ObjectFile.h"
@@ -345,7 +346,7 @@ protected:
}
} else if (sub_command.equals_lower("increment")) {
bool success;
- bool increment = Args::StringToBoolean(param, false, &success);
+ bool increment = OptionArgParser::ToBoolean(param, false, &success);
if (success) {
Timer::SetQuiet(!increment);
result.SetStatus(eReturnStatusSuccessFinishNoResult);
Modified: lldb/trunk/source/Commands/CommandObjectMemory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMemory.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectMemory.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectMemory.cpp Tue Apr 10 02:03:59 2018
@@ -27,6 +27,7 @@
#include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionGroupFormat.h"
#include "lldb/Interpreter/OptionGroupOutputFile.h"
#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
@@ -590,8 +591,8 @@ protected:
}
if (argc > 0)
- addr = Args::StringToAddress(&m_exe_ctx, command[0].ref,
- LLDB_INVALID_ADDRESS, &error);
+ addr = OptionArgParser::ToAddress(&m_exe_ctx, command[0].ref,
+ LLDB_INVALID_ADDRESS, &error);
if (addr == LLDB_INVALID_ADDRESS) {
result.AppendError("invalid start address expression.");
@@ -601,7 +602,7 @@ protected:
}
if (argc == 2) {
- lldb::addr_t end_addr = Args::StringToAddress(
+ lldb::addr_t end_addr = OptionArgParser::ToAddress(
&m_exe_ctx, command[1].ref, LLDB_INVALID_ADDRESS, nullptr);
if (end_addr == LLDB_INVALID_ADDRESS) {
result.AppendError("invalid end address expression.");
@@ -1036,13 +1037,13 @@ protected:
}
Status error;
- lldb::addr_t low_addr = Args::StringToAddress(&m_exe_ctx, command[0].ref,
- LLDB_INVALID_ADDRESS, &error);
+ lldb::addr_t low_addr = OptionArgParser::ToAddress(
+ &m_exe_ctx, command[0].ref, LLDB_INVALID_ADDRESS, &error);
if (low_addr == LLDB_INVALID_ADDRESS || error.Fail()) {
result.AppendError("invalid low address");
return false;
}
- lldb::addr_t high_addr = Args::StringToAddress(
+ lldb::addr_t high_addr = OptionArgParser::ToAddress(
&m_exe_ctx, command[1].ref, LLDB_INVALID_ADDRESS, &error);
if (high_addr == LLDB_INVALID_ADDRESS || error.Fail()) {
result.AppendError("invalid high address");
@@ -1345,8 +1346,8 @@ protected:
size_t item_byte_size = byte_size_value.GetCurrentValue();
Status error;
- lldb::addr_t addr = Args::StringToAddress(&m_exe_ctx, command[0].ref,
- LLDB_INVALID_ADDRESS, &error);
+ lldb::addr_t addr = OptionArgParser::ToAddress(
+ &m_exe_ctx, command[0].ref, LLDB_INVALID_ADDRESS, &error);
if (addr == LLDB_INVALID_ADDRESS) {
result.AppendError("invalid address expression\n");
@@ -1469,7 +1470,7 @@ protected:
break;
}
case eFormatBoolean:
- uval64 = Args::StringToBoolean(entry.ref, false, &success);
+ uval64 = OptionArgParser::ToBoolean(entry.ref, false, &success);
if (!success) {
result.AppendErrorWithFormat(
"'%s' is not a valid boolean string value.\n", entry.c_str());
@@ -1642,8 +1643,8 @@ protected:
}
Status error;
- lldb::addr_t addr = Args::StringToAddress(&m_exe_ctx, command[0].ref,
- LLDB_INVALID_ADDRESS, &error);
+ lldb::addr_t addr = OptionArgParser::ToAddress(
+ &m_exe_ctx, command[0].ref, LLDB_INVALID_ADDRESS, &error);
if (addr == LLDB_INVALID_ADDRESS) {
result.AppendError("invalid address expression");
@@ -1711,8 +1712,8 @@ protected:
} else {
auto load_addr_str = command[0].ref;
if (command.GetArgumentCount() == 1) {
- load_addr = Args::StringToAddress(&m_exe_ctx, load_addr_str,
- LLDB_INVALID_ADDRESS, &error);
+ load_addr = OptionArgParser::ToAddress(&m_exe_ctx, load_addr_str,
+ LLDB_INVALID_ADDRESS, &error);
if (error.Fail() || load_addr == LLDB_INVALID_ADDRESS) {
result.AppendErrorWithFormat(
"invalid address argument \"%s\": %s\n", command[0].c_str(),
Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Tue Apr 10 02:03:59 2018
@@ -24,6 +24,7 @@
#include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/Options.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
@@ -756,7 +757,7 @@ public:
case 's':
bool tmp_result;
bool success;
- tmp_result = Args::StringToBoolean(option_arg, false, &success);
+ tmp_result = OptionArgParser::ToBoolean(option_arg, false, &success);
if (!success)
error.SetErrorStringWithFormat("invalid boolean option: \"%s\"",
option_arg.str().c_str());
@@ -1440,7 +1441,7 @@ public:
bool VerifyCommandOptionValue(const std::string &option, int &real_value) {
bool okay = true;
bool success = false;
- bool tmp_value = Args::StringToBoolean(option, false, &success);
+ bool tmp_value = OptionArgParser::ToBoolean(option, false, &success);
if (success && tmp_value)
real_value = 1;
Modified: lldb/trunk/source/Commands/CommandObjectSource.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectSource.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectSource.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectSource.cpp Tue Apr 10 02:03:59 2018
@@ -22,6 +22,7 @@
#include "lldb/Interpreter/CommandCompletions.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/Options.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/Function.h"
@@ -91,8 +92,8 @@ class CommandObjectSourceInfo : public C
break;
case 'a': {
- address = Args::StringToAddress(execution_context, option_arg,
- LLDB_INVALID_ADDRESS, &error);
+ address = OptionArgParser::ToAddress(execution_context, option_arg,
+ LLDB_INVALID_ADDRESS, &error);
} break;
case 's':
modules.push_back(std::string(option_arg));
@@ -709,8 +710,8 @@ class CommandObjectSourceList : public C
break;
case 'a': {
- address = Args::StringToAddress(execution_context, option_arg,
- LLDB_INVALID_ADDRESS, &error);
+ address = OptionArgParser::ToAddress(execution_context, option_arg,
+ LLDB_INVALID_ADDRESS, &error);
} break;
case 's':
modules.push_back(std::string(option_arg));
Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Tue Apr 10 02:03:59 2018
@@ -24,6 +24,7 @@
#include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionGroupArchitecture.h"
#include "lldb/Interpreter/OptionGroupBoolean.h"
#include "lldb/Interpreter/OptionGroupFile.h"
@@ -1983,7 +1984,7 @@ public:
switch (short_option) {
case 's':
- m_sort_order = (SortOrder)Args::StringToOptionEnum(
+ m_sort_order = (SortOrder)OptionArgParser::ToOptionEnum(
option_arg, GetDefinitions()[option_idx].enum_values,
eSortOrderNone, error);
break;
@@ -2885,8 +2886,8 @@ public:
if (short_option == 'g') {
m_use_global_module_list = true;
} else if (short_option == 'a') {
- m_module_addr = Args::StringToAddress(execution_context, option_arg,
- LLDB_INVALID_ADDRESS, &error);
+ m_module_addr = OptionArgParser::ToAddress(
+ execution_context, option_arg, LLDB_INVALID_ADDRESS, &error);
} else {
unsigned long width = 0;
option_arg.getAsInteger(0, width);
@@ -3251,8 +3252,8 @@ public:
case 'a': {
m_str = option_arg;
m_type = eLookupTypeAddress;
- m_addr = Args::StringToAddress(execution_context, option_arg,
- LLDB_INVALID_ADDRESS, &error);
+ m_addr = OptionArgParser::ToAddress(execution_context, option_arg,
+ LLDB_INVALID_ADDRESS, &error);
if (m_addr == LLDB_INVALID_ADDRESS)
error.SetErrorStringWithFormat("invalid address string '%s'",
option_arg.str().c_str());
@@ -3567,8 +3568,8 @@ public:
switch (short_option) {
case 'a': {
m_type = eLookupTypeAddress;
- m_addr = Args::StringToAddress(execution_context, option_arg,
- LLDB_INVALID_ADDRESS, &error);
+ m_addr = OptionArgParser::ToAddress(execution_context, option_arg,
+ LLDB_INVALID_ADDRESS, &error);
} break;
case 'o':
Modified: lldb/trunk/source/Commands/CommandObjectThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectThread.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectThread.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectThread.cpp Tue Apr 10 02:03:59 2018
@@ -21,6 +21,7 @@
#include "lldb/Host/StringConvert.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/Options.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/Function.h"
@@ -290,7 +291,7 @@ public:
case 'e': {
bool success;
m_extended_backtrace =
- Args::StringToBoolean(option_arg, false, &success);
+ OptionArgParser::ToBoolean(option_arg, false, &success);
if (!success)
error.SetErrorStringWithFormat(
"invalid boolean value for option '%c'", short_option);
@@ -447,7 +448,8 @@ public:
switch (short_option) {
case 'a': {
bool success;
- bool avoid_no_debug = Args::StringToBoolean(option_arg, true, &success);
+ bool avoid_no_debug =
+ OptionArgParser::ToBoolean(option_arg, true, &success);
if (!success)
error.SetErrorStringWithFormat(
"invalid boolean value for option '%c'", short_option);
@@ -459,7 +461,8 @@ public:
case 'A': {
bool success;
- bool avoid_no_debug = Args::StringToBoolean(option_arg, true, &success);
+ bool avoid_no_debug =
+ OptionArgParser::ToBoolean(option_arg, true, &success);
if (!success)
error.SetErrorStringWithFormat(
"invalid boolean value for option '%c'", short_option);
@@ -483,7 +486,7 @@ public:
case 'm': {
OptionEnumValueElement *enum_values =
GetDefinitions()[option_idx].enum_values;
- m_run_mode = (lldb::RunMode)Args::StringToOptionEnum(
+ m_run_mode = (lldb::RunMode)OptionArgParser::ToOptionEnum(
option_arg, enum_values, eOnlyDuringStepping, error);
} break;
@@ -1030,7 +1033,7 @@ public:
switch (short_option) {
case 'a': {
- lldb::addr_t tmp_addr = Args::StringToAddress(
+ lldb::addr_t tmp_addr = OptionArgParser::ToAddress(
execution_context, option_arg, LLDB_INVALID_ADDRESS, &error);
if (error.Success())
m_until_addrs.push_back(tmp_addr);
@@ -1052,7 +1055,7 @@ public:
case 'm': {
OptionEnumValueElement *enum_values =
GetDefinitions()[option_idx].enum_values;
- lldb::RunMode run_mode = (lldb::RunMode)Args::StringToOptionEnum(
+ lldb::RunMode run_mode = (lldb::RunMode)OptionArgParser::ToOptionEnum(
option_arg, enum_values, eOnlyDuringStepping, error);
if (error.Success()) {
@@ -1541,7 +1544,8 @@ public:
switch (short_option) {
case 'x': {
bool success;
- bool tmp_value = Args::StringToBoolean(option_arg, false, &success);
+ bool tmp_value =
+ OptionArgParser::ToBoolean(option_arg, false, &success);
if (success)
m_from_expression = tmp_value;
else {
@@ -1737,8 +1741,8 @@ public:
return Status("invalid line offset: '%s'.", option_arg.str().c_str());
break;
case 'a':
- m_load_addr = Args::StringToAddress(execution_context, option_arg,
- LLDB_INVALID_ADDRESS, &error);
+ m_load_addr = OptionArgParser::ToAddress(execution_context, option_arg,
+ LLDB_INVALID_ADDRESS, &error);
break;
case 'r':
m_force = true;
Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Tue Apr 10 02:03:59 2018
@@ -24,6 +24,7 @@
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandObject.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionGroupFormat.h"
#include "lldb/Interpreter/OptionValueBoolean.h"
#include "lldb/Interpreter/OptionValueLanguage.h"
@@ -329,7 +330,7 @@ private:
switch (short_option) {
case 'C':
- m_cascade = Args::StringToBoolean(option_arg, true, &success);
+ m_cascade = OptionArgParser::ToBoolean(option_arg, true, &success);
if (!success)
error.SetErrorStringWithFormat("invalid value for cascade: %s",
option_arg.str().c_str());
@@ -571,7 +572,7 @@ private:
switch (short_option) {
case 'C':
- m_cascade = Args::StringToBoolean(option_value, true, &success);
+ m_cascade = OptionArgParser::ToBoolean(option_value, true, &success);
if (!success)
error.SetErrorStringWithFormat("invalid value for cascade: %s",
option_value.str().c_str());
@@ -1252,7 +1253,7 @@ Status CommandObjectTypeSummaryAdd::Comm
switch (short_option) {
case 'C':
- m_flags.SetCascades(Args::StringToBoolean(option_arg, true, &success));
+ m_flags.SetCascades(OptionArgParser::ToBoolean(option_arg, true, &success));
if (!success)
error.SetErrorStringWithFormat("invalid value for cascade: %s",
option_arg.str().c_str());
@@ -2520,7 +2521,7 @@ private:
switch (short_option) {
case 'C':
- m_cascade = Args::StringToBoolean(option_arg, true, &success);
+ m_cascade = OptionArgParser::ToBoolean(option_arg, true, &success);
if (!success)
error.SetErrorStringWithFormat("invalid value for cascade: %s",
option_arg.str().c_str());
Modified: lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp Tue Apr 10 02:03:59 2018
@@ -22,6 +22,7 @@
#include "lldb/Host/OptionParser.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
@@ -331,7 +332,7 @@ are no syntax errors may indicate that a
break;
case 's':
- m_script_language = (lldb::ScriptLanguage)Args::StringToOptionEnum(
+ m_script_language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
option_arg, GetDefinitions()[option_idx].enum_values,
eScriptLanguageNone, error);
@@ -341,7 +342,8 @@ are no syntax errors may indicate that a
case 'e': {
bool success = false;
- m_stop_on_error = Args::StringToBoolean(option_arg, false, &success);
+ m_stop_on_error =
+ OptionArgParser::ToBoolean(option_arg, false, &success);
if (!success)
error.SetErrorStringWithFormat(
"invalid value for stop-on-error: \"%s\"",
Modified: lldb/trunk/source/Interpreter/Args.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Args.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Args.cpp (original)
+++ lldb/trunk/source/Interpreter/Args.cpp Tue Apr 10 02:03:59 2018
@@ -12,11 +12,12 @@
// C++ Includes
// Other libraries and framework includes
// Project includes
-#include "lldb/DataFormatters/FormatManager.h"
#include "lldb/Interpreter/Args.h"
-#include "lldb/Target/Target.h"
+#include "lldb/Interpreter/Options.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Stream.h"
-#include "lldb/Utility/StreamString.h"
+#include "lldb/Utility/StringList.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
@@ -401,121 +402,6 @@ void Args::Clear() {
m_argv.push_back(nullptr);
}
-lldb::addr_t Args::StringToAddress(const ExecutionContext *exe_ctx,
- llvm::StringRef s, lldb::addr_t fail_value,
- Status *error_ptr) {
- bool error_set = false;
- if (s.empty()) {
- if (error_ptr)
- error_ptr->SetErrorStringWithFormat("invalid address expression \"%s\"",
- s.str().c_str());
- return fail_value;
- }
-
- llvm::StringRef sref = s;
-
- lldb::addr_t addr = LLDB_INVALID_ADDRESS;
- if (!s.getAsInteger(0, addr)) {
- if (error_ptr)
- error_ptr->Clear();
- return addr;
- }
-
- // Try base 16 with no prefix...
- if (!s.getAsInteger(16, addr)) {
- if (error_ptr)
- error_ptr->Clear();
- return addr;
- }
-
- Target *target = nullptr;
- if (!exe_ctx || !(target = exe_ctx->GetTargetPtr())) {
- if (error_ptr)
- error_ptr->SetErrorStringWithFormat("invalid address expression \"%s\"",
- s.str().c_str());
- return fail_value;
- }
-
- lldb::ValueObjectSP valobj_sp;
- EvaluateExpressionOptions options;
- options.SetCoerceToId(false);
- options.SetUnwindOnError(true);
- options.SetKeepInMemory(false);
- options.SetTryAllThreads(true);
-
- ExpressionResults expr_result =
- target->EvaluateExpression(s, exe_ctx->GetFramePtr(), valobj_sp, options);
-
- bool success = false;
- if (expr_result == eExpressionCompleted) {
- if (valobj_sp)
- valobj_sp = valobj_sp->GetQualifiedRepresentationIfAvailable(
- valobj_sp->GetDynamicValueType(), true);
- // Get the address to watch.
- if (valobj_sp)
- addr = valobj_sp->GetValueAsUnsigned(fail_value, &success);
- if (success) {
- if (error_ptr)
- error_ptr->Clear();
- return addr;
- } else {
- if (error_ptr) {
- error_set = true;
- error_ptr->SetErrorStringWithFormat(
- "address expression \"%s\" resulted in a value whose type "
- "can't be converted to an address: %s",
- s.str().c_str(), valobj_sp->GetTypeName().GetCString());
- }
- }
-
- } else {
- // Since the compiler can't handle things like "main + 12" we should
- // try to do this for now. The compiler doesn't like adding offsets
- // to function pointer types.
- static RegularExpression g_symbol_plus_offset_regex(
- "^(.*)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*$");
- RegularExpression::Match regex_match(3);
- if (g_symbol_plus_offset_regex.Execute(sref, ®ex_match)) {
- uint64_t offset = 0;
- bool add = true;
- std::string name;
- std::string str;
- if (regex_match.GetMatchAtIndex(s, 1, name)) {
- if (regex_match.GetMatchAtIndex(s, 2, str)) {
- add = str[0] == '+';
-
- if (regex_match.GetMatchAtIndex(s, 3, str)) {
- if (!llvm::StringRef(str).getAsInteger(0, offset)) {
- Status error;
- addr = StringToAddress(exe_ctx, name.c_str(),
- LLDB_INVALID_ADDRESS, &error);
- if (addr != LLDB_INVALID_ADDRESS) {
- if (add)
- return addr + offset;
- else
- return addr - offset;
- }
- }
- }
- }
- }
- }
-
- if (error_ptr) {
- error_set = true;
- error_ptr->SetErrorStringWithFormat(
- "address expression \"%s\" evaluation failed", s.str().c_str());
- }
- }
-
- if (error_ptr) {
- if (!error_set)
- error_ptr->SetErrorStringWithFormat("invalid address expression \"%s\"",
- s.str().c_str());
- }
- return fail_value;
-}
-
const char *Args::StripSpaces(std::string &s, bool leading, bool trailing,
bool return_null_if_empty) {
static const char *k_white_space = " \t\v";
@@ -539,34 +425,6 @@ const char *Args::StripSpaces(std::strin
return s.c_str();
}
-bool Args::StringToBoolean(llvm::StringRef ref, bool fail_value,
- bool *success_ptr) {
- if (success_ptr)
- *success_ptr = true;
- ref = ref.trim();
- if (ref.equals_lower("false") || ref.equals_lower("off") ||
- ref.equals_lower("no") || ref.equals_lower("0")) {
- return false;
- } else if (ref.equals_lower("true") || ref.equals_lower("on") ||
- ref.equals_lower("yes") || ref.equals_lower("1")) {
- return true;
- }
- if (success_ptr)
- *success_ptr = false;
- return fail_value;
-}
-
-char Args::StringToChar(llvm::StringRef s, char fail_value, bool *success_ptr) {
- if (success_ptr)
- *success_ptr = false;
- if (s.size() != 1)
- return fail_value;
-
- if (success_ptr)
- *success_ptr = true;
- return s[0];
-}
-
bool Args::StringToVersion(llvm::StringRef string, uint32_t &major,
uint32_t &minor, uint32_t &update) {
major = UINT32_MAX;
@@ -628,98 +486,6 @@ const char *Args::GetShellSafeArgument(c
return safe_arg.c_str();
}
-int64_t Args::StringToOptionEnum(llvm::StringRef s,
- OptionEnumValueElement *enum_values,
- int32_t fail_value, Status &error) {
- error.Clear();
- if (!enum_values) {
- error.SetErrorString("invalid enumeration argument");
- return fail_value;
- }
-
- if (s.empty()) {
- error.SetErrorString("empty enumeration string");
- return fail_value;
- }
-
- for (int i = 0; enum_values[i].string_value != nullptr; i++) {
- llvm::StringRef this_enum(enum_values[i].string_value);
- if (this_enum.startswith(s))
- return enum_values[i].value;
- }
-
- StreamString strm;
- strm.PutCString("invalid enumeration value, valid values are: ");
- for (int i = 0; enum_values[i].string_value != nullptr; i++) {
- strm.Printf("%s\"%s\"", i > 0 ? ", " : "", enum_values[i].string_value);
- }
- error.SetErrorString(strm.GetString());
- return fail_value;
-}
-
-lldb::ScriptLanguage
-Args::StringToScriptLanguage(llvm::StringRef s, lldb::ScriptLanguage fail_value,
- bool *success_ptr) {
- if (success_ptr)
- *success_ptr = true;
-
- if (s.equals_lower("python"))
- return eScriptLanguagePython;
- if (s.equals_lower("default"))
- return eScriptLanguageDefault;
- if (s.equals_lower("none"))
- return eScriptLanguageNone;
-
- if (success_ptr)
- *success_ptr = false;
- return fail_value;
-}
-
-Status Args::StringToFormat(const char *s, lldb::Format &format,
- size_t *byte_size_ptr) {
- format = eFormatInvalid;
- Status error;
-
- if (s && s[0]) {
- if (byte_size_ptr) {
- if (isdigit(s[0])) {
- char *format_char = nullptr;
- unsigned long byte_size = ::strtoul(s, &format_char, 0);
- if (byte_size != ULONG_MAX)
- *byte_size_ptr = byte_size;
- s = format_char;
- } else
- *byte_size_ptr = 0;
- }
-
- const bool partial_match_ok = true;
- if (!FormatManager::GetFormatFromCString(s, partial_match_ok, format)) {
- StreamString error_strm;
- error_strm.Printf(
- "Invalid format character or name '%s'. Valid values are:\n", s);
- for (Format f = eFormatDefault; f < kNumFormats; f = Format(f + 1)) {
- char format_char = FormatManager::GetFormatAsFormatChar(f);
- if (format_char)
- error_strm.Printf("'%c' or ", format_char);
-
- error_strm.Printf("\"%s\"", FormatManager::GetFormatAsCString(f));
- error_strm.EOL();
- }
-
- if (byte_size_ptr)
- error_strm.PutCString(
- "An optional byte size can precede the format character.\n");
- error.SetErrorString(error_strm.GetString());
- }
-
- if (error.Fail())
- return error;
- } else {
- error.SetErrorStringWithFormat("%s option string", s ? "empty" : "invalid");
- }
- return error;
-}
-
lldb::Encoding Args::StringToEncoding(llvm::StringRef s,
lldb::Encoding fail_value) {
return llvm::StringSwitch<lldb::Encoding>(s)
Modified: lldb/trunk/source/Interpreter/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CMakeLists.txt?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CMakeLists.txt (original)
+++ lldb/trunk/source/Interpreter/CMakeLists.txt Tue Apr 10 02:03:59 2018
@@ -8,6 +8,7 @@ add_lldb_library(lldbInterpreter
CommandObjectScript.cpp
CommandOptionValidators.cpp
CommandReturnObject.cpp
+ OptionArgParser.cpp
OptionGroupArchitecture.cpp
OptionGroupBoolean.cpp
OptionGroupFile.cpp
Added: lldb/trunk/source/Interpreter/OptionArgParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionArgParser.cpp?rev=329677&view=auto
==============================================================================
--- lldb/trunk/source/Interpreter/OptionArgParser.cpp (added)
+++ lldb/trunk/source/Interpreter/OptionArgParser.cpp Tue Apr 10 02:03:59 2018
@@ -0,0 +1,253 @@
+//===-- OptionArgParser.cpp -------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Interpreter/OptionArgParser.h"
+#include "lldb/DataFormatters/FormatManager.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/StreamString.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+bool OptionArgParser::ToBoolean(llvm::StringRef ref, bool fail_value,
+ bool *success_ptr) {
+ if (success_ptr)
+ *success_ptr = true;
+ ref = ref.trim();
+ if (ref.equals_lower("false") || ref.equals_lower("off") ||
+ ref.equals_lower("no") || ref.equals_lower("0")) {
+ return false;
+ } else if (ref.equals_lower("true") || ref.equals_lower("on") ||
+ ref.equals_lower("yes") || ref.equals_lower("1")) {
+ return true;
+ }
+ if (success_ptr)
+ *success_ptr = false;
+ return fail_value;
+}
+
+char OptionArgParser::ToChar(llvm::StringRef s, char fail_value,
+ bool *success_ptr) {
+ if (success_ptr)
+ *success_ptr = false;
+ if (s.size() != 1)
+ return fail_value;
+
+ if (success_ptr)
+ *success_ptr = true;
+ return s[0];
+}
+
+int64_t OptionArgParser::ToOptionEnum(llvm::StringRef s,
+ OptionEnumValueElement *enum_values,
+ int32_t fail_value, Status &error) {
+ error.Clear();
+ if (!enum_values) {
+ error.SetErrorString("invalid enumeration argument");
+ return fail_value;
+ }
+
+ if (s.empty()) {
+ error.SetErrorString("empty enumeration string");
+ return fail_value;
+ }
+
+ for (int i = 0; enum_values[i].string_value != nullptr; i++) {
+ llvm::StringRef this_enum(enum_values[i].string_value);
+ if (this_enum.startswith(s))
+ return enum_values[i].value;
+ }
+
+ StreamString strm;
+ strm.PutCString("invalid enumeration value, valid values are: ");
+ for (int i = 0; enum_values[i].string_value != nullptr; i++) {
+ strm.Printf("%s\"%s\"", i > 0 ? ", " : "", enum_values[i].string_value);
+ }
+ error.SetErrorString(strm.GetString());
+ return fail_value;
+}
+
+Status OptionArgParser::ToFormat(const char *s, lldb::Format &format,
+ size_t *byte_size_ptr) {
+ format = eFormatInvalid;
+ Status error;
+
+ if (s && s[0]) {
+ if (byte_size_ptr) {
+ if (isdigit(s[0])) {
+ char *format_char = nullptr;
+ unsigned long byte_size = ::strtoul(s, &format_char, 0);
+ if (byte_size != ULONG_MAX)
+ *byte_size_ptr = byte_size;
+ s = format_char;
+ } else
+ *byte_size_ptr = 0;
+ }
+
+ const bool partial_match_ok = true;
+ if (!FormatManager::GetFormatFromCString(s, partial_match_ok, format)) {
+ StreamString error_strm;
+ error_strm.Printf(
+ "Invalid format character or name '%s'. Valid values are:\n", s);
+ for (Format f = eFormatDefault; f < kNumFormats; f = Format(f + 1)) {
+ char format_char = FormatManager::GetFormatAsFormatChar(f);
+ if (format_char)
+ error_strm.Printf("'%c' or ", format_char);
+
+ error_strm.Printf("\"%s\"", FormatManager::GetFormatAsCString(f));
+ error_strm.EOL();
+ }
+
+ if (byte_size_ptr)
+ error_strm.PutCString(
+ "An optional byte size can precede the format character.\n");
+ error.SetErrorString(error_strm.GetString());
+ }
+
+ if (error.Fail())
+ return error;
+ } else {
+ error.SetErrorStringWithFormat("%s option string", s ? "empty" : "invalid");
+ }
+ return error;
+}
+
+lldb::ScriptLanguage OptionArgParser::ToScriptLanguage(
+ llvm::StringRef s, lldb::ScriptLanguage fail_value, bool *success_ptr) {
+ if (success_ptr)
+ *success_ptr = true;
+
+ if (s.equals_lower("python"))
+ return eScriptLanguagePython;
+ if (s.equals_lower("default"))
+ return eScriptLanguageDefault;
+ if (s.equals_lower("none"))
+ return eScriptLanguageNone;
+
+ if (success_ptr)
+ *success_ptr = false;
+ return fail_value;
+}
+
+lldb::addr_t OptionArgParser::ToAddress(const ExecutionContext *exe_ctx,
+ llvm::StringRef s,
+ lldb::addr_t fail_value,
+ Status *error_ptr) {
+ bool error_set = false;
+ if (s.empty()) {
+ if (error_ptr)
+ error_ptr->SetErrorStringWithFormat("invalid address expression \"%s\"",
+ s.str().c_str());
+ return fail_value;
+ }
+
+ llvm::StringRef sref = s;
+
+ lldb::addr_t addr = LLDB_INVALID_ADDRESS;
+ if (!s.getAsInteger(0, addr)) {
+ if (error_ptr)
+ error_ptr->Clear();
+ return addr;
+ }
+
+ // Try base 16 with no prefix...
+ if (!s.getAsInteger(16, addr)) {
+ if (error_ptr)
+ error_ptr->Clear();
+ return addr;
+ }
+
+ Target *target = nullptr;
+ if (!exe_ctx || !(target = exe_ctx->GetTargetPtr())) {
+ if (error_ptr)
+ error_ptr->SetErrorStringWithFormat("invalid address expression \"%s\"",
+ s.str().c_str());
+ return fail_value;
+ }
+
+ lldb::ValueObjectSP valobj_sp;
+ EvaluateExpressionOptions options;
+ options.SetCoerceToId(false);
+ options.SetUnwindOnError(true);
+ options.SetKeepInMemory(false);
+ options.SetTryAllThreads(true);
+
+ ExpressionResults expr_result =
+ target->EvaluateExpression(s, exe_ctx->GetFramePtr(), valobj_sp, options);
+
+ bool success = false;
+ if (expr_result == eExpressionCompleted) {
+ if (valobj_sp)
+ valobj_sp = valobj_sp->GetQualifiedRepresentationIfAvailable(
+ valobj_sp->GetDynamicValueType(), true);
+ // Get the address to watch.
+ if (valobj_sp)
+ addr = valobj_sp->GetValueAsUnsigned(fail_value, &success);
+ if (success) {
+ if (error_ptr)
+ error_ptr->Clear();
+ return addr;
+ } else {
+ if (error_ptr) {
+ error_set = true;
+ error_ptr->SetErrorStringWithFormat(
+ "address expression \"%s\" resulted in a value whose type "
+ "can't be converted to an address: %s",
+ s.str().c_str(), valobj_sp->GetTypeName().GetCString());
+ }
+ }
+
+ } else {
+ // Since the compiler can't handle things like "main + 12" we should
+ // try to do this for now. The compiler doesn't like adding offsets
+ // to function pointer types.
+ static RegularExpression g_symbol_plus_offset_regex(
+ "^(.*)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*$");
+ RegularExpression::Match regex_match(3);
+ if (g_symbol_plus_offset_regex.Execute(sref, ®ex_match)) {
+ uint64_t offset = 0;
+ bool add = true;
+ std::string name;
+ std::string str;
+ if (regex_match.GetMatchAtIndex(s, 1, name)) {
+ if (regex_match.GetMatchAtIndex(s, 2, str)) {
+ add = str[0] == '+';
+
+ if (regex_match.GetMatchAtIndex(s, 3, str)) {
+ if (!llvm::StringRef(str).getAsInteger(0, offset)) {
+ Status error;
+ addr = ToAddress(exe_ctx, name.c_str(), LLDB_INVALID_ADDRESS,
+ &error);
+ if (addr != LLDB_INVALID_ADDRESS) {
+ if (add)
+ return addr + offset;
+ else
+ return addr - offset;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (error_ptr) {
+ error_set = true;
+ error_ptr->SetErrorStringWithFormat(
+ "address expression \"%s\" evaluation failed", s.str().c_str());
+ }
+ }
+
+ if (error_ptr) {
+ if (!error_set)
+ error_ptr->SetErrorStringWithFormat("invalid address expression \"%s\"",
+ s.str().c_str());
+ }
+ return fail_value;
+}
Modified: lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp Tue Apr 10 02:03:59 2018
@@ -16,6 +16,7 @@
#include "lldb/DataFormatters/ValueObjectPrinter.h"
#include "lldb/Host/OptionParser.h"
#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Target/Target.h"
#include "llvm/ADT/ArrayRef.h"
@@ -85,8 +86,8 @@ Status OptionGroupValueObjectDisplay::Se
switch (short_option) {
case 'd': {
int32_t result;
- result =
- Args::StringToOptionEnum(option_arg, g_dynamic_value_types, 2, error);
+ result = OptionArgParser::ToOptionEnum(option_arg, g_dynamic_value_types, 2,
+ error);
if (error.Success())
use_dynamic = (lldb::DynamicValueType)result;
} break;
@@ -144,14 +145,14 @@ Status OptionGroupValueObjectDisplay::Se
break;
case 'S':
- use_synth = Args::StringToBoolean(option_arg, true, &success);
+ use_synth = OptionArgParser::ToBoolean(option_arg, true, &success);
if (!success)
error.SetErrorStringWithFormat("invalid synthetic-type '%s'",
option_arg.str().c_str());
break;
case 'V':
- run_validator = Args::StringToBoolean(option_arg, true, &success);
+ run_validator = OptionArgParser::ToBoolean(option_arg, true, &success);
if (!success)
error.SetErrorStringWithFormat("invalid validate '%s'",
option_arg.str().c_str());
Modified: lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupWatchpoint.cpp Tue Apr 10 02:03:59 2018
@@ -14,7 +14,7 @@
// Other libraries and framework includes
// Project includes
#include "lldb/Host/OptionParser.h"
-#include "lldb/Interpreter/Args.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/lldb-enumerations.h"
using namespace lldb;
@@ -65,7 +65,7 @@ OptionGroupWatchpoint::SetOptionValue(ui
switch (short_option) {
case 'w': {
WatchType tmp_watch_type;
- tmp_watch_type = (WatchType)Args::StringToOptionEnum(
+ tmp_watch_type = (WatchType)OptionArgParser::ToOptionEnum(
option_arg, g_option_table[option_idx].enum_values, 0, error);
if (error.Success()) {
watch_type = tmp_watch_type;
@@ -74,7 +74,7 @@ OptionGroupWatchpoint::SetOptionValue(ui
break;
}
case 's':
- watch_size = (uint32_t)Args::StringToOptionEnum(
+ watch_size = (uint32_t)OptionArgParser::ToOptionEnum(
option_arg, g_option_table[option_idx].enum_values, 0, error);
break;
Modified: lldb/trunk/source/Interpreter/OptionValueBoolean.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueBoolean.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValueBoolean.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionValueBoolean.cpp Tue Apr 10 02:03:59 2018
@@ -14,7 +14,7 @@
// Other libraries and framework includes
// Project includes
#include "lldb/Host/PosixApi.h"
-#include "lldb/Interpreter/Args.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/StringList.h"
#include "llvm/ADT/STLExtras.h"
@@ -47,7 +47,7 @@ Status OptionValueBoolean::SetValueFromS
case eVarSetOperationReplace:
case eVarSetOperationAssign: {
bool success = false;
- bool value = Args::StringToBoolean(value_str, false, &success);
+ bool value = OptionArgParser::ToBoolean(value_str, false, &success);
if (success) {
m_value_was_set = true;
m_current_value = value;
Modified: lldb/trunk/source/Interpreter/OptionValueChar.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueChar.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValueChar.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionValueChar.cpp Tue Apr 10 02:03:59 2018
@@ -13,7 +13,7 @@
// C++ Includes
// Other libraries and framework includes
// Project includes
-#include "lldb/Interpreter/Args.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/StringList.h"
#include "llvm/ADT/STLExtras.h"
@@ -47,7 +47,7 @@ Status OptionValueChar::SetValueFromStri
case eVarSetOperationReplace:
case eVarSetOperationAssign: {
bool success = false;
- char char_value = Args::StringToChar(value, '\0', &success);
+ char char_value = OptionArgParser::ToChar(value, '\0', &success);
if (success) {
m_current_value = char_value;
m_value_was_set = true;
Modified: lldb/trunk/source/Interpreter/OptionValueFormat.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueFormat.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValueFormat.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionValueFormat.cpp Tue Apr 10 02:03:59 2018
@@ -14,7 +14,7 @@
// Other libraries and framework includes
// Project includes
#include "lldb/DataFormatters/FormatManager.h"
-#include "lldb/Interpreter/Args.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Utility/Stream.h"
using namespace lldb;
@@ -43,7 +43,7 @@ Status OptionValueFormat::SetValueFromSt
case eVarSetOperationReplace:
case eVarSetOperationAssign: {
Format new_format;
- error = Args::StringToFormat(value.str().c_str(), new_format, nullptr);
+ error = OptionArgParser::ToFormat(value.str().c_str(), new_format, nullptr);
if (error.Success()) {
m_value_was_set = true;
m_current_value = new_format;
Modified: lldb/trunk/source/Interpreter/Property.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Property.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Property.cpp (original)
+++ lldb/trunk/source/Interpreter/Property.cpp Tue Apr 10 02:03:59 2018
@@ -16,6 +16,7 @@
#include "lldb/Core/UserSettingsController.h"
#include "lldb/Host/StringConvert.h"
#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionValues.h"
#include "lldb/Target/Language.h"
@@ -53,7 +54,7 @@ Property::Property(const PropertyDefinit
// "definition.default_cstr_value" as a string value that represents the
// default value.
if (definition.default_cstr_value)
- m_value_sp.reset(new OptionValueBoolean(Args::StringToBoolean(
+ m_value_sp.reset(new OptionValueBoolean(OptionArgParser::ToBoolean(
llvm::StringRef(definition.default_cstr_value), false, nullptr)));
else
m_value_sp.reset(
@@ -62,7 +63,8 @@ Property::Property(const PropertyDefinit
case OptionValue::eTypeChar: {
llvm::StringRef s(definition.default_cstr_value ? definition.default_cstr_value : "");
- m_value_sp = std::make_shared<OptionValueChar>(Args::StringToChar(s, '\0', nullptr));
+ m_value_sp = std::make_shared<OptionValueChar>(
+ OptionArgParser::ToChar(s, '\0', nullptr));
break;
}
case OptionValue::eTypeDictionary:
@@ -123,8 +125,8 @@ Property::Property(const PropertyDefinit
{
Format new_format = eFormatInvalid;
if (definition.default_cstr_value)
- Args::StringToFormat(definition.default_cstr_value, new_format,
- nullptr);
+ OptionArgParser::ToFormat(definition.default_cstr_value, new_format,
+ nullptr);
else
new_format = (Format)definition.default_uint_value;
m_value_sp.reset(new OptionValueFormat(new_format));
Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Tue Apr 10 02:03:59 2018
@@ -37,6 +37,7 @@
#include "lldb/Interpreter/CommandObject.h"
#include "lldb/Interpreter/CommandObjectMultiword.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionValueBoolean.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/ObjectFile.h"
@@ -682,7 +683,7 @@ protected:
if (!arg_str)
continue;
Status error;
- lldb::addr_t arg_addr = Args::StringToAddress(
+ lldb::addr_t arg_addr = OptionArgParser::ToAddress(
&exe_ctx, arg_str, LLDB_INVALID_ADDRESS, &error);
if (arg_addr == 0 || arg_addr == LLDB_INVALID_ADDRESS || error.Fail())
continue;
Modified: lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp Tue Apr 10 02:03:59 2018
@@ -12,6 +12,7 @@
#include "lldb/Core/StreamFile.h"
#include "lldb/DataFormatters/FormatManager.h"
#include "lldb/Host/StringConvert.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/RegularExpression.h"
#include "lldb/Utility/StringExtractor.h"
@@ -283,7 +284,8 @@ DynamicRegisterInfo::SetRegisterInfo(con
llvm::StringRef format_str;
if (reg_info_dict->GetValueForKeyAsString("format", format_str, nullptr)) {
- if (Args::StringToFormat(format_str.str().c_str(), reg_info.format, NULL)
+ if (OptionArgParser::ToFormat(format_str.str().c_str(), reg_info.format,
+ NULL)
.Fail()) {
Clear();
printf("error: invalid 'format' value in register dictionary\n");
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp Tue Apr 10 02:03:59 2018
@@ -28,7 +28,7 @@
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
-#include "lldb/Interpreter/Args.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/FileAction.h"
#include "lldb/Target/Platform.h"
@@ -405,7 +405,7 @@ GDBRemoteCommunicationServerCommon::Hand
match_info.GetProcessInfo().SetEffectiveGroupID(gid);
} else if (key.equals("all_users")) {
match_info.SetMatchAllUsers(
- Args::StringToBoolean(value, false, &success));
+ OptionArgParser::ToBoolean(value, false, &success));
} else if (key.equals("triple")) {
match_info.GetProcessInfo().GetArchitecture() =
HostInfo::GetAugmentedArchSpec(value);
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Tue Apr 10 02:03:59 2018
@@ -52,6 +52,7 @@
#include "lldb/Interpreter/CommandObject.h"
#include "lldb/Interpreter/CommandObjectMultiword.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionGroupBoolean.h"
#include "lldb/Interpreter/OptionGroupUInt64.h"
#include "lldb/Interpreter/OptionValueProperties.h"
@@ -534,7 +535,7 @@ void ProcessGDBRemote::BuildDynamicRegis
reg_info.encoding = encoding;
} else if (name.equals("format")) {
Format format = eFormatInvalid;
- if (Args::StringToFormat(value.str().c_str(), format, NULL)
+ if (OptionArgParser::ToFormat(value.str().c_str(), format, NULL)
.Success())
reg_info.format = format;
else {
@@ -4388,7 +4389,7 @@ bool ParseRegisters(XMLNode feature_node
} else if (name == "format") {
format_set = true;
Format format = eFormatInvalid;
- if (Args::StringToFormat(value.data(), format, NULL).Success())
+ if (OptionArgParser::ToFormat(value.data(), format, NULL).Success())
reg_info.format = format;
else if (value == "vector-sint8")
reg_info.format = eFormatVectorOfSInt8;
Modified: lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp (original)
+++ lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp Tue Apr 10 02:03:59 2018
@@ -23,6 +23,7 @@
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandObjectMultiword.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionValueProperties.h"
#include "lldb/Interpreter/OptionValueString.h"
#include "lldb/Interpreter/Property.h"
@@ -544,7 +545,8 @@ public:
break;
case 'b':
- m_broadcast_events = Args::StringToBoolean(option_arg, true, nullptr);
+ m_broadcast_events =
+ OptionArgParser::ToBoolean(option_arg, true, nullptr);
break;
case 'c':
@@ -560,7 +562,7 @@ public:
break;
case 'e':
- m_echo_to_stderr = Args::StringToBoolean(option_arg, false, nullptr);
+ m_echo_to_stderr = OptionArgParser::ToBoolean(option_arg, false, nullptr);
break;
case 'f':
@@ -571,12 +573,12 @@ public:
break;
case 'l':
- m_live_stream = Args::StringToBoolean(option_arg, false, nullptr);
+ m_live_stream = OptionArgParser::ToBoolean(option_arg, false, nullptr);
break;
case 'n':
m_filter_fall_through_accepts =
- Args::StringToBoolean(option_arg, true, nullptr);
+ OptionArgParser::ToBoolean(option_arg, true, nullptr);
break;
case 'r':
Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Tue Apr 10 02:03:59 2018
@@ -39,6 +39,7 @@
#include "lldb/Host/Terminal.h"
#include "lldb/Host/ThreadLauncher.h"
#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionValueProperties.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/Symbol.h"
@@ -489,7 +490,7 @@ Status ProcessLaunchCommandOptions::SetO
{
bool success;
const bool disable_aslr_arg =
- Args::StringToBoolean(option_arg, true, &success);
+ OptionArgParser::ToBoolean(option_arg, true, &success);
if (success)
disable_aslr = disable_aslr_arg ? eLazyBoolYes : eLazyBoolNo;
else
@@ -502,7 +503,8 @@ Status ProcessLaunchCommandOptions::SetO
case 'X': // shell expand args.
{
bool success;
- const bool expand_args = Args::StringToBoolean(option_arg, true, &success);
+ const bool expand_args =
+ OptionArgParser::ToBoolean(option_arg, true, &success);
if (success)
launch_info.SetShellExpandArguments(expand_args);
else
Modified: lldb/trunk/unittests/Interpreter/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Interpreter/CMakeLists.txt?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/unittests/Interpreter/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Interpreter/CMakeLists.txt Tue Apr 10 02:03:59 2018
@@ -1,6 +1,7 @@
add_lldb_unittest(InterpreterTests
TestArgs.cpp
TestCompletion.cpp
+ TestOptionArgParser.cpp
LINK_LIBS
lldbInterpreter
Modified: lldb/trunk/unittests/Interpreter/TestArgs.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Interpreter/TestArgs.cpp?rev=329677&r1=329676&r2=329677&view=diff
==============================================================================
--- lldb/trunk/unittests/Interpreter/TestArgs.cpp (original)
+++ lldb/trunk/unittests/Interpreter/TestArgs.cpp Tue Apr 10 02:03:59 2018
@@ -187,92 +187,3 @@ TEST(ArgsTest, GetArgumentArrayRef) {
EXPECT_STREQ("foo", ref[0]);
EXPECT_STREQ("bar", ref[1]);
}
-
-TEST(ArgsTest, StringToBoolean) {
- bool success = false;
- EXPECT_TRUE(Args::StringToBoolean(llvm::StringRef("true"), false, nullptr));
- EXPECT_TRUE(Args::StringToBoolean(llvm::StringRef("on"), false, nullptr));
- EXPECT_TRUE(Args::StringToBoolean(llvm::StringRef("yes"), false, nullptr));
- EXPECT_TRUE(Args::StringToBoolean(llvm::StringRef("1"), false, nullptr));
-
- EXPECT_TRUE(Args::StringToBoolean(llvm::StringRef("true"), false, &success));
- EXPECT_TRUE(success);
- EXPECT_TRUE(Args::StringToBoolean(llvm::StringRef("on"), false, &success));
- EXPECT_TRUE(success);
- EXPECT_TRUE(Args::StringToBoolean(llvm::StringRef("yes"), false, &success));
- EXPECT_TRUE(success);
- EXPECT_TRUE(Args::StringToBoolean(llvm::StringRef("1"), false, &success));
- EXPECT_TRUE(success);
-
- EXPECT_FALSE(Args::StringToBoolean(llvm::StringRef("false"), true, nullptr));
- EXPECT_FALSE(Args::StringToBoolean(llvm::StringRef("off"), true, nullptr));
- EXPECT_FALSE(Args::StringToBoolean(llvm::StringRef("no"), true, nullptr));
- EXPECT_FALSE(Args::StringToBoolean(llvm::StringRef("0"), true, nullptr));
-
- EXPECT_FALSE(Args::StringToBoolean(llvm::StringRef("false"), true, &success));
- EXPECT_TRUE(success);
- EXPECT_FALSE(Args::StringToBoolean(llvm::StringRef("off"), true, &success));
- EXPECT_TRUE(success);
- EXPECT_FALSE(Args::StringToBoolean(llvm::StringRef("no"), true, &success));
- EXPECT_TRUE(success);
- EXPECT_FALSE(Args::StringToBoolean(llvm::StringRef("0"), true, &success));
- EXPECT_TRUE(success);
-
- EXPECT_FALSE(Args::StringToBoolean(llvm::StringRef("10"), false, &success));
- EXPECT_FALSE(success);
- EXPECT_TRUE(Args::StringToBoolean(llvm::StringRef("10"), true, &success));
- EXPECT_FALSE(success);
- EXPECT_TRUE(Args::StringToBoolean(llvm::StringRef(""), true, &success));
- EXPECT_FALSE(success);
-}
-
-TEST(ArgsTest, StringToChar) {
- bool success = false;
-
- EXPECT_EQ('A', Args::StringToChar("A", 'B', nullptr));
- EXPECT_EQ('B', Args::StringToChar("B", 'A', nullptr));
-
- EXPECT_EQ('A', Args::StringToChar("A", 'B', &success));
- EXPECT_TRUE(success);
- EXPECT_EQ('B', Args::StringToChar("B", 'A', &success));
- EXPECT_TRUE(success);
-
- EXPECT_EQ('A', Args::StringToChar("", 'A', &success));
- EXPECT_FALSE(success);
- EXPECT_EQ('A', Args::StringToChar("ABC", 'A', &success));
- EXPECT_FALSE(success);
-}
-
-TEST(ArgsTest, StringToScriptLanguage) {
- bool success = false;
-
- EXPECT_EQ(lldb::eScriptLanguageDefault,
- Args::StringToScriptLanguage(llvm::StringRef("default"),
- lldb::eScriptLanguageNone, nullptr));
- EXPECT_EQ(lldb::eScriptLanguagePython,
- Args::StringToScriptLanguage(llvm::StringRef("python"),
- lldb::eScriptLanguageNone, nullptr));
- EXPECT_EQ(lldb::eScriptLanguageNone,
- Args::StringToScriptLanguage(llvm::StringRef("none"),
- lldb::eScriptLanguagePython, nullptr));
-
- EXPECT_EQ(lldb::eScriptLanguageDefault,
- Args::StringToScriptLanguage(llvm::StringRef("default"),
- lldb::eScriptLanguageNone, &success));
- EXPECT_TRUE(success);
- EXPECT_EQ(lldb::eScriptLanguagePython,
- Args::StringToScriptLanguage(llvm::StringRef("python"),
- lldb::eScriptLanguageNone, &success));
- EXPECT_TRUE(success);
- EXPECT_EQ(lldb::eScriptLanguageNone,
- Args::StringToScriptLanguage(llvm::StringRef("none"),
- lldb::eScriptLanguagePython,
- &success));
- EXPECT_TRUE(success);
-
- EXPECT_EQ(lldb::eScriptLanguagePython,
- Args::StringToScriptLanguage(llvm::StringRef("invalid"),
- lldb::eScriptLanguagePython,
- &success));
- EXPECT_FALSE(success);
-}
Added: lldb/trunk/unittests/Interpreter/TestOptionArgParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Interpreter/TestOptionArgParser.cpp?rev=329677&view=auto
==============================================================================
--- lldb/trunk/unittests/Interpreter/TestOptionArgParser.cpp (added)
+++ lldb/trunk/unittests/Interpreter/TestOptionArgParser.cpp Tue Apr 10 02:03:59 2018
@@ -0,0 +1,121 @@
+//===-- ArgsTest.cpp --------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "lldb/Interpreter/OptionArgParser.h"
+
+using namespace lldb_private;
+
+TEST(OptionArgParserTest, toBoolean) {
+ bool success = false;
+ EXPECT_TRUE(
+ OptionArgParser::ToBoolean(llvm::StringRef("true"), false, nullptr));
+ EXPECT_TRUE(
+ OptionArgParser::ToBoolean(llvm::StringRef("on"), false, nullptr));
+ EXPECT_TRUE(
+ OptionArgParser::ToBoolean(llvm::StringRef("yes"), false, nullptr));
+ EXPECT_TRUE(OptionArgParser::ToBoolean(llvm::StringRef("1"), false, nullptr));
+
+ EXPECT_TRUE(
+ OptionArgParser::ToBoolean(llvm::StringRef("true"), false, &success));
+ EXPECT_TRUE(success);
+ EXPECT_TRUE(
+ OptionArgParser::ToBoolean(llvm::StringRef("on"), false, &success));
+ EXPECT_TRUE(success);
+ EXPECT_TRUE(
+ OptionArgParser::ToBoolean(llvm::StringRef("yes"), false, &success));
+ EXPECT_TRUE(success);
+ EXPECT_TRUE(
+ OptionArgParser::ToBoolean(llvm::StringRef("1"), false, &success));
+ EXPECT_TRUE(success);
+
+ EXPECT_FALSE(
+ OptionArgParser::ToBoolean(llvm::StringRef("false"), true, nullptr));
+ EXPECT_FALSE(
+ OptionArgParser::ToBoolean(llvm::StringRef("off"), true, nullptr));
+ EXPECT_FALSE(
+ OptionArgParser::ToBoolean(llvm::StringRef("no"), true, nullptr));
+ EXPECT_FALSE(OptionArgParser::ToBoolean(llvm::StringRef("0"), true, nullptr));
+
+ EXPECT_FALSE(
+ OptionArgParser::ToBoolean(llvm::StringRef("false"), true, &success));
+ EXPECT_TRUE(success);
+ EXPECT_FALSE(
+ OptionArgParser::ToBoolean(llvm::StringRef("off"), true, &success));
+ EXPECT_TRUE(success);
+ EXPECT_FALSE(
+ OptionArgParser::ToBoolean(llvm::StringRef("no"), true, &success));
+ EXPECT_TRUE(success);
+ EXPECT_FALSE(
+ OptionArgParser::ToBoolean(llvm::StringRef("0"), true, &success));
+ EXPECT_TRUE(success);
+
+ EXPECT_FALSE(
+ OptionArgParser::ToBoolean(llvm::StringRef("10"), false, &success));
+ EXPECT_FALSE(success);
+ EXPECT_TRUE(
+ OptionArgParser::ToBoolean(llvm::StringRef("10"), true, &success));
+ EXPECT_FALSE(success);
+ EXPECT_TRUE(OptionArgParser::ToBoolean(llvm::StringRef(""), true, &success));
+ EXPECT_FALSE(success);
+}
+
+TEST(OptionArgParserTest, toChar) {
+ bool success = false;
+
+ EXPECT_EQ('A', OptionArgParser::ToChar("A", 'B', nullptr));
+ EXPECT_EQ('B', OptionArgParser::ToChar("B", 'A', nullptr));
+
+ EXPECT_EQ('A', OptionArgParser::ToChar("A", 'B', &success));
+ EXPECT_TRUE(success);
+ EXPECT_EQ('B', OptionArgParser::ToChar("B", 'A', &success));
+ EXPECT_TRUE(success);
+
+ EXPECT_EQ('A', OptionArgParser::ToChar("", 'A', &success));
+ EXPECT_FALSE(success);
+ EXPECT_EQ('A', OptionArgParser::ToChar("ABC", 'A', &success));
+ EXPECT_FALSE(success);
+}
+
+TEST(OptionArgParserTest, toScriptLanguage) {
+ bool success = false;
+
+ EXPECT_EQ(lldb::eScriptLanguageDefault,
+ OptionArgParser::ToScriptLanguage(llvm::StringRef("default"),
+ lldb::eScriptLanguageNone,
+ nullptr));
+ EXPECT_EQ(lldb::eScriptLanguagePython,
+ OptionArgParser::ToScriptLanguage(
+ llvm::StringRef("python"), lldb::eScriptLanguageNone, nullptr));
+ EXPECT_EQ(lldb::eScriptLanguageNone,
+ OptionArgParser::ToScriptLanguage(
+ llvm::StringRef("none"), lldb::eScriptLanguagePython, nullptr));
+
+ EXPECT_EQ(lldb::eScriptLanguageDefault,
+ OptionArgParser::ToScriptLanguage(llvm::StringRef("default"),
+ lldb::eScriptLanguageNone,
+ &success));
+ EXPECT_TRUE(success);
+ EXPECT_EQ(lldb::eScriptLanguagePython,
+ OptionArgParser::ToScriptLanguage(llvm::StringRef("python"),
+ lldb::eScriptLanguageNone,
+ &success));
+ EXPECT_TRUE(success);
+ EXPECT_EQ(lldb::eScriptLanguageNone,
+ OptionArgParser::ToScriptLanguage(llvm::StringRef("none"),
+ lldb::eScriptLanguagePython,
+ &success));
+ EXPECT_TRUE(success);
+
+ EXPECT_EQ(lldb::eScriptLanguagePython,
+ OptionArgParser::ToScriptLanguage(llvm::StringRef("invalid"),
+ lldb::eScriptLanguagePython,
+ &success));
+ EXPECT_FALSE(success);
+}
More information about the lldb-commits
mailing list