blob: aae8636bff098f3c65e5f71345649dfa6a6b1af7 [file] [log] [blame]
Alexander Shaposhnikov696bd632016-11-26 05:23:44 +00001//===-- StreamAsynchronousIO.cpp --------------------------------*- C++ -*-===//
Caroline Tice969ed3d2011-05-02 20:41:46 +00002//
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 Labath44464872015-05-27 12:40:32 +000010#include "lldb/Core/StreamAsynchronousIO.h"
Caroline Tice969ed3d2011-05-02 20:41:46 +000011
Pavel Labath44464872015-05-27 12:40:32 +000012#include "lldb/Core/Debugger.h"
Zachary Turner2f3df612017-04-06 21:28:29 +000013#include "lldb/lldb-enumerations.h" // for ByteOrder::eByteOrderBig
Caroline Tice969ed3d2011-05-02 20:41:46 +000014
15using namespace lldb;
16using namespace lldb_private;
17
Kate Stoneb9c1b512016-09-06 20:57:50 +000018StreamAsynchronousIO::StreamAsynchronousIO(Debugger &debugger, bool for_stdout)
19 : Stream(0, 4, eByteOrderBig), m_debugger(debugger), m_data(),
20 m_for_stdout(for_stdout) {}
Caroline Tice969ed3d2011-05-02 20:41:46 +000021
Kate Stoneb9c1b512016-09-06 20:57:50 +000022StreamAsynchronousIO::~StreamAsynchronousIO() {
23 // Flush when we destroy to make sure we display the data
24 Flush();
Caroline Tice969ed3d2011-05-02 20:41:46 +000025}
26
Kate Stoneb9c1b512016-09-06 20:57:50 +000027void 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 Tice969ed3d2011-05-02 20:41:46 +000032}
33
Kate Stoneb9c1b512016-09-06 20:57:50 +000034size_t StreamAsynchronousIO::Write(const void *s, size_t length) {
35 m_data.append((const char *)s, length);
36 return length;
Caroline Tice969ed3d2011-05-02 20:41:46 +000037}