summaryrefslogtreecommitdiffstats
path: root/lldb/tools/lldb-mi/MICmdArgValString.cpp
diff options
context:
space:
mode:
authorIlia K <ki.stfu@gmail.com>2015-02-26 18:21:22 +0000
committerIlia K <ki.stfu@gmail.com>2015-02-26 18:21:22 +0000
commit69b95f49f1f093ef58d638a9366aabfbfdae7827 (patch)
tree9c79ea4144e2c4ffc8250de6794ac40e465670cd /lldb/tools/lldb-mi/MICmdArgValString.cpp
parentd55ae6ba37b158a254d87d7ad8511392b7dadb43 (diff)
downloadbcm5719-llvm-69b95f49f1f093ef58d638a9366aabfbfdae7827.tar.gz
bcm5719-llvm-69b95f49f1f093ef58d638a9366aabfbfdae7827.zip
Fix handling of double quotes (MI)
Summary: * Clean CMICmdArgValString::Validate: now it's based on CMIUtilString::SplitConsiderQuotes method: A bit of introduction: # Command line is wrapped into CMICmdArgContext. # CMICmdArgSet is a set of arguments to be parsed. This class contains CMICmdArgContext as a private member. # MI command is class which is inhereted from CMICmdBase. It contains CMICmdArgSet as a private member. When command is executed CMICmdBase::ParseArgs() is called. This method adds args for parsing using CMICmdArgSet::Add(). Then CMICmdBase::ParseValidateCmdOptions() is called, which calls CMICmdArgSet::Validate(). Then it gets a number of arguments (using SplitConsiderQuotes().array_length) and for each arguments registered in ParseArgs() tries to validate it using CMICmdArgValBase::Validate(). Every user commands parses this string again (first time it was made in SplitConsiderQuotes) and in case of CMICmdArgValString it was made incorrectly. It searches the first and last quotes (but it should be first and next after first). Besides, it was splitted into 4 cases. I'm just using SplitConsiderQuotes directly, and I don't split them by hand again. Actually, I think we should do so in every CMICmdArgVal_XXX::Validate() method. * Enable MiInterpreterExecTestCase.test_lldbmi_target_create test * Fix MiExecTestCase.test_lldbmi_exec_arguments_set test All tests pass on OS X. Reviewers: abidh, emaste, zturner, clayborg Reviewed By: clayborg Subscribers: lldb-commits, zturner, emaste, clayborg, abidh Differential Revision: http://reviews.llvm.org/D7860 llvm-svn: 230654
Diffstat (limited to 'lldb/tools/lldb-mi/MICmdArgValString.cpp')
-rw-r--r--lldb/tools/lldb-mi/MICmdArgValString.cpp176
1 files changed, 16 insertions, 160 deletions
diff --git a/lldb/tools/lldb-mi/MICmdArgValString.cpp b/lldb/tools/lldb-mi/MICmdArgValString.cpp
index c09eead072d..eead6600b8e 100644
--- a/lldb/tools/lldb-mi/MICmdArgValString.cpp
+++ b/lldb/tools/lldb-mi/MICmdArgValString.cpp
@@ -46,7 +46,7 @@ CMICmdArgValString::CMICmdArgValString(void)
// Throws: None.
//--
CMICmdArgValString::CMICmdArgValString(const bool vbAnything)
- : m_bHandleQuotedString(false)
+ : m_bHandleQuotedString(vbAnything ? true : false)
, m_bAcceptNumbers(false)
, m_bHandleDirPaths(false)
, m_bHandleAnything(vbAnything)
@@ -123,7 +123,7 @@ CMICmdArgValString::Validate(CMICmdArgContext &vrwArgContext)
return MIstatus::success;
if (m_bHandleQuotedString)
- return (ValidateQuotedText(vrwArgContext) || ValidateQuotedTextEmbedded(vrwArgContext));
+ return ValidateQuotedText(vrwArgContext);
return ValidateSingleText(vrwArgContext);
}
@@ -140,22 +140,6 @@ CMICmdArgValString::Validate(CMICmdArgContext &vrwArgContext)
bool
CMICmdArgValString::ValidateSingleText(CMICmdArgContext &vrwArgContext)
{
- if (vrwArgContext.GetNumberArgsPresent() == 1)
- {
- const CMIUtilString &rArg(vrwArgContext.GetArgsLeftToParse());
- if (IsStringArg(rArg))
- {
- m_bFound = true;
- m_bValid = true;
- m_argValue = rArg;
- vrwArgContext.RemoveArg(rArg);
- return MIstatus::success;
- }
- else
- return MIstatus::failure;
- }
-
- // More than one option...
const CMIUtilString::VecString_t vecOptions(vrwArgContext.GetArgs());
CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
while (it != vecOptions.end())
@@ -168,7 +152,7 @@ CMICmdArgValString::ValidateSingleText(CMICmdArgContext &vrwArgContext)
if (vrwArgContext.RemoveArg(rArg))
{
m_bValid = true;
- m_argValue = rArg;
+ m_argValue = rArg.StripSlashes();
return MIstatus::success;
}
else
@@ -184,8 +168,7 @@ CMICmdArgValString::ValidateSingleText(CMICmdArgContext &vrwArgContext)
//++ ------------------------------------------------------------------------------------
// Details: Parse the command's argument options string and try to extract all the words
-// between quotes then delimited by the next space. Can fall through to
-// ValidateSingleText() or ValidateQuotedQuotedTextEmbedded().
+// between quotes then delimited by the next space.
// Type: Method.
// Args: vrwArgContext - (RW) The command's argument options string.
// Return: MIstatus::success - Functional succeeded.
@@ -195,148 +178,21 @@ CMICmdArgValString::ValidateSingleText(CMICmdArgContext &vrwArgContext)
bool
CMICmdArgValString::ValidateQuotedText(CMICmdArgContext &vrwArgContext)
{
- // CODETAG_QUOTEDTEXT_SIMILAR_CODE
- CMIUtilString strOptions = vrwArgContext.GetArgsLeftToParse();
- const MIchar cQuote = '"';
-
- // Look for first quote of two
- MIint nPos = strOptions.find(cQuote);
- if (nPos == (MIint)std::string::npos)
- return ValidateSingleText(vrwArgContext);
-
- // Is one and only quote at end of the string
- const MIint nLen = strOptions.length();
- if (nPos == (MIint)(nLen - 1))
- return MIstatus::failure;
-
- // Quote must be the first character in the string or be preceeded by a space
- if ((nPos > 0) && (strOptions[nPos - 1] != ' '))
- return MIstatus::failure;
-
- // Need to find the other quote
- const MIint nPos2 = strOptions.rfind(cQuote);
- if (nPos2 == (MIint)std::string::npos)
- return MIstatus::failure;
-
- // Is there quotes surrounding string formatting embedded quotes
- if (IsStringArgQuotedQuotedTextEmbedded(strOptions))
- return ValidateQuotedQuotedTextEmbedded(vrwArgContext);
-
- // Make sure not same back quote, need two quotes
- if (nPos == nPos2)
- return MIstatus::failure;
-
- // Extract quoted text
- const CMIUtilString strQuotedTxt = strOptions.substr(nPos, nPos2 - nPos + 1).c_str();
- if (vrwArgContext.RemoveArg(strQuotedTxt))
- {
- m_bFound = true;
- m_bValid = true;
- m_argValue = strOptions.substr(nPos + 1, nPos2 - nPos - 1).c_str();
- return MIstatus::success;
- }
-
- return MIstatus::failure;
-}
-
-//++ ------------------------------------------------------------------------------------
-// Details: Parse the command's argument options string and try to extract all the words
-// between quotes then delimited by the next space. If there any string format
-// characters '\\' used to embed quotes these are ignored i.e. "\\\"%5d\\\""
-// becomes "%5d". Can fall through to ValidateQuotedText().
-// Type: Method.
-// Args: vrwArgContext - (RW) The command's argument options string.
-// Return: MIstatus::success - Functional succeeded.
-// MIstatus::failure - Functional failed.
-// Throws: None.
-//--
-bool
-CMICmdArgValString::ValidateQuotedTextEmbedded(CMICmdArgContext &vrwArgContext)
-{
- // CODETAG_QUOTEDTEXT_SIMILAR_CODE
- CMIUtilString strOptions = vrwArgContext.GetArgsLeftToParse();
- const MIchar cBckSlash = '\\';
- const MIint nPos = strOptions.find(cBckSlash);
- if (nPos == (MIint)std::string::npos)
- return ValidateQuotedText(vrwArgContext);
-
- // Back slash must be the first character in the string or be preceeded by a space
- // or '\\'
- const MIchar cSpace = ' ';
- if ((nPos > 0) && (strOptions[nPos - 1] != cSpace))
- return MIstatus::failure;
-
- // Need to find the other back slash
- const MIint nPos2 = strOptions.rfind(cBckSlash);
- if (nPos2 == (MIint)std::string::npos)
- return MIstatus::failure;
-
- // Make sure not same back slash, need two slashs
- if (nPos == nPos2)
- return MIstatus::failure;
-
- // Look for the two quotes
- const MIint nLen = strOptions.length();
- const MIchar cQuote = '"';
- const MIint nPosQuote1 = nPos + 1;
- const MIint nPosQuote2 = (nPos2 < nLen) ? nPos2 + 1 : nPos2;
- if ((nPosQuote1 != nPosQuote2) && (strOptions[nPosQuote1] != cQuote) && (strOptions[nPosQuote2] != cQuote))
- return MIstatus::failure;
-
- // Extract quoted text
- const CMIUtilString strQuotedTxt = strOptions.substr(nPos, nPosQuote2 - nPos + 1).c_str();
- if (vrwArgContext.RemoveArg(strQuotedTxt))
- {
- m_bFound = true;
- m_bValid = true;
- m_argValue = strQuotedTxt;
- return MIstatus::success;
- }
-
- return MIstatus::failure;
-}
-
-//++ ------------------------------------------------------------------------------------
-// Details: Parse the command's argument options string and try to extract all the words
-// between quotes then delimited by the next space. If there any string format
-// characters '\\' used to embed quotes these are ignored i.e. "\\\"%5d\\\""
-// becomes "%5d".
-// Type: Method.
-// Args: vrwArgContext - (RW) The command's argument options string.
-// Return: MIstatus::success - Functional succeeded.
-// MIstatus::failure - Functional failed.
-// Throws: None.
-//--
-bool
-CMICmdArgValString::ValidateQuotedQuotedTextEmbedded(CMICmdArgContext &vrwArgContext)
-{
- // CODETAG_QUOTEDTEXT_SIMILAR_CODE
- CMIUtilString strOptions = vrwArgContext.GetArgsLeftToParse();
- const MIint nPos = strOptions.find("\"\\\"");
- if (nPos == (MIint)std::string::npos)
+ const CMIUtilString::VecString_t vecOptions(vrwArgContext.GetArgs());
+ if (vecOptions.size() == 0)
return MIstatus::failure;
- const MIint nPos2 = strOptions.rfind("\\\"\"");
- if (nPos2 == (MIint)std::string::npos)
+ const CMIUtilString &rArg(vecOptions[0]);
+ if (!IsStringArg(rArg))
return MIstatus::failure;
- const MIint nLen = strOptions.length();
- if ((nLen > 5) && ((nPos + 2) == (nPos2 - 2)))
- return MIstatus::failure;
+ m_bFound = true;
- // Quote must be the first character in the string or be preceeded by a space
- // or '\\'
- const MIchar cSpace = ' ';
- if ((nPos > 0) && (strOptions[nPos - 1] != cSpace))
- return MIstatus::failure;
-
- // Extract quoted text
- const CMIUtilString strQuotedTxt = strOptions.substr(nPos, nPos2 - nPos + 3).c_str();
- if (vrwArgContext.RemoveArg(strQuotedTxt))
+ if (vrwArgContext.RemoveArg(rArg))
{
- m_bFound = true;
m_bValid = true;
- m_argValue = strQuotedTxt;
+ const MIchar cQuote = '"';
+ m_argValue = rArg.Trim(cQuote).StripSlashes();
return MIstatus::success;
}
@@ -373,10 +229,6 @@ CMICmdArgValString::IsStringArg(const CMIUtilString &vrTxt) const
bool
CMICmdArgValString::IsStringArgSingleText(const CMIUtilString &vrTxt) const
{
- // Accept anything as string word
- if (m_bHandleAnything)
- return true;
-
if (!m_bHandleDirPaths)
{
// Look for directory file paths, if found reject
@@ -417,6 +269,10 @@ CMICmdArgValString::IsStringArgSingleText(const CMIUtilString &vrTxt) const
bool
CMICmdArgValString::IsStringArgQuotedText(const CMIUtilString &vrTxt) const
{
+ // Accept anything as string word
+ if (m_bHandleAnything)
+ return true;
+
// CODETAG_QUOTEDTEXT_SIMILAR_CODE
const MIchar cQuote = '"';
const MIint nPos = vrTxt.find(cQuote);
OpenPOWER on IntegriCloud