diff options
author | Caroline Tice <ctice@apple.com> | 2011-05-02 20:41:46 +0000 |
---|---|---|
committer | Caroline Tice <ctice@apple.com> | 2011-05-02 20:41:46 +0000 |
commit | 969ed3d10f2bed3ef9c4d53114594827fefecf68 (patch) | |
tree | b7055dc7c40247fe6accf64529b215cd455b6f30 /lldb/source/Core | |
parent | f897d3b88bf5b09b7aa142e2033146bdeda5316f (diff) | |
download | bcm5719-llvm-969ed3d10f2bed3ef9c4d53114594827fefecf68.tar.gz bcm5719-llvm-969ed3d10f2bed3ef9c4d53114594827fefecf68.zip |
This patch captures and serializes all output being written by the
command line driver, including the lldb prompt being output by
editline, the asynchronous process output & error messages, and
asynchronous messages written by target stop-hooks.
As part of this it introduces a new Stream class,
StreamAsynchronousIO. A StreamAsynchronousIO object is created with a
broadcaster, who will eventually broadcast the stream's data for a
listener to handle, and an event type indicating what type of event
the broadcaster will broadcast. When the Write method is called on a
StreamAsynchronousIO object, the data is appended to an internal
string. When the Flush method is called on a StreamAsynchronousIO
object, it broadcasts it's data string and clears the string.
Anything in lldb-core that needs to generate asynchronous output for
the end-user should use the StreamAsynchronousIO objects.
I have also added a new notification type for InputReaders, to let
them know that a asynchronous output has been written. This is to
allow the input readers to, for example, refresh their prompts and
lines, if desired. I added the case statements to all the input
readers to catch this notification, but I haven't added any code for
handling them yet (except to the IOChannel input reader).
llvm-svn: 130721
Diffstat (limited to 'lldb/source/Core')
-rw-r--r-- | lldb/source/Core/Debugger.cpp | 14 | ||||
-rw-r--r-- | lldb/source/Core/Event.cpp | 7 | ||||
-rw-r--r-- | lldb/source/Core/InputReader.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Core/StreamAsynchronousIO.cpp | 52 |
4 files changed, 76 insertions, 0 deletions
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index f1a64b98209..f328c626fd1 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -423,6 +423,20 @@ Debugger::CleanUpInputReaders () } void +Debugger::NotifyTopInputReader (InputReaderAction notification) +{ + InputReaderSP reader_sp (GetCurrentInputReader()); + if (reader_sp) + { + reader_sp->Notify (notification); + + // Flush out any input readers that are done. + while (CheckIfTopInputReaderIsDone ()) + /* Do nothing. */; + } +} + +void Debugger::WriteToDefaultReader (const char *bytes, size_t bytes_len) { if (bytes && bytes_len) diff --git a/lldb/source/Core/Event.cpp b/lldb/source/Core/Event.cpp index 8b0ac16e2b6..ac122858c71 100644 --- a/lldb/source/Core/Event.cpp +++ b/lldb/source/Core/Event.cpp @@ -198,3 +198,10 @@ EventDataBytes::GetEventDataFromEvent (const Event *event_ptr) return NULL; } +void +EventDataBytes::SwapBytes (std::string &new_bytes) +{ + m_bytes.swap (new_bytes); +} + + diff --git a/lldb/source/Core/InputReader.cpp b/lldb/source/Core/InputReader.cpp index fc94bed0834..26f7f842314 100644 --- a/lldb/source/Core/InputReader.cpp +++ b/lldb/source/Core/InputReader.cpp @@ -327,6 +327,9 @@ InputReader::Notify (InputReaderAction notification) m_active = false; break; + case eInputReaderAsynchronousOutputWritten: + break; + case eInputReaderInterrupt: case eInputReaderEndOfFile: break; diff --git a/lldb/source/Core/StreamAsynchronousIO.cpp b/lldb/source/Core/StreamAsynchronousIO.cpp new file mode 100644 index 00000000000..84659c6e16b --- /dev/null +++ b/lldb/source/Core/StreamAsynchronousIO.cpp @@ -0,0 +1,52 @@ +//===-- StreamBroadcast.cpp -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> + +#include "lldb/lldb-private.h" +#include "lldb/Core/Broadcaster.h" +#include "lldb/Core/Event.h" +#include "lldb/Core/StreamAsynchronousIO.h" + +using namespace lldb; +using namespace lldb_private; + + +StreamAsynchronousIO::StreamAsynchronousIO (Broadcaster &broadcaster, uint32_t broadcast_event_type) : + Stream (0, 4, eByteOrderBig), + m_broadcaster (broadcaster), + m_broadcast_event_type (broadcast_event_type), + m_accumulated_data () +{ +} + +StreamAsynchronousIO::~StreamAsynchronousIO () +{ +} + +void +StreamAsynchronousIO::Flush () +{ + if (m_accumulated_data.GetSize() > 0) + { + std::auto_ptr<EventDataBytes> data_bytes_ap (new EventDataBytes); + // Let's swap the bytes to avoid LARGE string copies. + data_bytes_ap->SwapBytes (m_accumulated_data.GetString()); + EventSP new_event_sp (new Event (m_broadcast_event_type, data_bytes_ap.release())); + m_broadcaster.BroadcastEvent (new_event_sp); + m_accumulated_data.Clear(); + } +} + +int +StreamAsynchronousIO::Write (const void *s, size_t length) +{ + m_accumulated_data.Write (s, length); + return length; +} |