Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 1 | //===-- StreamBroadcast.cpp -------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 10 | #include "lldb/Core/StreamAsynchronousIO.h" |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 11 | |
| 12 | #include "lldb/lldb-private.h" |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Debugger.h" |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 14 | |
| 15 | using namespace lldb; |
| 16 | using namespace lldb_private; |
| 17 | |
| 18 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 19 | StreamAsynchronousIO::StreamAsynchronousIO (Debugger &debugger, bool for_stdout) : |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 20 | Stream (0, 4, eByteOrderBig), |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 21 | m_debugger (debugger), |
| 22 | m_data (), |
| 23 | m_for_stdout (for_stdout) |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 24 | { |
| 25 | } |
| 26 | |
| 27 | StreamAsynchronousIO::~StreamAsynchronousIO () |
| 28 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 29 | // Flush when we destroy to make sure we display the data |
| 30 | Flush(); |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | void |
| 34 | StreamAsynchronousIO::Flush () |
| 35 | { |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 36 | if (!m_data.empty()) |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 37 | { |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 38 | m_debugger.PrintAsync (m_data.data(), m_data.size(), m_for_stdout); |
| 39 | m_data = std::move(std::string()); |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 40 | } |
| 41 | } |
| 42 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 43 | size_t |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 44 | StreamAsynchronousIO::Write (const void *s, size_t length) |
| 45 | { |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 46 | m_data.append ((const char *)s, length); |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 47 | return length; |
| 48 | } |