LLDB  mainline
StringPrinter.h
Go to the documentation of this file.
1 //===-- StringPrinter.h -----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_DATAFORMATTERS_STRINGPRINTER_H
10 #define LLDB_DATAFORMATTERS_STRINGPRINTER_H
11 
12 #include <functional>
13 #include <string>
14 
15 #include "lldb/lldb-forward.h"
16 
18 
19 namespace lldb_private {
20 namespace formatters {
22 public:
23  enum class StringElementType { ASCII, UTF8, UTF16, UTF32 };
24 
26 
27  enum class EscapeStyle { CXX, Swift };
28 
30  public:
31  DumpToStreamOptions() = default;
32 
33  void SetStream(Stream *s) { m_stream = s; }
34 
35  Stream *GetStream() const { return m_stream; }
36 
37  void SetPrefixToken(const std::string &p) { m_prefix_token = p; }
38 
39  void SetPrefixToken(std::nullptr_t) { m_prefix_token.clear(); }
40 
41  const char *GetPrefixToken() const { return m_prefix_token.c_str(); }
42 
43  void SetSuffixToken(const std::string &p) { m_suffix_token = p; }
44 
45  void SetSuffixToken(std::nullptr_t) { m_suffix_token.clear(); }
46 
47  const char *GetSuffixToken() const { return m_suffix_token.c_str(); }
48 
49  void SetQuote(char q) { m_quote = q; }
50 
51  char GetQuote() const { return m_quote; }
52 
54 
55  uint32_t GetSourceSize() const { return m_source_size; }
56 
58 
60 
62 
64 
66 
68 
70 
71  bool GetIgnoreMaxLength() const { return m_ignore_max_length; }
72 
73  void SetEscapeStyle(EscapeStyle style) { m_escape_style = style; }
74 
76 
77  private:
78  /// The used output stream.
79  Stream *m_stream = nullptr;
80  /// String that should be printed before the heading quote character.
82  /// String that should be printed after the trailing quote character.
84  /// The quote character that should surround the string.
85  char m_quote = '"';
86  /// The length of the memory region that should be dumped in bytes.
89  /// True iff non-printable characters should be escaped when dumping
90  /// them to the stream.
92  /// True iff the max-string-summary-length setting of the target should
93  /// be ignored.
94  bool m_ignore_max_length = false;
95  /// True iff a zero bytes ('\0') should terminate the memory region that
96  /// is being dumped.
97  bool m_zero_is_terminator = true;
98  /// The language-specific style for escaping special characters.
100  };
101 
103  public:
105 
107 
108  void SetLocation(uint64_t l) { m_location = l; }
109 
110  uint64_t GetLocation() const { return m_location; }
111 
112  void SetProcessSP(lldb::ProcessSP p) { m_process_sp = std::move(p); }
113 
114  lldb::ProcessSP GetProcessSP() const { return m_process_sp; }
115 
116  void SetHasSourceSize(bool e) { m_has_source_size = e; }
117 
118  bool HasSourceSize() const { return m_has_source_size; }
119 
120  private:
121  uint64_t m_location = 0;
122  lldb::ProcessSP m_process_sp;
123  /// True iff we know the source size of the string.
124  bool m_has_source_size = false;
125  };
126 
128  public:
130 
132 
134  const ReadStringAndDumpToStreamOptions &options);
135 
136  void SetData(DataExtractor d) { m_data = d; }
137 
139 
140  void SetIsTruncated(bool t) { m_is_truncated = t; }
141 
142  bool GetIsTruncated() const { return m_is_truncated; }
143  private:
145  bool m_is_truncated = false;
146  };
147 
148  template <StringElementType element_type>
149  static bool
151 
152  template <StringElementType element_type>
153  static bool
155 };
156 
157 } // namespace formatters
158 } // namespace lldb_private
159 
160 #endif // LLDB_DATAFORMATTERS_STRINGPRINTER_H
lldb_private::formatters::StringPrinter::DumpToStreamOptions::m_ignore_max_length
bool m_ignore_max_length
True iff the max-string-summary-length setting of the target should be ignored.
Definition: StringPrinter.h:94
lldb_private::formatters::StringPrinter::StringElementType::UTF16
@ UTF16
lldb_private::formatters::StringPrinter::DumpToStreamOptions::SetPrefixToken
void SetPrefixToken(const std::string &p)
Definition: StringPrinter.h:37
lldb_private::formatters::StringPrinter::DumpToStreamOptions::m_escape_style
EscapeStyle m_escape_style
The language-specific style for escaping special characters.
Definition: StringPrinter.h:99
lldb_private::formatters::StringPrinter::ReadStringAndDumpToStreamOptions::SetProcessSP
void SetProcessSP(lldb::ProcessSP p)
Definition: StringPrinter.h:112
lldb_private::formatters::StringPrinter::ReadStringAndDumpToStream
static bool ReadStringAndDumpToStream(const ReadStringAndDumpToStreamOptions &options)
lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions::ReadBufferAndDumpToStreamOptions
ReadBufferAndDumpToStreamOptions()=default
lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions::GetData
lldb_private::DataExtractor GetData() const
Definition: StringPrinter.h:138
lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions::m_data
DataExtractor m_data
Definition: StringPrinter.h:144
lldb_private::formatters::StringPrinter::GetPrintableElementType
GetPrintableElementType
Definition: StringPrinter.h:25
lldb_private::formatters::StringPrinter::DumpToStreamOptions::m_zero_is_terminator
bool m_zero_is_terminator
True iff a zero bytes ('\0') should terminate the memory region that is being dumped.
Definition: StringPrinter.h:97
lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions
Definition: StringPrinter.h:127
lldb_private::formatters::StringPrinter::DumpToStreamOptions::GetSuffixToken
const char * GetSuffixToken() const
Definition: StringPrinter.h:47
lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStream
static bool ReadBufferAndDumpToStream(const ReadBufferAndDumpToStreamOptions &options)
lldb_private::formatters::StringPrinter::ReadStringAndDumpToStreamOptions::SetLocation
void SetLocation(uint64_t l)
Definition: StringPrinter.h:108
lldb_private::formatters::StringPrinter::DumpToStreamOptions::GetStream
Stream * GetStream() const
Definition: StringPrinter.h:35
lldb_private::formatters::StringPrinter::ReadStringAndDumpToStreamOptions::m_process_sp
lldb::ProcessSP m_process_sp
Definition: StringPrinter.h:122
lldb_private::formatters::StringPrinter::DumpToStreamOptions::SetNeedsZeroTermination
void SetNeedsZeroTermination(bool z)
Definition: StringPrinter.h:57
lldb_private::formatters::StringPrinter::DumpToStreamOptions::GetNeedsZeroTermination
bool GetNeedsZeroTermination() const
Definition: StringPrinter.h:59
lldb_private::formatters::StringPrinter::DumpToStreamOptions::SetSuffixToken
void SetSuffixToken(std::nullptr_t)
Definition: StringPrinter.h:45
lldb_private::Stream
Definition: Stream.h:28
lldb_private::formatters::StringPrinter::DumpToStreamOptions::SetSourceSize
void SetSourceSize(uint32_t s)
Definition: StringPrinter.h:53
lldb_private::formatters::StringPrinter::DumpToStreamOptions::SetSuffixToken
void SetSuffixToken(const std::string &p)
Definition: StringPrinter.h:43
lldb_private::formatters::StringPrinter
Definition: StringPrinter.h:21
lldb_private::formatters::StringPrinter::DumpToStreamOptions::SetBinaryZeroIsTerminator
void SetBinaryZeroIsTerminator(bool e)
Definition: StringPrinter.h:61
lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions::GetIsTruncated
bool GetIsTruncated() const
Definition: StringPrinter.h:142
lldb_private::formatters::StringPrinter::DumpToStreamOptions::DumpToStreamOptions
DumpToStreamOptions()=default
lldb_private::formatters::StringPrinter::EscapeStyle
EscapeStyle
Definition: StringPrinter.h:27
lldb_private::DataExtractor
Definition: DataExtractor.h:48
lldb_private::formatters::StringPrinter::EscapeStyle::Swift
@ Swift
lldb_private::formatters::StringPrinter::DumpToStreamOptions::SetQuote
void SetQuote(char q)
Definition: StringPrinter.h:49
lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions::SetIsTruncated
void SetIsTruncated(bool t)
Definition: StringPrinter.h:140
lldb_private::formatters::StringPrinter::DumpToStreamOptions::m_stream
Stream * m_stream
The used output stream.
Definition: StringPrinter.h:79
lldb_private::formatters::StringPrinter::StringElementType::UTF32
@ UTF32
lldb_private::formatters::StringPrinter::GetPrintableElementType::ASCII
@ ASCII
lldb_private::formatters::StringPrinter::ReadStringAndDumpToStreamOptions::GetLocation
uint64_t GetLocation() const
Definition: StringPrinter.h:110
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:39
lldb_private::formatters::StringPrinter::DumpToStreamOptions::m_prefix_token
std::string m_prefix_token
String that should be printed before the heading quote character.
Definition: StringPrinter.h:81
lldb_private::formatters::StringPrinter::DumpToStreamOptions::SetIgnoreMaxLength
void SetIgnoreMaxLength(bool e)
Definition: StringPrinter.h:69
lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions::SetData
void SetData(DataExtractor d)
Definition: StringPrinter.h:136
lldb_private::formatters::StringPrinter::DumpToStreamOptions::m_source_size
uint32_t m_source_size
The length of the memory region that should be dumped in bytes.
Definition: StringPrinter.h:87
lldb_private::formatters::StringPrinter::DumpToStreamOptions::m_needs_zero_termination
bool m_needs_zero_termination
Definition: StringPrinter.h:88
lldb_private::formatters::StringPrinter::ReadStringAndDumpToStreamOptions::SetHasSourceSize
void SetHasSourceSize(bool e)
Definition: StringPrinter.h:116
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions::m_is_truncated
bool m_is_truncated
Definition: StringPrinter.h:145
lldb_private::formatters::StringPrinter::DumpToStreamOptions::m_escape_non_printables
bool m_escape_non_printables
True iff non-printable characters should be escaped when dumping them to the stream.
Definition: StringPrinter.h:91
uint32_t
lldb_private::formatters::StringPrinter::StringElementType
StringElementType
Definition: StringPrinter.h:23
lldb_private::formatters::StringPrinter::ReadStringAndDumpToStreamOptions::HasSourceSize
bool HasSourceSize() const
Definition: StringPrinter.h:118
lldb_private::formatters::StringPrinter::ReadStringAndDumpToStreamOptions::ReadStringAndDumpToStreamOptions
ReadStringAndDumpToStreamOptions()=default
lldb_private::formatters::StringPrinter::DumpToStreamOptions::m_quote
char m_quote
The quote character that should surround the string.
Definition: StringPrinter.h:85
lldb_private::formatters::StringPrinter::StringElementType::UTF8
@ UTF8
lldb_private::formatters::StringPrinter::DumpToStreamOptions::GetEscapeNonPrintables
bool GetEscapeNonPrintables() const
Definition: StringPrinter.h:67
lldb_private::formatters::StringPrinter::ReadStringAndDumpToStreamOptions
Definition: StringPrinter.h:102
lldb_private::formatters::StringPrinter::DumpToStreamOptions::m_suffix_token
std::string m_suffix_token
String that should be printed after the trailing quote character.
Definition: StringPrinter.h:83
DataExtractor.h
lldb-forward.h
lldb_private::formatters::StringPrinter::DumpToStreamOptions::SetEscapeNonPrintables
void SetEscapeNonPrintables(bool e)
Definition: StringPrinter.h:65
lldb_private::formatters::StringPrinter::StringElementType::ASCII
@ ASCII
lldb_private::formatters::StringPrinter::DumpToStreamOptions::GetBinaryZeroIsTerminator
bool GetBinaryZeroIsTerminator() const
Definition: StringPrinter.h:63
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::formatters::StringPrinter::ReadStringAndDumpToStreamOptions::GetProcessSP
lldb::ProcessSP GetProcessSP() const
Definition: StringPrinter.h:114
lldb_private::formatters::StringPrinter::ReadStringAndDumpToStreamOptions::m_location
uint64_t m_location
Definition: StringPrinter.h:121
lldb_private::formatters::StringPrinter::DumpToStreamOptions::GetSourceSize
uint32_t GetSourceSize() const
Definition: StringPrinter.h:55
lldb_private::formatters::StringPrinter::DumpToStreamOptions::GetIgnoreMaxLength
bool GetIgnoreMaxLength() const
Definition: StringPrinter.h:71
lldb_private::formatters::StringPrinter::GetPrintableElementType::UTF8
@ UTF8
lldb_private::formatters::StringPrinter::EscapeStyle::CXX
@ CXX
lldb_private::formatters::StringPrinter::DumpToStreamOptions::SetStream
void SetStream(Stream *s)
Definition: StringPrinter.h:33
lldb_private::formatters::StringPrinter::DumpToStreamOptions::GetEscapeStyle
EscapeStyle GetEscapeStyle() const
Definition: StringPrinter.h:75
lldb_private::formatters::StringPrinter::DumpToStreamOptions::SetPrefixToken
void SetPrefixToken(std::nullptr_t)
Definition: StringPrinter.h:39
lldb_private::formatters::StringPrinter::ReadStringAndDumpToStreamOptions::m_has_source_size
bool m_has_source_size
True iff we know the source size of the string.
Definition: StringPrinter.h:124
lldb_private::formatters::StringPrinter::DumpToStreamOptions::SetEscapeStyle
void SetEscapeStyle(EscapeStyle style)
Definition: StringPrinter.h:73
lldb_private::formatters::StringPrinter::DumpToStreamOptions::GetQuote
char GetQuote() const
Definition: StringPrinter.h:51
lldb_private::formatters::StringPrinter::DumpToStreamOptions::GetPrefixToken
const char * GetPrefixToken() const
Definition: StringPrinter.h:41
lldb_private::formatters::StringPrinter::DumpToStreamOptions
Definition: StringPrinter.h:29