Alexander Shaposhnikov | 696bd63 | 2016-11-26 05:23:44 +0000 | [diff] [blame] | 1 | //===-- StreamAsynchronousIO.cpp --------------------------------*- C++ -*-===// |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 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 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Debugger.h" |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 13 | #include "lldb/lldb-enumerations.h" // for ByteOrder::eByteOrderBig |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 14 | |
| 15 | using namespace lldb; |
| 16 | using namespace lldb_private; |
| 17 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 18 | StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout) |
| 19 | : Stream(0, 4, eByteOrderBig), m_debugger(debugger), m_data(), |
| 20 | m_for_stdout(for_stdout) {} |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 21 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 22 | StreamAsynchronousIO::~StreamAsynchronousIO() { |
| 23 | // Flush when we destroy to make sure we display the data |
| 24 | Flush(); |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 25 | } |
| 26 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 27 | void StreamAsynchronousIO::Flush() { |
| 28 | if (!m_data.empty()) { |
| 29 | m_debugger.PrintAsync(m_data.data(), m_data.size(), m_for_stdout); |
| 30 | m_data = std::string(); |
| 31 | } |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 34 | size_t StreamAsynchronousIO::Write(const void *s, size_t length) { |
| 35 | m_data.append((const char *)s, length); |
| 36 | return length; |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 37 | } |