14#include "llvm/ADT/SmallString.h"
15#include "llvm/Support/Format.h"
16#include "llvm/Support/LEB128.h"
17#include "llvm/Support/Regex.h"
29 : m_flags(flags), m_addr_size(addr_size), m_byte_order(byte_order),
30 m_forwarder(*this, colors) {}
33 : m_flags(0), m_byte_order(endian::InlHostByteOrder()),
34 m_forwarder(*this, colors) {}
42 return old_byte_order;
53 return Printf(
"0x%" PRIi64, sval);
61 return Printf(
"0x%" PRIx64, uval);
66 size_t bytes_written = 0;
67 bytes_written =
Write(str.data(), str.size());
76 llvm::StringRef text, std::optional<HighlightSettings> pattern_info) {
79 if (!pattern_info.has_value()) {
84 llvm::Regex reg_pattern(pattern_info->pattern);
85 llvm::SmallVector<llvm::StringRef, 1> matches;
86 llvm::StringRef remaining = text;
88 pattern_info->prefix.str() +
"%.*s" + pattern_info->suffix.str());
89 while (reg_pattern.match(remaining, &matches)) {
90 llvm::StringRef match = matches[0];
91 size_t match_start_pos = match.data() - remaining.data();
92 PutCString(remaining.take_front(match_start_pos));
93 Printf(format_str.c_str(), match.size(), match.data());
94 remaining = remaining.drop_front(match_start_pos + match.size());
109 uint32_t addr_size,
const char *prefix,
110 const char *suffix) {
111 if (prefix ==
nullptr)
113 if (suffix ==
nullptr)
115 s << prefix << llvm::format_hex(addr, 2 + 2 * addr_size) << suffix;
121 uint64_t hi_addr, uint32_t addr_size,
122 const char *prefix,
const char *suffix) {
123 if (prefix && prefix[0])
127 if (suffix && suffix[0])
136 va_start(args, format);
144 llvm::SmallString<1024> buf;
148 size_t length = buf.size();
151 return Write(buf.c_str(), length);
160 return ind_length + str_length;
176 Write(str.data(), str.size());
182 Printf(
"0x%.*tx",
static_cast<int>(
sizeof(
const void *)) * 2, (ptrdiff_t)p);
223 va_start(args, format);
225 llvm::SmallString<1024> buf;
239 for (
size_t i = 0; i < n; ++i)
251 static char g_hex_to_ascii_hex_char[16] = {
'0',
'1',
'2',
'3',
'4',
'5',
252 '6',
'7',
'8',
'9',
'a',
'b',
254 char nibble_chars[2];
255 nibble_chars[0] = g_hex_to_ascii_hex_char[(uvalue >> 4) & 0xf];
256 nibble_chars[1] = g_hex_to_ascii_hex_char[(uvalue >> 0) & 0xf];
257 Write(nibble_chars,
sizeof(nibble_chars));
274 for (
size_t byte = 0;
byte <
sizeof(uvalue); ++byte)
275 _PutHex8(
static_cast<uint8_t
>(uvalue >> (
byte * 8)),
false);
277 for (
size_t byte =
sizeof(uvalue) - 1;
byte <
sizeof(uvalue); --byte)
278 _PutHex8(
static_cast<uint8_t
>(uvalue >> (
byte * 8)),
false);
290 for (
size_t byte = 0;
byte <
sizeof(uvalue); ++byte)
291 _PutHex8(
static_cast<uint8_t
>(uvalue >> (
byte * 8)),
false);
293 for (
size_t byte =
sizeof(uvalue) - 1;
byte <
sizeof(uvalue); --byte)
294 _PutHex8(
static_cast<uint8_t
>(uvalue >> (
byte * 8)),
false);
306 for (
size_t byte = 0;
byte <
sizeof(uvalue); ++byte)
307 _PutHex8(
static_cast<uint8_t
>(uvalue >> (
byte * 8)),
false);
309 for (
size_t byte =
sizeof(uvalue) - 1;
byte <
sizeof(uvalue); --byte)
310 _PutHex8(
static_cast<uint8_t
>(uvalue >> (
byte * 8)),
false);
319 return PutHex8(
static_cast<uint8_t
>(uvalue));
321 return PutHex16(
static_cast<uint16_t
>(uvalue), byte_order);
323 return PutHex32(
static_cast<uint32_t
>(uvalue), byte_order);
325 return PutHex64(uvalue, byte_order);
366 const uint8_t *src =
static_cast<const uint8_t *
>(s);
370 if (src_byte_order == dst_byte_order) {
371 for (
size_t i = 0; i < src_len; ++i)
374 for (
size_t i = src_len; i > 0; --i)
394 const uint8_t *src =
static_cast<const uint8_t *
>(s);
397 if (src_byte_order == dst_byte_order) {
398 for (
size_t i = 0; i < src_len; ++i)
401 for (
size_t i = src_len; i > 0; --i)
ValueType Clear(ValueType mask=~static_cast< ValueType >(0))
Clear one or more flags.
bool Test(ValueType bit) const
Test a single flag bit.
ValueType Set(ValueType mask)
Set one or more flags by logical OR'ing mask with the current flags.
A stream class that can stream formatted output to a file.
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
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.
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)
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.
Stream & operator<<(const char *cstr)
Output a NULL terminated C string cstr to the stream s.
Stream(uint32_t flags, uint32_t addr_size, lldb::ByteOrder byte_order, bool colors=false)
Construct with flags and address size and byte order.
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)
size_t EOL()
Output and End of Line character to the stream.
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.
std::string FormatAnsiTerminalCodes(llvm::StringRef format, bool do_color=true)
lldb::ByteOrder InlHostByteOrder()
A class that represents a running process on the host machine.
bool VASprintf(llvm::SmallVectorImpl< char > &buf, const char *fmt, va_list args)
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.