[Lldb-commits] [PATCH] D50159: Add byte counting mechanism to stream.

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 1 14:32:43 PDT 2018


teemperor created this revision.
teemperor added a reviewer: labath.

This patch allows LLDB's Stream class to count the bytes it has written to so far.

There are two major motivations for this patch:

The first one is that this will allow us to get rid of all the handwritten byte counting code
we have in LLDB so far. Examples for this are pretty much all functions in LLDB that
take a Stream to write to and return a size_t, which usually represents the bytes written.

By moving to this centralized byte counting mechanism, we hopefully can avoid some
tricky errors that happen when some code forgets to count the written bytes while
writing something to a stream.

The second motivation is that this is needed for the migration away from LLDB's `Stream`
and towards LLVM's `raw_ostream`. My current plan is to start offering a fake raw_ostream
class that just forwards to a LLDB Stream.

However, for this raw_ostream wrapper we need to fulfill the raw_ostream interface with
LLDB's Stream, which currently lacks the ability to count the bytes written so far (which
raw_ostream exposes by it's `tell()` method). By adding this functionality it is trivial to start
rolling out our raw_ostream wrapper (and then eventually completely move to raw_ostream).

Also, once this fake raw_ostream is available, we can start replacing our own code writing
to LLDB's Stream by LLVM code writing to raw_ostream. The best example for this is the
LEB128 encoding we currently ship, which can be replaced with by LLVM's version which
accepts an raw_ostream.


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50159.158634.patch
Type: text/x-patch
Size: 23784 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180801/9d0a319c/attachment-0001.bin>


More information about the lldb-commits mailing list