[Lldb-commits] [lldb] r203185 - Allow line numbers to be shown in multi-line expressions.

Greg Clayton gclayton at apple.com
Thu Mar 6 16:53:25 PST 2014


Author: gclayton
Date: Thu Mar  6 18:53:24 2014
New Revision: 203185

URL: http://llvm.org/viewvc/llvm-project?rev=203185&view=rev
Log:
Allow line numbers to be shown in multi-line expressions.


Modified:
    lldb/trunk/include/lldb/Core/IOHandler.h
    lldb/trunk/include/lldb/Host/Editline.h
    lldb/trunk/source/Commands/CommandObjectCommands.cpp
    lldb/trunk/source/Commands/CommandObjectExpression.cpp
    lldb/trunk/source/Core/IOHandler.cpp
    lldb/trunk/source/Host/common/Editline.cpp
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp

Modified: lldb/trunk/include/lldb/Core/IOHandler.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/IOHandler.h?rev=203185&r1=203184&r2=203185&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/IOHandler.h (original)
+++ lldb/trunk/include/lldb/Core/IOHandler.h Thu Mar  6 18:53:24 2014
@@ -380,6 +380,7 @@ namespace lldb_private {
                            const char *editline_name, // Used for saving history files
                            const char *prompt,
                            bool multi_line,
+                           uint32_t line_number_start, // If non-zero show line numbers starting at 'line_number_start'
                            IOHandlerDelegate &delegate);
 
         IOHandlerEditline (Debugger &debugger,
@@ -390,6 +391,7 @@ namespace lldb_private {
                            const char *editline_name, // Used for saving history files
                            const char *prompt,
                            bool multi_line,
+                           uint32_t line_number_start, // If non-zero show line numbers starting at 'line_number_start'
                            IOHandlerDelegate &delegate);
         
         virtual
@@ -437,7 +439,10 @@ namespace lldb_private {
         
         bool
         GetLines (StringList &lines);
-
+        
+        void
+        SetBaseLineNumber (uint32_t line);
+        
     private:
         static LineStatus
         LineCompletedCallback (Editline *editline,
@@ -458,6 +463,7 @@ namespace lldb_private {
         std::unique_ptr<Editline> m_editline_ap;
         IOHandlerDelegate &m_delegate;
         std::string m_prompt;
+        uint32_t m_base_line_number; // If non-zero, then show line numbers in prompt
         bool m_multi_line;        
     };
     

Modified: lldb/trunk/include/lldb/Host/Editline.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Editline.h?rev=203185&r1=203184&r2=203185&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Editline.h (original)
+++ lldb/trunk/include/lldb/Host/Editline.h Thu Mar  6 18:53:24 2014
@@ -135,7 +135,14 @@ public:
     
     void
     SetPrompt (const char *p);
-
+    
+    void
+    ShowLineNumbers (bool enable, uint32_t line_offset)
+    {
+        m_prompt_with_line_numbers = enable;
+        m_line_offset = line_offset;
+    }
+    
 private:
 
     Error
@@ -193,6 +200,7 @@ private:
     LineCompletedCallbackType m_line_complete_callback;
     void *m_line_complete_callback_baton;
     Command m_lines_command;
+    uint32_t m_line_offset;
     uint32_t m_lines_curr_line;
     uint32_t m_lines_max_line;
     bool m_prompt_with_line_numbers;

Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=203185&r1=203184&r2=203185&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Thu Mar  6 18:53:24 2014
@@ -1034,9 +1034,10 @@ protected:
                 Debugger &debugger = m_interpreter.GetDebugger();
                 const bool multiple_lines = true; // Get multiple lines
                 IOHandlerSP io_handler_sp (new IOHandlerEditline (debugger,
-                                                                  "lldb",      // Name of input reader for history
-                                                                  "\033[K> ",  // Prompt and clear line
+                                                                  "lldb",       // Name of input reader for history
+                                                                  "\033[K> ",   // Prompt and clear line
                                                                   multiple_lines,
+                                                                  0,            // Don't show line numbers
                                                                   *this));
                 
                 if (io_handler_sp)

Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=203185&r1=203184&r2=203185&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Thu Mar  6 18:53:24 2014
@@ -428,6 +428,7 @@ CommandObjectExpression::DoExecute
                                                           "lldb-expr",      // Name of input reader for history
                                                           NULL,             // No prompt
                                                           multiple_lines,
+                                                          1,                // Show line numbers starting at 1
                                                           *this));
         
         StreamFileSP output_sp(io_handler_sp->GetOutputStreamFile());

Modified: lldb/trunk/source/Core/IOHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/IOHandler.cpp?rev=203185&r1=203184&r2=203185&view=diff
==============================================================================
--- lldb/trunk/source/Core/IOHandler.cpp (original)
+++ lldb/trunk/source/Core/IOHandler.cpp Thu Mar  6 18:53:24 2014
@@ -157,6 +157,7 @@ IOHandlerConfirm::IOHandlerConfirm (Debu
                       NULL,     // NULL editline_name means no history loaded/saved
                       NULL,
                       false,    // Multi-line
+                      0,
                       *this),
     m_default_response (default_response),
     m_user_response (default_response)
@@ -311,6 +312,7 @@ IOHandlerEditline::IOHandlerEditline (De
                                       const char *editline_name, // Used for saving history files
                                       const char *prompt,
                                       bool multi_line,
+                                      uint32_t line_number_start,
                                       IOHandlerDelegate &delegate) :
     IOHandlerEditline(debugger,
                       StreamFileSP(), // Inherit input from top input reader
@@ -320,6 +322,7 @@ IOHandlerEditline::IOHandlerEditline (De
                       editline_name,  // Used for saving history files
                       prompt,
                       multi_line,
+                      line_number_start,
                       delegate)
 {
 }
@@ -332,11 +335,13 @@ IOHandlerEditline::IOHandlerEditline (De
                                       const char *editline_name, // Used for saving history files
                                       const char *prompt,
                                       bool multi_line,
+                                      uint32_t line_number_start,
                                       IOHandlerDelegate &delegate) :
     IOHandler (debugger, input_sp, output_sp, error_sp, flags),
     m_editline_ap (),
     m_delegate (delegate),
     m_prompt (),
+    m_base_line_number (line_number_start),
     m_multi_line (multi_line)
 {
     SetPrompt(prompt);
@@ -356,6 +361,8 @@ IOHandlerEditline::IOHandlerEditline (De
                                           GetInputFILE (),
                                           GetOutputFILE (),
                                           GetErrorFILE ()));
+        if (m_base_line_number > 0)
+            m_editline_ap->ShowLineNumbers(true, m_base_line_number);
         m_editline_ap->SetLineCompleteCallback (LineCompletedCallback, this);
         m_editline_ap->SetAutoCompleteCallback (AutoCompleteCallback, this);
     }
@@ -491,6 +498,14 @@ IOHandlerEditline::SetPrompt (const char
     return true;
 }
 
+void
+IOHandlerEditline::SetBaseLineNumber (uint32_t line)
+{
+    m_base_line_number = line;
+    if (m_editline_ap)
+        m_editline_ap->ShowLineNumbers (true, line);
+    
+}
 bool
 IOHandlerEditline::GetLines (StringList &lines)
 {
@@ -506,7 +521,15 @@ IOHandlerEditline::GetLines (StringList
 
         while (lines_status == LineStatus::Success)
         {
+            // Show line numbers if we are asked to
             std::string line;
+            if (m_base_line_number > 0 && GetIsInteractive())
+            {
+                FILE *out = GetOutputFILE();
+                if (out)
+                    ::fprintf(out, "%u", m_base_line_number + (uint32_t)lines.GetSize());
+            }
+            
             if (GetLine(line))
             {
                 lines.AppendString(line);

Modified: lldb/trunk/source/Host/common/Editline.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Editline.cpp?rev=203185&r1=203184&r2=203185&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Editline.cpp (original)
+++ lldb/trunk/source/Host/common/Editline.cpp Thu Mar  6 18:53:24 2014
@@ -42,6 +42,7 @@ Editline::Editline (const char *prog,
     m_line_complete_callback (NULL),
     m_line_complete_callback_baton (NULL),
     m_lines_command (Command::None),
+    m_line_offset (0),
     m_lines_curr_line (0),
     m_lines_max_line (0),
     m_prompt_with_line_numbers (false),

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=203185&r1=203184&r2=203185&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Thu Mar  6 18:53:24 2014
@@ -2663,6 +2663,7 @@ CommandInterpreter::HandleCommandsFromFi
                                                               NULL, // Pass in NULL for "editline_name" so no history is saved, or written
                                                               debugger.GetPrompt(),
                                                               false, // Not multi-line
+                                                              0,
                                                               *this));
             const bool old_async_execution = debugger.GetAsyncExecution();
             
@@ -3052,6 +3053,7 @@ CommandInterpreter::GetLLDBCommandsFromI
                                                       "lldb",       // Name of input reader for history
                                                       prompt,       // Prompt
                                                       true,         // Get multiple lines
+                                                      0,            // Don't show line numbers
                                                       delegate));   // IOHandlerDelegate
     
     if (io_handler_sp)
@@ -3077,6 +3079,7 @@ CommandInterpreter::GetPythonCommandsFro
                                                       "lldb-python",    // Name of input reader for history
                                                       prompt,           // Prompt
                                                       true,             // Get multiple lines
+                                                      0,                // Don't show line numbers
                                                       delegate));       // IOHandlerDelegate
     
     if (io_handler_sp)
@@ -3110,6 +3113,7 @@ CommandInterpreter::RunCommandInterprete
                                                              "lldb",
                                                              m_debugger.GetPrompt(),
                                                              multiple_lines,
+                                                             0,            // Don't show line numbers
                                                              *this));
     m_debugger.PushIOHandler(m_command_io_handler_sp);
     





More information about the lldb-commits mailing list