blob: ccfde0c9a011934e2dd430caaf8aa5d99a9bc5e0 [file] [log] [blame]
Caroline Tice969ed3d2011-05-02 20:41:46 +00001//===-- 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 Labath44464872015-05-27 12:40:32 +000010#include "lldb/Core/StreamAsynchronousIO.h"
Caroline Tice969ed3d2011-05-02 20:41:46 +000011
12#include "lldb/lldb-private.h"
Pavel Labath44464872015-05-27 12:40:32 +000013#include "lldb/Core/Debugger.h"
Caroline Tice969ed3d2011-05-02 20:41:46 +000014
15using namespace lldb;
16using namespace lldb_private;
17
18
Pavel Labath44464872015-05-27 12:40:32 +000019StreamAsynchronousIO::StreamAsynchronousIO (Debugger &debugger, bool for_stdout) :
Caroline Tice969ed3d2011-05-02 20:41:46 +000020 Stream (0, 4, eByteOrderBig),
Pavel Labath44464872015-05-27 12:40:32 +000021 m_debugger (debugger),
22 m_data (),
23 m_for_stdout (for_stdout)
Caroline Tice969ed3d2011-05-02 20:41:46 +000024{
25}
26
27StreamAsynchronousIO::~StreamAsynchronousIO ()
28{
Greg Clayton44d93782014-01-27 23:43:24 +000029 // Flush when we destroy to make sure we display the data
30 Flush();
Caroline Tice969ed3d2011-05-02 20:41:46 +000031}
32
33void
34StreamAsynchronousIO::Flush ()
35{
Pavel Labath44464872015-05-27 12:40:32 +000036 if (!m_data.empty())
Caroline Tice969ed3d2011-05-02 20:41:46 +000037 {
Pavel Labath44464872015-05-27 12:40:32 +000038 m_debugger.PrintAsync (m_data.data(), m_data.size(), m_for_stdout);
39 m_data = std::move(std::string());
Caroline Tice969ed3d2011-05-02 20:41:46 +000040 }
41}
42
Greg Claytonc7bece562013-01-25 18:06:21 +000043size_t
Caroline Tice969ed3d2011-05-02 20:41:46 +000044StreamAsynchronousIO::Write (const void *s, size_t length)
45{
Pavel Labath44464872015-05-27 12:40:32 +000046 m_data.append ((const char *)s, length);
Caroline Tice969ed3d2011-05-02 20:41:46 +000047 return length;
48}