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

llvm-svn: 237248
This commit is contained in:
Ilia K 2015-05-13 12:18:20 +00:00
parent b526681e08
commit 0e919bca7f
6 changed files with 34 additions and 24 deletions

View File

@ -1022,7 +1022,7 @@ CMICmnLLDBDebuggerHandleEvents::HandleProcessEventStopSignal(bool &vwrbShouldBrk
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::HandleProcessEventStopSignal(bool &vwrbShouldBrk
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::HandleProcessEventStopException(void)
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::MiStoppedAtBreakPoint(const MIuint64 vBrkPtId, c
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::MiStoppedAtBreakPoint(const MIuint64 vBrkPtId, c
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::HandleProcessEventStopReasonTrace(void)
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::HandleProcessEventStopReasonTrace(void)
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::HandleProcessEventStateRunning(void)
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::HandleProcessEventStateExited(void)
CMICmnMIOutOfBandRecord miOutOfBandRecord3(CMICmnMIOutOfBandRecord::eOutOfBand_Stopped, miValueResult4);
bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord3);
}
bOk = bOk && TextToStdout("(gdb)");
bOk = bOk && CMICmnStreamStdout::WritePrompt();
return bOk;
}
@ -1693,7 +1693,7 @@ CMICmnLLDBDebuggerHandleEvents::ChkForStateChanges(void)
++it;
}
return TextToStdout("(gdb)");
return CMICmnStreamStdout::WritePrompt();
}
//++ ------------------------------------------------------------------------------------

View File

@ -31,7 +31,6 @@
CMICmnStreamStdin::CMICmnStreamStdin(void)
: m_strPromptCurrent("(gdb)")
, m_bShowPrompt(true)
, m_bRedrawPrompt(true)
, m_pCmdBuffer(nullptr)
{
}

View File

@ -56,7 +56,6 @@ class CMICmnStreamStdin : public CMICmnBase, public MI::ISingleton<CMICmnStreamS
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;
};

View File

@ -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();
return bOk;
const bool bSendToLog = true;
return CMICmnStreamStdout::Instance().WriteMIResponse(vrTxt, bSendToLog);
}
//++ ------------------------------------------------------------------------------------
// 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;
}

View File

@ -31,6 +31,7 @@ class CMICmnStreamStdout : public CMICmnBase, public MI::ISingleton<CMICmnStream
// Statics:
public:
static bool TextToStdout(const CMIUtilString &vrTxt);
static bool WritePrompt(void);
// Methods:
public:

View File

@ -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) const
bool
CMIDriver::InitClientIDEEclipse(void) const
{
return CMICmnStreamStdout::TextToStdout("(gdb)");
return CMICmnStreamStdout::WritePrompt();
}
//++ ------------------------------------------------------------------------------------
@ -1223,8 +1222,7 @@ CMIDriver::LocalDebugSessionStartupExecuteCommands(void)
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 vbAsyncMode)
}
// 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)