[Lldb-commits] [lldb] r314371 - Revert patch r313904, as it breaks "command source" and in

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 27 18:39:08 PDT 2017


Author: jingham
Date: Wed Sep 27 18:39:07 2017
New Revision: 314371

URL: http://llvm.org/viewvc/llvm-project?rev=314371&view=rev
Log:
Revert patch r313904, as it breaks "command source" and in 
particular causes lldb to die on startup if you have a ~/.lldbinit file.

I filed:

https://bugs.llvm.org/show_bug.cgi?id=34758

to cover fixing the bug.

Modified:
    lldb/trunk/include/lldb/API/SBCommandInterpreter.h
    lldb/trunk/include/lldb/Core/IOHandler.h
    lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
    lldb/trunk/scripts/interface/SBCommandInterpreter.i
    lldb/trunk/source/API/SBCommandInterpreter.cpp
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp

Modified: lldb/trunk/include/lldb/API/SBCommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBCommandInterpreter.h?rev=314371&r1=314370&r2=314371&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBCommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/API/SBCommandInterpreter.h Wed Sep 27 18:39:07 2017
@@ -165,8 +165,6 @@ public:
                        int match_start_point, int max_return_elements,
                        lldb::SBStringList &matches);
 
-  bool WasInterrupted() const;
-
   // Catch commands before they execute by registering a callback that will
   // get called when the command gets executed. This allows GUI or command
   // line interfaces to intercept a command and stop it from happening

Modified: lldb/trunk/include/lldb/Core/IOHandler.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/IOHandler.h?rev=314371&r1=314370&r2=314371&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/IOHandler.h (original)
+++ lldb/trunk/include/lldb/Core/IOHandler.h Wed Sep 27 18:39:07 2017
@@ -195,7 +195,7 @@ public:
   enum class Completion { None, LLDBCommand, Expression };
 
   IOHandlerDelegate(Completion completion = Completion::None)
-      : m_completion(completion) {}
+      : m_completion(completion), m_io_handler_done(false) {}
 
   virtual ~IOHandlerDelegate() = default;
 
@@ -296,6 +296,7 @@ public:
 
 protected:
   Completion m_completion; // Support for common builtin completions
+  bool m_io_handler_done;
 };
 
 //----------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=314371&r1=314370&r2=314371&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Wed Sep 27 18:39:07 2017
@@ -242,8 +242,6 @@ public:
                      bool repeat_on_empty_command = true,
                      bool no_context_switching = false);
 
-  bool WasInterrupted() const;
-
   //------------------------------------------------------------------
   /// Execute a list of commands in sequence.
   ///
@@ -524,24 +522,6 @@ private:
                               StringList &commands_help,
                               CommandObject::CommandMap &command_map);
 
-  // An interruptible wrapper around the stream output
-  void PrintCommandOutput(Stream &stream, llvm::StringRef str,
-                          bool interruptible);
-
-  // A very simple state machine which models the command handling transitions
-  enum class CommandHandlingState {
-    eIdle,
-    eInProgress,
-    eInterrupted,
-  };
-
-  std::atomic<CommandHandlingState> m_command_state{
-      CommandHandlingState::eIdle};
-
-  void StartHandlingCommand();
-  void FinishHandlingCommand();
-  bool InterruptCommand();
-
   Debugger &m_debugger; // The debugger session that this interpreter is
                         // associated with
   ExecutionContextRef m_exe_ctx_ref; // The current execution context to use

Modified: lldb/trunk/scripts/interface/SBCommandInterpreter.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBCommandInterpreter.i?rev=314371&r1=314370&r2=314371&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBCommandInterpreter.i (original)
+++ lldb/trunk/scripts/interface/SBCommandInterpreter.i Wed Sep 27 18:39:07 2017
@@ -125,18 +125,18 @@ public:
     {
         eBroadcastBitThreadShouldExit       = (1 << 0),
         eBroadcastBitResetPrompt            = (1 << 1),
-        eBroadcastBitQuitCommandReceived    = (1 << 2),           // User entered quit
+        eBroadcastBitQuitCommandReceived    = (1 << 2),           // User entered quit 
         eBroadcastBitAsynchronousOutputData = (1 << 3),
         eBroadcastBitAsynchronousErrorData  = (1 << 4)
     };
 
     SBCommandInterpreter (const lldb::SBCommandInterpreter &rhs);
-
+    
     ~SBCommandInterpreter ();
 
-    static const char *
+    static const char * 
     GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type);
-
+    
     static const char *
     GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type);
 
@@ -181,7 +181,7 @@ public:
 
     lldb::SBProcess
     GetProcess ();
-
+    
     lldb::SBDebugger
     GetDebugger ();
 
@@ -209,12 +209,10 @@ public:
                       int match_start_point,
                       int max_return_elements,
                       lldb::SBStringList &matches);
-
+    
     bool
     IsActive ();
 
-    bool
-    WasInterrupted () const;
 };
 
 } // namespace lldb

Modified: lldb/trunk/source/API/SBCommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommandInterpreter.cpp?rev=314371&r1=314370&r2=314371&view=diff
==============================================================================
--- lldb/trunk/source/API/SBCommandInterpreter.cpp (original)
+++ lldb/trunk/source/API/SBCommandInterpreter.cpp Wed Sep 27 18:39:07 2017
@@ -161,10 +161,6 @@ bool SBCommandInterpreter::IsActive() {
   return (IsValid() ? m_opaque_ptr->IsActive() : false);
 }
 
-bool SBCommandInterpreter::WasInterrupted() const {
-  return (IsValid() ? m_opaque_ptr->WasInterrupted() : false);
-}
-
 const char *SBCommandInterpreter::GetIOHandlerControlSequence(char ch) {
   return (IsValid()
               ? m_opaque_ptr->GetDebugger()

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=314371&r1=314370&r2=314371&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Wed Sep 27 18:39:07 2017
@@ -2053,8 +2053,6 @@ protected:
               result.GetOutputStream().EOL();
               result.GetOutputStream().EOL();
             }
-            if (m_interpreter.WasInterrupted())
-              break;
             num_dumped++;
             DumpModuleSymtab(
                 m_interpreter, result.GetOutputStream(),
@@ -2083,8 +2081,6 @@ protected:
                   result.GetOutputStream().EOL();
                   result.GetOutputStream().EOL();
                 }
-                if (m_interpreter.WasInterrupted())
-                  break;
                 num_dumped++;
                 DumpModuleSymtab(m_interpreter, result.GetOutputStream(),
                                  module, m_options.m_sort_order);
@@ -2150,8 +2146,6 @@ protected:
                                           " modules.\n",
                                           (uint64_t)num_modules);
           for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
-            if (m_interpreter.WasInterrupted())
-              break;
             num_dumped++;
             DumpModuleSections(
                 m_interpreter, result.GetOutputStream(),
@@ -2173,8 +2167,6 @@ protected:
               FindModulesByName(target, arg_cstr, module_list, true);
           if (num_matches > 0) {
             for (size_t i = 0; i < num_matches; ++i) {
-              if (m_interpreter.WasInterrupted())
-                break;
               Module *module = module_list.GetModulePointerAtIndex(i);
               if (module) {
                 num_dumped++;
@@ -2247,8 +2239,6 @@ protected:
                                           " modules.\n",
                                           (uint64_t)num_modules);
           for (uint32_t image_idx = 0; image_idx < num_modules; ++image_idx) {
-            if (m_interpreter.WasInterrupted())
-              break;
             if (DumpModuleSymbolVendor(
                     result.GetOutputStream(),
                     target_modules.GetModulePointerAtIndexUnlocked(image_idx)))
@@ -2270,8 +2260,6 @@ protected:
               FindModulesByName(target, arg_cstr, module_list, true);
           if (num_matches > 0) {
             for (size_t i = 0; i < num_matches; ++i) {
-              if (m_interpreter.WasInterrupted())
-                break;
               Module *module = module_list.GetModulePointerAtIndex(i);
               if (module) {
                 if (DumpModuleSymbolVendor(result.GetOutputStream(), module))
@@ -2339,8 +2327,6 @@ protected:
         if (num_modules > 0) {
           uint32_t num_dumped = 0;
           for (uint32_t i = 0; i < num_modules; ++i) {
-            if (m_interpreter.WasInterrupted())
-              break;
             if (DumpCompileUnitLineTable(
                     m_interpreter, result.GetOutputStream(),
                     target_modules.GetModulePointerAtIndexUnlocked(i),

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=314371&r1=314370&r2=314371&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Wed Sep 27 18:39:07 2017
@@ -1170,7 +1170,7 @@ TestPromptFormats (StackFrame *frame)
         return;
 
     StreamString s;
-    const char *prompt_format =
+    const char *prompt_format =         
     "{addr = '${addr}'\n}"
     "{addr-file-or-load = '${addr-file-or-load}'\n}"
     "{current-pc-arrow = '${current-pc-arrow}'\n}"

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=314371&r1=314370&r2=314371&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Wed Sep 27 18:39:07 2017
@@ -546,7 +546,7 @@ void CommandInterpreter::LoadCommandDict
       char buffer[1024];
       int num_printed =
           snprintf(buffer, 1024, "%s %s", break_regexes[i][1], "-o");
-      lldbassert(num_printed < 1024);
+      assert(num_printed < 1024);
       UNUSED_IF_ASSERT_DISABLED(num_printed);
       success =
           tbreak_regex_cmd_ap->AddRegexCommand(break_regexes[i][0], buffer);
@@ -891,8 +891,8 @@ bool CommandInterpreter::AddCommand(llvm
                                     const lldb::CommandObjectSP &cmd_sp,
                                     bool can_replace) {
   if (cmd_sp.get())
-    lldbassert((this == &cmd_sp->GetCommandInterpreter()) &&
-               "tried to add a CommandObject from a different interpreter");
+    assert((this == &cmd_sp->GetCommandInterpreter()) &&
+           "tried to add a CommandObject from a different interpreter");
 
   if (name.empty())
     return false;
@@ -913,8 +913,8 @@ bool CommandInterpreter::AddUserCommand(
                                         const lldb::CommandObjectSP &cmd_sp,
                                         bool can_replace) {
   if (cmd_sp.get())
-    lldbassert((this == &cmd_sp->GetCommandInterpreter()) &&
-               "tried to add a CommandObject from a different interpreter");
+    assert((this == &cmd_sp->GetCommandInterpreter()) &&
+           "tried to add a CommandObject from a different interpreter");
 
   if (!name.empty()) {
     // do not allow replacement of internal commands
@@ -1062,8 +1062,8 @@ CommandInterpreter::AddAlias(llvm::Strin
                              lldb::CommandObjectSP &command_obj_sp,
                              llvm::StringRef args_string) {
   if (command_obj_sp.get())
-    lldbassert((this == &command_obj_sp->GetCommandInterpreter()) &&
-               "tried to add a CommandObject from a different interpreter");
+    assert((this == &command_obj_sp->GetCommandInterpreter()) &&
+           "tried to add a CommandObject from a different interpreter");
 
   std::unique_ptr<CommandAlias> command_alias_up(
       new CommandAlias(*this, command_obj_sp, args_string, alias_name));
@@ -1839,7 +1839,7 @@ int CommandInterpreter::HandleCompletion
   matches.Clear();
 
   // Only max_return_elements == -1 is supported at present:
-  lldbassert(max_return_elements == -1);
+  assert(max_return_elements == -1);
   bool word_complete;
   num_command_matches = HandleCompletionMatches(
       parsed_line, cursor_index, cursor_char_position, match_start_point,
@@ -2677,57 +2677,6 @@ size_t CommandInterpreter::GetProcessOut
   return total_bytes;
 }
 
-void CommandInterpreter::StartHandlingCommand() {
-  auto prev_state = m_command_state.exchange(CommandHandlingState::eInProgress);
-  lldbassert(prev_state == CommandHandlingState::eIdle);
-}
-
-void CommandInterpreter::FinishHandlingCommand() {
-  auto prev_state = m_command_state.exchange(CommandHandlingState::eIdle);
-  lldbassert(prev_state != CommandHandlingState::eIdle);
-}
-
-bool CommandInterpreter::InterruptCommand() {
-  auto in_progress = CommandHandlingState::eInProgress;
-  return m_command_state.compare_exchange_strong(
-      in_progress, CommandHandlingState::eInterrupted);
-}
-
-bool CommandInterpreter::WasInterrupted() const {
-  return m_command_state == CommandHandlingState::eInterrupted;
-}
-
-void CommandInterpreter::PrintCommandOutput(Stream &stream, llvm::StringRef str,
-                                            bool interruptible) {
-  if (str.empty())
-    return;
-
-  if (interruptible) {
-    // Split the output into lines and poll for interrupt requests
-    const char *data = str.data();
-    size_t size = str.size();
-    while (size > 0 && !WasInterrupted()) {
-      size_t chunk_size = 0;
-      for (; chunk_size < size; ++chunk_size) {
-        lldbassert(data[chunk_size] != '\0');
-        if (data[chunk_size] == '\n') {
-          ++chunk_size;
-          break;
-        }
-      }
-      chunk_size = stream.Write(data, chunk_size);
-      lldbassert(size >= chunk_size);
-      data += chunk_size;
-      size -= chunk_size;
-    }
-    if (size > 0) {
-      stream.Printf("\n... Interrupted.\n");
-    }
-  } else {
-    stream.PutCString(str);
-  }
-}
-
 void CommandInterpreter::IOHandlerInputComplete(IOHandler &io_handler,
                                                 std::string &line) {
   const bool is_interactive = io_handler.GetIsInteractive();
@@ -2751,8 +2700,6 @@ void CommandInterpreter::IOHandlerInputC
                                                line.c_str());
   }
 
-  StartHandlingCommand();
-
   lldb_private::CommandReturnObject result;
   HandleCommand(line.c_str(), eLazyBoolCalculate, result);
 
@@ -2763,20 +2710,18 @@ void CommandInterpreter::IOHandlerInputC
 
     if (!result.GetImmediateOutputStream()) {
       llvm::StringRef output = result.GetOutputData();
-      PrintCommandOutput(*io_handler.GetOutputStreamFile(), output,
-                         is_interactive);
+      if (!output.empty())
+        io_handler.GetOutputStreamFile()->PutCString(output);
     }
 
     // Now emit the command error text from the command we just executed
     if (!result.GetImmediateErrorStream()) {
       llvm::StringRef error = result.GetErrorData();
-      PrintCommandOutput(*io_handler.GetErrorStreamFile(), error,
-                         is_interactive);
+      if (!error.empty())
+        io_handler.GetErrorStreamFile()->PutCString(error);
     }
   }
 
-  FinishHandlingCommand();
-
   switch (result.GetStatus()) {
   case eReturnStatusInvalid:
   case eReturnStatusSuccessFinishNoResult:
@@ -2832,9 +2777,6 @@ bool CommandInterpreter::IOHandlerInterr
   ExecutionContext exe_ctx(GetExecutionContext());
   Process *process = exe_ctx.GetProcessPtr();
 
-  if (InterruptCommand())
-    return true;
-
   if (process) {
     StateType state = process->GetState();
     if (StateIsRunningState(state)) {
@@ -3056,7 +2998,7 @@ CommandInterpreter::ResolveCommandImpl(s
         result.AppendRawError(error_msg.GetString());
       } else {
         // We didn't have only one match, otherwise we wouldn't get here.
-        lldbassert(num_matches == 0);
+        assert(num_matches == 0);
         result.AppendErrorWithFormat("'%s' is not a valid command.\n",
                                      next_word.c_str());
       }




More information about the lldb-commits mailing list