1 //===-- CXXFormatterFunctions.cpp---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
12 #include "lldb/DataFormatters/CXXFormatterFunctions.h"
13 #include "lldb/DataFormatters/StringPrinter.h"
14 #include "lldb/DataFormatters/TypeSummary.h"
16 #include "llvm/Support/ConvertUTF.h"
18 #include "lldb/Core/DataBufferHeap.h"
19 #include "lldb/Core/Error.h"
20 #include "lldb/Core/Stream.h"
21 #include "lldb/Core/ValueObject.h"
22 #include "lldb/Core/ValueObjectConstResult.h"
23 #include "lldb/Host/Endian.h"
24 #include "lldb/Symbol/ClangASTContext.h"
25 #include "lldb/Target/SectionLoadList.h"
26 #include "lldb/Target/Target.h"
27 #include "lldb/Target/Thread.h"
29 #include "lldb/Utility/ProcessStructReader.h"
33 #include <sys/types.h>
37 using namespace lldb_private;
38 using namespace lldb_private::formatters;
41 lldb_private::formatters::GetViableFrame (ExecutionContext exe_ctx)
43 StackFrame* frame = exe_ctx.GetFramePtr();
47 Process* process = exe_ctx.GetProcessPtr();
51 ThreadSP thread_sp(process->GetThreadList().GetSelectedThread());
53 return thread_sp->GetSelectedFrame().get();
58 lldb_private::formatters::ExtractValueFromObjCExpression (ValueObject &valobj,
59 const char* target_type,
63 if (!target_type || !*target_type)
65 if (!selector || !*selector)
68 expr.Printf("(%s)[(id)0x%" PRIx64 " %s]",target_type,valobj.GetPointerValue(),selector);
69 ExecutionContext exe_ctx (valobj.GetExecutionContextRef());
70 lldb::ValueObjectSP result_sp;
71 Target* target = exe_ctx.GetTargetPtr();
72 StackFrame* stack_frame = GetViableFrame(exe_ctx);
73 if (!target || !stack_frame)
76 EvaluateExpressionOptions options;
77 options.SetCoerceToId(false);
78 options.SetUnwindOnError(true);
79 options.SetKeepInMemory(true);
81 target->EvaluateExpression(expr.GetData(),
87 value = result_sp->GetValueAsUnsigned(0);
92 lldb_private::formatters::ExtractSummaryFromObjCExpression (ValueObject &valobj,
93 const char* target_type,
97 if (!target_type || !*target_type)
99 if (!selector || !*selector)
102 expr.Printf("(%s)[(id)0x%" PRIx64 " %s]",target_type,valobj.GetPointerValue(),selector);
103 ExecutionContext exe_ctx (valobj.GetExecutionContextRef());
104 lldb::ValueObjectSP result_sp;
105 Target* target = exe_ctx.GetTargetPtr();
106 StackFrame* stack_frame = GetViableFrame(exe_ctx);
107 if (!target || !stack_frame)
110 EvaluateExpressionOptions options;
111 options.SetCoerceToId(false);
112 options.SetUnwindOnError(true);
113 options.SetKeepInMemory(true);
114 options.SetUseDynamic(lldb::eDynamicCanRunTarget);
116 target->EvaluateExpression(expr.GetData(),
122 stream.Printf("%s",result_sp->GetSummaryAsCString());
127 lldb_private::formatters::CallSelectorOnObject (ValueObject &valobj,
128 const char* return_type,
129 const char* selector,
132 lldb::ValueObjectSP valobj_sp;
133 if (!return_type || !*return_type)
135 if (!selector || !*selector)
137 StreamString expr_path_stream;
138 valobj.GetExpressionPath(expr_path_stream, false);
140 expr.Printf("(%s)[%s %s:%" PRId64 "]",return_type,expr_path_stream.GetData(),selector,index);
141 ExecutionContext exe_ctx (valobj.GetExecutionContextRef());
142 lldb::ValueObjectSP result_sp;
143 Target* target = exe_ctx.GetTargetPtr();
144 StackFrame* stack_frame = GetViableFrame(exe_ctx);
145 if (!target || !stack_frame)
148 EvaluateExpressionOptions options;
149 options.SetCoerceToId(false);
150 options.SetUnwindOnError(true);
151 options.SetKeepInMemory(true);
152 options.SetUseDynamic(lldb::eDynamicCanRunTarget);
154 target->EvaluateExpression(expr.GetData(),
162 lldb_private::formatters::CallSelectorOnObject (ValueObject &valobj,
163 const char* return_type,
164 const char* selector,
167 lldb::ValueObjectSP valobj_sp;
168 if (!return_type || !*return_type)
170 if (!selector || !*selector)
174 StreamString expr_path_stream;
175 valobj.GetExpressionPath(expr_path_stream, false);
177 expr.Printf("(%s)[%s %s:%s]",return_type,expr_path_stream.GetData(),selector,key);
178 ExecutionContext exe_ctx (valobj.GetExecutionContextRef());
179 lldb::ValueObjectSP result_sp;
180 Target* target = exe_ctx.GetTargetPtr();
181 StackFrame* stack_frame = GetViableFrame(exe_ctx);
182 if (!target || !stack_frame)
185 EvaluateExpressionOptions options;
186 options.SetCoerceToId(false);
187 options.SetUnwindOnError(true);
188 options.SetKeepInMemory(true);
189 options.SetUseDynamic(lldb::eDynamicCanRunTarget);
191 target->EvaluateExpression(expr.GetData(),
199 lldb_private::formatters::FunctionPointerSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options)
201 std::string destination;
203 AddressType func_ptr_address_type = eAddressTypeInvalid;
204 addr_t func_ptr_address = valobj.GetPointerValue (&func_ptr_address_type);
205 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
207 switch (func_ptr_address_type)
209 case eAddressTypeInvalid:
210 case eAddressTypeFile:
211 case eAddressTypeHost:
214 case eAddressTypeLoad:
216 ExecutionContext exe_ctx (valobj.GetExecutionContextRef());
219 Target *target = exe_ctx.GetTargetPtr();
220 if (target && target->GetSectionLoadList().IsEmpty() == false)
222 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
225 exe_ctx.GetBestExecutionContextScope(),
226 Address::DumpStyleResolvedDescription,
227 Address::DumpStyleSectionNameOffset);
234 if (sstr.GetSize() > 0)
236 stream.Printf("(%s)", sstr.GetData());
244 lldb_private::formatters::Char16StringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions&)
246 ProcessSP process_sp = valobj.GetProcessSP();
250 lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
255 ReadStringAndDumpToStreamOptions options(valobj);
256 options.SetLocation(valobj_addr);
257 options.SetProcessSP(process_sp);
258 options.SetStream(&stream);
259 options.SetPrefixToken('u');
261 if (!ReadStringAndDumpToStream<StringElementType::UTF16>(options))
263 stream.Printf("Summary Unavailable");
271 lldb_private::formatters::Char32StringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions&)
273 ProcessSP process_sp = valobj.GetProcessSP();
277 lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
282 ReadStringAndDumpToStreamOptions options(valobj);
283 options.SetLocation(valobj_addr);
284 options.SetProcessSP(process_sp);
285 options.SetStream(&stream);
286 options.SetPrefixToken('U');
288 if (!ReadStringAndDumpToStream<StringElementType::UTF32>(options))
290 stream.Printf("Summary Unavailable");
298 lldb_private::formatters::WCharStringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions&)
300 ProcessSP process_sp = valobj.GetProcessSP();
304 lldb::addr_t data_addr = 0;
306 if (valobj.IsPointerType())
307 data_addr = valobj.GetValueAsUnsigned(0);
308 else if (valobj.IsArrayType())
309 data_addr = valobj.GetAddressOf();
311 if (data_addr == 0 || data_addr == LLDB_INVALID_ADDRESS)
314 clang::ASTContext* ast = valobj.GetClangType().GetASTContext();
319 ClangASTType wchar_clang_type = ClangASTContext::GetBasicType(ast, lldb::eBasicTypeWChar);
320 const uint32_t wchar_size = wchar_clang_type.GetBitSize();
322 ReadStringAndDumpToStreamOptions options(valobj);
323 options.SetLocation(data_addr);
324 options.SetProcessSP(process_sp);
325 options.SetStream(&stream);
326 options.SetPrefixToken('L');
331 return ReadStringAndDumpToStream<StringElementType::UTF8>(options);
333 return ReadStringAndDumpToStream<StringElementType::UTF16>(options);
335 return ReadStringAndDumpToStream<StringElementType::UTF32>(options);
337 stream.Printf("size for wchar_t is not valid");
344 lldb_private::formatters::Char16SummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions&)
348 valobj.GetData(data, error);
354 valobj.GetValueAsCString(lldb::eFormatUnicode16, value);
356 stream.Printf("%s ", value.c_str());
358 ReadBufferAndDumpToStreamOptions options(valobj);
359 options.SetData(data);
360 options.SetStream(&stream);
361 options.SetPrefixToken('u');
362 options.SetQuote('\'');
363 options.SetSourceSize(1);
365 return ReadBufferAndDumpToStream<StringElementType::UTF16>(options);
369 lldb_private::formatters::Char32SummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions&)
373 valobj.GetData(data, error);
379 valobj.GetValueAsCString(lldb::eFormatUnicode32, value);
381 stream.Printf("%s ", value.c_str());
383 ReadBufferAndDumpToStreamOptions options(valobj);
384 options.SetData(data);
385 options.SetStream(&stream);
386 options.SetPrefixToken('U');
387 options.SetQuote('\'');
388 options.SetSourceSize(1);
390 return ReadBufferAndDumpToStream<StringElementType::UTF32>(options);
394 lldb_private::formatters::WCharSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions&)
398 valobj.GetData(data, error);
403 ReadBufferAndDumpToStreamOptions options(valobj);
404 options.SetData(data);
405 options.SetStream(&stream);
406 options.SetPrefixToken('L');
407 options.SetQuote('\'');
408 options.SetSourceSize(1);
410 return ReadBufferAndDumpToStream<StringElementType::UTF16>(options);
413 // the field layout in a libc++ string (cap, side, data or data, size, cap)
414 enum LibcxxStringLayoutMode
416 eLibcxxStringLayoutModeCSD = 0,
417 eLibcxxStringLayoutModeDSC = 1,
418 eLibcxxStringLayoutModeInvalid = 0xffff
421 // this function abstracts away the layout and mode details of a libc++ string
422 // and returns the address of the data and the size ready for callers to consume
424 ExtractLibcxxStringInfo (ValueObject& valobj,
425 ValueObjectSP &location_sp,
428 ValueObjectSP D(valobj.GetChildAtIndexPath({0,0,0,0}));
432 ValueObjectSP layout_decider(D->GetChildAtIndexPath({0,0}));
434 // this child should exist
438 ConstString g_data_name("__data_");
439 ConstString g_size_name("__size_");
440 bool short_mode = false; // this means the string is in short-mode and the data is stored inline
441 LibcxxStringLayoutMode layout = (layout_decider->GetName() == g_data_name) ? eLibcxxStringLayoutModeDSC : eLibcxxStringLayoutModeCSD;
442 uint64_t size_mode_value = 0;
444 if (layout == eLibcxxStringLayoutModeDSC)
446 ValueObjectSP size_mode(D->GetChildAtIndexPath({1,1,0}));
450 if (size_mode->GetName() != g_size_name)
452 // we are hitting the padding structure, move along
453 size_mode = D->GetChildAtIndexPath({1,1,1});
458 size_mode_value = (size_mode->GetValueAsUnsigned(0));
459 short_mode = ((size_mode_value & 0x80) == 0);
463 ValueObjectSP size_mode(D->GetChildAtIndexPath({1,0,0}));
467 size_mode_value = (size_mode->GetValueAsUnsigned(0));
468 short_mode = ((size_mode_value & 1) == 0);
473 ValueObjectSP s(D->GetChildAtIndex(1, true));
476 location_sp = s->GetChildAtIndex((layout == eLibcxxStringLayoutModeDSC) ? 0 : 1, true);
477 size = (layout == eLibcxxStringLayoutModeDSC) ? size_mode_value : ((size_mode_value >> 1) % 256);
478 return (location_sp.get() != nullptr);
482 ValueObjectSP l(D->GetChildAtIndex(0, true));
485 // we can use the layout_decider object as the data pointer
486 location_sp = (layout == eLibcxxStringLayoutModeDSC) ? layout_decider : l->GetChildAtIndex(2, true);
487 ValueObjectSP size_vo(l->GetChildAtIndex(1, true));
488 if (!size_vo || !location_sp)
490 size = size_vo->GetValueAsUnsigned(0);
496 lldb_private::formatters::LibcxxWStringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options)
499 ValueObjectSP location_sp((ValueObject*)nullptr);
500 if (!ExtractLibcxxStringInfo(valobj, location_sp, size))
504 stream.Printf("L\"\"");
509 return WCharStringSummaryProvider(*location_sp.get(), stream, options);
513 lldb_private::formatters::LibcxxStringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& summary_options)
516 ValueObjectSP location_sp((ValueObject*)nullptr);
518 if (!ExtractLibcxxStringInfo(valobj, location_sp, size))
523 stream.Printf("\"\"");
530 DataExtractor extractor;
531 if (summary_options.GetCapping() == TypeSummaryCapping::eTypeSummaryCapped)
532 size = std::min<decltype(size)>(size, valobj.GetTargetSP()->GetMaximumSizeOfStringSummary());
533 location_sp->GetPointeeData(extractor, 0, size);
535 ReadBufferAndDumpToStreamOptions options(valobj);
536 options.SetData(extractor); // none of this matters for a string - pass some defaults
537 options.SetStream(&stream);
538 options.SetPrefixToken(0);
539 options.SetQuote('"');
540 options.SetSourceSize(size);
541 lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::ASCII>(options);
547 lldb_private::formatters::ObjCClassSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options)
549 ProcessSP process_sp = valobj.GetProcessSP();
553 ObjCLanguageRuntime* runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
558 ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptorFromISA(valobj.GetValueAsUnsigned(0)));
560 if (!descriptor.get() || !descriptor->IsValid())
563 const char* class_name = descriptor->GetClassName().GetCString();
565 if (!class_name || !*class_name)
568 stream.Printf("%s",class_name);
572 class ObjCClassSyntheticChildrenFrontEnd : public SyntheticChildrenFrontEnd
575 ObjCClassSyntheticChildrenFrontEnd (lldb::ValueObjectSP valobj_sp) :
576 SyntheticChildrenFrontEnd(*valobj_sp.get())
581 CalculateNumChildren ()
586 virtual lldb::ValueObjectSP
587 GetChildAtIndex (size_t idx)
589 return lldb::ValueObjectSP();
605 GetIndexOfChildWithName (const ConstString &name)
611 ~ObjCClassSyntheticChildrenFrontEnd ()
616 SyntheticChildrenFrontEnd*
617 lldb_private::formatters::ObjCClassSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP valobj_sp)
619 return new ObjCClassSyntheticChildrenFrontEnd(valobj_sp);
622 template<bool needs_at>
624 lldb_private::formatters::NSDataSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options)
626 ProcessSP process_sp = valobj.GetProcessSP();
630 ObjCLanguageRuntime* runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
635 ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptor(valobj));
637 if (!descriptor.get() || !descriptor->IsValid())
640 bool is_64bit = (process_sp->GetAddressByteSize() == 8);
641 lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
648 const char* class_name = descriptor->GetClassName().GetCString();
650 if (!class_name || !*class_name)
653 if (!strcmp(class_name,"NSConcreteData") ||
654 !strcmp(class_name,"NSConcreteMutableData") ||
655 !strcmp(class_name,"__NSCFData"))
657 uint32_t offset = (is_64bit ? 16 : 8);
659 value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + offset, is_64bit ? 8 : 4, 0, error);
665 if (!ExtractValueFromObjCExpression(valobj, "int", "length", value))
669 stream.Printf("%s%" PRIu64 " byte%s%s",
670 (needs_at ? "@\"" : ""),
672 (value != 1 ? "s" : ""),
673 (needs_at ? "\"" : ""));
679 ReadAsciiBufferAndDumpToStream (lldb::addr_t location,
680 lldb::ProcessSP& process_sp,
684 size_t *data_read = NULL,
685 char prefix_token = '@',
690 if (!process_sp || location == 0)
694 size = process_sp->GetTarget().GetMaximumSizeOfStringSummary();
696 size = std::min(size,process_sp->GetTarget().GetMaximumSizeOfStringSummary());
698 lldb::DataBufferSP buffer_sp(new DataBufferHeap(size,0));
700 my_data_read = process_sp->ReadCStringFromMemory(location, (char*)buffer_sp->GetBytes(), size, my_error);
705 *data_read = my_data_read;
710 dest.Printf("%c%c",prefix_token,quote);
713 dest.Printf("%s",(char*)buffer_sp->GetBytes());
715 dest.Printf("%c",quote);
721 lldb_private::formatters::NSTaggedString_SummaryProvider (ObjCLanguageRuntime::ClassDescriptorSP descriptor, Stream& stream)
725 uint64_t len_bits = 0, data_bits = 0;
726 if (!descriptor->GetTaggedPointerInfo(&len_bits,&data_bits,nullptr))
729 static const int g_MaxNonBitmaskedLen = 7; //TAGGED_STRING_UNPACKED_MAXLEN
730 static const int g_SixbitMaxLen = 9;
731 static const int g_fiveBitMaxLen = 11;
733 static const char *sixBitToCharLookup = "eilotrm.apdnsIc ufkMShjTRxgC4013" "bDNvwyUL2O856P-B79AFKEWV_zGJ/HYX";
735 if (len_bits > g_fiveBitMaxLen)
738 // this is a fairly ugly trick - pretend that the numeric value is actually a char*
739 // this works under a few assumptions:
740 // little endian architecture
741 // sizeof(uint64_t) > g_MaxNonBitmaskedLen
742 if (len_bits <= g_MaxNonBitmaskedLen)
744 stream.Printf("@\"%s\"",(const char*)&data_bits);
748 // if the data is bitmasked, we need to actually process the bytes
750 uint8_t shift_offset = 0;
752 if (len_bits <= g_SixbitMaxLen)
763 std::vector<uint8_t> bytes;
764 bytes.resize(len_bits);
765 for (; len_bits > 0; data_bits >>= shift_offset, --len_bits)
767 uint8_t packed = data_bits & bitmask;
768 bytes.insert(bytes.begin(), sixBitToCharLookup[packed]);
771 stream.Printf("@\"%s\"",&bytes[0]);
776 GetNSPathStore2Type (Target &target)
778 static ConstString g_type_name("__lldb_autogen_nspathstore2");
780 ClangASTContext *ast_ctx = target.GetScratchClangASTContext();
783 return ClangASTType();
785 ClangASTType voidstar = ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType();
786 ClangASTType uint32 = ast_ctx->GetIntTypeFromBitSize(32, false);
788 return ast_ctx->GetOrCreateStructForIdentifier(g_type_name, {
790 {"lengthAndRef",uint32},
796 lldb_private::formatters::NSStringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& summary_options)
798 ProcessSP process_sp = valobj.GetProcessSP();
802 ObjCLanguageRuntime* runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
807 ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptor(valobj));
809 if (!descriptor.get() || !descriptor->IsValid())
812 uint32_t ptr_size = process_sp->GetAddressByteSize();
814 lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
819 const char* class_name = descriptor->GetClassName().GetCString();
821 if (!class_name || !*class_name)
824 bool is_tagged_ptr = (0 == strcmp(class_name,"NSTaggedPointerString")) && descriptor->GetTaggedPointerInfo();
825 // for a tagged pointer, the descriptor has everything we need
827 return NSTaggedString_SummaryProvider(descriptor, stream);
829 // if not a tagged pointer that we know about, try the normal route
830 uint64_t info_bits_location = valobj_addr + ptr_size;
831 if (process_sp->GetByteOrder() != lldb::eByteOrderLittle)
832 info_bits_location += 3;
836 uint8_t info_bits = process_sp->ReadUnsignedIntegerFromMemory(info_bits_location, 1, 0, error);
840 bool is_mutable = (info_bits & 1) == 1;
841 bool is_inline = (info_bits & 0x60) == 0;
842 bool has_explicit_length = (info_bits & (1 | 4)) != 4;
843 bool is_unicode = (info_bits & 0x10) == 0x10;
844 bool is_special = strcmp(class_name,"NSPathStore2") == 0;
845 bool has_null = (info_bits & 8) == 8;
847 size_t explicit_length = 0;
848 if (!has_null && has_explicit_length && !is_special)
850 lldb::addr_t explicit_length_offset = 2*ptr_size;
851 if (is_mutable && !is_inline)
852 explicit_length_offset = explicit_length_offset + ptr_size; // notInlineMutable.length;
854 explicit_length = explicit_length + 0; // inline1.length;
855 else if (!is_inline && !is_mutable)
856 explicit_length_offset = explicit_length_offset + ptr_size; // notInlineImmutable1.length;
858 explicit_length_offset = 0;
860 if (explicit_length_offset)
862 explicit_length_offset = valobj_addr + explicit_length_offset;
863 explicit_length = process_sp->ReadUnsignedIntegerFromMemory(explicit_length_offset, 4, 0, error);
867 if (strcmp(class_name,"NSString") &&
868 strcmp(class_name,"CFStringRef") &&
869 strcmp(class_name,"CFMutableStringRef") &&
870 strcmp(class_name,"__NSCFConstantString") &&
871 strcmp(class_name,"__NSCFString") &&
872 strcmp(class_name,"NSCFConstantString") &&
873 strcmp(class_name,"NSCFString") &&
874 strcmp(class_name,"NSPathStore2"))
876 // not one of us - but tell me class name
877 stream.Printf("class name = %s",class_name);
883 uint64_t location = 2 * ptr_size + valobj_addr;
884 location = process_sp->ReadPointerFromMemory(location, error);
887 if (has_explicit_length && is_unicode)
889 ReadStringAndDumpToStreamOptions options(valobj);
890 options.SetLocation(location);
891 options.SetProcessSP(process_sp);
892 options.SetStream(&stream);
893 options.SetPrefixToken('@');
894 options.SetQuote('"');
895 options.SetSourceSize(explicit_length);
896 options.SetNeedsZeroTermination(false);
897 options.SetIgnoreMaxLength(summary_options.GetCapping() == TypeSummaryCapping::eTypeSummaryUncapped);
898 return ReadStringAndDumpToStream<StringElementType::UTF16>(options);
902 ReadStringAndDumpToStreamOptions options(valobj);
903 options.SetLocation(location+1);
904 options.SetProcessSP(process_sp);
905 options.SetStream(&stream);
906 options.SetPrefixToken('@');
907 options.SetSourceSize(explicit_length);
908 options.SetNeedsZeroTermination(false);
909 options.SetIgnoreMaxLength(summary_options.GetCapping() == TypeSummaryCapping::eTypeSummaryUncapped);
910 return ReadStringAndDumpToStream<StringElementType::ASCII>(options);
913 else if (is_inline && has_explicit_length && !is_unicode && !is_special && !is_mutable)
915 uint64_t location = 3 * ptr_size + valobj_addr;
916 return ReadAsciiBufferAndDumpToStream(location,process_sp,stream,explicit_length);
920 uint64_t location = valobj_addr + 2*ptr_size;
923 if (!has_explicit_length)
925 stream.Printf("found new combo");
929 location += ptr_size;
933 location = process_sp->ReadPointerFromMemory(location, error);
937 ReadStringAndDumpToStreamOptions options(valobj);
938 options.SetLocation(location);
939 options.SetProcessSP(process_sp);
940 options.SetStream(&stream);
941 options.SetPrefixToken('@');
942 options.SetQuote('"');
943 options.SetSourceSize(explicit_length);
944 options.SetNeedsZeroTermination(has_explicit_length == false);
945 options.SetIgnoreMaxLength(summary_options.GetCapping() == TypeSummaryCapping::eTypeSummaryUncapped);
946 return ReadStringAndDumpToStream<StringElementType::UTF16> (options);
950 ProcessStructReader reader(valobj.GetProcessSP().get(), valobj.GetValueAsUnsigned(0), GetNSPathStore2Type(*valobj.GetTargetSP()));
951 explicit_length = reader.GetField<uint32_t>(ConstString("lengthAndRef")) >> 20;
952 lldb::addr_t location = valobj.GetValueAsUnsigned(0) + ptr_size + 4;
954 ReadStringAndDumpToStreamOptions options(valobj);
955 options.SetLocation(location);
956 options.SetProcessSP(process_sp);
957 options.SetStream(&stream);
958 options.SetPrefixToken('@');
959 options.SetQuote('"');
960 options.SetSourceSize(explicit_length);
961 options.SetNeedsZeroTermination(has_explicit_length == false);
962 options.SetIgnoreMaxLength(summary_options.GetCapping() == TypeSummaryCapping::eTypeSummaryUncapped);
963 return ReadStringAndDumpToStream<StringElementType::UTF16> (options);
967 uint64_t location = valobj_addr + 2*ptr_size;
968 if (!has_explicit_length)
970 ReadStringAndDumpToStreamOptions options(valobj);
971 options.SetLocation(location);
972 options.SetProcessSP(process_sp);
973 options.SetStream(&stream);
974 options.SetPrefixToken('@');
975 options.SetSourceSize(explicit_length);
976 options.SetIgnoreMaxLength(summary_options.GetCapping() == TypeSummaryCapping::eTypeSummaryUncapped);
977 return ReadStringAndDumpToStream<StringElementType::ASCII>(options);
981 uint64_t location = valobj_addr + 2*ptr_size;
982 location = process_sp->ReadPointerFromMemory(location, error);
985 if (has_explicit_length && !has_null)
986 explicit_length++; // account for the fact that there is no NULL and we need to have one added
987 ReadStringAndDumpToStreamOptions options(valobj);
988 options.SetLocation(location);
989 options.SetProcessSP(process_sp);
990 options.SetPrefixToken('@');
991 options.SetStream(&stream);
992 options.SetSourceSize(explicit_length);
993 options.SetIgnoreMaxLength(summary_options.GetCapping() == TypeSummaryCapping::eTypeSummaryUncapped);
994 return ReadStringAndDumpToStream<StringElementType::ASCII>(options);
999 lldb_private::formatters::NSAttributedStringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options)
1001 TargetSP target_sp(valobj.GetTargetSP());
1004 uint32_t addr_size = target_sp->GetArchitecture().GetAddressByteSize();
1005 uint64_t pointer_value = valobj.GetValueAsUnsigned(0);
1008 pointer_value += addr_size;
1009 ClangASTType type(valobj.GetClangType());
1010 ExecutionContext exe_ctx(target_sp,false);
1011 ValueObjectSP child_ptr_sp(valobj.CreateValueObjectFromAddress("string_ptr", pointer_value, exe_ctx, type));
1016 child_ptr_sp->GetData(data, error);
1019 ValueObjectSP child_sp(child_ptr_sp->CreateValueObjectFromData("string_data", data, exe_ctx, type));
1020 child_sp->GetValueAsUnsigned(0);
1022 return NSStringSummaryProvider(*child_sp, stream, options);
1027 lldb_private::formatters::NSMutableAttributedStringSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options)
1029 return NSAttributedStringSummaryProvider(valobj, stream, options);
1033 lldb_private::formatters::RuntimeSpecificDescriptionSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options)
1035 stream.Printf("%s",valobj.GetObjectDescription());
1040 lldb_private::formatters::ObjCBOOLSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options)
1042 const uint32_t type_info = valobj.GetClangType().GetTypeInfo();
1044 ValueObjectSP real_guy_sp = valobj.GetSP();
1046 if (type_info & eTypeIsPointer)
1049 real_guy_sp = valobj.Dereference(err);
1050 if (err.Fail() || !real_guy_sp)
1053 else if (type_info & eTypeIsReference)
1055 real_guy_sp = valobj.GetChildAtIndex(0, true);
1059 uint64_t value = real_guy_sp->GetValueAsUnsigned(0);
1062 stream.Printf("NO");
1065 stream.Printf("YES");
1069 template <bool is_sel_ptr>
1071 lldb_private::formatters::ObjCSELSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options)
1073 lldb::ValueObjectSP valobj_sp;
1075 ClangASTType charstar (valobj.GetClangType().GetBasicTypeFromAST(eBasicTypeChar).GetPointerType());
1080 ExecutionContext exe_ctx(valobj.GetExecutionContextRef());
1084 lldb::addr_t data_address = valobj.GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
1085 if (data_address == LLDB_INVALID_ADDRESS)
1087 valobj_sp = ValueObject::CreateValueObjectFromAddress("text", data_address, exe_ctx, charstar);
1093 valobj.GetData(data, error);
1096 valobj_sp = ValueObject::CreateValueObjectFromData("text", data, exe_ctx, charstar);
1102 stream.Printf("%s",valobj_sp->GetSummaryAsCString());
1106 // POSIX has an epoch on Jan-1-1970, but Cocoa prefers Jan-1-2001
1107 // this call gives the POSIX equivalent of the Cocoa epoch
1109 lldb_private::formatters::GetOSXEpoch ()
1111 static time_t epoch = 0;
1117 tm_epoch.tm_sec = 0;
1118 tm_epoch.tm_hour = 0;
1119 tm_epoch.tm_min = 0;
1120 tm_epoch.tm_mon = 0;
1121 tm_epoch.tm_mday = 1;
1122 tm_epoch.tm_year = 2001-1900; // for some reason, we need to subtract 1900 from this field. not sure why.
1123 tm_epoch.tm_isdst = -1;
1124 tm_epoch.tm_gmtoff = 0;
1125 tm_epoch.tm_zone = NULL;
1126 epoch = timegm(&tm_epoch);
1133 lldb_private::formatters::ExtractIndexFromString (const char* item_name)
1135 if (!item_name || !*item_name)
1137 if (*item_name != '[')
1140 char* endptr = NULL;
1141 unsigned long int idx = ::strtoul(item_name, &endptr, 0);
1142 if (idx == 0 && endptr == item_name)
1144 if (idx == ULONG_MAX)
1149 lldb_private::formatters::VectorIteratorSyntheticFrontEnd::VectorIteratorSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp,
1150 ConstString item_name) :
1151 SyntheticChildrenFrontEnd(*valobj_sp.get()),
1153 m_item_name(item_name),
1161 lldb_private::formatters::VectorIteratorSyntheticFrontEnd::Update()
1165 ValueObjectSP valobj_sp = m_backend.GetSP();
1172 ValueObjectSP item_ptr(valobj_sp->GetChildMemberWithName(m_item_name,true));
1175 if (item_ptr->GetValueAsUnsigned(0) == 0)
1178 m_exe_ctx_ref = valobj_sp->GetExecutionContextRef();
1179 m_item_sp = CreateValueObjectFromAddress("item", item_ptr->GetValueAsUnsigned(0), m_exe_ctx_ref, item_ptr->GetClangType().GetPointeeType());
1186 lldb_private::formatters::VectorIteratorSyntheticFrontEnd::CalculateNumChildren ()
1192 lldb_private::formatters::VectorIteratorSyntheticFrontEnd::GetChildAtIndex (size_t idx)
1196 return lldb::ValueObjectSP();
1200 lldb_private::formatters::VectorIteratorSyntheticFrontEnd::MightHaveChildren ()
1206 lldb_private::formatters::VectorIteratorSyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name)
1208 if (name == ConstString("item"))
1213 lldb_private::formatters::VectorIteratorSyntheticFrontEnd::~VectorIteratorSyntheticFrontEnd ()
1218 lldb_private::formatters::NSDataSummaryProvider<true> (ValueObject&, Stream&, const TypeSummaryOptions&) ;
1221 lldb_private::formatters::NSDataSummaryProvider<false> (ValueObject&, Stream&, const TypeSummaryOptions&) ;
1224 lldb_private::formatters::ObjCSELSummaryProvider<true> (ValueObject&, Stream&, const TypeSummaryOptions&) ;
1227 lldb_private::formatters::ObjCSELSummaryProvider<false> (ValueObject&, Stream&, const TypeSummaryOptions&) ;