[llvm-branch-commits] [lldb] r199341 - Adding some support in the IOHandler branch that is required for Xcode.

Greg Clayton gclayton at apple.com
Wed Jan 15 16:09:08 PST 2014


Author: gclayton
Date: Wed Jan 15 18:09:08 2014
New Revision: 199341

URL: http://llvm.org/viewvc/llvm-project?rev=199341&view=rev
Log:
Adding some support in the IOHandler branch that is required for Xcode.

We now have the notion of a prompt delimiter character that can be set so IDE's can watch the out and err file handles and properly do any needed colorization.

The command interpreter can also be run in a separate thread.


Modified:
    lldb/branches/iohandler/include/lldb/API/SBDebugger.h
    lldb/branches/iohandler/include/lldb/Core/Debugger.h
    lldb/branches/iohandler/include/lldb/Interpreter/CommandInterpreter.h
    lldb/branches/iohandler/scripts/Python/interface/SBDebugger.i
    lldb/branches/iohandler/source/API/SBDebugger.cpp
    lldb/branches/iohandler/source/Core/Debugger.cpp
    lldb/branches/iohandler/source/Core/IOHandler.cpp
    lldb/branches/iohandler/source/Interpreter/CommandInterpreter.cpp
    lldb/branches/iohandler/tools/driver/Driver.cpp

Modified: lldb/branches/iohandler/include/lldb/API/SBDebugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/iohandler/include/lldb/API/SBDebugger.h?rev=199341&r1=199340&r2=199341&view=diff
==============================================================================
--- lldb/branches/iohandler/include/lldb/API/SBDebugger.h (original)
+++ lldb/branches/iohandler/include/lldb/API/SBDebugger.h Wed Jan 15 18:09:08 2014
@@ -318,7 +318,9 @@ public:
 #endif
 
     void
-    RunCommandInterpreter (bool auto_handle_events);
+    RunCommandInterpreter (bool auto_handle_events,
+                           bool spawn_thread,
+                           char prompt_delimiter);
 
 private:
 

Modified: lldb/branches/iohandler/include/lldb/Core/Debugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/iohandler/include/lldb/Core/Debugger.h?rev=199341&r1=199340&r2=199341&view=diff
==============================================================================
--- lldb/branches/iohandler/include/lldb/Core/Debugger.h (original)
+++ lldb/branches/iohandler/include/lldb/Core/Debugger.h Wed Jan 15 18:09:08 2014
@@ -355,11 +355,19 @@ protected:
 
     void
     StopEventHandlerThread();
-    
 
     static lldb::thread_result_t
     EventHandlerThread (lldb::thread_arg_t arg);
+
+    bool
+    StartIOHandlerThread();
+    
+    void
+    StopIOHandlerThread();
     
+    static lldb::thread_result_t
+    IOHandlerThread (lldb::thread_arg_t arg);
+
     void
     DefaultEventHandler();
 
@@ -404,6 +412,7 @@ protected:
     typedef std::vector<lldb::DynamicLibrarySP> LoadedPluginsList;
     LoadedPluginsList m_loaded_plugins;
     lldb::thread_t m_event_handler_thread;
+    lldb::thread_t m_io_handler_thread;
     lldb::ListenerSP m_forward_listener_sp;
     bool m_event_handler_thread_alive;
     void

Modified: lldb/branches/iohandler/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/iohandler/include/lldb/Interpreter/CommandInterpreter.h?rev=199341&r1=199340&r2=199341&view=diff
==============================================================================
--- lldb/branches/iohandler/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/branches/iohandler/include/lldb/Interpreter/CommandInterpreter.h Wed Jan 15 18:09:08 2014
@@ -435,7 +435,9 @@ public:
     }
     
     void
-    RunCommandInterpreter(bool auto_handle_events);
+    RunCommandInterpreter (bool auto_handle_events,
+                           bool spawn_thread,
+                           char prompt_delimiter);
 
     void
     GetLLDBCommandsFromIOHandler (const char *prompt,
@@ -461,6 +463,12 @@ public:
     bool
     GetStopCmdSourceOnError () const;
     
+    char
+    GetPromptDelimiterChar () const
+    {
+        return m_prompt_delimiter_char;
+    }
+
 protected:
     friend class Debugger;
 
@@ -480,6 +488,7 @@ protected:
     lldb::CommandObjectSP
     GetCommandSP (const char *cmd, bool include_aliases = true, bool exact = true, StringList *matches = NULL);
 
+    
 private:
     
     Error
@@ -499,6 +508,7 @@ private:
     std::unique_ptr<ScriptInterpreter> m_script_interpreter_ap;
     lldb::IOHandlerSP m_command_io_handler_sp;
     char m_comment_char;
+    char m_prompt_delimiter_char;                    // If set to a non-NULL character, all prompts should be emitted as %c%s%c where both %c's are this character and the '%s' is the prompt
     bool m_batch_command_mode;
     ChildrenTruncatedWarningStatus m_truncation_warning;    // Whether we truncated children and whether the user has been told
     uint32_t m_command_source_depth;

Modified: lldb/branches/iohandler/scripts/Python/interface/SBDebugger.i
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/iohandler/scripts/Python/interface/SBDebugger.i?rev=199341&r1=199340&r2=199341&view=diff
==============================================================================
--- lldb/branches/iohandler/scripts/Python/interface/SBDebugger.i (original)
+++ lldb/branches/iohandler/scripts/Python/interface/SBDebugger.i Wed Jan 15 18:09:08 2014
@@ -365,7 +365,9 @@ public:
     GetSyntheticForType (lldb::SBTypeNameSpecifier);
     
     void
-    RunCommandInterpreter (bool auto_handle_events);
+    RunCommandInterpreter (bool auto_handle_events,
+                           bool spawn_thread,
+                           char prompt_delimiter);
 
 }; // class SBDebugger
 

Modified: lldb/branches/iohandler/source/API/SBDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/iohandler/source/API/SBDebugger.cpp?rev=199341&r1=199340&r2=199341&view=diff
==============================================================================
--- lldb/branches/iohandler/source/API/SBDebugger.cpp (original)
+++ lldb/branches/iohandler/source/API/SBDebugger.cpp Wed Jan 15 18:09:08 2014
@@ -56,23 +56,9 @@ SBInputReader::~SBInputReader()
 {
 }
 
-static lldb::thread_result_t
-RunCI (lldb::thread_arg_t baton)
-{
-    Debugger *debugger = (Debugger *)baton;
-    debugger->GetCommandInterpreter().RunCommandInterpreter(false);
-    return NULL;
-}
-
 SBError
 SBInputReader::Initialize(lldb::SBDebugger& sb_debugger, unsigned long (*)(void*, lldb::SBInputReader*, lldb::InputReaderAction, char const*, unsigned long), void*, lldb::InputReaderGranularity, char const*, char const*, bool)
 {
-    Debugger *debugger = sb_debugger.get();
-    if (debugger)
-    {
-        lldb::thread_t thread = Host::ThreadCreate("lldb.SBInputReader.command_interpreter", RunCI, debugger, NULL);
-        Host::ThreadDetach(thread, NULL);
-    }
     return SBError();
 }
 
@@ -968,10 +954,12 @@ SBDebugger::PushInputReader (SBInputRead
 }
 
 void
-SBDebugger::RunCommandInterpreter (bool auto_handle_events)
+SBDebugger::RunCommandInterpreter (bool auto_handle_events,
+                                   bool spawn_thread,
+                                   char prompt_delimiter)
 {
     if (m_opaque_sp)
-        m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter(auto_handle_events);
+        m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter(auto_handle_events, spawn_thread, prompt_delimiter);
 }
 
 void

Modified: lldb/branches/iohandler/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/iohandler/source/Core/Debugger.cpp?rev=199341&r1=199340&r2=199341&view=diff
==============================================================================
--- lldb/branches/iohandler/source/Core/Debugger.cpp (original)
+++ lldb/branches/iohandler/source/Core/Debugger.cpp Wed Jan 15 18:09:08 2014
@@ -629,6 +629,7 @@ Debugger::Debugger (lldb::LogOutputCallb
     m_instance_name (),
     m_loaded_plugins (),
     m_event_handler_thread (LLDB_INVALID_HOST_THREAD),
+    m_io_handler_thread (LLDB_INVALID_HOST_THREAD),
     m_event_handler_thread_alive(false)
 {
     char instance_cstr[256];
@@ -673,6 +674,8 @@ void
 Debugger::Clear()
 {
     ClearIOHandlers();
+    StopIOHandlerThread();
+    StopEventHandlerThread();
     m_listener.Clear();
     int num_targets = m_target_list.GetNumTargets();
     for (int i = 0; i < num_targets; i++)
@@ -3109,6 +3112,37 @@ Debugger::StopEventHandlerThread()
     {
         GetCommandInterpreter().BroadcastEvent(CommandInterpreter::eBroadcastBitQuitCommandReceived);
         Host::ThreadJoin(m_event_handler_thread, NULL, NULL);
+        m_event_handler_thread = LLDB_INVALID_HOST_THREAD;
+    }
+}
+
+
+lldb::thread_result_t
+Debugger::IOHandlerThread (lldb::thread_arg_t arg)
+{
+    Debugger *debugger = (Debugger *)arg;
+    debugger->ExecuteIOHanders();
+    debugger->StopEventHandlerThread();
+    return NULL;
+}
+
+bool
+Debugger::StartIOHandlerThread()
+{
+    if (!IS_VALID_LLDB_HOST_THREAD(m_io_handler_thread))
+        m_io_handler_thread = Host::ThreadCreate("lldb.debugger.io-handler", IOHandlerThread, this, NULL);
+    return IS_VALID_LLDB_HOST_THREAD(m_io_handler_thread);
+}
+
+void
+Debugger::StopIOHandlerThread()
+{
+    if (IS_VALID_LLDB_HOST_THREAD(m_io_handler_thread))
+    {
+        if (m_input_file_sp)
+            m_input_file_sp->GetFile().Close();
+        Host::ThreadJoin(m_io_handler_thread, NULL, NULL);
+        m_io_handler_thread = LLDB_INVALID_HOST_THREAD;
     }
 }
 

Modified: lldb/branches/iohandler/source/Core/IOHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/iohandler/source/Core/IOHandler.cpp?rev=199341&r1=199340&r2=199341&view=diff
==============================================================================
--- lldb/branches/iohandler/source/Core/IOHandler.cpp (original)
+++ lldb/branches/iohandler/source/Core/IOHandler.cpp Wed Jan 15 18:09:08 2014
@@ -293,8 +293,7 @@ IOHandlerEditline::IOHandlerEditline (De
     m_multi_line (multi_line),
     m_interactive (false)
 {
-    if (prompt && prompt[0])
-        m_prompt = prompt;
+    SetPrompt(prompt);
 
     const int in_fd = GetInputFD();
     struct winsize window_size;
@@ -428,12 +427,22 @@ IOHandlerEditline::GetPrompt ()
 bool
 IOHandlerEditline::SetPrompt (const char *p)
 {
+    const char prompt_delimiter_char = m_debugger.GetCommandInterpreter().GetPromptDelimiterChar();
     if (p && p[0])
-        m_prompt = p;
+    {
+        if (prompt_delimiter_char)
+        {
+            m_prompt.assign(1, prompt_delimiter_char);
+            m_prompt.append(p);
+            m_prompt.append(1, prompt_delimiter_char);
+        }
+        else
+            m_prompt = p;
+    }
     else
         m_prompt.clear();
     if (m_editline_ap)
-        m_editline_ap->SetPrompt (p);
+        m_editline_ap->SetPrompt (m_prompt.empty() ? NULL : m_prompt.c_str());
     return true;
 }
 

Modified: lldb/branches/iohandler/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/iohandler/source/Interpreter/CommandInterpreter.cpp?rev=199341&r1=199340&r2=199341&view=diff
==============================================================================
--- lldb/branches/iohandler/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/branches/iohandler/source/Interpreter/CommandInterpreter.cpp Wed Jan 15 18:09:08 2014
@@ -109,6 +109,7 @@ CommandInterpreter::CommandInterpreter
     m_script_interpreter_ap (),
     m_command_io_handler_sp (),
     m_comment_char ('#'),
+    m_prompt_delimiter_char ('\0'),
     m_batch_command_mode (false),
     m_truncation_warning(eNoTruncation),
     m_command_source_depth (0)
@@ -2968,8 +2969,11 @@ CommandInterpreter::GetPythonCommandsFro
 
 }
 void
-CommandInterpreter::RunCommandInterpreter(bool auto_handle_events)
+CommandInterpreter::RunCommandInterpreter(bool auto_handle_events,
+                                          bool spawn_thread,
+                                          char prompt_delimiter)
 {
+    m_prompt_delimiter_char = prompt_delimiter;
     const bool multiple_lines = false; // Only get one line at a time
     if (!m_command_io_handler_sp)
         m_command_io_handler_sp.reset(new IOHandlerEditline (m_debugger,
@@ -2985,10 +2989,17 @@ CommandInterpreter::RunCommandInterprete
     if (auto_handle_events)
         m_debugger.StartEventHandlerThread();
     
-    m_debugger.ExecuteIOHanders();
+    if (spawn_thread)
+    {
+        m_debugger.StartEventHandlerThread();
+    }
+    else
+    {
+        m_debugger.ExecuteIOHanders();
     
-    if (auto_handle_events)
-        m_debugger.StopEventHandlerThread();
+        if (auto_handle_events)
+            m_debugger.StopEventHandlerThread();
+    }
 
 }
 

Modified: lldb/branches/iohandler/tools/driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/iohandler/tools/driver/Driver.cpp?rev=199341&r1=199340&r2=199341&view=diff
==============================================================================
--- lldb/branches/iohandler/tools/driver/Driver.cpp (original)
+++ lldb/branches/iohandler/tools/driver/Driver.cpp Wed Jan 15 18:09:08 2014
@@ -940,8 +940,11 @@ Driver::MainLoop ()
         result.PutError(m_debugger.GetErrorFileHandle());
         result.PutOutput(m_debugger.GetOutputFileHandle());
     }
-        
-    m_debugger.RunCommandInterpreter(true);
+    
+    bool handle_events = true;
+    bool spawn_thread = false;
+    char prompt_delimiter = '\0';
+    m_debugger.RunCommandInterpreter(handle_events, spawn_thread, prompt_delimiter);
     
     reset_stdin_termios();
     fclose (stdin);





More information about the llvm-branch-commits mailing list