[Lldb-commits] [lldb] r237248 - Refactor lldb-mi's prompt

Ilia K ki.stfu at gmail.com
Wed May 13 05:18:21 PDT 2015


Author: ki.stfu
Date: Wed May 13 07:18:20 2015
New Revision: 237248

URL: http://llvm.org/viewvc/llvm-project?rev=237248&view=rev
Log:
Refactor lldb-mi's prompt

Summary:
This patch fixes/cleans code around of (gdb) prompt:
# Add CMICmnStreamStdout::WritePrompt
# Clean up CMICmnStreamStdout::TextToStdout (don't lock
  the m_mutex twice because it will be locked in CMICmnStreamStdout::WritePriv)
# Remove unused CMICmnStreamStdin::m_bShowPrompt field
# Refactor CMICmnLLDBDebuggerHandleEvents to use CMICmnStreamStdout::WritePrompt
  instead of TextToStdout("(gdb)")
# Refactor CMIDriver to use CMICmnStreamStdout::WritePrompt instead of
  ```
    if (bOk && m_rStdin.GetEnablePrompt())
        bOk = m_rStdOut.WriteMIResponse(m_rStdin.GetPrompt());
  ```

Test Plan: ./dotest.py -v --executable $BUILDDIR/bin/lldb tools/lldb-mi/

Reviewers: abidh

Reviewed By: abidh

Subscribers: lldb-commits, abidh

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

Modified:
    lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp
    lldb/trunk/tools/lldb-mi/MICmnStreamStdin.cpp
    lldb/trunk/tools/lldb-mi/MICmnStreamStdin.h
    lldb/trunk/tools/lldb-mi/MICmnStreamStdout.cpp
    lldb/trunk/tools/lldb-mi/MICmnStreamStdout.h
    lldb/trunk/tools/lldb-mi/MIDriver.cpp

Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp?rev=237248&r1=237247&r2=237248&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp Wed May 13 07:18:20 2015
@@ -1022,7 +1022,7 @@ CMICmnLLDBDebuggerHandleEvents::HandlePr
         const CMICmnMIValueResult miValueResult7("stopped-threads", miValueConst7);
         bOk = bOk && miOutOfBandRecord.Add(miValueResult7);
         bOk = bOk && MiOutOfBandRecordToStdout(miOutOfBandRecord);
-        bOk = bOk && TextToStdout("(gdb)");
+        bOk = bOk && CMICmnStreamStdout::WritePrompt();
     }
     else if (nStopReason == m_SIGSEGV)
     {
@@ -1090,7 +1090,7 @@ CMICmnLLDBDebuggerHandleEvents::HandlePr
         const CMICmnMIValueResult miValueResult4("stopped-threads", miValueConst4);
         bOk = bOk && miOutOfBandRecord.Add(miValueResult4);
         bOk = bOk && MiOutOfBandRecordToStdout(miOutOfBandRecord);
-        bOk = bOk && TextToStdout("(gdb)");
+        bOk = bOk && CMICmnStreamStdout::WritePrompt();
     }
     return bOk;
 }
@@ -1128,7 +1128,7 @@ CMICmnLLDBDebuggerHandleEvents::HandlePr
     const CMICmnMIValueResult miValueResult4("stopped-threads", miValueConst4);
     bOk = bOk && miOutOfBandRecord.Add(miValueResult4);
     bOk = bOk && MiOutOfBandRecordToStdout(miOutOfBandRecord);
-    bOk = bOk && TextToStdout("(gdb)");
+    bOk = bOk && CMICmnStreamStdout::WritePrompt();
 
     return bOk;
 }
@@ -1248,7 +1248,7 @@ CMICmnLLDBDebuggerHandleEvents::MiStoppe
         const CMICmnMIValueResult miValueResult6("stopped-threads", miValueConst6);
         bOk = bOk && miOutOfBandRecord.Add(miValueResult6);
         bOk = bOk && MiOutOfBandRecordToStdout(miOutOfBandRecord);
-        bOk = bOk && TextToStdout("(gdb)");
+        bOk = bOk && CMICmnStreamStdout::WritePrompt();
         return bOk;
     }
 
@@ -1290,7 +1290,7 @@ CMICmnLLDBDebuggerHandleEvents::MiStoppe
         const CMICmnMIValueResult miValueResult9("stopped-threads", miValueConst9);
         bOk = miOutOfBandRecord.Add(miValueResult9);
         bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord);
-        bOk = bOk && TextToStdout("(gdb)");
+        bOk = bOk && CMICmnStreamStdout::WritePrompt();
     }
 
     return MIstatus::success;
@@ -1321,7 +1321,7 @@ CMICmnLLDBDebuggerHandleEvents::HandlePr
         const CMICmnMIValueResult miValueResult2("stopped-threads", miValueConst2);
         bOk = miOutOfBandRecord.Add(miValueResult2);
         bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord);
-        bOk = bOk && TextToStdout("(gdb)");
+        bOk = bOk && CMICmnStreamStdout::WritePrompt();
         return bOk;
     }
 
@@ -1355,7 +1355,7 @@ CMICmnLLDBDebuggerHandleEvents::HandlePr
         const CMICmnMIValueResult miValueResult9("stopped-threads", miValueConst9);
         bOk = miOutOfBandRecord.Add(miValueResult9);
         bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord);
-        bOk = bOk && TextToStdout("(gdb)");
+        bOk = bOk && CMICmnStreamStdout::WritePrompt();
     }
 
     return bOk;
@@ -1447,7 +1447,7 @@ CMICmnLLDBDebuggerHandleEvents::HandlePr
     CMICmnMIValueResult miValueResult("thread-id", miValueConst);
     CMICmnMIOutOfBandRecord miOutOfBandRecord(CMICmnMIOutOfBandRecord::eOutOfBand_Running, miValueResult);
     bool bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord);
-    bOk = bOk && TextToStdout("(gdb)");
+    bOk = bOk && CMICmnStreamStdout::WritePrompt();
 
     return bOk;
 }
@@ -1491,7 +1491,7 @@ CMICmnLLDBDebuggerHandleEvents::HandlePr
         CMICmnMIOutOfBandRecord miOutOfBandRecord3(CMICmnMIOutOfBandRecord::eOutOfBand_Stopped, miValueResult4);
         bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord3);
     }
-    bOk = bOk && TextToStdout("(gdb)");
+    bOk = bOk && CMICmnStreamStdout::WritePrompt();
 
     return bOk;
 }
@@ -1693,7 +1693,7 @@ CMICmnLLDBDebuggerHandleEvents::ChkForSt
             ++it;
     }
 
-    return TextToStdout("(gdb)");
+    return CMICmnStreamStdout::WritePrompt();
 }
 
 //++ ------------------------------------------------------------------------------------

Modified: lldb/trunk/tools/lldb-mi/MICmnStreamStdin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnStreamStdin.cpp?rev=237248&r1=237247&r2=237248&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnStreamStdin.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnStreamStdin.cpp Wed May 13 07:18:20 2015
@@ -31,7 +31,6 @@
 CMICmnStreamStdin::CMICmnStreamStdin(void)
     : m_strPromptCurrent("(gdb)")
     , m_bShowPrompt(true)
-    , m_bRedrawPrompt(true)
     , m_pCmdBuffer(nullptr)
 {
 }

Modified: lldb/trunk/tools/lldb-mi/MICmnStreamStdin.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnStreamStdin.h?rev=237248&r1=237247&r2=237248&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnStreamStdin.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmnStreamStdin.h Wed May 13 07:18:20 2015
@@ -56,7 +56,6 @@ class CMICmnStreamStdin : public CMICmnB
   private:
     CMIUtilString m_strPromptCurrent; // Command line prompt as shown to the user
     bool m_bShowPrompt;               // True = Yes prompt is shown/output to the user (stdout), false = no prompt
-    bool m_bRedrawPrompt;             // True = Prompt needs to be redrawn
     static const int m_constBufferSize = 2048;
     MIchar *m_pCmdBuffer;
 };

Modified: lldb/trunk/tools/lldb-mi/MICmnStreamStdout.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnStreamStdout.cpp?rev=237248&r1=237247&r2=237248&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnStreamStdout.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnStreamStdout.cpp Wed May 13 07:18:20 2015
@@ -216,9 +216,23 @@ CMICmnStreamStdout::Unlock(void)
 bool
 CMICmnStreamStdout::TextToStdout(const CMIUtilString &vrTxt)
 {
-    const bool bLock = CMICmnStreamStdout::Instance().Lock();
-    const bool bOk = bLock && CMICmnStreamStdout::Instance().WriteMIResponse(vrTxt);
-    bLock &&CMICmnStreamStdout::Instance().Unlock();
+    const bool bSendToLog = true;
+    return CMICmnStreamStdout::Instance().WriteMIResponse(vrTxt, bSendToLog);
+}
 
-    return bOk;
+//++ ------------------------------------------------------------------------------------
+// Details: Write prompt to stdout if it's enabled.
+// Type:    Static method.
+// Args:    None.
+// Return:  MIstatus::success - Function succeeded.
+//          MIstatus::failure - Function failed.
+// Throws:  None.
+//--
+bool
+CMICmnStreamStdout::WritePrompt(void)
+{
+    const CMICmnStreamStdin &rStdinMan = CMICmnStreamStdin::Instance();
+    if (rStdinMan.GetEnablePrompt())
+        return TextToStdout(rStdinMan.GetPrompt());
+    return MIstatus::success;
 }

Modified: lldb/trunk/tools/lldb-mi/MICmnStreamStdout.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnStreamStdout.h?rev=237248&r1=237247&r2=237248&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnStreamStdout.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmnStreamStdout.h Wed May 13 07:18:20 2015
@@ -31,6 +31,7 @@ class CMICmnStreamStdout : public CMICmn
     // Statics:
   public:
     static bool TextToStdout(const CMIUtilString &vrTxt);
+    static bool WritePrompt(void);
 
     // Methods:
   public:

Modified: lldb/trunk/tools/lldb-mi/MIDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIDriver.cpp?rev=237248&r1=237247&r2=237248&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIDriver.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MIDriver.cpp Wed May 13 07:18:20 2015
@@ -576,8 +576,7 @@ CMIDriver::DoMainLoop(void)
                 }
 
                 // Draw prompt if desired
-                if (bOk && m_rStdin.GetEnablePrompt())
-                    bOk = m_rStdOut.WriteMIResponse(m_rStdin.GetPrompt());
+                bOk = bOk && CMICmnStreamStdout::WritePrompt();
 
                 // Wait while the handler thread handles incoming events
                 CMICmnLLDBDebugger::Instance().WaitForHandleEvent();
@@ -1173,7 +1172,7 @@ CMIDriver::InitClientIDEToMIDriver(void)
 bool
 CMIDriver::InitClientIDEEclipse(void) const
 {
-    return CMICmnStreamStdout::TextToStdout("(gdb)");
+    return CMICmnStreamStdout::WritePrompt();
 }
 
 //++ ------------------------------------------------------------------------------------
@@ -1223,8 +1222,7 @@ CMIDriver::LocalDebugSessionStartupExecu
     const CMIUtilString strCmd(CMIUtilString::Format("-file-exec-and-symbols \"%s\"", m_strCmdLineArgExecuteableFileNamePath.AddSlashes().c_str()));
     bool bOk = CMICmnStreamStdout::TextToStdout(strCmd);
     bOk = bOk && InterpretCommand(strCmd);
-    if (bOk && m_rStdin.GetEnablePrompt())
-        bOk = m_rStdOut.WriteMIResponse(m_rStdin.GetPrompt());
+    bOk = bOk && CMICmnStreamStdout::WritePrompt();
     return bOk;
 }
 
@@ -1304,8 +1302,7 @@ CMIDriver::ExecuteCommandFile(const bool
         }
 
         // Draw the prompt after command will be executed (if enabled)
-        if (bOk && m_rStdin.GetEnablePrompt())
-            bOk = m_rStdOut.WriteMIResponse(m_rStdin.GetPrompt());
+        bOk = bOk && CMICmnStreamStdout::WritePrompt();
 
         // Exit if there is an error
         if (!bOk)





More information about the lldb-commits mailing list