[Lldb-commits] [lldb] r125255 - in /lldb/trunk: include/lldb/Core/Debugger.h source/Core/Debugger.cpp

Caroline Tice ctice at apple.com
Wed Feb 9 17:15:13 PST 2011


Author: ctice
Date: Wed Feb  9 19:15:13 2011
New Revision: 125255

URL: http://llvm.org/viewvc/llvm-project?rev=125255&view=rev
Log:
Add a new function to Debugger for finding the top/current 
input reader.

Always make sure the input reader stack is not empty before
trying to get the top element from the stack.



Modified:
    lldb/trunk/include/lldb/Core/Debugger.h
    lldb/trunk/source/Core/Debugger.cpp

Modified: lldb/trunk/include/lldb/Core/Debugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=125255&r1=125254&r2=125255&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Debugger.h (original)
+++ lldb/trunk/include/lldb/Core/Debugger.h Wed Feb  9 19:15:13 2011
@@ -394,6 +394,9 @@
     static void
     DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len);
 
+    lldb::InputReaderSP
+    GetCurrentInputReader ();
+    
     void
     ActivateInputReader (const lldb::InputReaderSP &reader_sp);
 

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=125255&r1=125254&r2=125255&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Wed Feb  9 19:15:13 2011
@@ -347,6 +347,23 @@
     return m_target_list;
 }
 
+InputReaderSP 
+Debugger::GetCurrentInputReader ()
+{
+    InputReaderSP reader_sp;
+    
+    if (!m_input_readers.empty())
+    {
+        // Clear any finished readers from the stack
+        while (CheckIfTopInputReaderIsDone()) ;
+        
+        if (!m_input_readers.empty())
+            reader_sp = m_input_readers.top();
+    }
+    
+    return reader_sp;
+}
+
 void
 Debugger::DispatchInputCallback (void *baton, const void *bytes, size_t bytes_len)
 {
@@ -371,14 +388,12 @@
 {
     m_input_reader_data.clear();
     
-    if (!m_input_readers.empty())
+    InputReaderSP reader_sp (GetCurrentInputReader ());
+    if (reader_sp)
     {
-        while (CheckIfTopInputReaderIsDone ()) ;
+        reader_sp->Notify (eInputReaderInterrupt);
         
-        InputReaderSP reader_sp(m_input_readers.top());
-        if (reader_sp)
-            reader_sp->Notify (eInputReaderInterrupt);
-
+        // If notifying the reader of the interrupt finished the reader, we should pop it off the stack.
         while (CheckIfTopInputReaderIsDone ()) ;
     }
 }
@@ -388,14 +403,12 @@
 {
     m_input_reader_data.clear();
     
-    if (!m_input_readers.empty())
+    InputReaderSP reader_sp (GetCurrentInputReader ());
+    if (reader_sp)
     {
-        while (CheckIfTopInputReaderIsDone ()) ;
+        reader_sp->Notify (eInputReaderEndOfFile);
         
-        InputReaderSP reader_sp(m_input_readers.top());
-        if (reader_sp)
-            reader_sp->Notify (eInputReaderEndOfFile);
-
+        // If notifying the reader of the end-of-file finished the reader, we should pop it off the stack.
         while (CheckIfTopInputReaderIsDone ()) ;
     }
 }
@@ -405,11 +418,10 @@
 {
     m_input_reader_data.clear();
     
+    // The bottom input reader should be the main debugger input reader.  We do not want to close that one here.
     while (m_input_readers.size() > 1)
     {
-        while (CheckIfTopInputReaderIsDone ()) ;
-        
-        InputReaderSP reader_sp (m_input_readers.top());
+        InputReaderSP reader_sp (GetCurrentInputReader ());
         if (reader_sp)
         {
             reader_sp->Notify (eInputReaderEndOfFile);
@@ -429,12 +441,8 @@
 
     while (!m_input_readers.empty() && !m_input_reader_data.empty())
     {
-        while (CheckIfTopInputReaderIsDone ())
-            /* Do nothing. */;
-        
         // Get the input reader from the top of the stack
-        InputReaderSP reader_sp(m_input_readers.top());
-        
+        InputReaderSP reader_sp (GetCurrentInputReader ());
         if (!reader_sp)
             break;
 
@@ -452,7 +460,7 @@
         }
     }
     
-    // Flush out any input readers that are donesvn
+    // Flush out any input readers that are done.
     while (CheckIfTopInputReaderIsDone ())
         /* Do nothing. */;
 
@@ -463,13 +471,13 @@
 {
     if (!reader_sp)
         return;
-    if (!m_input_readers.empty())
-    {
-        // Deactivate the old top reader
-        InputReaderSP top_reader_sp (m_input_readers.top());
-        if (top_reader_sp)
-            top_reader_sp->Notify (eInputReaderDeactivate);
-    }
+ 
+    // Deactivate the old top reader
+    InputReaderSP top_reader_sp (GetCurrentInputReader ());
+    
+    if (top_reader_sp)
+        top_reader_sp->Notify (eInputReaderDeactivate);
+
     m_input_readers.push (reader_sp);
     reader_sp->Notify (eInputReaderActivate);
     ActivateInputReader (reader_sp);
@@ -484,6 +492,7 @@
     // read on the stack referesh its prompt and if there is one...
     if (!m_input_readers.empty())
     {
+        // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
         InputReaderSP reader_sp(m_input_readers.top());
         
         if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
@@ -513,6 +522,7 @@
     bool result = false;
     if (!m_input_readers.empty())
     {
+        // Cannot call GetCurrentInputReader here, as that would cause an infinite loop.
         InputReaderSP reader_sp(m_input_readers.top());
         
         if (reader_sp && reader_sp->IsDone())





More information about the lldb-commits mailing list