[Lldb-commits] [lldb] r125253 - in /lldb/branches/apple/calcite/lldb: include/lldb/Core/Debugger.h source/Core/Debugger.cpp

Caroline Tice ctice at apple.com
Wed Feb 9 17:04:43 PST 2011


Author: ctice
Date: Wed Feb  9 19:04:43 2011
New Revision: 125253

URL: http://llvm.org/viewvc/llvm-project?rev=125253&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/branches/apple/calcite/lldb/include/lldb/Core/Debugger.h
    lldb/branches/apple/calcite/lldb/source/Core/Debugger.cpp

Modified: lldb/branches/apple/calcite/lldb/include/lldb/Core/Debugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/apple/calcite/lldb/include/lldb/Core/Debugger.h?rev=125253&r1=125252&r2=125253&view=diff
==============================================================================
--- lldb/branches/apple/calcite/lldb/include/lldb/Core/Debugger.h (original)
+++ lldb/branches/apple/calcite/lldb/include/lldb/Core/Debugger.h Wed Feb  9 19:04:43 2011
@@ -384,6 +384,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/branches/apple/calcite/lldb/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/apple/calcite/lldb/source/Core/Debugger.cpp?rev=125253&r1=125252&r2=125253&view=diff
==============================================================================
--- lldb/branches/apple/calcite/lldb/source/Core/Debugger.cpp (original)
+++ lldb/branches/apple/calcite/lldb/source/Core/Debugger.cpp Wed Feb  9 19:04:43 2011
@@ -366,6 +366,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)
 {
@@ -390,14 +407,13 @@
 {
     m_input_reader_data.clear();
     
-    if (!m_input_readers.empty())
+    InputReaderSP reader_sp (GetCurrentInputReader());
+    
+    if (reader_sp)
     {
-        while (CheckIfTopInputReaderIsDone ()) ;
-        
-        InputReaderSP reader_sp(m_input_readers.top());
-        if (reader_sp)
-            reader_sp->Notify (eInputReaderInterrupt);
+        reader_sp->Notify (eInputReaderInterrupt);
 
+        // If notifying the reader of the interrupt finished the reader, we should pop it off the stack.
         while (CheckIfTopInputReaderIsDone ()) ;
     }
 }
@@ -407,14 +423,13 @@
 {
     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 ()) ;
     }
 }
@@ -424,11 +439,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);
@@ -448,12 +462,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;
 
@@ -471,7 +481,7 @@
         }
     }
     
-    // Flush out any input readers that are donesvn
+    // Flush out any input readers that are done.
     while (CheckIfTopInputReaderIsDone ())
         /* Do nothing. */;
 
@@ -482,13 +492,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);
@@ -503,8 +513,12 @@
     // 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 (!reader_sp)
+            return false;
+        
         if (!pop_reader_sp || pop_reader_sp.get() == reader_sp.get())
         {
             m_input_readers.pop ();
@@ -514,7 +528,7 @@
 
             if (!m_input_readers.empty())
             {
-                reader_sp = m_input_readers.top();
+                reader_sp = GetCurrentInputReader();
                 if (reader_sp)
                 {
                     ActivateInputReader (reader_sp);
@@ -532,6 +546,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