[Lldb-commits] [lldb] r248566 - Allow to construct CMIUtilString using std::string directly + cleanup CMIUtilString (MI)

Ilia K via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 25 01:29:00 PDT 2015


Author: ki.stfu
Date: Fri Sep 25 03:28:58 2015
New Revision: 248566

URL: http://llvm.org/viewvc/llvm-project?rev=248566&view=rev
Log:
Allow to construct CMIUtilString using std::string directly + cleanup CMIUtilString (MI)

Summary:
Allow to construct CMIUtilString using std::string directly + cleanup CMIUtilString (MI)

This patch cleans up lldb-mi code, and serves to simplify
the following case:
```
  std::string strGoodbye = "!Hello";
  CMIUtilString strHello(strGoodbye.substr(1).c_str());
```

With CMIUtilString(std::string) we can omit .c_str():
```
  std::string strGoodbye = "!Hello";
  CMIUtilString strHello(strGoodbye.substr(1));
```

Also, it removes 2 ctors because they aren't needed:
# CMIUtilString::CMIUtilString(const char *const *vpData)
# CMIUtilString::CMIUtilString(const char *vpData, size_t nLen)
and cleans up CMIUtilString::operator=(const std::string &vrRhs).

Reviewers: brucem, abidh

Subscribers: lldb-commits, brucem, abidh

Differential Revision: http://reviews.llvm.org/D13158

Modified:
    lldb/trunk/tools/lldb-mi/MICmdArgContext.cpp
    lldb/trunk/tools/lldb-mi/MICmdArgValOptionLong.cpp
    lldb/trunk/tools/lldb-mi/MICmdArgValOptionShort.cpp
    lldb/trunk/tools/lldb-mi/MICmdArgValThreadGrp.cpp
    lldb/trunk/tools/lldb-mi/MICmdCmdData.cpp
    lldb/trunk/tools/lldb-mi/MICmdCmdVar.cpp
    lldb/trunk/tools/lldb-mi/MICmdInterpreter.cpp
    lldb/trunk/tools/lldb-mi/MICmnLLDBDebugger.cpp
    lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp
    lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp
    lldb/trunk/tools/lldb-mi/MIDriver.cpp
    lldb/trunk/tools/lldb-mi/MIUtilString.cpp
    lldb/trunk/tools/lldb-mi/MIUtilString.h

Modified: lldb/trunk/tools/lldb-mi/MICmdArgContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdArgContext.cpp?rev=248566&r1=248565&r2=248566&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdArgContext.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdArgContext.cpp Fri Sep 25 03:28:58 2015
@@ -130,7 +130,7 @@ CMICmdArgContext::RemoveArg(const CMIUti
     }
 
     const size_t nPosEnd = nLen + nExtraSpace;
-    m_strCmdArgsAndOptions = m_strCmdArgsAndOptions.replace(nPos, nPosEnd, "").c_str();
+    m_strCmdArgsAndOptions = m_strCmdArgsAndOptions.replace(nPos, nPosEnd, "");
     m_strCmdArgsAndOptions = m_strCmdArgsAndOptions.Trim();
 
     return MIstatus::success;

Modified: lldb/trunk/tools/lldb-mi/MICmdArgValOptionLong.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdArgValOptionLong.cpp?rev=248566&r1=248565&r2=248566&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdArgValOptionLong.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdArgValOptionLong.cpp Fri Sep 25 03:28:58 2015
@@ -261,7 +261,7 @@ CMICmdArgValOptionLong::IsArgLongOption(
     if (vrTxt.length() < 3)
         return false;
 
-    const CMIUtilString strArg = vrTxt.substr(2).c_str();
+    const CMIUtilString strArg = vrTxt.substr(2);
     if (strArg.IsNumber())
         return false;
 
@@ -293,7 +293,7 @@ CMICmdArgValOptionLong::IsArgOptionCorre
 bool
 CMICmdArgValOptionLong::ArgNameMatch(const CMIUtilString &vrTxt) const
 {
-    const CMIUtilString strArg = vrTxt.substr(2).c_str();
+    const CMIUtilString strArg = vrTxt.substr(2);
     return (strArg == GetName());
 }
 

Modified: lldb/trunk/tools/lldb-mi/MICmdArgValOptionShort.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdArgValOptionShort.cpp?rev=248566&r1=248565&r2=248566&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdArgValOptionShort.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdArgValOptionShort.cpp Fri Sep 25 03:28:58 2015
@@ -115,6 +115,6 @@ CMICmdArgValOptionShort::IsArgOptionCorr
 bool
 CMICmdArgValOptionShort::ArgNameMatch(const CMIUtilString &vrTxt) const
 {
-    const CMIUtilString strArg = vrTxt.substr(1).c_str();
+    const CMIUtilString strArg = vrTxt.substr(1);
     return (strArg == GetName());
 }

Modified: lldb/trunk/tools/lldb-mi/MICmdArgValThreadGrp.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdArgValThreadGrp.cpp?rev=248566&r1=248565&r2=248566&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdArgValThreadGrp.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdArgValThreadGrp.cpp Fri Sep 25 03:28:58 2015
@@ -121,7 +121,7 @@ CMICmdArgValThreadGrp::IsArgThreadGrp(co
     if (nPos != 0)
         return false;
 
-    const CMIUtilString strNum = vrTxt.substr(1).c_str();
+    const CMIUtilString strNum = vrTxt.substr(1);
     if (!strNum.IsNumber())
         return false;
 
@@ -139,7 +139,7 @@ CMICmdArgValThreadGrp::IsArgThreadGrp(co
 bool
 CMICmdArgValThreadGrp::ExtractNumber(const CMIUtilString &vrTxt)
 {
-    const CMIUtilString strNum = vrTxt.substr(1).c_str();
+    const CMIUtilString strNum = vrTxt.substr(1);
     MIint64 nNumber = 0;
     bool bOk = strNum.ExtractNumber(nNumber);
     if (bOk)

Modified: lldb/trunk/tools/lldb-mi/MICmdCmdData.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdData.cpp?rev=248566&r1=248565&r2=248566&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCmdData.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdData.cpp Fri Sep 25 03:28:58 2015
@@ -1613,7 +1613,7 @@ CMICmdCmdDataInfoLine::Execute()
         // Parse argument:
         // *0x12345
         //  ^^^^^^^ -- address
-        const CMIUtilString strAddress(strLocation.c_str() + 1);
+        const CMIUtilString strAddress(strLocation.substr(1));
         strCmdOptionsLocation = CMIUtilString::Format("--address %s", strAddress.c_str());
     }
     else
@@ -1629,8 +1629,8 @@ CMICmdCmdDataInfoLine::Execute()
         // hello.cpp:5
         // ^^^^^^^^^ -- file
         //           ^ -- line
-        const CMIUtilString strFile(strLocation.substr(0, nLineStartPos).c_str());
-        const CMIUtilString strLine(strLocation.substr(nLineStartPos + 1).c_str());
+        const CMIUtilString strFile(strLocation.substr(0, nLineStartPos));
+        const CMIUtilString strLine(strLocation.substr(nLineStartPos + 1));
         strCmdOptionsLocation = CMIUtilString::Format("--file \"%s\" --line %s", strFile.AddSlashes().c_str(), strLine.c_str());
     }
     const CMIUtilString strCmd(CMIUtilString::Format("target modules lookup -v %s", strCmdOptionsLocation.c_str()));

Modified: lldb/trunk/tools/lldb-mi/MICmdCmdVar.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdVar.cpp?rev=248566&r1=248565&r2=248566&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCmdVar.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdVar.cpp Fri Sep 25 03:28:58 2015
@@ -179,7 +179,7 @@ CMICmdCmdVarCreate::Execute()
 
     if (rStrExpression[0] == '$')
     {
-        const CMIUtilString rStrRegister(rStrExpression.substr(1).c_str());
+        const CMIUtilString rStrRegister(rStrExpression.substr(1));
         value = frame.FindRegister(rStrRegister.c_str());
     }
     else

Modified: lldb/trunk/tools/lldb-mi/MICmdInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdInterpreter.cpp?rev=248566&r1=248565&r2=248566&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdInterpreter.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdInterpreter.cpp Fri Sep 25 03:28:58 2015
@@ -160,10 +160,10 @@ CMICmdInterpreter::MiHasCmdTokenEndingHy
     if (MiHasCmdTokenPresent(vTextLine))
     {
         const std::string strNum = vTextLine.substr(0, nPos);
-        if (!CMIUtilString(strNum.c_str()).IsNumber())
+        if (!CMIUtilString(strNum).IsNumber())
             return false;
 
-        m_miCmdData.strMiCmdToken = strNum.c_str();
+        m_miCmdData.strMiCmdToken = strNum;
     }
 
     m_miCmdData.bMIOldStyle = false;
@@ -256,20 +256,20 @@ CMICmdInterpreter::MiHasCmd(const CMIUti
     {
         if (nPos2 == nLen)
             return false;
-        const CMIUtilString cmd = CMIUtilString(vTextLine.substr(nPos + 1, nPos2 - nPos - 1).c_str());
+        const CMIUtilString cmd = CMIUtilString(vTextLine.substr(nPos + 1, nPos2 - nPos - 1));
         if (cmd.empty())
             return false;
 
         m_miCmdData.strMiCmd = cmd;
 
         if (nPos2 < nLen)
-            m_miCmdData.strMiCmdOption = CMIUtilString(vTextLine.substr(nPos2 + 1, nLen - nPos2 - 1).c_str());
+            m_miCmdData.strMiCmdOption = CMIUtilString(vTextLine.substr(nPos2 + 1, nLen - nPos2 - 1));
 
         bFoundCmd = true;
     }
     else
     {
-        const CMIUtilString cmd = CMIUtilString(vTextLine.substr(nPos + 1, nLen - nPos - 1).c_str());
+        const CMIUtilString cmd = CMIUtilString(vTextLine.substr(nPos + 1, nLen - nPos - 1));
         if (cmd.empty())
             return false;
         m_miCmdData.strMiCmd = cmd;

Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBDebugger.cpp?rev=248566&r1=248565&r2=248566&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnLLDBDebugger.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBDebugger.cpp Fri Sep 25 03:28:58 2015
@@ -585,7 +585,7 @@ CMICmnLLDBDebugger::ClientGetMaskForAllC
     while (it != m_mapIdToEventMask.end())
     {
         const CMIUtilString &rId((*it).first);
-        if (rId.find(vBroadcasterClass.c_str()) != std::string::npos)
+        if (rId.find(vBroadcasterClass) != std::string::npos)
         {
             const MIuint clientsMask = (*it).second;
             mask |= clientsMask;
@@ -678,9 +678,7 @@ CMICmnLLDBDebugger::ClientGetTheirMask(c
         return MIstatus::failure;
     }
 
-    CMIUtilString strId(vBroadcasterClass.c_str());
-    strId += vClientName;
-
+    const CMIUtilString strId(vBroadcasterClass + vClientName);
     const MapIdToEventMask_t::const_iterator it = m_mapIdToEventMask.find(strId);
     if (it != m_mapIdToEventMask.end())
     {

Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp?rev=248566&r1=248565&r2=248566&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp Fri Sep 25 03:28:58 2015
@@ -1572,7 +1572,7 @@ CMICmnLLDBDebuggerHandleEvents::GetProce
             if (nNewLine == std::string::npos)
                 break;
 
-            const CMIUtilString line(text.substr(0, nNewLine + 1).c_str());
+            const CMIUtilString line(text.substr(0, nNewLine + 1));
             text.erase(0, nNewLine + 1);
             const bool bEscapeQuotes(true);
             CMICmnMIValueConst miValueConst(line.Escape(bEscapeQuotes));
@@ -1625,7 +1625,7 @@ CMICmnLLDBDebuggerHandleEvents::GetProce
             if (nNewLine == std::string::npos)
                 break;
 
-            const CMIUtilString line(text.substr(0, nNewLine + 1).c_str());
+            const CMIUtilString line(text.substr(0, nNewLine + 1));
             const bool bEscapeQuotes(true);
             CMICmnMIValueConst miValueConst(line.Escape(bEscapeQuotes));
             CMICmnMIOutOfBandRecord miOutOfBandRecord(CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput, miValueConst);

Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp?rev=248566&r1=248565&r2=248566&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp Fri Sep 25 03:28:58 2015
@@ -505,7 +505,7 @@ CMICmnLLDBUtilSBValue::ReadCStringFromHo
         addr += sizeof(ch);
     }
 
-    return result.c_str();
+    return result;
 }
 
 //++ ------------------------------------------------------------------------------------

Modified: lldb/trunk/tools/lldb-mi/MIDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIDriver.cpp?rev=248566&r1=248565&r2=248566&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIDriver.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MIDriver.cpp Fri Sep 25 03:28:58 2015
@@ -893,7 +893,7 @@ CMIDriver::WrapCLICommandIntoMICommand(c
    const std::string vToken(vTextLine.begin(), vTextLine.begin() + nCommandOffset);
    // 001target create "/path/to/file"
    //    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- CLI command
-   const CMIUtilString vCliCommand(std::string(vTextLine, nCommandOffset).c_str());
+   const CMIUtilString vCliCommand(std::string(vTextLine, nCommandOffset));
 
    // 5. Escape special characters and embed the command in a string
    // Result: it looks like -- target create \"/path/to/file\".

Modified: lldb/trunk/tools/lldb-mi/MIUtilString.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilString.cpp?rev=248566&r1=248565&r2=248566&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIUtilString.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MIUtilString.cpp Fri Sep 25 03:28:58 2015
@@ -45,25 +45,12 @@ CMIUtilString::CMIUtilString(const char
 //++ ------------------------------------------------------------------------------------
 // Details: CMIUtilString constructor.
 // Type:    Method.
-// Args:    vpData  - Pointer to UTF8 text data.
+// Args:    vpStr  - Text data.
 // Return:  None.
 // Throws:  None.
 //--
-CMIUtilString::CMIUtilString(const char *const *vpData)
-    : std::string((const char *)vpData)
-{
-}
-
-//++ ------------------------------------------------------------------------------------
-// Details: CMIUtilString constructor.
-// Type:    Method.
-// Args:    vpData  - Pointer to UTF8 text data.
-//          nLen    - Length of string.
-// Return:  None.
-// Throws:  None.
-//--
-CMIUtilString::CMIUtilString(const char *vpData, size_t nLen)
-    : std::string(vpData, nLen)
+CMIUtilString::CMIUtilString(const std::string& vrStr)
+    : std::string(vrStr)
 {
 }
 
@@ -96,11 +83,7 @@ CMIUtilString &CMIUtilString::operator=(
 //--
 CMIUtilString &CMIUtilString::operator=(const std::string &vrRhs)
 {
-    if (*this == vrRhs)
-        return *this;
-
     assign(vrRhs);
-
     return *this;
 }
 
@@ -243,7 +226,7 @@ CMIUtilString::Split(const CMIUtilString
         // Extract string between delimiters
         const size_t nSectionLen(nNextDelimiterPos - nSectionPos);
         const std::string strSection(substr(nSectionPos, nSectionLen));
-        vwVecSplits.push_back(strSection.c_str());
+        vwVecSplits.push_back(strSection);
 
         // Next
         nOffset = nNextDelimiterPos + 1;
@@ -299,7 +282,7 @@ CMIUtilString::SplitConsiderQuotes(const
         // Extract string between delimiters
         const size_t nSectionLen(nNextDelimiterPos - nSectionPos);
         const std::string strSection(substr(nSectionPos, nSectionLen));
-        vwVecSplits.push_back(strSection.c_str());
+        vwVecSplits.push_back(strSection);
 
         // Next
         nOffset = nNextDelimiterPos + 1;
@@ -337,7 +320,7 @@ CMIUtilString::StripCREndOfLine() const
     if (nPos == std::string::npos)
         return *this;
 
-    const CMIUtilString strNew(substr(0, nPos).c_str());
+    const CMIUtilString strNew(substr(0, nPos));
 
     return strNew;
 }
@@ -542,12 +525,12 @@ CMIUtilString::Trim() const
     const size_t nPos = find_last_not_of(pWhiteSpace);
     if (nPos != std::string::npos)
     {
-        strNew = substr(0, nPos + 1).c_str();
+        strNew = substr(0, nPos + 1);
     }
     const size_t nPos2 = strNew.find_first_not_of(pWhiteSpace);
     if (nPos2 != std::string::npos)
     {
-        strNew = strNew.substr(nPos2).c_str();
+        strNew = strNew.substr(nPos2);
     }
 
     return strNew;
@@ -568,7 +551,7 @@ CMIUtilString::Trim(const char vChar) co
     if (nLen > 1)
     {
         if ((strNew[0] == vChar) && (strNew[nLen - 1] == vChar))
-            strNew = strNew.substr(1, nLen - 2).c_str();
+            strNew = strNew.substr(1, nLen - 2);
     }
 
     return strNew;

Modified: lldb/trunk/tools/lldb-mi/MIUtilString.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilString.h?rev=248566&r1=248565&r2=248566&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIUtilString.h (original)
+++ lldb/trunk/tools/lldb-mi/MIUtilString.h Fri Sep 25 03:28:58 2015
@@ -43,8 +43,7 @@ class CMIUtilString : public std::string
   public:
     /* ctor */ CMIUtilString();
     /* ctor */ CMIUtilString(const char *vpData);
-    /* ctor */ CMIUtilString(const char *const *vpData);
-    /* ctor */ CMIUtilString(const char *vpData, size_t nLen);
+    /* ctor */ CMIUtilString(const std::string& vrStr);
     //
     bool ExtractNumber(MIint64 &vwrNumber) const;
     CMIUtilString FindAndReplace(const CMIUtilString &vFind, const CMIUtilString &vReplaceWith) const;




More information about the lldb-commits mailing list