Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 1 | //===-- CXXFormatterFunctions.cpp---------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Enrico Granata | f509c5e | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 10 | #include "lldb/DataFormatters/CXXFormatterFunctions.h" |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 11 | |
Dmitri Gribenko | 2a64f9a | 2013-01-30 15:05:59 +0000 | [diff] [blame] | 12 | #include "llvm/Support/ConvertUTF.h" |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 13 | |
Enrico Granata | f91e78f | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 14 | #include "lldb/Core/DataBufferHeap.h" |
| 15 | #include "lldb/Core/Error.h" |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Stream.h" |
| 17 | #include "lldb/Core/ValueObject.h" |
Enrico Granata | f91e78f | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 18 | #include "lldb/Core/ValueObjectConstResult.h" |
| 19 | #include "lldb/Host/Endian.h" |
Enrico Granata | db05491 | 2012-10-29 21:18:03 +0000 | [diff] [blame] | 20 | #include "lldb/Symbol/ClangASTContext.h" |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 21 | #include "lldb/Target/ObjCLanguageRuntime.h" |
| 22 | #include "lldb/Target/Target.h" |
| 23 | |
Enrico Granata | fb1493d | 2013-04-02 21:25:34 +0000 | [diff] [blame] | 24 | #include <algorithm> |
| 25 | |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 26 | using namespace lldb; |
| 27 | using namespace lldb_private; |
| 28 | using namespace lldb_private::formatters; |
| 29 | |
| 30 | bool |
Enrico Granata | f91e78f | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 31 | lldb_private::formatters::ExtractValueFromObjCExpression (ValueObject &valobj, |
| 32 | const char* target_type, |
| 33 | const char* selector, |
| 34 | uint64_t &value) |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 35 | { |
| 36 | if (!target_type || !*target_type) |
| 37 | return false; |
| 38 | if (!selector || !*selector) |
| 39 | return false; |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 40 | StreamString expr; |
Daniel Malea | b9db9d5 | 2012-12-07 22:21:08 +0000 | [diff] [blame] | 41 | expr.Printf("(%s)[(id)0x%" PRIx64 " %s]",target_type,valobj.GetPointerValue(),selector); |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 42 | ExecutionContext exe_ctx (valobj.GetExecutionContextRef()); |
| 43 | lldb::ValueObjectSP result_sp; |
| 44 | Target* target = exe_ctx.GetTargetPtr(); |
| 45 | StackFrame* stack_frame = exe_ctx.GetFramePtr(); |
| 46 | if (!target || !stack_frame) |
| 47 | return false; |
Enrico Granata | d27026e | 2012-09-05 20:41:26 +0000 | [diff] [blame] | 48 | |
Jim Ingham | 47beabb | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 49 | EvaluateExpressionOptions options; |
Enrico Granata | d27026e | 2012-09-05 20:41:26 +0000 | [diff] [blame] | 50 | options.SetCoerceToId(false) |
| 51 | .SetUnwindOnError(true) |
Sean Callanan | 99611fe | 2012-12-04 20:56:04 +0000 | [diff] [blame] | 52 | .SetKeepInMemory(true); |
Enrico Granata | d27026e | 2012-09-05 20:41:26 +0000 | [diff] [blame] | 53 | |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 54 | target->EvaluateExpression(expr.GetData(), |
| 55 | stack_frame, |
Enrico Granata | d27026e | 2012-09-05 20:41:26 +0000 | [diff] [blame] | 56 | result_sp, |
| 57 | options); |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 58 | if (!result_sp) |
| 59 | return false; |
| 60 | value = result_sp->GetValueAsUnsigned(0); |
| 61 | return true; |
| 62 | } |
| 63 | |
Enrico Granata | ea68753 | 2013-02-15 23:38:37 +0000 | [diff] [blame] | 64 | bool |
| 65 | lldb_private::formatters::ExtractSummaryFromObjCExpression (ValueObject &valobj, |
| 66 | const char* target_type, |
| 67 | const char* selector, |
| 68 | Stream &stream) |
| 69 | { |
| 70 | if (!target_type || !*target_type) |
| 71 | return false; |
| 72 | if (!selector || !*selector) |
| 73 | return false; |
| 74 | StreamString expr; |
Enrico Granata | 04d3bb2 | 2013-02-19 01:14:06 +0000 | [diff] [blame] | 75 | expr.Printf("(%s)[(id)0x%" PRIx64 " %s]",target_type,valobj.GetPointerValue(),selector); |
Enrico Granata | ea68753 | 2013-02-15 23:38:37 +0000 | [diff] [blame] | 76 | ExecutionContext exe_ctx (valobj.GetExecutionContextRef()); |
| 77 | lldb::ValueObjectSP result_sp; |
| 78 | Target* target = exe_ctx.GetTargetPtr(); |
| 79 | StackFrame* stack_frame = exe_ctx.GetFramePtr(); |
| 80 | if (!target || !stack_frame) |
| 81 | return false; |
| 82 | |
| 83 | EvaluateExpressionOptions options; |
| 84 | options.SetCoerceToId(false) |
| 85 | .SetUnwindOnError(true) |
| 86 | .SetKeepInMemory(true) |
| 87 | .SetUseDynamic(lldb::eDynamicCanRunTarget); |
| 88 | |
| 89 | target->EvaluateExpression(expr.GetData(), |
| 90 | stack_frame, |
| 91 | result_sp, |
| 92 | options); |
| 93 | if (!result_sp) |
| 94 | return false; |
| 95 | stream.Printf("%s",result_sp->GetSummaryAsCString()); |
| 96 | return true; |
| 97 | } |
| 98 | |
Enrico Granata | f91e78f | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 99 | lldb::ValueObjectSP |
| 100 | lldb_private::formatters::CallSelectorOnObject (ValueObject &valobj, |
| 101 | const char* return_type, |
| 102 | const char* selector, |
| 103 | uint64_t index) |
| 104 | { |
| 105 | lldb::ValueObjectSP valobj_sp; |
| 106 | if (!return_type || !*return_type) |
| 107 | return valobj_sp; |
| 108 | if (!selector || !*selector) |
| 109 | return valobj_sp; |
| 110 | StreamString expr_path_stream; |
| 111 | valobj.GetExpressionPath(expr_path_stream, false); |
| 112 | StreamString expr; |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 113 | expr.Printf("(%s)[%s %s:%" PRId64 "]",return_type,expr_path_stream.GetData(),selector,index); |
Enrico Granata | f91e78f | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 114 | ExecutionContext exe_ctx (valobj.GetExecutionContextRef()); |
| 115 | lldb::ValueObjectSP result_sp; |
| 116 | Target* target = exe_ctx.GetTargetPtr(); |
| 117 | StackFrame* stack_frame = exe_ctx.GetFramePtr(); |
| 118 | if (!target || !stack_frame) |
| 119 | return valobj_sp; |
| 120 | |
Jim Ingham | 47beabb | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 121 | EvaluateExpressionOptions options; |
Enrico Granata | f91e78f | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 122 | options.SetCoerceToId(false) |
| 123 | .SetUnwindOnError(true) |
| 124 | .SetKeepInMemory(true) |
| 125 | .SetUseDynamic(lldb::eDynamicCanRunTarget); |
| 126 | |
| 127 | target->EvaluateExpression(expr.GetData(), |
| 128 | stack_frame, |
| 129 | valobj_sp, |
| 130 | options); |
| 131 | return valobj_sp; |
| 132 | } |
| 133 | |
| 134 | lldb::ValueObjectSP |
| 135 | lldb_private::formatters::CallSelectorOnObject (ValueObject &valobj, |
| 136 | const char* return_type, |
| 137 | const char* selector, |
| 138 | const char* key) |
| 139 | { |
| 140 | lldb::ValueObjectSP valobj_sp; |
| 141 | if (!return_type || !*return_type) |
| 142 | return valobj_sp; |
| 143 | if (!selector || !*selector) |
| 144 | return valobj_sp; |
| 145 | if (!key || !*key) |
| 146 | return valobj_sp; |
| 147 | StreamString expr_path_stream; |
| 148 | valobj.GetExpressionPath(expr_path_stream, false); |
| 149 | StreamString expr; |
| 150 | expr.Printf("(%s)[%s %s:%s]",return_type,expr_path_stream.GetData(),selector,key); |
| 151 | ExecutionContext exe_ctx (valobj.GetExecutionContextRef()); |
| 152 | lldb::ValueObjectSP result_sp; |
| 153 | Target* target = exe_ctx.GetTargetPtr(); |
| 154 | StackFrame* stack_frame = exe_ctx.GetFramePtr(); |
| 155 | if (!target || !stack_frame) |
| 156 | return valobj_sp; |
| 157 | |
Jim Ingham | 47beabb | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 158 | EvaluateExpressionOptions options; |
Enrico Granata | f91e78f | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 159 | options.SetCoerceToId(false) |
| 160 | .SetUnwindOnError(true) |
| 161 | .SetKeepInMemory(true) |
| 162 | .SetUseDynamic(lldb::eDynamicCanRunTarget); |
| 163 | |
| 164 | target->EvaluateExpression(expr.GetData(), |
| 165 | stack_frame, |
| 166 | valobj_sp, |
| 167 | options); |
| 168 | return valobj_sp; |
| 169 | } |
| 170 | |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 171 | // use this call if you already have an LLDB-side buffer for the data |
| 172 | template<typename SourceDataType> |
Enrico Granata | f5545f9 | 2013-01-10 22:08:35 +0000 | [diff] [blame] | 173 | static bool |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 174 | DumpUTFBufferToStream (ConversionResult (*ConvertFunction) (const SourceDataType**, |
| 175 | const SourceDataType*, |
| 176 | UTF8**, |
| 177 | UTF8*, |
| 178 | ConversionFlags), |
| 179 | DataExtractor& data, |
| 180 | Stream& stream, |
| 181 | char prefix_token = '@', |
| 182 | char quote = '"', |
Enrico Granata | fb1493d | 2013-04-02 21:25:34 +0000 | [diff] [blame] | 183 | uint32_t sourceSize = 0) |
Enrico Granata | f5545f9 | 2013-01-10 22:08:35 +0000 | [diff] [blame] | 184 | { |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 185 | if (prefix_token != 0) |
| 186 | stream.Printf("%c",prefix_token); |
| 187 | if (quote != 0) |
| 188 | stream.Printf("%c",quote); |
| 189 | if (data.GetByteSize() && data.GetDataStart() && data.GetDataEnd()) |
Enrico Granata | f5545f9 | 2013-01-10 22:08:35 +0000 | [diff] [blame] | 190 | { |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 191 | const int bufferSPSize = data.GetByteSize(); |
| 192 | if (sourceSize == 0) |
| 193 | { |
| 194 | const int origin_encoding = 8*sizeof(SourceDataType); |
Greg Clayton | 0cd3340 | 2013-02-08 21:59:34 +0000 | [diff] [blame] | 195 | sourceSize = bufferSPSize/(origin_encoding / 4); |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | SourceDataType *data_ptr = (SourceDataType*)data.GetDataStart(); |
Enrico Granata | f5545f9 | 2013-01-10 22:08:35 +0000 | [diff] [blame] | 199 | SourceDataType *data_end_ptr = data_ptr + sourceSize; |
| 200 | |
| 201 | while (data_ptr < data_end_ptr) |
| 202 | { |
| 203 | if (!*data_ptr) |
| 204 | { |
| 205 | data_end_ptr = data_ptr; |
| 206 | break; |
| 207 | } |
| 208 | data_ptr++; |
| 209 | } |
| 210 | |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 211 | data_ptr = (SourceDataType*)data.GetDataStart(); |
Enrico Granata | f5545f9 | 2013-01-10 22:08:35 +0000 | [diff] [blame] | 212 | |
Enrico Granata | 06d58b0 | 2013-01-11 02:44:00 +0000 | [diff] [blame] | 213 | lldb::DataBufferSP utf8_data_buffer_sp; |
| 214 | UTF8* utf8_data_ptr = nullptr; |
| 215 | UTF8* utf8_data_end_ptr = nullptr; |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 216 | |
Enrico Granata | f5545f9 | 2013-01-10 22:08:35 +0000 | [diff] [blame] | 217 | if (ConvertFunction) |
Enrico Granata | 06d58b0 | 2013-01-11 02:44:00 +0000 | [diff] [blame] | 218 | { |
| 219 | utf8_data_buffer_sp.reset(new DataBufferHeap(bufferSPSize,0)); |
| 220 | utf8_data_ptr = (UTF8*)utf8_data_buffer_sp->GetBytes(); |
| 221 | utf8_data_end_ptr = utf8_data_ptr + bufferSPSize; |
Enrico Granata | f5545f9 | 2013-01-10 22:08:35 +0000 | [diff] [blame] | 222 | ConvertFunction ( (const SourceDataType**)&data_ptr, data_end_ptr, &utf8_data_ptr, utf8_data_end_ptr, lenientConversion ); |
Enrico Granata | 06d58b0 | 2013-01-11 02:44:00 +0000 | [diff] [blame] | 223 | utf8_data_ptr = (UTF8*)utf8_data_buffer_sp->GetBytes(); // needed because the ConvertFunction will change the value of the data_ptr |
| 224 | } |
Enrico Granata | f5545f9 | 2013-01-10 22:08:35 +0000 | [diff] [blame] | 225 | else |
| 226 | { |
| 227 | // just copy the pointers - the cast is necessary to make the compiler happy |
| 228 | // but this should only happen if we are reading UTF8 data |
| 229 | utf8_data_ptr = (UTF8*)data_ptr; |
| 230 | utf8_data_end_ptr = (UTF8*)data_end_ptr; |
| 231 | } |
| 232 | |
Enrico Granata | b698579 | 2013-01-12 01:00:22 +0000 | [diff] [blame] | 233 | // since we tend to accept partial data (and even partially malformed data) |
| 234 | // we might end up with no NULL terminator before the end_ptr |
| 235 | // hence we need to take a slower route and ensure we stay within boundaries |
Enrico Granata | f5545f9 | 2013-01-10 22:08:35 +0000 | [diff] [blame] | 236 | for (;utf8_data_ptr != utf8_data_end_ptr; utf8_data_ptr++) |
| 237 | { |
| 238 | if (!*utf8_data_ptr) |
| 239 | break; |
| 240 | stream.Printf("%c",*utf8_data_ptr); |
| 241 | } |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 242 | } |
| 243 | if (quote != 0) |
| 244 | stream.Printf("%c",quote); |
| 245 | return true; |
| 246 | } |
| 247 | |
| 248 | template<typename SourceDataType> |
| 249 | static bool |
| 250 | ReadUTFBufferAndDumpToStream (ConversionResult (*ConvertFunction) (const SourceDataType**, |
| 251 | const SourceDataType*, |
| 252 | UTF8**, |
| 253 | UTF8*, |
| 254 | ConversionFlags), |
| 255 | uint64_t location, |
| 256 | const ProcessSP& process_sp, |
| 257 | Stream& stream, |
| 258 | char prefix_token = '@', |
| 259 | char quote = '"', |
Enrico Granata | fb1493d | 2013-04-02 21:25:34 +0000 | [diff] [blame] | 260 | uint32_t sourceSize = 0) |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 261 | { |
| 262 | if (location == 0 || location == LLDB_INVALID_ADDRESS) |
| 263 | return false; |
| 264 | if (!process_sp) |
| 265 | return false; |
| 266 | |
| 267 | const int origin_encoding = 8*sizeof(SourceDataType); |
| 268 | if (origin_encoding != 8 && origin_encoding != 16 && origin_encoding != 32) |
| 269 | return false; |
| 270 | // if not UTF8, I need a conversion function to return proper UTF8 |
| 271 | if (origin_encoding != 8 && !ConvertFunction) |
| 272 | return false; |
| 273 | |
Enrico Granata | 54f3020 | 2013-04-02 23:07:55 +0000 | [diff] [blame^] | 274 | if (!sourceSize) |
| 275 | sourceSize = process_sp->GetTarget().GetMaximumSizeOfStringSummary(); |
| 276 | else |
| 277 | sourceSize = std::min(sourceSize,process_sp->GetTarget().GetMaximumSizeOfStringSummary()); |
| 278 | |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 279 | const int bufferSPSize = sourceSize * (origin_encoding >> 2); |
| 280 | |
| 281 | Error error; |
| 282 | lldb::DataBufferSP buffer_sp(new DataBufferHeap(bufferSPSize,0)); |
| 283 | |
| 284 | if (!buffer_sp->GetBytes()) |
| 285 | return false; |
| 286 | |
| 287 | size_t data_read = process_sp->ReadMemoryFromInferior(location, (char*)buffer_sp->GetBytes(), bufferSPSize, error); |
| 288 | if (error.Fail() || data_read == 0) |
| 289 | { |
| 290 | stream.Printf("unable to read data"); |
Enrico Granata | f5545f9 | 2013-01-10 22:08:35 +0000 | [diff] [blame] | 291 | return true; |
| 292 | } |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 293 | |
| 294 | DataExtractor data(buffer_sp, process_sp->GetByteOrder(), process_sp->GetAddressByteSize()); |
| 295 | |
| 296 | return DumpUTFBufferToStream(ConvertFunction, data, stream, prefix_token, quote, sourceSize); |
Enrico Granata | f5545f9 | 2013-01-10 22:08:35 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | bool |
| 300 | lldb_private::formatters::Char16StringSummaryProvider (ValueObject& valobj, Stream& stream) |
| 301 | { |
| 302 | ProcessSP process_sp = valobj.GetProcessSP(); |
| 303 | if (!process_sp) |
| 304 | return false; |
| 305 | |
| 306 | lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0); |
| 307 | |
| 308 | if (!valobj_addr) |
| 309 | return false; |
| 310 | |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 311 | if (!ReadUTFBufferAndDumpToStream<UTF16>(ConvertUTF16toUTF8,valobj_addr, |
Enrico Granata | f5545f9 | 2013-01-10 22:08:35 +0000 | [diff] [blame] | 312 | process_sp, |
| 313 | stream, |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 314 | 'u')) |
Enrico Granata | f5545f9 | 2013-01-10 22:08:35 +0000 | [diff] [blame] | 315 | { |
| 316 | stream.Printf("Summary Unavailable"); |
| 317 | return true; |
| 318 | } |
| 319 | |
| 320 | return true; |
| 321 | } |
| 322 | |
| 323 | bool |
| 324 | lldb_private::formatters::Char32StringSummaryProvider (ValueObject& valobj, Stream& stream) |
| 325 | { |
| 326 | ProcessSP process_sp = valobj.GetProcessSP(); |
| 327 | if (!process_sp) |
| 328 | return false; |
| 329 | |
| 330 | lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0); |
| 331 | |
| 332 | if (!valobj_addr) |
| 333 | return false; |
| 334 | |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 335 | if (!ReadUTFBufferAndDumpToStream<UTF32>(ConvertUTF32toUTF8,valobj_addr, |
Enrico Granata | f5545f9 | 2013-01-10 22:08:35 +0000 | [diff] [blame] | 336 | process_sp, |
| 337 | stream, |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 338 | 'U')) |
Enrico Granata | f5545f9 | 2013-01-10 22:08:35 +0000 | [diff] [blame] | 339 | { |
| 340 | stream.Printf("Summary Unavailable"); |
| 341 | return true; |
| 342 | } |
| 343 | |
| 344 | return true; |
| 345 | } |
| 346 | |
| 347 | bool |
| 348 | lldb_private::formatters::WCharStringSummaryProvider (ValueObject& valobj, Stream& stream) |
| 349 | { |
Enrico Granata | 06d58b0 | 2013-01-11 02:44:00 +0000 | [diff] [blame] | 350 | ProcessSP process_sp = valobj.GetProcessSP(); |
| 351 | if (!process_sp) |
| 352 | return false; |
| 353 | |
Enrico Granata | b698579 | 2013-01-12 01:00:22 +0000 | [diff] [blame] | 354 | lldb::addr_t data_addr = 0; |
| 355 | |
| 356 | if (valobj.IsPointerType()) |
| 357 | data_addr = valobj.GetValueAsUnsigned(0); |
| 358 | else if (valobj.IsArrayType()) |
| 359 | data_addr = valobj.GetAddressOf(); |
Enrico Granata | 06d58b0 | 2013-01-11 02:44:00 +0000 | [diff] [blame] | 360 | |
Enrico Granata | b698579 | 2013-01-12 01:00:22 +0000 | [diff] [blame] | 361 | if (data_addr == 0 || data_addr == LLDB_INVALID_ADDRESS) |
Enrico Granata | 06d58b0 | 2013-01-11 02:44:00 +0000 | [diff] [blame] | 362 | return false; |
| 363 | |
| 364 | clang::ASTContext* ast = valobj.GetClangAST(); |
| 365 | |
| 366 | if (!ast) |
| 367 | return false; |
| 368 | |
| 369 | uint32_t wchar_size = ClangASTType::GetClangTypeBitWidth(ast, ClangASTType::GetBasicType(ast, lldb::eBasicTypeWChar).GetOpaqueQualType()); |
| 370 | |
| 371 | switch (wchar_size) |
| 372 | { |
| 373 | case 8: |
| 374 | // utf 8 |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 375 | return ReadUTFBufferAndDumpToStream<UTF8>(nullptr, data_addr, |
Enrico Granata | 06d58b0 | 2013-01-11 02:44:00 +0000 | [diff] [blame] | 376 | process_sp, |
| 377 | stream, |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 378 | 'L'); |
Enrico Granata | 06d58b0 | 2013-01-11 02:44:00 +0000 | [diff] [blame] | 379 | case 16: |
| 380 | // utf 16 |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 381 | return ReadUTFBufferAndDumpToStream<UTF16>(ConvertUTF16toUTF8, data_addr, |
Enrico Granata | 06d58b0 | 2013-01-11 02:44:00 +0000 | [diff] [blame] | 382 | process_sp, |
| 383 | stream, |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 384 | 'L'); |
Enrico Granata | 06d58b0 | 2013-01-11 02:44:00 +0000 | [diff] [blame] | 385 | case 32: |
| 386 | // utf 32 |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 387 | return ReadUTFBufferAndDumpToStream<UTF32>(ConvertUTF32toUTF8, data_addr, |
Enrico Granata | 06d58b0 | 2013-01-11 02:44:00 +0000 | [diff] [blame] | 388 | process_sp, |
| 389 | stream, |
Enrico Granata | cd8cd61 | 2013-01-14 23:53:26 +0000 | [diff] [blame] | 390 | 'L'); |
| 391 | default: |
| 392 | stream.Printf("size for wchar_t is not valid"); |
| 393 | return true; |
| 394 | } |
| 395 | return true; |
| 396 | } |
| 397 | |
| 398 | bool |
| 399 | lldb_private::formatters::Char16SummaryProvider (ValueObject& valobj, Stream& stream) |
| 400 | { |
| 401 | DataExtractor data; |
| 402 | valobj.GetData(data); |
| 403 | |
| 404 | std::string value; |
| 405 | valobj.GetValueAsCString(lldb::eFormatUnicode16, value); |
| 406 | if (!value.empty()) |
| 407 | stream.Printf("%s ", value.c_str()); |
| 408 | |
| 409 | return DumpUTFBufferToStream<UTF16>(ConvertUTF16toUTF8,data,stream, 'u','\'',1); |
| 410 | } |
| 411 | |
| 412 | bool |
| 413 | lldb_private::formatters::Char32SummaryProvider (ValueObject& valobj, Stream& stream) |
| 414 | { |
| 415 | DataExtractor data; |
| 416 | valobj.GetData(data); |
| 417 | |
| 418 | std::string value; |
| 419 | valobj.GetValueAsCString(lldb::eFormatUnicode32, value); |
| 420 | if (!value.empty()) |
| 421 | stream.Printf("%s ", value.c_str()); |
| 422 | |
| 423 | return DumpUTFBufferToStream<UTF32>(ConvertUTF32toUTF8,data,stream, 'U','\'',1); |
| 424 | } |
| 425 | |
| 426 | bool |
| 427 | lldb_private::formatters::WCharSummaryProvider (ValueObject& valobj, Stream& stream) |
| 428 | { |
| 429 | DataExtractor data; |
| 430 | valobj.GetData(data); |
| 431 | |
| 432 | clang::ASTContext* ast = valobj.GetClangAST(); |
| 433 | |
| 434 | if (!ast) |
| 435 | return false; |
| 436 | |
| 437 | std::string value; |
| 438 | |
| 439 | uint32_t wchar_size = ClangASTType::GetClangTypeBitWidth(ast, ClangASTType::GetBasicType(ast, lldb::eBasicTypeWChar).GetOpaqueQualType()); |
| 440 | |
| 441 | switch (wchar_size) |
| 442 | { |
| 443 | case 8: |
| 444 | // utf 8 |
| 445 | valobj.GetValueAsCString(lldb::eFormatChar, value); |
| 446 | if (!value.empty()) |
| 447 | stream.Printf("%s ", value.c_str()); |
| 448 | return DumpUTFBufferToStream<UTF8>(nullptr, |
| 449 | data, |
| 450 | stream, |
| 451 | 'L', |
| 452 | '\'', |
| 453 | 1); |
| 454 | case 16: |
| 455 | // utf 16 |
| 456 | valobj.GetValueAsCString(lldb::eFormatUnicode16, value); |
| 457 | if (!value.empty()) |
| 458 | stream.Printf("%s ", value.c_str()); |
| 459 | return DumpUTFBufferToStream<UTF16>(ConvertUTF16toUTF8, |
| 460 | data, |
| 461 | stream, |
| 462 | 'L', |
| 463 | '\'', |
| 464 | 1); |
| 465 | case 32: |
| 466 | // utf 32 |
| 467 | valobj.GetValueAsCString(lldb::eFormatUnicode32, value); |
| 468 | if (!value.empty()) |
| 469 | stream.Printf("%s ", value.c_str()); |
| 470 | return DumpUTFBufferToStream<UTF32>(ConvertUTF32toUTF8, |
| 471 | data, |
| 472 | stream, |
| 473 | 'L', |
| 474 | '\'', |
| 475 | 1); |
Enrico Granata | 06d58b0 | 2013-01-11 02:44:00 +0000 | [diff] [blame] | 476 | default: |
| 477 | stream.Printf("size for wchar_t is not valid"); |
| 478 | return true; |
| 479 | } |
| 480 | return true; |
Enrico Granata | f5545f9 | 2013-01-10 22:08:35 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Enrico Granata | b698579 | 2013-01-12 01:00:22 +0000 | [diff] [blame] | 483 | // this function extracts information from a libcxx std::basic_string<> |
| 484 | // irregardless of template arguments. it reports the size (in item count not bytes) |
| 485 | // and the location in memory where the string data can be found |
| 486 | static bool |
| 487 | ExtractLibcxxStringInfo (ValueObject& valobj, |
| 488 | ValueObjectSP &location_sp, |
| 489 | uint64_t& size) |
| 490 | { |
| 491 | ValueObjectSP D(valobj.GetChildAtIndexPath({0,0,0,0})); |
| 492 | if (!D) |
| 493 | return false; |
| 494 | |
| 495 | ValueObjectSP size_mode(D->GetChildAtIndexPath({1,0,0})); |
| 496 | if (!size_mode) |
| 497 | return false; |
| 498 | |
| 499 | uint64_t size_mode_value(size_mode->GetValueAsUnsigned(0)); |
| 500 | |
| 501 | if ((size_mode_value & 1) == 0) // this means the string is in short-mode and the data is stored inline |
| 502 | { |
| 503 | ValueObjectSP s(D->GetChildAtIndex(1, true)); |
| 504 | if (!s) |
| 505 | return false; |
| 506 | size = ((size_mode_value >> 1) % 256); |
| 507 | location_sp = s->GetChildAtIndex(1, true); |
| 508 | return (location_sp.get() != nullptr); |
| 509 | } |
| 510 | else |
| 511 | { |
| 512 | ValueObjectSP l(D->GetChildAtIndex(0, true)); |
| 513 | if (!l) |
| 514 | return false; |
| 515 | location_sp = l->GetChildAtIndex(2, true); |
| 516 | ValueObjectSP size_vo(l->GetChildAtIndex(1, true)); |
| 517 | if (!size_vo || !location_sp) |
| 518 | return false; |
| 519 | size = size_vo->GetValueAsUnsigned(0); |
| 520 | return true; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | bool |
| 525 | lldb_private::formatters::LibcxxWStringSummaryProvider (ValueObject& valobj, Stream& stream) |
| 526 | { |
| 527 | uint64_t size = 0; |
| 528 | ValueObjectSP location_sp((ValueObject*)nullptr); |
| 529 | if (!ExtractLibcxxStringInfo(valobj, location_sp, size)) |
| 530 | return false; |
| 531 | if (size == 0) |
| 532 | { |
| 533 | stream.Printf("L\"\""); |
| 534 | return true; |
| 535 | } |
| 536 | if (!location_sp) |
| 537 | return false; |
| 538 | return WCharStringSummaryProvider(*location_sp.get(), stream); |
| 539 | } |
| 540 | |
| 541 | bool |
| 542 | lldb_private::formatters::LibcxxStringSummaryProvider (ValueObject& valobj, Stream& stream) |
| 543 | { |
| 544 | uint64_t size = 0; |
| 545 | ValueObjectSP location_sp((ValueObject*)nullptr); |
| 546 | if (!ExtractLibcxxStringInfo(valobj, location_sp, size)) |
| 547 | return false; |
| 548 | if (size == 0) |
| 549 | { |
| 550 | stream.Printf("\"\""); |
| 551 | return true; |
| 552 | } |
| 553 | if (!location_sp) |
| 554 | return false; |
| 555 | Error error; |
Enrico Granata | 32d7ee3 | 2013-02-21 19:57:10 +0000 | [diff] [blame] | 556 | if (location_sp->ReadPointedString(stream, |
| 557 | error, |
| 558 | 0, // max length is decided by the settings |
| 559 | false) == 0) // do not honor array (terminates on first 0 byte even for a char[]) |
| 560 | stream.Printf("\"\""); // if nothing was read, print an empty string |
Enrico Granata | b698579 | 2013-01-12 01:00:22 +0000 | [diff] [blame] | 561 | return error.Success(); |
| 562 | } |
| 563 | |
Enrico Granata | 280b30f | 2013-03-15 18:55:30 +0000 | [diff] [blame] | 564 | bool |
| 565 | lldb_private::formatters::ObjCClassSummaryProvider (ValueObject& valobj, Stream& stream) |
| 566 | { |
| 567 | ProcessSP process_sp = valobj.GetProcessSP(); |
| 568 | if (!process_sp) |
| 569 | return false; |
| 570 | |
| 571 | ObjCLanguageRuntime* runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC); |
| 572 | |
| 573 | if (!runtime) |
| 574 | return false; |
| 575 | |
| 576 | ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptor(valobj.GetValueAsUnsigned(0))); |
| 577 | |
| 578 | if (!descriptor.get() || !descriptor->IsValid()) |
| 579 | return false; |
| 580 | |
| 581 | const char* class_name = descriptor->GetClassName().GetCString(); |
| 582 | |
| 583 | if (!class_name || !*class_name) |
| 584 | return false; |
| 585 | |
| 586 | stream.Printf("%s",class_name); |
| 587 | return true; |
| 588 | } |
| 589 | |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 590 | template<bool needs_at> |
| 591 | bool |
Enrico Granata | f91e78f | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 592 | lldb_private::formatters::NSDataSummaryProvider (ValueObject& valobj, Stream& stream) |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 593 | { |
| 594 | ProcessSP process_sp = valobj.GetProcessSP(); |
| 595 | if (!process_sp) |
| 596 | return false; |
| 597 | |
| 598 | ObjCLanguageRuntime* runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC); |
| 599 | |
| 600 | if (!runtime) |
| 601 | return false; |
| 602 | |
| 603 | ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptor(valobj)); |
| 604 | |
| 605 | if (!descriptor.get() || !descriptor->IsValid()) |
| 606 | return false; |
| 607 | |
| 608 | bool is_64bit = (process_sp->GetAddressByteSize() == 8); |
| 609 | lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0); |
| 610 | |
| 611 | if (!valobj_addr) |
| 612 | return false; |
| 613 | |
| 614 | uint64_t value = 0; |
| 615 | |
| 616 | const char* class_name = descriptor->GetClassName().GetCString(); |
Enrico Granata | 7685a56 | 2012-09-29 00:47:43 +0000 | [diff] [blame] | 617 | |
| 618 | if (!class_name || !*class_name) |
| 619 | return false; |
| 620 | |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 621 | if (!strcmp(class_name,"NSConcreteData") || |
| 622 | !strcmp(class_name,"NSConcreteMutableData") || |
| 623 | !strcmp(class_name,"__NSCFData")) |
| 624 | { |
| 625 | uint32_t offset = (is_64bit ? 16 : 8); |
| 626 | Error error; |
| 627 | value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + offset, is_64bit ? 8 : 4, 0, error); |
| 628 | if (error.Fail()) |
| 629 | return false; |
| 630 | } |
| 631 | else |
| 632 | { |
Enrico Granata | f91e78f | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 633 | if (!ExtractValueFromObjCExpression(valobj, "int", "length", value)) |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 634 | return false; |
| 635 | } |
| 636 | |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 637 | stream.Printf("%s%" PRIu64 " byte%s%s", |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 638 | (needs_at ? "@\"" : ""), |
| 639 | value, |
| 640 | (value > 1 ? "s" : ""), |
| 641 | (needs_at ? "\"" : "")); |
| 642 | |
| 643 | return true; |
| 644 | } |
| 645 | |
Enrico Granata | f3a217e | 2013-02-21 20:31:18 +0000 | [diff] [blame] | 646 | static bool |
| 647 | ReadAsciiBufferAndDumpToStream (lldb::addr_t location, |
| 648 | lldb::ProcessSP& process_sp, |
| 649 | Stream& dest, |
Enrico Granata | fb1493d | 2013-04-02 21:25:34 +0000 | [diff] [blame] | 650 | uint32_t size = 0, |
Enrico Granata | f3a217e | 2013-02-21 20:31:18 +0000 | [diff] [blame] | 651 | Error* error = NULL, |
| 652 | size_t *data_read = NULL, |
| 653 | char prefix_token = '@', |
| 654 | char quote = '"') |
| 655 | { |
| 656 | Error my_error; |
| 657 | size_t my_data_read; |
| 658 | if (!process_sp || location == 0) |
| 659 | return false; |
| 660 | |
Enrico Granata | 54f3020 | 2013-04-02 23:07:55 +0000 | [diff] [blame^] | 661 | if (!size) |
| 662 | size = process_sp->GetTarget().GetMaximumSizeOfStringSummary(); |
| 663 | else |
| 664 | size = std::min(size,process_sp->GetTarget().GetMaximumSizeOfStringSummary()); |
Enrico Granata | f3a217e | 2013-02-21 20:31:18 +0000 | [diff] [blame] | 665 | |
| 666 | lldb::DataBufferSP buffer_sp(new DataBufferHeap(size,0)); |
| 667 | |
| 668 | my_data_read = process_sp->ReadCStringFromMemory(location, (char*)buffer_sp->GetBytes(), size, my_error); |
| 669 | |
| 670 | if (error) |
| 671 | *error = my_error; |
| 672 | if (data_read) |
| 673 | *data_read = my_data_read; |
| 674 | |
| 675 | if (my_error.Fail()) |
| 676 | return false; |
| 677 | if (my_data_read) |
| 678 | dest.Printf("%c%c%s%c",prefix_token,quote,(char*)buffer_sp->GetBytes(),quote); |
| 679 | |
| 680 | return true; |
| 681 | } |
| 682 | |
Enrico Granata | fb1493d | 2013-04-02 21:25:34 +0000 | [diff] [blame] | 683 | #ifdef WANT_DEEP_PRINT |
| 684 | struct lldb__notInlineMutable { |
| 685 | void *buffer; |
| 686 | signed long length; |
| 687 | signed long capacity; |
| 688 | unsigned int hasGap:1; |
| 689 | unsigned int isFixedCapacity:1; |
| 690 | unsigned int isExternalMutable:1; |
| 691 | unsigned int capacityProvidedExternally:1; |
| 692 | #if __LP64__ |
| 693 | unsigned long desiredCapacity:60; |
| 694 | #else |
| 695 | unsigned long desiredCapacity:28; |
| 696 | #endif |
| 697 | void* contentsAllocator; |
| 698 | }; |
| 699 | |
| 700 | struct lldb__CFString { |
| 701 | uintptr_t _cfisa; |
| 702 | uint8_t _cfinfo[4]; |
| 703 | uint32_t _rc; |
| 704 | union { |
| 705 | struct __inline1 { |
| 706 | signed long length; |
| 707 | } inline1; |
| 708 | struct __notInlineImmutable1 { |
| 709 | void *buffer; |
| 710 | signed long length; |
| 711 | void* contentsDeallocator; |
| 712 | } notInlineImmutable1; |
| 713 | struct __notInlineImmutable2 { |
| 714 | void *buffer; |
| 715 | void* contentsDeallocator; |
| 716 | } notInlineImmutable2; |
| 717 | struct lldb__notInlineMutable notInlineMutable; |
| 718 | } variants; |
| 719 | }; |
| 720 | #endif |
| 721 | |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 722 | bool |
Enrico Granata | f91e78f | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 723 | lldb_private::formatters::NSStringSummaryProvider (ValueObject& valobj, Stream& stream) |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 724 | { |
| 725 | ProcessSP process_sp = valobj.GetProcessSP(); |
| 726 | if (!process_sp) |
| 727 | return false; |
| 728 | |
| 729 | ObjCLanguageRuntime* runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC); |
| 730 | |
| 731 | if (!runtime) |
| 732 | return false; |
| 733 | |
| 734 | ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptor(valobj)); |
| 735 | |
| 736 | if (!descriptor.get() || !descriptor->IsValid()) |
| 737 | return false; |
| 738 | |
| 739 | uint32_t ptr_size = process_sp->GetAddressByteSize(); |
| 740 | |
| 741 | lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0); |
| 742 | |
| 743 | if (!valobj_addr) |
| 744 | return false; |
| 745 | |
| 746 | const char* class_name = descriptor->GetClassName().GetCString(); |
| 747 | |
Enrico Granata | 25c9ade | 2012-09-29 00:45:53 +0000 | [diff] [blame] | 748 | if (!class_name || !*class_name) |
| 749 | return false; |
| 750 | |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 751 | uint64_t info_bits_location = valobj_addr + ptr_size; |
| 752 | if (process_sp->GetByteOrder() != lldb::eByteOrderLittle) |
| 753 | info_bits_location += 3; |
| 754 | |
Enrico Granata | f3a217e | 2013-02-21 20:31:18 +0000 | [diff] [blame] | 755 | Error error; |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 756 | |
| 757 | uint8_t info_bits = process_sp->ReadUnsignedIntegerFromMemory(info_bits_location, 1, 0, error); |
| 758 | if (error.Fail()) |
| 759 | return false; |
| 760 | |
| 761 | bool is_mutable = (info_bits & 1) == 1; |
| 762 | bool is_inline = (info_bits & 0x60) == 0; |
| 763 | bool has_explicit_length = (info_bits & (1 | 4)) != 4; |
| 764 | bool is_unicode = (info_bits & 0x10) == 0x10; |
| 765 | bool is_special = strcmp(class_name,"NSPathStore2") == 0; |
Enrico Granata | fb1493d | 2013-04-02 21:25:34 +0000 | [diff] [blame] | 766 | bool has_null = (info_bits & 8) == 8; |
| 767 | |
| 768 | size_t explicit_length = 0; |
| 769 | if (!has_null && has_explicit_length && !is_special) |
| 770 | { |
| 771 | lldb::addr_t explicit_length_offset = 2*ptr_size; |
| 772 | if (is_mutable and not is_inline) |
| 773 | explicit_length_offset = explicit_length_offset + ptr_size; // notInlineMutable.length; |
| 774 | else if (is_inline) |
| 775 | explicit_length = explicit_length + 0; // inline1.length; |
| 776 | else if (not is_inline and not is_mutable) |
| 777 | explicit_length_offset = explicit_length_offset + ptr_size; // notInlineImmutable1.length; |
| 778 | else |
| 779 | explicit_length_offset = 0; |
| 780 | |
| 781 | if (explicit_length_offset) |
| 782 | { |
| 783 | explicit_length_offset = valobj_addr + explicit_length_offset; |
| 784 | explicit_length = process_sp->ReadUnsignedIntegerFromMemory(explicit_length_offset, 4, 0, error); |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | #ifdef WANT_DEEP_PRINT |
| 789 | lldb__CFString my_string_data; |
| 790 | process_sp->ReadMemory(valobj_addr, &my_string_data, sizeof(lldb__CFString),error); |
| 791 | |
| 792 | printf(R"( |
| 793 | __CFString my_string_data = { |
| 794 | uintptr_t _cfisa = %lu |
| 795 | uint8_t _cfinfo[4] = %c%c%c%c |
| 796 | uint32_t _rc = %d |
| 797 | union { |
| 798 | struct __inline1 { |
| 799 | signed long length = %ld |
| 800 | } inline1; |
| 801 | struct __notInlineImmutable1 { |
| 802 | void *buffer = %p |
| 803 | signed long length = %ld |
| 804 | void* contentsDeallocator = %p |
| 805 | } notInlineImmutable1; |
| 806 | struct __notInlineImmutable2 { |
| 807 | void *buffer = %p |
| 808 | void* contentsDeallocator = %p |
| 809 | } notInlineImmutable2; |
| 810 | struct __notInlineMutable notInlineMutable { |
| 811 | void *buffer = %p |
| 812 | signed long length = %ld |
| 813 | signed long capacity = %ld |
| 814 | unsigned int hasGap:1 = %d |
| 815 | unsigned int isFixedCapacity:1 = %d |
| 816 | unsigned int isExternalMutable:1 = %d |
| 817 | unsigned int capacityProvidedExternally:1 = %d |
| 818 | #if __LP64__ |
| 819 | unsigned long desiredCapacity:60 = %lu |
| 820 | #else |
| 821 | unsigned long desiredCapacity:28 = %lu |
| 822 | #endif |
| 823 | void* contentsAllocator = %p |
| 824 | } |
| 825 | } variants; |
| 826 | };\n)", |
| 827 | my_string_data._cfisa, |
| 828 | my_string_data._cfinfo[0],my_string_data._cfinfo[1],my_string_data._cfinfo[2],my_string_data._cfinfo[3], |
| 829 | my_string_data._rc, |
| 830 | my_string_data.variants.inline1.length, |
| 831 | my_string_data.variants.notInlineImmutable1.buffer, |
| 832 | my_string_data.variants.notInlineImmutable1.length, |
| 833 | my_string_data.variants.notInlineImmutable1.contentsDeallocator, |
| 834 | my_string_data.variants.notInlineImmutable2.buffer, |
| 835 | my_string_data.variants.notInlineImmutable2.contentsDeallocator, |
| 836 | my_string_data.variants.notInlineMutable.buffer, |
| 837 | my_string_data.variants.notInlineMutable.length, |
| 838 | my_string_data.variants.notInlineMutable.capacity, |
| 839 | my_string_data.variants.notInlineMutable.hasGap, |
| 840 | my_string_data.variants.notInlineMutable.isFixedCapacity, |
| 841 | my_string_data.variants.notInlineMutable.isExternalMutable, |
| 842 | my_string_data.variants.notInlineMutable.capacityProvidedExternally, |
| 843 | my_string_data.variants.notInlineMutable.desiredCapacity, |
| 844 | my_string_data.variants.notInlineMutable.desiredCapacity, |
| 845 | my_string_data.variants.notInlineMutable.contentsAllocator); |
| 846 | #endif |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 847 | |
| 848 | if (strcmp(class_name,"NSString") && |
| 849 | strcmp(class_name,"CFStringRef") && |
| 850 | strcmp(class_name,"CFMutableStringRef") && |
| 851 | strcmp(class_name,"__NSCFConstantString") && |
| 852 | strcmp(class_name,"__NSCFString") && |
| 853 | strcmp(class_name,"NSCFConstantString") && |
| 854 | strcmp(class_name,"NSCFString") && |
| 855 | strcmp(class_name,"NSPathStore2")) |
| 856 | { |
Enrico Granata | f3a217e | 2013-02-21 20:31:18 +0000 | [diff] [blame] | 857 | // not one of us - but tell me class name |
| 858 | stream.Printf("class name = %s",class_name); |
| 859 | return true; |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 860 | } |
| 861 | |
Enrico Granata | fb1493d | 2013-04-02 21:25:34 +0000 | [diff] [blame] | 862 | #ifdef WANT_DEEP_PRNT |
| 863 | stream.Printf("(M:%dI:%dL:%zuU:%dS:%dN:%d) ", |
| 864 | is_mutable, |
| 865 | is_inline, |
| 866 | explicit_length, |
| 867 | is_unicode, |
| 868 | is_special, |
| 869 | has_null); |
| 870 | #endif |
| 871 | |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 872 | if (is_mutable) |
| 873 | { |
| 874 | uint64_t location = 2 * ptr_size + valobj_addr; |
| 875 | location = process_sp->ReadPointerFromMemory(location, error); |
| 876 | if (error.Fail()) |
| 877 | return false; |
| 878 | if (has_explicit_length and is_unicode) |
Enrico Granata | fb1493d | 2013-04-02 21:25:34 +0000 | [diff] [blame] | 879 | return ReadUTFBufferAndDumpToStream<UTF16> (ConvertUTF16toUTF8,location, process_sp, stream, '@', '"', explicit_length); |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 880 | else |
Enrico Granata | fb1493d | 2013-04-02 21:25:34 +0000 | [diff] [blame] | 881 | return ReadAsciiBufferAndDumpToStream(location+1,process_sp,stream, explicit_length); |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 882 | } |
| 883 | else if (is_inline && has_explicit_length && !is_unicode && !is_special && !is_mutable) |
| 884 | { |
| 885 | uint64_t location = 3 * ptr_size + valobj_addr; |
Enrico Granata | fb1493d | 2013-04-02 21:25:34 +0000 | [diff] [blame] | 886 | return ReadAsciiBufferAndDumpToStream(location,process_sp,stream,explicit_length); |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 887 | } |
| 888 | else if (is_unicode) |
| 889 | { |
Enrico Granata | f3a217e | 2013-02-21 20:31:18 +0000 | [diff] [blame] | 890 | uint64_t location = valobj_addr + 2*ptr_size; |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 891 | if (is_inline) |
| 892 | { |
| 893 | if (!has_explicit_length) |
| 894 | { |
| 895 | stream.Printf("found new combo"); |
| 896 | return true; |
| 897 | } |
| 898 | else |
| 899 | location += ptr_size; |
| 900 | } |
| 901 | else |
| 902 | { |
| 903 | location = process_sp->ReadPointerFromMemory(location, error); |
| 904 | if (error.Fail()) |
| 905 | return false; |
| 906 | } |
Enrico Granata | fb1493d | 2013-04-02 21:25:34 +0000 | [diff] [blame] | 907 | return ReadUTFBufferAndDumpToStream<UTF16> (ConvertUTF16toUTF8, location, process_sp, stream, '@', '"', explicit_length); |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 908 | } |
| 909 | else if (is_special) |
| 910 | { |
| 911 | uint64_t location = valobj_addr + (ptr_size == 8 ? 12 : 8); |
Enrico Granata | fb1493d | 2013-04-02 21:25:34 +0000 | [diff] [blame] | 912 | return ReadUTFBufferAndDumpToStream<UTF16> (ConvertUTF16toUTF8, location, process_sp, stream, '@', '"', explicit_length); |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 913 | } |
| 914 | else if (is_inline) |
| 915 | { |
Enrico Granata | f3a217e | 2013-02-21 20:31:18 +0000 | [diff] [blame] | 916 | uint64_t location = valobj_addr + 2*ptr_size; |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 917 | if (!has_explicit_length) |
| 918 | location++; |
Enrico Granata | fb1493d | 2013-04-02 21:25:34 +0000 | [diff] [blame] | 919 | return ReadAsciiBufferAndDumpToStream(location,process_sp,stream,explicit_length); |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 920 | } |
| 921 | else |
| 922 | { |
Enrico Granata | f3a217e | 2013-02-21 20:31:18 +0000 | [diff] [blame] | 923 | uint64_t location = valobj_addr + 2*ptr_size; |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 924 | location = process_sp->ReadPointerFromMemory(location, error); |
| 925 | if (error.Fail()) |
| 926 | return false; |
Enrico Granata | fb1493d | 2013-04-02 21:25:34 +0000 | [diff] [blame] | 927 | return ReadAsciiBufferAndDumpToStream(location,process_sp,stream,explicit_length); |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | stream.Printf("class name = %s",class_name); |
| 931 | return true; |
| 932 | |
| 933 | } |
| 934 | |
Enrico Granata | 9abbfba | 2012-10-03 23:53:45 +0000 | [diff] [blame] | 935 | bool |
Enrico Granata | dcffc1a | 2013-02-08 01:55:46 +0000 | [diff] [blame] | 936 | lldb_private::formatters::NSAttributedStringSummaryProvider (ValueObject& valobj, Stream& stream) |
| 937 | { |
| 938 | TargetSP target_sp(valobj.GetTargetSP()); |
| 939 | if (!target_sp) |
| 940 | return false; |
| 941 | uint32_t addr_size = target_sp->GetArchitecture().GetAddressByteSize(); |
| 942 | uint64_t pointee = valobj.GetValueAsUnsigned(0); |
| 943 | if (!pointee) |
| 944 | return false; |
| 945 | pointee += addr_size; |
| 946 | ClangASTType type(valobj.GetClangAST(),valobj.GetClangType()); |
| 947 | ExecutionContext exe_ctx(target_sp,false); |
| 948 | ValueObjectSP child_ptr_sp(valobj.CreateValueObjectFromAddress("string_ptr", pointee, exe_ctx, type)); |
| 949 | if (!child_ptr_sp) |
| 950 | return false; |
| 951 | DataExtractor data; |
| 952 | child_ptr_sp->GetData(data); |
| 953 | ValueObjectSP child_sp(child_ptr_sp->CreateValueObjectFromData("string_data", data, exe_ctx, type)); |
| 954 | child_sp->GetValueAsUnsigned(0); |
| 955 | if (child_sp) |
| 956 | return NSStringSummaryProvider(*child_sp, stream); |
| 957 | return false; |
| 958 | } |
| 959 | |
| 960 | bool |
| 961 | lldb_private::formatters::NSMutableAttributedStringSummaryProvider (ValueObject& valobj, Stream& stream) |
| 962 | { |
| 963 | return NSAttributedStringSummaryProvider(valobj, stream); |
| 964 | } |
| 965 | |
| 966 | bool |
Enrico Granata | 9abbfba | 2012-10-03 23:53:45 +0000 | [diff] [blame] | 967 | lldb_private::formatters::RuntimeSpecificDescriptionSummaryProvider (ValueObject& valobj, Stream& stream) |
| 968 | { |
| 969 | stream.Printf("%s",valobj.GetObjectDescription()); |
| 970 | return true; |
| 971 | } |
| 972 | |
Enrico Granata | db05491 | 2012-10-29 21:18:03 +0000 | [diff] [blame] | 973 | bool |
| 974 | lldb_private::formatters::ObjCBOOLSummaryProvider (ValueObject& valobj, Stream& stream) |
| 975 | { |
| 976 | const uint32_t type_info = ClangASTContext::GetTypeInfo(valobj.GetClangType(), |
| 977 | valobj.GetClangAST(), |
| 978 | NULL); |
| 979 | |
| 980 | ValueObjectSP real_guy_sp = valobj.GetSP(); |
| 981 | |
| 982 | if (type_info & ClangASTContext::eTypeIsPointer) |
| 983 | { |
| 984 | Error err; |
| 985 | real_guy_sp = valobj.Dereference(err); |
| 986 | if (err.Fail() || !real_guy_sp) |
| 987 | return false; |
| 988 | } |
| 989 | else if (type_info & ClangASTContext::eTypeIsReference) |
| 990 | { |
| 991 | real_guy_sp = valobj.GetChildAtIndex(0, true); |
| 992 | if (!real_guy_sp) |
| 993 | return false; |
| 994 | } |
| 995 | uint64_t value = real_guy_sp->GetValueAsUnsigned(0); |
| 996 | if (value == 0) |
| 997 | { |
| 998 | stream.Printf("NO"); |
| 999 | return true; |
| 1000 | } |
| 1001 | stream.Printf("YES"); |
| 1002 | return true; |
| 1003 | } |
| 1004 | |
| 1005 | template <bool is_sel_ptr> |
| 1006 | bool |
| 1007 | lldb_private::formatters::ObjCSELSummaryProvider (ValueObject& valobj, Stream& stream) |
| 1008 | { |
Enrico Granata | 1f9df78 | 2013-02-15 00:06:04 +0000 | [diff] [blame] | 1009 | lldb::ValueObjectSP valobj_sp; |
Enrico Granata | db05491 | 2012-10-29 21:18:03 +0000 | [diff] [blame] | 1010 | |
Enrico Granata | 1f9df78 | 2013-02-15 00:06:04 +0000 | [diff] [blame] | 1011 | if (!valobj.GetClangAST()) |
Enrico Granata | db05491 | 2012-10-29 21:18:03 +0000 | [diff] [blame] | 1012 | return false; |
Enrico Granata | 1f9df78 | 2013-02-15 00:06:04 +0000 | [diff] [blame] | 1013 | void* char_opaque_type = valobj.GetClangAST()->CharTy.getAsOpaquePtr(); |
| 1014 | if (!char_opaque_type) |
| 1015 | return false; |
| 1016 | ClangASTType charstar(valobj.GetClangAST(),ClangASTType::GetPointerType(valobj.GetClangAST(), char_opaque_type)); |
| 1017 | |
Enrico Granata | db05491 | 2012-10-29 21:18:03 +0000 | [diff] [blame] | 1018 | ExecutionContext exe_ctx(valobj.GetExecutionContextRef()); |
| 1019 | |
Enrico Granata | 1f9df78 | 2013-02-15 00:06:04 +0000 | [diff] [blame] | 1020 | if (is_sel_ptr) |
| 1021 | { |
| 1022 | lldb::addr_t data_address = valobj.GetValueAsUnsigned(LLDB_INVALID_ADDRESS); |
| 1023 | if (data_address == LLDB_INVALID_ADDRESS) |
| 1024 | return false; |
| 1025 | valobj_sp = ValueObject::CreateValueObjectFromAddress("text", data_address, exe_ctx, charstar); |
| 1026 | } |
| 1027 | else |
| 1028 | { |
| 1029 | DataExtractor data; |
| 1030 | valobj.GetData(data); |
| 1031 | valobj_sp = ValueObject::CreateValueObjectFromData("text", data, exe_ctx, charstar); |
| 1032 | } |
Enrico Granata | db05491 | 2012-10-29 21:18:03 +0000 | [diff] [blame] | 1033 | |
Enrico Granata | 1f9df78 | 2013-02-15 00:06:04 +0000 | [diff] [blame] | 1034 | if (!valobj_sp) |
| 1035 | return false; |
Enrico Granata | db05491 | 2012-10-29 21:18:03 +0000 | [diff] [blame] | 1036 | |
| 1037 | stream.Printf("%s",valobj_sp->GetSummaryAsCString()); |
| 1038 | return true; |
| 1039 | } |
| 1040 | |
Enrico Granata | cba09f6 | 2013-03-19 00:27:22 +0000 | [diff] [blame] | 1041 | // POSIX has an epoch on Jan-1-1970, but Cocoa prefers Jan-1-2001 |
| 1042 | // this call gives the POSIX equivalent of the Cocoa epoch |
| 1043 | time_t |
Enrico Granata | cc5d274 | 2013-03-19 22:58:48 +0000 | [diff] [blame] | 1044 | lldb_private::formatters::GetOSXEpoch () |
Enrico Granata | cba09f6 | 2013-03-19 00:27:22 +0000 | [diff] [blame] | 1045 | { |
| 1046 | static time_t epoch = 0; |
| 1047 | if (!epoch) |
| 1048 | { |
| 1049 | tzset(); |
| 1050 | tm tm_epoch; |
| 1051 | tm_epoch.tm_sec = 0; |
| 1052 | tm_epoch.tm_hour = 0; |
| 1053 | tm_epoch.tm_min = 0; |
| 1054 | tm_epoch.tm_mon = 0; |
| 1055 | tm_epoch.tm_mday = 1; |
| 1056 | tm_epoch.tm_year = 2001-1900; // for some reason, we need to subtract 1900 from this field. not sure why. |
| 1057 | tm_epoch.tm_isdst = -1; |
| 1058 | tm_epoch.tm_gmtoff = 0; |
| 1059 | tm_epoch.tm_zone = NULL; |
| 1060 | epoch = timegm(&tm_epoch); |
| 1061 | } |
| 1062 | return epoch; |
| 1063 | } |
| 1064 | |
Greg Clayton | 36da2aa | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1065 | size_t |
Enrico Granata | ea68753 | 2013-02-15 23:38:37 +0000 | [diff] [blame] | 1066 | lldb_private::formatters::ExtractIndexFromString (const char* item_name) |
Enrico Granata | f91e78f | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 1067 | { |
| 1068 | if (!item_name || !*item_name) |
| 1069 | return UINT32_MAX; |
| 1070 | if (*item_name != '[') |
| 1071 | return UINT32_MAX; |
| 1072 | item_name++; |
Enrico Granata | ea68753 | 2013-02-15 23:38:37 +0000 | [diff] [blame] | 1073 | char* endptr = NULL; |
| 1074 | unsigned long int idx = ::strtoul(item_name, &endptr, 0); |
| 1075 | if (idx == 0 && endptr == item_name) |
Enrico Granata | f91e78f | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 1076 | return UINT32_MAX; |
Enrico Granata | ea68753 | 2013-02-15 23:38:37 +0000 | [diff] [blame] | 1077 | if (idx == ULONG_MAX) |
Enrico Granata | f91e78f | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 1078 | return UINT32_MAX; |
| 1079 | return idx; |
| 1080 | } |
| 1081 | |
Enrico Granata | 32d7ee3 | 2013-02-21 19:57:10 +0000 | [diff] [blame] | 1082 | lldb_private::formatters::VectorIteratorSyntheticFrontEnd::VectorIteratorSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp, |
| 1083 | ConstString item_name) : |
Enrico Granata | 689696c | 2013-02-04 22:54:42 +0000 | [diff] [blame] | 1084 | SyntheticChildrenFrontEnd(*valobj_sp.get()), |
| 1085 | m_exe_ctx_ref(), |
Enrico Granata | 32d7ee3 | 2013-02-21 19:57:10 +0000 | [diff] [blame] | 1086 | m_item_name(item_name), |
| 1087 | m_item_sp() |
Enrico Granata | 689696c | 2013-02-04 22:54:42 +0000 | [diff] [blame] | 1088 | { |
| 1089 | if (valobj_sp) |
| 1090 | Update(); |
Enrico Granata | 689696c | 2013-02-04 22:54:42 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
Enrico Granata | 689696c | 2013-02-04 22:54:42 +0000 | [diff] [blame] | 1093 | bool |
Enrico Granata | 32d7ee3 | 2013-02-21 19:57:10 +0000 | [diff] [blame] | 1094 | lldb_private::formatters::VectorIteratorSyntheticFrontEnd::Update() |
Enrico Granata | 689696c | 2013-02-04 22:54:42 +0000 | [diff] [blame] | 1095 | { |
Enrico Granata | d32acdb | 2013-03-28 18:50:54 +0000 | [diff] [blame] | 1096 | m_item_sp.reset(); |
| 1097 | |
Enrico Granata | 689696c | 2013-02-04 22:54:42 +0000 | [diff] [blame] | 1098 | ValueObjectSP valobj_sp = m_backend.GetSP(); |
| 1099 | if (!valobj_sp) |
| 1100 | return false; |
Enrico Granata | 32d7ee3 | 2013-02-21 19:57:10 +0000 | [diff] [blame] | 1101 | |
Enrico Granata | 689696c | 2013-02-04 22:54:42 +0000 | [diff] [blame] | 1102 | if (!valobj_sp) |
| 1103 | return false; |
Enrico Granata | 32d7ee3 | 2013-02-21 19:57:10 +0000 | [diff] [blame] | 1104 | |
| 1105 | ValueObjectSP item_ptr(valobj_sp->GetChildMemberWithName(m_item_name,true)); |
| 1106 | if (!item_ptr) |
| 1107 | return false; |
| 1108 | if (item_ptr->GetValueAsUnsigned(0) == 0) |
| 1109 | return false; |
| 1110 | Error err; |
Enrico Granata | 689696c | 2013-02-04 22:54:42 +0000 | [diff] [blame] | 1111 | m_exe_ctx_ref = valobj_sp->GetExecutionContextRef(); |
Enrico Granata | 32d7ee3 | 2013-02-21 19:57:10 +0000 | [diff] [blame] | 1112 | m_item_sp = ValueObject::CreateValueObjectFromAddress("item", item_ptr->GetValueAsUnsigned(0), m_exe_ctx_ref, ClangASTType(item_ptr->GetClangAST(),ClangASTType::GetPointeeType(item_ptr->GetClangType()))); |
| 1113 | if (err.Fail()) |
| 1114 | m_item_sp.reset(); |
Enrico Granata | d32acdb | 2013-03-28 18:50:54 +0000 | [diff] [blame] | 1115 | return false; |
Enrico Granata | 32d7ee3 | 2013-02-21 19:57:10 +0000 | [diff] [blame] | 1116 | } |
Enrico Granata | 689696c | 2013-02-04 22:54:42 +0000 | [diff] [blame] | 1117 | |
Enrico Granata | 32d7ee3 | 2013-02-21 19:57:10 +0000 | [diff] [blame] | 1118 | size_t |
| 1119 | lldb_private::formatters::VectorIteratorSyntheticFrontEnd::CalculateNumChildren () |
| 1120 | { |
| 1121 | return 1; |
| 1122 | } |
Enrico Granata | 689696c | 2013-02-04 22:54:42 +0000 | [diff] [blame] | 1123 | |
Enrico Granata | 32d7ee3 | 2013-02-21 19:57:10 +0000 | [diff] [blame] | 1124 | lldb::ValueObjectSP |
| 1125 | lldb_private::formatters::VectorIteratorSyntheticFrontEnd::GetChildAtIndex (size_t idx) |
| 1126 | { |
| 1127 | if (idx == 0) |
| 1128 | return m_item_sp; |
| 1129 | return lldb::ValueObjectSP(); |
Enrico Granata | 689696c | 2013-02-04 22:54:42 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | bool |
Enrico Granata | 32d7ee3 | 2013-02-21 19:57:10 +0000 | [diff] [blame] | 1133 | lldb_private::formatters::VectorIteratorSyntheticFrontEnd::MightHaveChildren () |
Enrico Granata | 689696c | 2013-02-04 22:54:42 +0000 | [diff] [blame] | 1134 | { |
| 1135 | return true; |
| 1136 | } |
| 1137 | |
| 1138 | size_t |
Enrico Granata | 32d7ee3 | 2013-02-21 19:57:10 +0000 | [diff] [blame] | 1139 | lldb_private::formatters::VectorIteratorSyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name) |
Enrico Granata | 689696c | 2013-02-04 22:54:42 +0000 | [diff] [blame] | 1140 | { |
Enrico Granata | 32d7ee3 | 2013-02-21 19:57:10 +0000 | [diff] [blame] | 1141 | if (name == ConstString("item")) |
| 1142 | return 0; |
| 1143 | return UINT32_MAX; |
Enrico Granata | 689696c | 2013-02-04 22:54:42 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
Enrico Granata | 32d7ee3 | 2013-02-21 19:57:10 +0000 | [diff] [blame] | 1146 | lldb_private::formatters::VectorIteratorSyntheticFrontEnd::~VectorIteratorSyntheticFrontEnd () |
Enrico Granata | 689696c | 2013-02-04 22:54:42 +0000 | [diff] [blame] | 1147 | { |
Enrico Granata | 689696c | 2013-02-04 22:54:42 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
Enrico Granata | caaf010 | 2012-09-04 18:48:21 +0000 | [diff] [blame] | 1150 | template bool |
Enrico Granata | f91e78f | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 1151 | lldb_private::formatters::NSDataSummaryProvider<true> (ValueObject&, Stream&) ; |
| 1152 | |
| 1153 | template bool |
| 1154 | lldb_private::formatters::NSDataSummaryProvider<false> (ValueObject&, Stream&) ; |
Enrico Granata | db05491 | 2012-10-29 21:18:03 +0000 | [diff] [blame] | 1155 | |
| 1156 | template bool |
| 1157 | lldb_private::formatters::ObjCSELSummaryProvider<true> (ValueObject&, Stream&) ; |
| 1158 | |
| 1159 | template bool |
| 1160 | lldb_private::formatters::ObjCSELSummaryProvider<false> (ValueObject&, Stream&) ; |