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
30 public:
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
53 void SetSourceSize(uint32_t s) { m_source_size = s; }
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.
81 std::string m_prefix_token;
82 /// String that should be printed after the trailing quote character.
83 std::string m_suffix_token;
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.
87 uint32_t m_source_size = 0;
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.
98 /// The language-specific style for escaping special characters.
100 };
101
103 public:
105
107
108 void SetLocation(Address l) { m_location = std::move(l); }
109
110 const Address &GetLocation() const { return m_location; }
111
112 void SetTargetSP(lldb::TargetSP t) { m_target_sp = std::move(t); }
113
115
117
118 bool HasSourceSize() const { return m_has_source_size; }
119
120 private:
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 = std::move(d); }
137
138 const lldb_private::DataExtractor &GetData() const { return m_data; }
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
A section + offset based address class.
Definition: Address.h:62
An data extractor class.
Definition: DataExtractor.h:48
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.
Definition: StringPrinter.h:94
char m_quote
The quote character that should surround the string.
Definition: StringPrinter.h:85
uint32_t m_source_size
The length of the memory region that should be dumped in bytes.
Definition: StringPrinter.h:87
std::string m_suffix_token
String that should be printed after the trailing quote character.
Definition: StringPrinter.h:83
std::string m_prefix_token
String that should be printed before the heading quote character.
Definition: StringPrinter.h:81
bool m_zero_is_terminator
True iff a zero bytes ('\0') should terminate the memory region that is being dumped.
Definition: StringPrinter.h:97
bool m_escape_non_printables
True iff non-printable characters should be escaped when dumping them to the stream.
Definition: StringPrinter.h:91
EscapeStyle m_escape_style
The language-specific style for escaping special characters.
Definition: StringPrinter.h:99
bool m_has_source_size
True iff we know the source size of the string.
static bool ReadBufferAndDumpToStream(const ReadBufferAndDumpToStreamOptions &options)
static bool ReadStringAndDumpToStream(const ReadStringAndDumpToStreamOptions &options)
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:443