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/Core/Address.h"
17#include "lldb/lldb-forward.h"
18
19namespace lldb_private {
20namespace formatters {
22public:
24
26
27 enum class EscapeStyle { CXX, Swift };
28
29 enum class ZeroTermination {
30 /// Don't look for a terminator - print the whole buffer.
32 /// Stop printing at the first zero terminator.
34 /// Print embedded zeros, but ignore zeros at the end of the buffer.
36 };
37
39 public:
41
42 void SetStream(Stream *s) { m_stream = s; }
43
44 Stream *GetStream() const { return m_stream; }
45
46 void SetPrefixToken(const std::string &p) { m_prefix_token = p; }
47
48 void SetPrefixToken(std::nullptr_t) { m_prefix_token.clear(); }
49
50 const char *GetPrefixToken() const { return m_prefix_token.c_str(); }
51
52 void SetSuffixToken(const std::string &p) { m_suffix_token = p; }
53
54 void SetSuffixToken(std::nullptr_t) { m_suffix_token.clear(); }
55
56 const char *GetSuffixToken() const { return m_suffix_token.c_str(); }
57
58 void SetQuote(char q) { m_quote = q; }
59
60 char GetQuote() const { return m_quote; }
61
62 void SetSourceSize(uint32_t s) { m_source_size = s; }
63
64 uint32_t GetSourceSize() const { return m_source_size; }
65
67
69
71
73
75
76 bool GetIgnoreMaxLength() const { return m_ignore_max_length; }
77
78 void SetEscapeStyle(EscapeStyle style) { m_escape_style = style; }
79
81
82 private:
83 /// The used output stream.
84 Stream *m_stream = nullptr;
85 /// String that should be printed before the heading quote character.
86 std::string m_prefix_token;
87 /// String that should be printed after the trailing quote character.
88 std::string m_suffix_token;
89 /// The quote character that should surround the string.
90 char m_quote = '"';
91 /// The length of the memory region that should be dumped in bytes.
92 uint32_t m_source_size = 0;
93 /// True iff non-printable characters should be escaped when dumping
94 /// them to the stream.
96 /// True iff the max-string-summary-length setting of the target should
97 /// be ignored.
98 bool m_ignore_max_length = false;
99 /// The language-specific style for escaping special characters.
102 };
103
105 public:
107
109
110 void SetLocation(Address l) { m_location = std::move(l); }
111
112 const Address &GetLocation() const { return m_location; }
113
114 void SetTargetSP(lldb::TargetSP t) { m_target_sp = std::move(t); }
115
117
119
120 bool HasSourceSize() const { return m_has_source_size; }
121
122 private:
125 /// True iff we know the source size of the string.
126 bool m_has_source_size = false;
127 };
128
130 public:
132
134
136 const ReadStringAndDumpToStreamOptions &options);
137
138 void SetData(DataExtractor &&d) { m_data = std::move(d); }
139
140 const lldb_private::DataExtractor &GetData() const { return m_data; }
141
142 void SetIsTruncated(bool t) { m_is_truncated = t; }
143
144 bool GetIsTruncated() const { return m_is_truncated; }
145 private:
147 bool m_is_truncated = false;
148 };
149
150 template <StringElementType element_type>
151 static bool
153
154 template <StringElementType element_type>
155 static bool
157};
158
159} // namespace formatters
160} // namespace lldb_private
161
162#endif // LLDB_DATAFORMATTERS_STRINGPRINTER_H
A section + offset based address class.
Definition Address.h:62
An data extractor class.
A stream class that can stream formatted output to a file.
Definition Stream.h:28
bool m_ignore_max_length
True iff the max-string-summary-length setting of the target should be ignored.
char m_quote
The quote character that should surround the string.
uint32_t m_source_size
The length of the memory region that should be dumped in bytes.
std::string m_suffix_token
String that should be printed after the trailing quote character.
std::string m_prefix_token
String that should be printed before the heading quote character.
bool m_escape_non_printables
True iff non-printable characters should be escaped when dumping them to the stream.
EscapeStyle m_escape_style
The language-specific style for escaping special characters.
bool m_has_source_size
True iff we know the source size of the string.
static bool ReadBufferAndDumpToStream(const ReadBufferAndDumpToStreamOptions &options)
@ TrimTrailingZeros
Print embedded zeros, but ignore zeros at the end of the buffer.
@ ZeroTerminate
Stop printing at the first zero terminator.
@ Ignore
Don't look for a terminator - print the whole buffer.
static bool ReadStringAndDumpToStream(const ReadStringAndDumpToStreamOptions &options)
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Target > TargetSP