teemperor updated this revision to Diff 158777. teemperor added a comment. - Fixing some of the merge conflicts. - Fixed doxygen comment.
Thanks for the reviews! https://reviews.llvm.org/D50159 Files: include/lldb/Core/StreamAsynchronousIO.h include/lldb/Core/StreamBuffer.h include/lldb/Core/StreamFile.h include/lldb/Utility/Stream.h include/lldb/Utility/StreamString.h include/lldb/Utility/StreamTee.h source/Core/StreamAsynchronousIO.cpp source/Core/StreamFile.cpp source/Utility/StreamString.cpp unittests/Utility/StreamTeeTest.cpp unittests/Utility/StreamTest.cpp
Index: unittests/Utility/StreamTest.cpp =================================================================== --- unittests/Utility/StreamTest.cpp +++ unittests/Utility/StreamTest.cpp @@ -44,149 +44,211 @@ TEST_F(StreamTest, PutChar) { s.PutChar('a'); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ("a", TakeValue()); s.PutChar('1'); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ("1", TakeValue()); } TEST_F(StreamTest, PutCharWhitespace) { s.PutChar(' '); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ(" ", TakeValue()); s.PutChar('\n'); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ("\n", TakeValue()); s.PutChar('\r'); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ("\r", TakeValue()); s.PutChar('\t'); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ("\t", TakeValue()); } TEST_F(StreamTest, PutCString) { s.PutCString(""); + EXPECT_EQ(0U, s.GetWrittenBytes()); EXPECT_EQ("", TakeValue()); s.PutCString("foobar"); + EXPECT_EQ(6U, s.GetWrittenBytes()); EXPECT_EQ("foobar", TakeValue()); s.PutCString(" "); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ(" ", TakeValue()); } TEST_F(StreamTest, PutCStringWithStringRef) { s.PutCString(llvm::StringRef("")); + EXPECT_EQ(0U, s.GetWrittenBytes()); EXPECT_EQ("", TakeValue()); s.PutCString(llvm::StringRef("foobar")); + EXPECT_EQ(6U, s.GetWrittenBytes()); EXPECT_EQ("foobar", TakeValue()); s.PutCString(llvm::StringRef(" ")); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ(" ", TakeValue()); } TEST_F(StreamTest, QuotedCString) { s.QuotedCString("foo"); + EXPECT_EQ(5U, s.GetWrittenBytes()); EXPECT_EQ(R"("foo")", TakeValue()); s.QuotedCString("ba r"); + EXPECT_EQ(6U, s.GetWrittenBytes()); EXPECT_EQ(R"("ba r")", TakeValue()); s.QuotedCString(" "); + EXPECT_EQ(3U, s.GetWrittenBytes()); EXPECT_EQ(R"(" ")", TakeValue()); } TEST_F(StreamTest, PutCharNull) { s.PutChar('\0'); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ(std::string("\0", 1), TakeValue()); s.PutChar('a'); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ(std::string("a", 1), TakeValue()); } TEST_F(StreamTest, PutCStringAsRawHex8) { s.PutCStringAsRawHex8(""); + EXPECT_EQ(0U, s.GetWrittenBytes()); EXPECT_EQ("", TakeValue()); s.PutCStringAsRawHex8("foobar"); + EXPECT_EQ(12U, s.GetWrittenBytes()); EXPECT_EQ("666f6f626172", TakeValue()); s.PutCStringAsRawHex8(" "); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("20", TakeValue()); } TEST_F(StreamTest, PutHex8) { s.PutHex8((uint8_t)55); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("37", TakeValue()); + s.PutHex8(std::numeric_limits<uint8_t>::max()); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("ff", TakeValue()); + s.PutHex8((uint8_t)0); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("00", TakeValue()); } TEST_F(StreamTest, PutNHex8) { s.PutNHex8(0, (uint8_t)55); + EXPECT_EQ(0U, s.GetWrittenBytes()); EXPECT_EQ("", TakeValue()); + s.PutNHex8(1, (uint8_t)55); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("37", TakeValue()); + s.PutNHex8(2, (uint8_t)55); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("3737", TakeValue()); + s.PutNHex8(1, (uint8_t)56); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("38", TakeValue()); } TEST_F(StreamTest, PutHex16ByteOrderLittle) { s.PutHex16(0x1234U, lldb::eByteOrderLittle); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("3412", TakeValue()); + s.PutHex16(std::numeric_limits<uint16_t>::max(), lldb::eByteOrderLittle); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("ffff", TakeValue()); + s.PutHex16(0U, lldb::eByteOrderLittle); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("0000", TakeValue()); } TEST_F(StreamTest, PutHex16ByteOrderBig) { s.PutHex16(0x1234U, lldb::eByteOrderBig); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("1234", TakeValue()); + s.PutHex16(std::numeric_limits<uint16_t>::max(), lldb::eByteOrderBig); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("ffff", TakeValue()); + s.PutHex16(0U, lldb::eByteOrderBig); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("0000", TakeValue()); } TEST_F(StreamTest, PutHex32ByteOrderLittle) { s.PutHex32(0x12345678U, lldb::eByteOrderLittle); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("78563412", TakeValue()); + s.PutHex32(std::numeric_limits<uint32_t>::max(), lldb::eByteOrderLittle); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("ffffffff", TakeValue()); + s.PutHex32(0U, lldb::eByteOrderLittle); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("00000000", TakeValue()); } TEST_F(StreamTest, PutHex32ByteOrderBig) { s.PutHex32(0x12345678U, lldb::eByteOrderBig); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("12345678", TakeValue()); + s.PutHex32(std::numeric_limits<uint32_t>::max(), lldb::eByteOrderBig); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("ffffffff", TakeValue()); + s.PutHex32(0U, lldb::eByteOrderBig); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("00000000", TakeValue()); } TEST_F(StreamTest, PutHex64ByteOrderLittle) { s.PutHex64(0x1234567890ABCDEFU, lldb::eByteOrderLittle); + EXPECT_EQ(16U, s.GetWrittenBytes()); EXPECT_EQ("efcdab9078563412", TakeValue()); + s.PutHex64(std::numeric_limits<uint64_t>::max(), lldb::eByteOrderLittle); + EXPECT_EQ(16U, s.GetWrittenBytes()); EXPECT_EQ("ffffffffffffffff", TakeValue()); + s.PutHex64(0U, lldb::eByteOrderLittle); + EXPECT_EQ(16U, s.GetWrittenBytes()); EXPECT_EQ("0000000000000000", TakeValue()); } TEST_F(StreamTest, PutHex64ByteOrderBig) { s.PutHex64(0x1234567890ABCDEFU, lldb::eByteOrderBig); + EXPECT_EQ(16U, s.GetWrittenBytes()); EXPECT_EQ("1234567890abcdef", TakeValue()); + s.PutHex64(std::numeric_limits<uint64_t>::max(), lldb::eByteOrderBig); + EXPECT_EQ(16U, s.GetWrittenBytes()); EXPECT_EQ("ffffffffffffffff", TakeValue()); + s.PutHex64(0U, lldb::eByteOrderBig); + EXPECT_EQ(16U, s.GetWrittenBytes()); EXPECT_EQ("0000000000000000", TakeValue()); } @@ -200,6 +262,7 @@ EXPECT_EQ(8U, bytes); bytes = s.PutMaxHex64(0x1234567890ABCDEFU, 8, lldb::eByteOrderBig); EXPECT_EQ(16U, bytes); + EXPECT_EQ(30U, s.GetWrittenBytes()); EXPECT_EQ("121234123456781234567890abcdef", TakeValue()); } @@ -213,6 +276,7 @@ EXPECT_EQ(8U, bytes); bytes = s.PutMaxHex64(0x1234567890ABCDEFU, 8, lldb::eByteOrderLittle); EXPECT_EQ(16U, bytes); + EXPECT_EQ(30U, s.GetWrittenBytes()); EXPECT_EQ("12341278563412efcdab9078563412", TakeValue()); } @@ -222,28 +286,33 @@ TEST_F(StreamTest, ShiftOperatorChars) { s << 'a' << 'b'; + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("ab", TakeValue()); } TEST_F(StreamTest, ShiftOperatorStrings) { s << "cstring\n"; + EXPECT_EQ(8U, s.GetWrittenBytes()); s << llvm::StringRef("llvm::StringRef\n"); + EXPECT_EQ(24U, s.GetWrittenBytes()); EXPECT_EQ("cstring\nllvm::StringRef\n", TakeValue()); } TEST_F(StreamTest, ShiftOperatorInts) { s << std::numeric_limits<int8_t>::max() << " "; s << std::numeric_limits<int16_t>::max() << " "; s << std::numeric_limits<int32_t>::max() << " "; s << std::numeric_limits<int64_t>::max(); + EXPECT_EQ(40U, s.GetWrittenBytes()); EXPECT_EQ("127 32767 2147483647 9223372036854775807", TakeValue()); } TEST_F(StreamTest, ShiftOperatorUInts) { s << std::numeric_limits<uint8_t>::max() << " "; s << std::numeric_limits<uint16_t>::max() << " "; s << std::numeric_limits<uint32_t>::max() << " "; s << std::numeric_limits<uint64_t>::max(); + EXPECT_EQ(33U, s.GetWrittenBytes()); EXPECT_EQ("ff ffff ffffffff ffffffffffffffff", TakeValue()); } @@ -259,6 +328,7 @@ int *ptr = &i; s << ptr; + EXPECT_NE(0U, s.GetWrittenBytes()); EXPECT_TRUE(!TakeValue().empty()); } @@ -268,6 +338,7 @@ int *ptr = &i; s.PutPointer(ptr); + EXPECT_NE(0U, s.GetWrittenBytes()); EXPECT_TRUE(!TakeValue().empty()); } @@ -283,27 +354,31 @@ uint32_t value = 0x12345678; s.PutBytesAsRawHex8(static_cast<void*>(&value), sizeof(value), hostByteOrder, lldb::eByteOrderBig); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("78563412", TakeValue()); } TEST_F(StreamTest, PutRawBytesToBigEndian) { uint32_t value = 0x12345678; s.PutRawBytes(static_cast<void*>(&value), sizeof(value), hostByteOrder, lldb::eByteOrderBig); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("\x78\x56\x34\x12", TakeValue()); } TEST_F(StreamTest, PutBytesAsRawHex8ToLittleEndian) { uint32_t value = 0x12345678; s.PutBytesAsRawHex8(static_cast<void*>(&value), sizeof(value), hostByteOrder, lldb::eByteOrderLittle); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("12345678", TakeValue()); } TEST_F(StreamTest, PutRawBytesToLittleEndian) { uint32_t value = 0x12345678; s.PutRawBytes(static_cast<void*>(&value), sizeof(value), hostByteOrder, lldb::eByteOrderLittle); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("\x12\x34\x56\x78", TakeValue()); } @@ -337,72 +412,84 @@ TEST_F(BinaryStreamTest, PutULEB128OneByte) { auto bytes = s.PutULEB128(0x74ULL); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ("\x74", TakeValue()); EXPECT_EQ(1U, bytes); } TEST_F(BinaryStreamTest, PutULEB128TwoBytes) { auto bytes = s.PutULEB128(0x1985ULL); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("\x85\x33", TakeValue()); EXPECT_EQ(2U, bytes); } TEST_F(BinaryStreamTest, PutULEB128ThreeBytes) { auto bytes = s.PutULEB128(0x5023ULL); + EXPECT_EQ(3U, s.GetWrittenBytes()); EXPECT_EQ("\xA3\xA0\x1", TakeValue()); EXPECT_EQ(3U, bytes); } TEST_F(BinaryStreamTest, PutULEB128FourBytes) { auto bytes = s.PutULEB128(0xA48032ULL); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("\xB2\x80\x92\x5", TakeValue()); EXPECT_EQ(4U, bytes); } TEST_F(BinaryStreamTest, PutULEB128FiveBytes) { auto bytes = s.PutULEB128(0x12345678ULL); + EXPECT_EQ(5U, s.GetWrittenBytes()); EXPECT_EQ("\xF8\xAC\xD1\x91\x1", TakeValue()); EXPECT_EQ(5U, bytes); } TEST_F(BinaryStreamTest, PutULEB128SixBytes) { auto bytes = s.PutULEB128(0xABFE3FAFDFULL); + EXPECT_EQ(6U, s.GetWrittenBytes()); EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\x15", TakeValue()); EXPECT_EQ(6U, bytes); } TEST_F(BinaryStreamTest, PutULEB128SevenBytes) { auto bytes = s.PutULEB128(0xDABFE3FAFDFULL); + EXPECT_EQ(7U, s.GetWrittenBytes()); EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\x3", TakeValue()); EXPECT_EQ(7U, bytes); } TEST_F(BinaryStreamTest, PutULEB128EightBytes) { auto bytes = s.PutULEB128(0x7CDABFE3FAFDFULL); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\xF3\x3", TakeValue()); EXPECT_EQ(8U, bytes); } TEST_F(BinaryStreamTest, PutULEB128NineBytes) { auto bytes = s.PutULEB128(0x327CDABFE3FAFDFULL); + EXPECT_EQ(9U, s.GetWrittenBytes()); EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\xF3\x93\x3", TakeValue()); EXPECT_EQ(9U, bytes); } TEST_F(BinaryStreamTest, PutULEB128MaxValue) { auto bytes = s.PutULEB128(std::numeric_limits<uint64_t>::max()); + EXPECT_EQ(10U, s.GetWrittenBytes()); EXPECT_EQ("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x1", TakeValue()); EXPECT_EQ(10U, bytes); } TEST_F(BinaryStreamTest, PutULEB128Zero) { auto bytes = s.PutULEB128(0x0U); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ(std::string("\0", 1), TakeValue()); EXPECT_EQ(1U, bytes); } TEST_F(BinaryStreamTest, PutULEB128One) { auto bytes = s.PutULEB128(0x1U); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ("\x1", TakeValue()); EXPECT_EQ(1U, bytes); } @@ -413,72 +500,84 @@ TEST_F(BinaryStreamTest, PutSLEB128OneByte) { auto bytes = s.PutSLEB128(0x74LL); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ(std::string("\xF4\0", 2), TakeValue()); EXPECT_EQ(2U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128TwoBytes) { auto bytes = s.PutSLEB128(0x1985LL); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("\x85\x33", TakeValue()); EXPECT_EQ(2U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128ThreeBytes) { auto bytes = s.PutSLEB128(0x5023LL); + EXPECT_EQ(3U, s.GetWrittenBytes()); EXPECT_EQ("\xA3\xA0\x1", TakeValue()); EXPECT_EQ(3U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128FourBytes) { auto bytes = s.PutSLEB128(0xA48032LL); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("\xB2\x80\x92\x5", TakeValue()); EXPECT_EQ(4U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128FiveBytes) { auto bytes = s.PutSLEB128(0x12345678LL); + EXPECT_EQ(5U, s.GetWrittenBytes()); EXPECT_EQ("\xF8\xAC\xD1\x91\x1", TakeValue()); EXPECT_EQ(5U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128SixBytes) { auto bytes = s.PutSLEB128(0xABFE3FAFDFLL); + EXPECT_EQ(6U, s.GetWrittenBytes()); EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\x15", TakeValue()); EXPECT_EQ(6U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128SevenBytes) { auto bytes = s.PutSLEB128(0xDABFE3FAFDFLL); + EXPECT_EQ(7U, s.GetWrittenBytes()); EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\x3", TakeValue()); EXPECT_EQ(7U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128EightBytes) { auto bytes = s.PutSLEB128(0x7CDABFE3FAFDFLL); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\xF3\x3", TakeValue()); EXPECT_EQ(8U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128NineBytes) { auto bytes = s.PutSLEB128(0x327CDABFE3FAFDFLL); + EXPECT_EQ(9U, s.GetWrittenBytes()); EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\xF3\x93\x3", TakeValue()); EXPECT_EQ(9U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128MaxValue) { auto bytes = s.PutSLEB128(std::numeric_limits<int64_t>::max()); + EXPECT_EQ(10U, s.GetWrittenBytes()); EXPECT_EQ(std::string("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\0", 10), TakeValue()); EXPECT_EQ(10U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128Zero) { auto bytes = s.PutSLEB128(0x0); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ(std::string("\0", 1), TakeValue()); EXPECT_EQ(1U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128One) { auto bytes = s.PutSLEB128(0x1); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ(std::string("\x1", 1), TakeValue()); EXPECT_EQ(1U, bytes); } @@ -492,12 +591,14 @@ TEST_F(StreamTest, PutULEB128) { auto bytes = s.PutULEB128(0x74ULL); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("0x74", TakeValue()); EXPECT_EQ(4U, bytes); } TEST_F(StreamTest, PutSLEB128) { auto bytes = s.PutSLEB128(0x1985LL); + EXPECT_EQ(6U, s.GetWrittenBytes()); EXPECT_EQ("0x6533", TakeValue()); EXPECT_EQ(6U, bytes); } Index: unittests/Utility/StreamTeeTest.cpp =================================================================== --- unittests/Utility/StreamTeeTest.cpp +++ unittests/Utility/StreamTeeTest.cpp @@ -90,7 +90,9 @@ void Flush() override { ++m_flush_count; } - size_t Write(const void *src, size_t src_len) override { return src_len; } + size_t WriteImpl(const void *src, size_t src_len) override { + return src_len; + } }; } Index: source/Utility/StreamString.cpp =================================================================== --- source/Utility/StreamString.cpp +++ source/Utility/StreamString.cpp @@ -24,12 +24,15 @@ // Nothing to do when flushing a buffer based stream... } -size_t StreamString::Write(const void *s, size_t length) { +size_t StreamString::WriteImpl(const void *s, size_t length) { m_packet.append(reinterpret_cast<const char *>(s), length); return length; } -void StreamString::Clear() { m_packet.clear(); } +void StreamString::Clear() { + m_packet.clear(); + m_bytes_written = 0; +} bool StreamString::Empty() const { return GetSize() == 0; } Index: source/Core/StreamFile.cpp =================================================================== --- source/Core/StreamFile.cpp +++ source/Core/StreamFile.cpp @@ -41,7 +41,7 @@ void StreamFile::Flush() { m_file.Flush(); } -size_t StreamFile::Write(const void *s, size_t length) { +size_t StreamFile::WriteImpl(const void *s, size_t length) { m_file.Write(s, length); return length; } Index: source/Core/StreamAsynchronousIO.cpp =================================================================== --- source/Core/StreamAsynchronousIO.cpp +++ source/Core/StreamAsynchronousIO.cpp @@ -31,7 +31,7 @@ } } -size_t StreamAsynchronousIO::Write(const void *s, size_t length) { +size_t StreamAsynchronousIO::WriteImpl(const void *s, size_t length) { m_data.append((const char *)s, length); return length; } Index: include/lldb/Utility/StreamTee.h =================================================================== --- include/lldb/Utility/StreamTee.h +++ include/lldb/Utility/StreamTee.h @@ -70,29 +70,6 @@ } } - size_t Write(const void *s, size_t length) override { - std::lock_guard<std::recursive_mutex> guard(m_streams_mutex); - if (m_streams.empty()) - return 0; - - size_t min_bytes_written = SIZE_MAX; - collection::iterator pos, end; - for (pos = m_streams.begin(), end = m_streams.end(); pos != end; ++pos) { - // Allow for our collection to contain NULL streams. This allows the - // StreamTee to be used with hard coded indexes for clients that might - // want N total streams with only a few that are set to valid values. - Stream *strm = pos->get(); - if (strm) { - const size_t bytes_written = strm->Write(s, length); - if (min_bytes_written > bytes_written) - min_bytes_written = bytes_written; - } - } - if (min_bytes_written == SIZE_MAX) - return 0; - return min_bytes_written; - } - size_t AppendStream(const lldb::StreamSP &stream_sp) { size_t new_idx = m_streams.size(); std::lock_guard<std::recursive_mutex> guard(m_streams_mutex); @@ -131,6 +108,29 @@ typedef std::vector<lldb::StreamSP> collection; mutable std::recursive_mutex m_streams_mutex; collection m_streams; + + size_t WriteImpl(const void *s, size_t length) override { + std::lock_guard<std::recursive_mutex> guard(m_streams_mutex); + if (m_streams.empty()) + return 0; + + size_t min_bytes_written = SIZE_MAX; + collection::iterator pos, end; + for (pos = m_streams.begin(), end = m_streams.end(); pos != end; ++pos) { + // Allow for our collection to contain NULL streams. This allows the + // StreamTee to be used with hard coded indexes for clients that might + // want N total streams with only a few that are set to valid values. + Stream *strm = pos->get(); + if (strm) { + const size_t bytes_written = strm->Write(s, length); + if (min_bytes_written > bytes_written) + min_bytes_written = bytes_written; + } + } + if (min_bytes_written == SIZE_MAX) + return 0; + return min_bytes_written; + } }; } // namespace lldb_private Index: include/lldb/Utility/StreamString.h =================================================================== --- include/lldb/Utility/StreamString.h +++ include/lldb/Utility/StreamString.h @@ -31,8 +31,6 @@ void Flush() override; - size_t Write(const void *s, size_t length) override; - void Clear(); bool Empty() const; @@ -49,6 +47,7 @@ protected: std::string m_packet; + size_t WriteImpl(const void *s, size_t length) override; }; } // namespace lldb_private Index: include/lldb/Utility/Stream.h =================================================================== --- include/lldb/Utility/Stream.h +++ include/lldb/Utility/Stream.h @@ -83,7 +83,13 @@ /// @return /// The number of bytes that were appended to the stream. //------------------------------------------------------------------ - virtual size_t Write(const void *src, size_t src_len) = 0; + size_t Write(const void *src, size_t src_len) { + size_t appended_byte_count = WriteImpl(src, src_len); + m_bytes_written += appended_byte_count; + return appended_byte_count; + } + + size_t GetWrittenBytes() const { return m_bytes_written; } //------------------------------------------------------------------ // Member functions @@ -523,8 +529,25 @@ lldb::ByteOrder m_byte_order; ///< Byte order to use when encoding scalar types. int m_indent_level; ///< Indention level. + std::size_t m_bytes_written = 0; ///< Number of bytes written so far. size_t _PutHex8(uint8_t uvalue, bool add_prefix); + + //------------------------------------------------------------------ + /// Output character bytes to the stream. + /// + /// Appends \a src_len characters from the buffer \a src to the stream. + /// + /// @param[in] src + /// A buffer containing at least \a src_len bytes of data. + /// + /// @param[in] src_len + /// A number of bytes to append to the stream. + /// + /// @return + /// The number of bytes that were appended to the stream. + //------------------------------------------------------------------ + virtual size_t WriteImpl(const void *src, size_t src_len) = 0; }; } // namespace lldb_private Index: include/lldb/Core/StreamFile.h =================================================================== --- include/lldb/Core/StreamFile.h +++ include/lldb/Core/StreamFile.h @@ -46,13 +46,13 @@ void Flush() override; - size_t Write(const void *s, size_t length) override; protected: //------------------------------------------------------------------ // Classes that inherit from StreamFile can see and modify these //------------------------------------------------------------------ File m_file; + size_t WriteImpl(const void *s, size_t length) override; private: DISALLOW_COPY_AND_ASSIGN(StreamFile); Index: include/lldb/Core/StreamBuffer.h =================================================================== --- include/lldb/Core/StreamBuffer.h +++ include/lldb/Core/StreamBuffer.h @@ -30,12 +30,6 @@ // Nothing to do when flushing a buffer based stream... } - virtual size_t Write(const void *s, size_t length) { - if (s && length) - m_packet.append((const char *)s, ((const char *)s) + length); - return length; - } - void Clear() { m_packet.clear(); } // Beware, this might not be NULL terminated as you can expect from @@ -48,6 +42,12 @@ protected: llvm::SmallVector<char, N> m_packet; + + virtual size_t WriteImpl(const void *s, size_t length) { + if (s && length) + m_packet.append((const char *)s, ((const char *)s) + length); + return length; + } }; } // namespace lldb_private Index: include/lldb/Core/StreamAsynchronousIO.h =================================================================== --- include/lldb/Core/StreamAsynchronousIO.h +++ include/lldb/Core/StreamAsynchronousIO.h @@ -30,7 +30,8 @@ void Flush() override; - size_t Write(const void *src, size_t src_len) override; +protected: + size_t WriteImpl(const void *src, size_t src_len) override; private: Debugger &m_debugger;
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits