aboutsummaryrefslogtreecommitdiff
path: root/include/lldb/DataFormatters/StringPrinter.h
blob: 48e27ace5d920d0fd4266586b8e99824704cbd6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
//===-- StringPrinter.h -----------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef liblldb_StringPrinter_h_
#define liblldb_StringPrinter_h_

#include "lldb/lldb-forward.h"

#include "lldb/Core/DataExtractor.h"

namespace lldb_private {
    namespace formatters
    {
        
        enum class StringElementType {
            ASCII,
            UTF8,
            UTF16,
            UTF32
        };
        
        class ReadStringAndDumpToStreamOptions
        {
        public:
            
            ReadStringAndDumpToStreamOptions () :
            m_location(0),
            m_process_sp(),
            m_stream(NULL),
            m_prefix_token(0),
            m_quote('"'),
            m_source_size(0),
            m_needs_zero_termination(true),
            m_escape_non_printables(true),
            m_ignore_max_length(false)
            {
            }
            
            ReadStringAndDumpToStreamOptions (ValueObject& valobj);
            
            ReadStringAndDumpToStreamOptions&
            SetLocation (uint64_t l)
            {
                m_location = l;
                return *this;
            }
            
            uint64_t
            GetLocation () const
            {
                return m_location;
            }
            
            ReadStringAndDumpToStreamOptions&
            SetProcessSP (lldb::ProcessSP p)
            {
                m_process_sp = p;
                return *this;
            }
            
            lldb::ProcessSP
            GetProcessSP () const
            {
                return m_process_sp;
            }
            
            ReadStringAndDumpToStreamOptions&
            SetStream (Stream* s)
            {
                m_stream = s;
                return *this;
            }
            
            Stream*
            GetStream () const
            {
                return m_stream;
            }
            
            ReadStringAndDumpToStreamOptions&
            SetPrefixToken (char p)
            {
                m_prefix_token = p;
                return *this;
            }
            
            char
            GetPrefixToken () const
            {
                return m_prefix_token;
            }
            
            ReadStringAndDumpToStreamOptions&
            SetQuote (char q)
            {
                m_quote = q;
                return *this;
            }
            
            char
            GetQuote () const
            {
                return m_quote;
            }
            
            ReadStringAndDumpToStreamOptions&
            SetSourceSize (uint32_t s)
            {
                m_source_size = s;
                return *this;
            }
            
            uint32_t
            GetSourceSize () const
            {
                return m_source_size;
            }
            
            ReadStringAndDumpToStreamOptions&
            SetNeedsZeroTermination (bool z)
            {
                m_needs_zero_termination = z;
                return *this;
            }
            
            bool
            GetNeedsZeroTermination () const
            {
                return m_needs_zero_termination;
            }
            
            ReadStringAndDumpToStreamOptions&
            SetEscapeNonPrintables (bool e)
            {
                m_escape_non_printables = e;
                return *this;
            }
            
            bool
            GetEscapeNonPrintables () const
            {
                return m_escape_non_printables;
            }
            
            ReadStringAndDumpToStreamOptions&
            SetIgnoreMaxLength (bool e)
            {
                m_ignore_max_length = e;
                return *this;
            }
            
            bool
            GetIgnoreMaxLength () const
            {
                return m_ignore_max_length;
            }
            
        private:
            uint64_t m_location;
            lldb::ProcessSP m_process_sp;
            Stream* m_stream;
            char m_prefix_token;
            char m_quote;
            uint32_t m_source_size;
            bool m_needs_zero_termination;
            bool m_escape_non_printables;
            bool m_ignore_max_length;
        };
        
        class ReadBufferAndDumpToStreamOptions
        {
        public:
            
            ReadBufferAndDumpToStreamOptions () :
            m_data(),
            m_stream(NULL),
            m_prefix_token(0),
            m_quote('"'),
            m_source_size(0),
            m_escape_non_printables(true)
            {
            }
            
            ReadBufferAndDumpToStreamOptions (ValueObject& valobj);
            
            ReadBufferAndDumpToStreamOptions&
            SetData (DataExtractor d)
            {
                m_data = d;
                return *this;
            }
            
            lldb_private::DataExtractor
            GetData () const
            {
                return m_data;
            }
            
            ReadBufferAndDumpToStreamOptions&
            SetStream (Stream* s)
            {
                m_stream = s;
                return *this;
            }
            
            Stream*
            GetStream () const
            {
                return m_stream;
            }
            
            ReadBufferAndDumpToStreamOptions&
            SetPrefixToken (char p)
            {
                m_prefix_token = p;
                return *this;
            }
            
            char
            GetPrefixToken () const
            {
                return m_prefix_token;
            }
            
            ReadBufferAndDumpToStreamOptions&
            SetQuote (char q)
            {
                m_quote = q;
                return *this;
            }
            
            char
            GetQuote () const
            {
                return m_quote;
            }
            
            ReadBufferAndDumpToStreamOptions&
            SetSourceSize (uint32_t s)
            {
                m_source_size = s;
                return *this;
            }
            
            uint32_t
            GetSourceSize () const
            {
                return m_source_size;
            }
            
            ReadBufferAndDumpToStreamOptions&
            SetEscapeNonPrintables (bool e)
            {
                m_escape_non_printables = e;
                return *this;
            }
            
            bool
            GetEscapeNonPrintables () const
            {
                return m_escape_non_printables;
            }
            
        private:
            DataExtractor m_data;
            Stream* m_stream;
            char m_prefix_token;
            char m_quote;
            uint32_t m_source_size;
            bool m_escape_non_printables;
        };
        
        template <StringElementType element_type>
        bool
        ReadStringAndDumpToStream (ReadStringAndDumpToStreamOptions options);
        
        template <StringElementType element_type>
        bool
        ReadBufferAndDumpToStream (ReadBufferAndDumpToStreamOptions options);
        
    } // namespace formatters
} // namespace lldb_private

#endif // liblldb_StringPrinter_h_