Utility class for counting the bytes that were written to a stream in a certain time span.
Utility class for counting the bytes that were written to a stream in a certain time span. ByteDelta delta(*this); WriteDataToStream("foo"); return *delta;
#ifndef LLDB_UTILITY_STREAM_H
#define LLDB_UTILITY_STREAM_H
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <type_traits>
class Stream {
public:
enum {
};
struct HighlightSettings {
HighlightSettings(llvm::StringRef p, llvm::StringRef pre,
llvm::StringRef suf)
};
class ByteDelta {
public:
};
bool colors = false);
Stream(bool colors = false);
Stream(
const Stream &other) :
m_forwarder(*
this) { (*this) = other; }
return *this;
}
virtual void Flush() = 0;
size_t Write(
const void *src,
size_t src_len) {
size_t appended_byte_count =
WriteImpl(src, src_len);
return appended_byte_count;
}
__attribute__((__format__(__printf__, 2, 3)));
size_t PutNHex8(
size_t n, uint8_t uvalue);
size_t
llvm::StringRef text,
std::optional<HighlightSettings> settings = std::nullopt);
size_t Indent(llvm::StringRef s =
"");
void Offset(uint32_t offset,
const char *format =
"0x%8.8x: ");
size_t Printf(
const char *format, ...) __attribute__((format(printf, 2, 3)));
template <typename... Args> void Format(const char *format, Args &&... args) {
PutCString(llvm::formatv(format, std::forward<Args>(args)...).str());
}
void QuotedCString(
const char *cstr,
const char *format =
"\"%s\"");
}
protected:
void _PutHex8(uint8_t uvalue,
bool add_prefix);
virtual size_t WriteImpl(
const void *src,
size_t src_len) = 0;
class RawOstreamForward : public llvm::raw_ostream {
void write_impl(
const char *Ptr,
size_t Size)
override {
}
}
public:
RawOstreamForward(Stream &target, bool colors = false)
: llvm::raw_ostream(
true),
m_target(target) {
enable_colors(colors);
}
};
};
void DumpAddress(llvm::raw_ostream &s, uint64_t addr, uint32_t addr_size,
const char *prefix = nullptr, const char *suffix = nullptr);
uint32_t addr_size, const char *prefix = nullptr,
const char *suffix = nullptr);
}
#endif
ValueType m_flags
The flags.
size_t operator*() const
Returns the number of bytes written to the given Stream since this ByteDelta object was created.
size_t m_start
Bytes we have written so far when ByteDelta was created.
uint64_t current_pos() const override
void write_impl(const char *Ptr, size_t Size) override
unsigned m_indent_level
Indention level.
size_t PrintfAsRawHex8(const char *format,...) __attribute__((__format__(__printf__
Format a C string from a printf style format and variable arguments and encode and append the resulti...
Flags & GetFlags()
The flags accessor.
lldb::ByteOrder GetByteOrder() const
virtual size_t WriteImpl(const void *src, size_t src_len)=0
Output character bytes to the stream.
size_t PutNHex8(size_t n, uint8_t uvalue)
uint32_t GetAddressByteSize() const
Get the address size in bytes.
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
void Offset(uint32_t offset, const char *format="0x%8.8x: ")
Output an offset value.
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
@ eBinary
Get and put data as binary instead of as the default string mode.
size_t PutDouble(double d, lldb::ByteOrder byte_order=lldb::eByteOrderInvalid)
size_t size_t PutHex8(uint8_t uvalue)
Append an uint8_t value in the hexadecimal format to the stream.
size_t PutStringAsRawHex8(llvm::StringRef s)
uint32_t m_addr_size
Size of an address in bytes.
size_t PutHex64(uint64_t uvalue, lldb::ByteOrder byte_order=lldb::eByteOrderInvalid)
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
void SetAddressByteSize(uint32_t addr_size)
Set the address size in bytes.
RawOstreamForward m_forwarder
virtual ~Stream()
Destructor.
lldb::ByteOrder SetByteOrder(lldb::ByteOrder byte_order)
Set the byte_order value.
size_t PutHex16(uint16_t uvalue, lldb::ByteOrder byte_order=lldb::eByteOrderInvalid)
Stream & operator=(const Stream &rhs)
void QuotedCString(const char *cstr, const char *format="\"%s\"")
Output a quoted C string value to the stream.
size_t size_t PrintfVarArg(const char *format, va_list args)
size_t PutHex32(uint32_t uvalue, lldb::ByteOrder byte_order=lldb::eByteOrderInvalid)
void SetIndentLevel(unsigned level)
Set the current indentation level.
std::size_t m_bytes_written
Number of bytes written so far.
Stream & operator<<(const char *cstr)
Output a NULL terminated C string cstr to the stream s.
void PutCStringColorHighlighted(llvm::StringRef text, std::optional< HighlightSettings > settings=std::nullopt)
Output a C string to the stream with color highlighting.
void _PutHex8(uint8_t uvalue, bool add_prefix)
virtual void Flush()=0
Flush the stream.
size_t EOL()
Output and End of Line character to the stream.
size_t GetWrittenBytes() const
lldb::ByteOrder m_byte_order
Byte order to use when encoding scalar types.
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
size_t PutULEB128(uint64_t uval)
Output a ULEB128 number to the stream.
size_t PutBytesAsRawHex8(const void *src, size_t src_len, lldb::ByteOrder src_byte_order=lldb::eByteOrderInvalid, lldb::ByteOrder dst_byte_order=lldb::eByteOrderInvalid)
size_t PutLongDouble(long double ld, lldb::ByteOrder byte_order=lldb::eByteOrderInvalid)
size_t PutSLEB128(int64_t uval)
Output a SLEB128 number to the stream.
void IndentMore(unsigned amount=2)
Increment the current indentation level.
size_t PutPointer(void *ptr)
size_t PutRawBytes(const void *s, size_t src_len, lldb::ByteOrder src_byte_order=lldb::eByteOrderInvalid, lldb::ByteOrder dst_byte_order=lldb::eByteOrderInvalid)
size_t PutFloat(float f, lldb::ByteOrder byte_order=lldb::eByteOrderInvalid)
size_t PutMaxHex64(uint64_t uvalue, size_t byte_size, lldb::ByteOrder byte_order=lldb::eByteOrderInvalid)
unsigned GetIndentLevel() const
Get the current indentation level.
A class that represents a running process on the host machine.
void DumpAddressRange(llvm::raw_ostream &s, uint64_t lo_addr, uint64_t hi_addr, uint32_t addr_size, const char *prefix=nullptr, const char *suffix=nullptr)
Output an address range to this stream.
void DumpAddress(llvm::raw_ostream &s, uint64_t addr, uint32_t addr_size, const char *prefix=nullptr, const char *suffix=nullptr)
Output an address value to this stream.
ByteOrder
Byte ordering definitions.
llvm::StringRef pattern
Regex pattern for highlighting.
llvm::StringRef prefix
ANSI color code to start colorization.
llvm::StringRef suffix
ANSI color code to end colorization.