[LLVMdev] [PATCH] Circular Buffered Debug Stream

Chris Lattner clattner at apple.com
Mon Dec 21 11:40:58 PST 2009

On Dec 21, 2009, at 8:05 AM, David Greene wrote:

> On Friday 18 December 2009 20:20, David Greene wrote:
>> I wanted something to signify in the output where the debug dump starts.
>> That's for that case where some stuff might still get output through
>> errs(). I anticipate that while I'll change most uses of errs() to dbgs(),
>> we probably don't want to change all of them.
>> I agree the naming here is poor.  I'll fix that.
> Here's the next iteration.

Gentle reminder, please include patches as attachments, it makes them easier to review.

>> Now that I understand the model :) I don't see why you need to fiddle
>> with the underlying buffering of TheStream.  In the dbgs() use case,
>> the underlying stream will be errs() which is already unbuffered.
> Might circular_raw_ostream be used with other streams at some point?

In that case, setting the underlying stream to unbuffered seems even more dangerous.    The client who sets up the buffers has both the power and the knowledge to set the streams up correctly when the streams are created.

> +    /// flushBuffer - Dump the contents of the buffer to Stream.
> +    ///
> +    void flushBuffer(void) {
> +      // Write the older portion of the buffer.
> +      TheStream->write(Cur, BufferArray + BufferSize - Cur);
> +      // Write the newer portion of the buffer.
> +      TheStream->write(BufferArray, Cur - BufferArray);
> +      Cur = BufferArray;
> +    }

Is this correct in the case when the circular buffer hasn't completely filled yet?

> +void circular_raw_ostream::flushBufferWithBanner(void) {
> +  if (BufferSize != 0) {
> +    // Write out the buffer
> +    const char *msg = "*** Log Output ***\n";

This is not generic.  If you really want something like this, the string to print should be provided to the ctor.


More information about the llvm-dev mailing list