1 //===-- Stream.h ------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Stream_h_
11 #define liblldb_Stream_h_
12 #if defined(__cplusplus)
14 #include "lldb/lldb-private.h"
15 #include "lldb/Core/Flags.h"
18 namespace lldb_private {
20 //----------------------------------------------------------------------
21 /// @class Stream Stream.h "lldb/Core/Stream.h"
22 /// @brief A stream class that can stream formatted output to a file.
23 //----------------------------------------------------------------------
27 //------------------------------------------------------------------
28 /// \a m_flags bit values.
29 //------------------------------------------------------------------
32 eVerbose = (1 << 0), ///< If set, verbose logging is enabled
33 eDebug = (1 << 1), ///< If set, debug logging is enabled
34 eAddPrefix = (1 << 2), ///< Add number prefixes for binary, octal and hex when eBinary is clear
35 eBinary = (1 << 3) ///< Get and put data as binary instead of as the default string mode.
38 //------------------------------------------------------------------
39 /// Construct with flags and address size and byte order.
41 /// Construct with dump flags \a flags and the default address
42 /// size. \a flags can be any of the above enumeration logical OR'ed
44 //------------------------------------------------------------------
45 Stream (uint32_t flags,
47 lldb::ByteOrder byte_order);
49 //------------------------------------------------------------------
50 /// Construct a default Stream, not binary, host byte order and
53 //------------------------------------------------------------------
56 //------------------------------------------------------------------
58 //------------------------------------------------------------------
62 //------------------------------------------------------------------
63 // Subclasses must override these methods
64 //------------------------------------------------------------------
66 //------------------------------------------------------------------
69 /// Subclasses should flush the stream to make any output appear
70 /// if the stream has any buffering.
71 //------------------------------------------------------------------
75 //------------------------------------------------------------------
76 /// Output character bytes to the stream.
78 /// Appends \a src_len characters from the buffer \a src to the
82 /// A buffer containing at least \a src_len bytes of data.
84 /// @param[in] src_len
85 /// A number of bytes to append to the stream.
88 /// The number of bytes that were appended to the stream.
89 //------------------------------------------------------------------
91 Write (const void *src, size_t src_len) = 0;
93 //------------------------------------------------------------------
95 //------------------------------------------------------------------
99 //------------------------------------------------------------------
100 /// Set the byte_order value.
102 /// Sets the byte order of the data to extract. Extracted values
103 /// will be swapped if necessary when decoding.
105 /// @param[in] byte_order
106 /// The byte order value to use when extracting data.
109 /// The old byte order value.
110 //------------------------------------------------------------------
112 SetByteOrder (lldb::ByteOrder byte_order);
114 //------------------------------------------------------------------
115 /// Format a C string from a printf style format and variable
116 /// arguments and encode and append the resulting C string as hex
119 /// @param[in] format
120 /// A printf style format string.
123 /// Any additional arguments needed for the printf format string.
126 /// The number of bytes that were appended to the stream.
127 //------------------------------------------------------------------
129 PrintfAsRawHex8 (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
131 //------------------------------------------------------------------
132 /// Format a C string from a printf style format and variable
133 /// arguments and encode and append the resulting C string as hex
136 /// @param[in] format
137 /// A printf style format string.
140 /// Any additional arguments needed for the printf format string.
143 /// The number of bytes that were appended to the stream.
144 //------------------------------------------------------------------
146 PutHex8 (uint8_t uvalue);
149 PutNHex8 (size_t n, uint8_t uvalue);
152 PutHex16 (uint16_t uvalue,
153 lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);
156 PutHex32 (uint32_t uvalue,
157 lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);
160 PutHex64 (uint64_t uvalue,
161 lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);
164 PutMaxHex64 (uint64_t uvalue,
166 lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);
169 lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);
173 lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);
176 PutLongDouble (long double ld,
177 lldb::ByteOrder byte_order = lldb::eByteOrderInvalid);
180 PutPointer (void *ptr);
182 // Append \a src_len bytes from \a src to the stream as hex characters
183 // (two ascii characters per byte of input data)
185 PutBytesAsRawHex8 (const void *src,
187 lldb::ByteOrder src_byte_order = lldb::eByteOrderInvalid,
188 lldb::ByteOrder dst_byte_order = lldb::eByteOrderInvalid);
190 // Append \a src_len bytes from \a s to the stream as binary data.
192 PutRawBytes (const void *s,
194 lldb::ByteOrder src_byte_order = lldb::eByteOrderInvalid,
195 lldb::ByteOrder dst_byte_order = lldb::eByteOrderInvalid);
198 PutCStringAsRawHex8 (const char *s);
200 //------------------------------------------------------------------
201 /// Output a NULL terminated C string \a cstr to the stream \a s.
204 /// A NULL terminated C string.
207 /// A reference to this class so multiple things can be streamed
208 /// in one statement.
209 //------------------------------------------------------------------
211 operator<< (const char *cstr);
213 //------------------------------------------------------------------
214 /// Output a pointer value \a p to the stream \a s.
220 /// A reference to this class so multiple things can be streamed
221 /// in one statement.
222 //------------------------------------------------------------------
224 operator<< (void *p);
226 //------------------------------------------------------------------
227 /// Output a character \a ch to the stream \a s.
230 /// A printable character value.
233 /// A reference to this class so multiple things can be streamed
234 /// in one statement.
235 //------------------------------------------------------------------
237 operator<< (char ch);
239 //------------------------------------------------------------------
240 /// Output a uint8_t \a uval to the stream \a s.
246 /// A reference to this class so multiple things can be streamed
247 /// in one statement.
248 //------------------------------------------------------------------
250 operator<< (uint8_t uval);
252 //------------------------------------------------------------------
253 /// Output a uint16_t \a uval to the stream \a s.
256 /// A uint16_t value.
259 /// A reference to this class so multiple things can be streamed
260 /// in one statement.
261 //------------------------------------------------------------------
263 operator<< (uint16_t uval);
265 //------------------------------------------------------------------
266 /// Output a uint32_t \a uval to the stream \a s.
269 /// A uint32_t value.
272 /// A reference to this class so multiple things can be streamed
273 /// in one statement.
274 //------------------------------------------------------------------
276 operator<< (uint32_t uval);
278 //------------------------------------------------------------------
279 /// Output a uint64_t \a uval to the stream \a s.
282 /// A uint64_t value.
285 /// A reference to this class so multiple things can be streamed
286 /// in one statement.
287 //------------------------------------------------------------------
289 operator<< (uint64_t uval);
291 //------------------------------------------------------------------
292 /// Output a int8_t \a sval to the stream \a s.
298 /// A reference to this class so multiple things can be streamed
299 /// in one statement.
300 //------------------------------------------------------------------
302 operator<< (int8_t sval);
304 //------------------------------------------------------------------
305 /// Output a int16_t \a sval to the stream \a s.
311 /// A reference to this class so multiple things can be streamed
312 /// in one statement.
313 //------------------------------------------------------------------
315 operator<< (int16_t sval);
317 //------------------------------------------------------------------
318 /// Output a int32_t \a sval to the stream \a s.
324 /// A reference to this class so multiple things can be streamed
325 /// in one statement.
326 //------------------------------------------------------------------
328 operator<< (int32_t sval);
330 //------------------------------------------------------------------
331 /// Output a int64_t \a sval to the stream \a s.
337 /// A reference to this class so multiple things can be streamed
338 /// in one statement.
339 //------------------------------------------------------------------
341 operator<< (int64_t sval);
343 //------------------------------------------------------------------
344 /// Output an address value to this stream.
346 /// Put an address \a addr out to the stream with optional \a prefix
347 /// and \a suffix strings.
350 /// An address value.
352 /// @param[in] addr_size
353 /// Size in bytes of the address, used for formatting.
355 /// @param[in] prefix
356 /// A prefix C string. If NULL, no prefix will be output.
358 /// @param[in] suffix
359 /// A suffix C string. If NULL, no suffix will be output.
360 //------------------------------------------------------------------
362 Address (uint64_t addr, uint32_t addr_size, const char *prefix = NULL, const char *suffix = NULL);
364 //------------------------------------------------------------------
365 /// Output an address range to this stream.
367 /// Put an address range \a lo_addr - \a hi_addr out to the stream
368 /// with optional \a prefix and \a suffix strings.
370 /// @param[in] lo_addr
371 /// The start address of the address range.
373 /// @param[in] hi_addr
374 /// The end address of the address range.
376 /// @param[in] addr_size
377 /// Size in bytes of the address, used for formatting.
379 /// @param[in] prefix
380 /// A prefix C string. If NULL, no prefix will be output.
382 /// @param[in] suffix
383 /// A suffix C string. If NULL, no suffix will be output.
384 //------------------------------------------------------------------
386 AddressRange(uint64_t lo_addr, uint64_t hi_addr, uint32_t addr_size, const char *prefix = NULL, const char *suffix = NULL);
388 //------------------------------------------------------------------
389 /// Output a C string to the stream.
391 /// Print a C string \a cstr to the stream.
394 /// The string to be output to the stream.
395 //------------------------------------------------------------------
397 PutCString (const char *cstr);
399 //------------------------------------------------------------------
400 /// Output and End of Line character to the stream.
401 //------------------------------------------------------------------
405 //------------------------------------------------------------------
406 /// Get the address size in bytes.
409 /// The size of an address in bytes that is used when outputting
410 /// address and pointer values to the stream.
411 //------------------------------------------------------------------
413 GetAddressByteSize () const;
415 //------------------------------------------------------------------
416 /// Test if debug logging is enabled.
419 // \b true if the debug flag bit is set in this stream, \b
421 //------------------------------------------------------------------
425 //------------------------------------------------------------------
426 /// The flags accessor.
429 /// A reference to the Flags member variable.
430 //------------------------------------------------------------------
434 //------------------------------------------------------------------
435 /// The flags const accessor.
438 /// A const reference to the Flags member variable.
439 //------------------------------------------------------------------
443 //------------------------------------------------------------------
444 //// The byte order accessor.
448 //------------------------------------------------------------------
450 GetByteOrder() const;
452 //------------------------------------------------------------------
453 /// Get the current indentation level.
456 /// The current indentation level as an integer.
457 //------------------------------------------------------------------
459 GetIndentLevel () const;
461 //------------------------------------------------------------------
462 /// Test if verbose logging is enabled.
465 // \b true if the verbose flag bit is set in this stream, \b
467 //------------------------------------------------------------------
471 //------------------------------------------------------------------
472 /// Indent the current line in the stream.
474 /// Indent the current line using the current indentation level and
475 /// print an optional string following the idenatation spaces.
478 /// A C string to print following the indentation. If NULL, just
479 /// output the indentation characters.
480 //------------------------------------------------------------------
482 Indent(const char *s = NULL);
484 //------------------------------------------------------------------
485 /// Decrement the current indentation level.
486 //------------------------------------------------------------------
488 IndentLess (int amount = 2);
490 //------------------------------------------------------------------
491 /// Increment the current indentation level.
492 //------------------------------------------------------------------
494 IndentMore (int amount = 2);
496 //------------------------------------------------------------------
497 /// Output an offset value.
499 /// Put an offset \a uval out to the stream using the printf format
502 /// @param[in] offset
503 /// The offset value.
505 /// @param[in] format
506 /// The printf style format to use when outputting the offset.
507 //------------------------------------------------------------------
509 Offset (uint32_t offset, const char *format = "0x%8.8x: ");
511 //------------------------------------------------------------------
512 /// Output printf formatted output to the stream.
514 /// Print some formatted output to the stream.
516 /// @param[in] format
517 /// A printf style format string.
520 /// Variable arguments that are needed for the printf style
521 /// format string \a format.
522 //------------------------------------------------------------------
524 Printf (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
527 PrintfVarArg(const char *format, va_list args);
529 //------------------------------------------------------------------
530 /// Output a quoted C string value to the stream.
532 /// Print a double quoted NULL terminated C string to the stream
533 /// using the printf format in \a format.
536 /// A NULL terminated C string value.
538 /// @param[in] format
539 /// The optional C string format that can be overridden.
540 //------------------------------------------------------------------
542 QuotedCString (const char *cstr, const char *format = "\"%s\"");
544 //------------------------------------------------------------------
545 /// Set the address size in bytes.
547 /// @param[in] addr_size
548 /// The new size in bytes of an address to use when outputting
549 /// address and pointer values.
550 //------------------------------------------------------------------
552 SetAddressByteSize (uint32_t addr_size);
554 //------------------------------------------------------------------
555 /// Set the current indentation level.
558 /// The new indentation level.
559 //------------------------------------------------------------------
561 SetIndentLevel (int level);
563 //------------------------------------------------------------------
564 /// Output a SLEB128 number to the stream.
566 /// Put an SLEB128 \a uval out to the stream using the printf format
570 /// A uint64_t value that was extracted as a SLEB128 value.
572 /// @param[in] format
573 /// The optional printf format that can be overridden.
574 //------------------------------------------------------------------
576 PutSLEB128 (int64_t uval);
578 //------------------------------------------------------------------
579 /// Output a ULEB128 number to the stream.
581 /// Put an ULEB128 \a uval out to the stream using the printf format
585 /// A uint64_t value that was extracted as a ULEB128 value.
587 /// @param[in] format
588 /// The optional printf format that can be overridden.
589 //------------------------------------------------------------------
591 PutULEB128 (uint64_t uval);
597 //------------------------------------------------------------------
599 //------------------------------------------------------------------
600 Flags m_flags; ///< Dump flags.
601 uint32_t m_addr_size; ///< Size of an address in bytes.
602 lldb::ByteOrder m_byte_order; ///< Byte order to use when encoding scalar types.
603 int m_indent_level; ///< Indention level.
605 size_t _PutHex8 (uint8_t uvalue, bool add_prefix);
608 } // namespace lldb_private
610 #endif // #if defined(__cplusplus)
611 #endif // liblldb_Stream_h_