LLDB mainline
LibCxx.cpp
Go to the documentation of this file.
1//===-- LibCxx.cpp --------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "LibCxx.h"
10
11#include "lldb/Core/Debugger.h"
18#include "lldb/Target/Target.h"
21#include "lldb/Utility/Endian.h"
22#include "lldb/Utility/Status.h"
23#include "lldb/Utility/Stream.h"
26
30#include "lldb/lldb-forward.h"
31#include <optional>
32#include <tuple>
33
34using namespace lldb;
35using namespace lldb_private;
36using namespace lldb_private::formatters;
37
38static void consumeInlineNamespace(llvm::StringRef &name) {
39 // Delete past an inline namespace, if any: __[a-zA-Z0-9_]+::
40 auto scratch = name;
41 if (scratch.consume_front("__") && std::isalnum(scratch[0])) {
42 scratch = scratch.drop_while([](char c) { return std::isalnum(c); });
43 if (scratch.consume_front("::")) {
44 // Successfully consumed a namespace.
45 name = scratch;
46 }
47 }
48}
49
51 ValueObject &pair_obj) {
52 return isStdTemplate(pair_obj.GetTypeName(), "__compressed_pair");
53}
54
56 llvm::StringRef type) {
57 llvm::StringRef name = type_name.GetStringRef();
58 // The type name may be prefixed with `std::__<inline-namespace>::`.
59 if (name.consume_front("std::"))
61 return name.consume_front(type) && name.starts_with("<");
62}
63
65 ValueObject &obj, llvm::ArrayRef<ConstString> alternative_names) {
66 for (ConstString name : alternative_names) {
68
69 if (child_sp)
70 return child_sp;
71 }
72 return {};
73}
74
77 ValueObject &pair) {
78 ValueObjectSP value;
79 ValueObjectSP first_child = pair.GetChildAtIndex(0);
80 if (first_child)
81 value = first_child->GetChildMemberWithName("__value_");
82 if (!value) {
83 // pre-c88580c member name
84 value = pair.GetChildMemberWithName("__first_");
85 }
86 return value;
87}
88
91 ValueObject &pair) {
92 ValueObjectSP value;
93 if (pair.GetNumChildrenIgnoringErrors() > 1) {
94 ValueObjectSP second_child = pair.GetChildAtIndex(1);
95 if (second_child) {
96 value = second_child->GetChildMemberWithName("__value_");
97 }
98 }
99 if (!value) {
100 // pre-c88580c member name
101 value = pair.GetChildMemberWithName("__second_");
102 }
103 return value;
104}
105
107 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
108
109 ValueObjectSP valobj_sp(valobj.GetNonSyntheticValue());
110
111 if (!valobj_sp)
112 return false;
113
114 ExecutionContext exe_ctx(valobj_sp->GetExecutionContextRef());
115 Process *process = exe_ctx.GetProcessPtr();
116
117 if (process == nullptr)
118 return false;
119
120 CPPLanguageRuntime *cpp_runtime = CPPLanguageRuntime::Get(*process);
121
122 if (!cpp_runtime)
123 return false;
124
126 cpp_runtime->FindLibCppStdFunctionCallableInfo(valobj_sp);
127
128 switch (callable_info.callable_case) {
129 case CPPLanguageRuntime::LibCppStdFunctionCallableCase::Invalid:
130 stream.Printf(" __f_ = %" PRIu64, callable_info.member_f_pointer_value);
131 return false;
132 break;
133 case CPPLanguageRuntime::LibCppStdFunctionCallableCase::Lambda:
134 stream.Printf(
135 " Lambda in File %s at Line %u",
137 callable_info.callable_line_entry.line);
138 break;
139 case CPPLanguageRuntime::LibCppStdFunctionCallableCase::CallableObject:
140 stream.Printf(
141 " Function in File %s at Line %u",
143 callable_info.callable_line_entry.line);
144 break;
145 case CPPLanguageRuntime::LibCppStdFunctionCallableCase::FreeOrMemberFunction:
146 stream.Printf(" Function = %s ",
147 callable_info.callable_symbol.GetName().GetCString());
148 break;
149 }
150
151 return true;
152}
153
155 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
156 ValueObjectSP valobj_sp(valobj.GetNonSyntheticValue());
157 if (!valobj_sp)
158 return false;
159 ValueObjectSP ptr_sp(valobj_sp->GetChildMemberWithName("__ptr_"));
160 ValueObjectSP count_sp(
161 valobj_sp->GetChildAtNamePath({"__cntrl_", "__shared_owners_"}));
162 ValueObjectSP weakcount_sp(
163 valobj_sp->GetChildAtNamePath({"__cntrl_", "__shared_weak_owners_"}));
164
165 if (!ptr_sp)
166 return false;
167
168 if (ptr_sp->GetValueAsUnsigned(0) == 0) {
169 stream.Printf("nullptr");
170 return true;
171 } else {
172 bool print_pointee = false;
174 ValueObjectSP pointee_sp = ptr_sp->Dereference(error);
175 if (pointee_sp && error.Success()) {
176 if (pointee_sp->DumpPrintableRepresentation(
179 ValueObject::PrintableRepresentationSpecialCases::eDisable,
180 false))
181 print_pointee = true;
182 }
183 if (!print_pointee)
184 stream.Printf("ptr = 0x%" PRIx64, ptr_sp->GetValueAsUnsigned(0));
185 }
186
187 if (count_sp)
188 stream.Printf(" strong=%" PRIu64, 1 + count_sp->GetValueAsUnsigned(0));
189
190 if (weakcount_sp)
191 stream.Printf(" weak=%" PRIu64, 1 + weakcount_sp->GetValueAsUnsigned(0));
192
193 return true;
194}
195
197 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
198 ValueObjectSP valobj_sp(valobj.GetNonSyntheticValue());
199 if (!valobj_sp)
200 return false;
201
202 ValueObjectSP ptr_sp(valobj_sp->GetChildMemberWithName("__ptr_"));
203 if (!ptr_sp)
204 return false;
205
206 if (isOldCompressedPairLayout(*ptr_sp))
207 ptr_sp = GetFirstValueOfLibCXXCompressedPair(*ptr_sp);
208
209 if (!ptr_sp)
210 return false;
211
212 if (ptr_sp->GetValueAsUnsigned(0) == 0) {
213 stream.Printf("nullptr");
214 return true;
215 } else {
216 bool print_pointee = false;
218 ValueObjectSP pointee_sp = ptr_sp->Dereference(error);
219 if (pointee_sp && error.Success()) {
220 if (pointee_sp->DumpPrintableRepresentation(
223 ValueObject::PrintableRepresentationSpecialCases::eDisable,
224 false))
225 print_pointee = true;
226 }
227 if (!print_pointee)
228 stream.Printf("ptr = 0x%" PRIx64, ptr_sp->GetValueAsUnsigned(0));
229 }
230
231 return true;
232}
233
234/*
235 (lldb) fr var ibeg --raw --ptr-depth 1 -T
236 (std::__1::__wrap_iter<int *>) ibeg = {
237 (std::__1::__wrap_iter<int *>::iterator_type) __i = 0x00000001001037a0 {
238 (int) *__i = 1
239 }
240 }
241*/
242
246 return (valobj_sp ? new VectorIteratorSyntheticFrontEnd(
247 valobj_sp, {ConstString("__i_"), ConstString("__i")})
248 : nullptr);
249}
250
253 : SyntheticChildrenFrontEnd(*valobj_sp), m_cntrl(nullptr) {
254 if (valobj_sp)
255 Update();
256}
257
258llvm::Expected<uint32_t> lldb_private::formatters::
260 return (m_cntrl ? 1 : 0);
261}
262
265 uint32_t idx) {
266 if (!m_cntrl)
267 return lldb::ValueObjectSP();
268
269 ValueObjectSP valobj_sp = m_backend.GetSP();
270 if (!valobj_sp)
271 return lldb::ValueObjectSP();
272
273 if (idx == 0)
274 return valobj_sp->GetChildMemberWithName("__ptr_");
275
276 if (idx == 1) {
277 if (auto ptr_sp = valobj_sp->GetChildMemberWithName("__ptr_")) {
278 Status status;
279 auto value_type_sp =
280 valobj_sp->GetCompilerType()
281 .GetTypeTemplateArgument(0).GetPointerType();
282 ValueObjectSP cast_ptr_sp = ptr_sp->Cast(value_type_sp);
283 ValueObjectSP value_sp = cast_ptr_sp->Dereference(status);
284 if (status.Success()) {
285 return value_sp;
286 }
287 }
288 }
289
290 return lldb::ValueObjectSP();
291}
292
295 m_cntrl = nullptr;
296
297 ValueObjectSP valobj_sp = m_backend.GetSP();
298 if (!valobj_sp)
300
301 TargetSP target_sp(valobj_sp->GetTargetSP());
302 if (!target_sp)
304
305 lldb::ValueObjectSP cntrl_sp(valobj_sp->GetChildMemberWithName("__cntrl_"));
306
307 m_cntrl = cntrl_sp.get(); // need to store the raw pointer to avoid a circular
308 // dependency
310}
311
314 return true;
315}
316
319 if (name == "__ptr_")
320 return 0;
321 if (name == "$$dereference$$")
322 return 1;
323 return UINT32_MAX;
324}
325
328
332 return (valobj_sp ? new LibcxxSharedPtrSyntheticFrontEnd(valobj_sp)
333 : nullptr);
334}
335
338 : SyntheticChildrenFrontEnd(*valobj_sp) {
339 if (valobj_sp)
340 Update();
341}
342
345
349 return (valobj_sp ? new LibcxxUniquePtrSyntheticFrontEnd(valobj_sp)
350 : nullptr);
351}
352
353llvm::Expected<uint32_t> lldb_private::formatters::
355 if (m_value_ptr_sp)
356 return m_deleter_sp ? 2 : 1;
357 return 0;
358}
359
362 uint32_t idx) {
363 if (!m_value_ptr_sp)
364 return lldb::ValueObjectSP();
365
366 if (idx == 0)
367 return m_value_ptr_sp;
368
369 if (idx == 1)
370 return m_deleter_sp;
371
372 if (idx == 2) {
373 Status status;
374 auto value_sp = m_value_ptr_sp->Dereference(status);
375 if (status.Success()) {
376 return value_sp;
377 }
378 }
379
380 return lldb::ValueObjectSP();
381}
382
385 ValueObjectSP valobj_sp = m_backend.GetSP();
386 if (!valobj_sp)
388
389 ValueObjectSP ptr_sp(valobj_sp->GetChildMemberWithName("__ptr_"));
390 if (!ptr_sp)
392
393 // Retrieve the actual pointer and the deleter, and clone them to give them
394 // user-friendly names.
395 if (isOldCompressedPairLayout(*ptr_sp)) {
396 if (ValueObjectSP value_pointer_sp =
398 m_value_ptr_sp = value_pointer_sp->Clone(ConstString("pointer"));
399
400 if (ValueObjectSP deleter_sp =
402 m_deleter_sp = deleter_sp->Clone(ConstString("deleter"));
403 } else {
404 m_value_ptr_sp = ptr_sp->Clone(ConstString("pointer"));
405
406 if (ValueObjectSP deleter_sp =
407 valobj_sp->GetChildMemberWithName("__deleter_"))
408 if (deleter_sp->GetNumChildrenIgnoringErrors() > 0)
409 m_deleter_sp = deleter_sp->Clone(ConstString("deleter"));
410 }
411
413}
414
417 return true;
418}
419
422 if (name == "pointer")
423 return 0;
424 if (name == "deleter")
425 return 1;
426 if (name == "$$dereference$$")
427 return 2;
428 return UINT32_MAX;
429}
430
432 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
433 if (valobj.IsPointerType()) {
434 uint64_t value = valobj.GetValueAsUnsigned(0);
435 if (!value)
436 return false;
437 stream.Printf("0x%016" PRIx64 " ", value);
438 }
439 return FormatEntity::FormatStringRef("size=${svar%#}", stream, nullptr,
440 nullptr, nullptr, &valobj, false, false);
441}
442
443/// The field layout in a libc++ string (cap, side, data or data, size, cap).
444namespace {
445enum class StringLayout { CSD, DSC };
446}
447
449 if (auto rep_sp = valobj.GetChildMemberWithName("__rep_"))
450 return rep_sp;
451
452 ValueObjectSP valobj_r_sp = valobj.GetChildMemberWithName("__r_");
453 if (!valobj_r_sp || !valobj_r_sp->GetError().Success())
454 return nullptr;
455
456 if (!isOldCompressedPairLayout(*valobj_r_sp))
457 return nullptr;
458
459 return GetFirstValueOfLibCXXCompressedPair(*valobj_r_sp);
460}
461
462/// Determine the size in bytes of \p valobj (a libc++ std::string object) and
463/// extract its data payload. Return the size + payload pair.
464// TODO: Support big-endian architectures.
465static std::optional<std::pair<uint64_t, ValueObjectSP>>
467 ValueObjectSP valobj_rep_sp = ExtractLibCxxStringData(valobj);
468 if (!valobj_rep_sp || !valobj_rep_sp->GetError().Success())
469 return {};
470
471 ValueObjectSP l = valobj_rep_sp->GetChildMemberWithName("__l");
472 if (!l)
473 return {};
474
475 StringLayout layout = l->GetIndexOfChildWithName("__data_") == 0
476 ? StringLayout::DSC
477 : StringLayout::CSD;
478
479 bool short_mode = false; // this means the string is in short-mode and the
480 // data is stored inline
481 bool using_bitmasks = true; // Whether the class uses bitmasks for the mode
482 // flag (pre-D123580).
483 uint64_t size;
484 uint64_t size_mode_value = 0;
485
486 ValueObjectSP short_sp = valobj_rep_sp->GetChildMemberWithName("__s");
487 if (!short_sp)
488 return {};
489
490 ValueObjectSP is_long = short_sp->GetChildMemberWithName("__is_long_");
491 ValueObjectSP size_sp = short_sp->GetChildMemberWithName("__size_");
492 if (!size_sp)
493 return {};
494
495 if (is_long) {
496 using_bitmasks = false;
497 short_mode = !is_long->GetValueAsUnsigned(/*fail_value=*/0);
498 size = size_sp->GetValueAsUnsigned(/*fail_value=*/0);
499 } else {
500 // The string mode is encoded in the size field.
501 size_mode_value = size_sp->GetValueAsUnsigned(0);
502 uint8_t mode_mask = layout == StringLayout::DSC ? 0x80 : 1;
503 short_mode = (size_mode_value & mode_mask) == 0;
504 }
505
506 if (short_mode) {
507 ValueObjectSP location_sp = short_sp->GetChildMemberWithName("__data_");
508 if (using_bitmasks)
509 size = (layout == StringLayout::DSC) ? size_mode_value
510 : ((size_mode_value >> 1) % 256);
511
512 if (!location_sp)
513 return {};
514
515 // When the small-string optimization takes place, the data must fit in the
516 // inline string buffer (23 bytes on x86_64/Darwin). If it doesn't, it's
517 // likely that the string isn't initialized and we're reading garbage.
518 ExecutionContext exe_ctx(location_sp->GetExecutionContextRef());
519 const std::optional<uint64_t> max_bytes =
520 location_sp->GetCompilerType().GetByteSize(
522 if (!max_bytes || size > *max_bytes)
523 return {};
524
525 return std::make_pair(size, location_sp);
526 }
527
528 // we can use the layout_decider object as the data pointer
529 ValueObjectSP location_sp = l->GetChildMemberWithName("__data_");
530 ValueObjectSP size_vo = l->GetChildMemberWithName("__size_");
531 ValueObjectSP capacity_vo = l->GetChildMemberWithName("__cap_");
532 if (!size_vo || !location_sp || !capacity_vo)
533 return {};
534 size = size_vo->GetValueAsUnsigned(LLDB_INVALID_OFFSET);
535 uint64_t capacity = capacity_vo->GetValueAsUnsigned(LLDB_INVALID_OFFSET);
536 if (!using_bitmasks && layout == StringLayout::CSD)
537 capacity *= 2;
538 if (size == LLDB_INVALID_OFFSET || capacity == LLDB_INVALID_OFFSET ||
539 capacity < size)
540 return {};
541 return std::make_pair(size, location_sp);
542}
543
544static bool
546 const TypeSummaryOptions &summary_options,
547 ValueObjectSP location_sp, size_t size) {
548 if (size == 0) {
549 stream.Printf("L\"\"");
550 return true;
551 }
552 if (!location_sp)
553 return false;
554
556 if (summary_options.GetCapping() == TypeSummaryCapping::eTypeSummaryCapped) {
557 const auto max_size = valobj.GetTargetSP()->GetMaximumSizeOfStringSummary();
558 if (size > max_size) {
559 size = max_size;
560 options.SetIsTruncated(true);
561 }
562 }
563
564 DataExtractor extractor;
565 const size_t bytes_read = location_sp->GetPointeeData(extractor, 0, size);
566 if (bytes_read < size)
567 return false;
568
569 // std::wstring::size() is measured in 'characters', not bytes
570 TypeSystemClangSP scratch_ts_sp =
572 if (!scratch_ts_sp)
573 return false;
574
575 auto wchar_t_size =
576 scratch_ts_sp->GetBasicType(lldb::eBasicTypeWChar).GetByteSize(nullptr);
577 if (!wchar_t_size)
578 return false;
579
580 options.SetData(std::move(extractor));
581 options.SetStream(&stream);
582 options.SetPrefixToken("L");
583 options.SetQuote('"');
584 options.SetSourceSize(size);
585 options.SetBinaryZeroIsTerminator(false);
586
587 switch (*wchar_t_size) {
588 case 1:
590 lldb_private::formatters::StringPrinter::StringElementType::UTF8>(
591 options);
592 break;
593
594 case 2:
596 lldb_private::formatters::StringPrinter::StringElementType::UTF16>(
597 options);
598 break;
599
600 case 4:
602 lldb_private::formatters::StringPrinter::StringElementType::UTF32>(
603 options);
604 }
605 return false;
606}
607
609 ValueObject &valobj, Stream &stream,
610 const TypeSummaryOptions &summary_options) {
611 auto string_info = ExtractLibcxxStringInfo(valobj);
612 if (!string_info)
613 return false;
614 uint64_t size;
615 ValueObjectSP location_sp;
616 std::tie(size, location_sp) = *string_info;
617
618 return ::LibcxxWStringSummaryProvider(valobj, stream, summary_options,
619 location_sp, size);
620}
621
622template <StringPrinter::StringElementType element_type>
623static bool
625 const TypeSummaryOptions &summary_options,
626 std::string prefix_token, ValueObjectSP location_sp,
627 uint64_t size) {
628
629 if (size == 0) {
630 stream.Printf("\"\"");
631 return true;
632 }
633
634 if (!location_sp)
635 return false;
636
638
639 if (summary_options.GetCapping() == TypeSummaryCapping::eTypeSummaryCapped) {
640 const auto max_size = valobj.GetTargetSP()->GetMaximumSizeOfStringSummary();
641 if (size > max_size) {
642 size = max_size;
643 options.SetIsTruncated(true);
644 }
645 }
646
647 {
648 DataExtractor extractor;
649 const size_t bytes_read = location_sp->GetPointeeData(extractor, 0, size);
650 if (bytes_read < size)
651 return false;
652
653 options.SetData(std::move(extractor));
654 }
655 options.SetStream(&stream);
656 if (prefix_token.empty())
657 options.SetPrefixToken(nullptr);
658 else
659 options.SetPrefixToken(prefix_token);
660 options.SetQuote('"');
661 options.SetSourceSize(size);
662 options.SetBinaryZeroIsTerminator(false);
663 return StringPrinter::ReadBufferAndDumpToStream<element_type>(options);
664}
665
666template <StringPrinter::StringElementType element_type>
667static bool
669 const TypeSummaryOptions &summary_options,
670 std::string prefix_token) {
671 auto string_info = ExtractLibcxxStringInfo(valobj);
672 if (!string_info)
673 return false;
674 uint64_t size;
675 ValueObjectSP location_sp;
676 std::tie(size, location_sp) = *string_info;
677
678 return LibcxxStringSummaryProvider<element_type>(
679 valobj, stream, summary_options, prefix_token, location_sp, size);
680}
681template <StringPrinter::StringElementType element_type>
682static bool formatStringImpl(ValueObject &valobj, Stream &stream,
683 const TypeSummaryOptions &summary_options,
684 std::string prefix_token) {
685 StreamString scratch_stream;
686 const bool success = LibcxxStringSummaryProvider<element_type>(
687 valobj, scratch_stream, summary_options, prefix_token);
688 if (success)
689 stream << scratch_stream.GetData();
690 else
691 stream << "Summary Unavailable";
692 return true;
693}
694
696 ValueObject &valobj, Stream &stream,
697 const TypeSummaryOptions &summary_options) {
698 return formatStringImpl<StringPrinter::StringElementType::ASCII>(
699 valobj, stream, summary_options, "");
700}
701
703 ValueObject &valobj, Stream &stream,
704 const TypeSummaryOptions &summary_options) {
705 return formatStringImpl<StringPrinter::StringElementType::UTF16>(
706 valobj, stream, summary_options, "u");
707}
708
710 ValueObject &valobj, Stream &stream,
711 const TypeSummaryOptions &summary_options) {
712 return formatStringImpl<StringPrinter::StringElementType::UTF32>(
713 valobj, stream, summary_options, "U");
714}
715
716static std::tuple<bool, ValueObjectSP, size_t>
718 auto dataobj = GetChildMemberWithName(
719 valobj, {ConstString("__data_"), ConstString("__data")});
720 auto sizeobj = GetChildMemberWithName(
721 valobj, {ConstString("__size_"), ConstString("__size")});
722 if (!dataobj || !sizeobj)
723 return std::make_tuple<bool,ValueObjectSP,size_t>(false, {}, {});
724
725 if (!dataobj->GetError().Success() || !sizeobj->GetError().Success())
726 return std::make_tuple<bool,ValueObjectSP,size_t>(false, {}, {});
727
728 bool success{false};
729 uint64_t size = sizeobj->GetValueAsUnsigned(0, &success);
730 if (!success)
731 return std::make_tuple<bool,ValueObjectSP,size_t>(false, {}, {});
732
733 return std::make_tuple(true,dataobj,size);
734}
735
736template <StringPrinter::StringElementType element_type>
737static bool formatStringViewImpl(ValueObject &valobj, Stream &stream,
738 const TypeSummaryOptions &summary_options,
739 std::string prefix_token) {
740
741 bool success;
742 ValueObjectSP dataobj;
743 size_t size;
744 std::tie(success, dataobj, size) = LibcxxExtractStringViewData(valobj);
745
746 if (!success) {
747 stream << "Summary Unavailable";
748 return true;
749 }
750
751 return LibcxxStringSummaryProvider<element_type>(
752 valobj, stream, summary_options, prefix_token, dataobj, size);
753}
754
756 ValueObject &valobj, Stream &stream,
757 const TypeSummaryOptions &summary_options) {
758 return formatStringViewImpl<StringPrinter::StringElementType::ASCII>(
759 valobj, stream, summary_options, "");
760}
761
763 ValueObject &valobj, Stream &stream,
764 const TypeSummaryOptions &summary_options) {
765 return formatStringViewImpl<StringPrinter::StringElementType::UTF16>(
766 valobj, stream, summary_options, "u");
767}
768
770 ValueObject &valobj, Stream &stream,
771 const TypeSummaryOptions &summary_options) {
772 return formatStringViewImpl<StringPrinter::StringElementType::UTF32>(
773 valobj, stream, summary_options, "U");
774}
775
777 ValueObject &valobj, Stream &stream,
778 const TypeSummaryOptions &summary_options) {
779
780 bool success;
781 ValueObjectSP dataobj;
782 size_t size;
783 std::tie(success, dataobj, size) = LibcxxExtractStringViewData(valobj);
784
785 if (!success) {
786 stream << "Summary Unavailable";
787 return true;
788 }
789
790 return ::LibcxxWStringSummaryProvider(valobj, stream, summary_options,
791 dataobj, size);
792}
793
794static bool
796 const TypeSummaryOptions &options,
797 const char *fmt) {
798 ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__d_");
799 if (!ptr_sp)
800 return false;
801 ptr_sp = ptr_sp->GetChildMemberWithName("__rep_");
802 if (!ptr_sp)
803 return false;
804
805#ifndef _WIN32
806 // The date time in the chrono library is valid in the range
807 // [-32767-01-01T00:00:00Z, 32767-12-31T23:59:59Z]. A 64-bit time_t has a
808 // larger range, the function strftime is not able to format the entire range
809 // of time_t. The exact point has not been investigated; it's limited to
810 // chrono's range.
811 const std::time_t chrono_timestamp_min =
812 -1'096'193'779'200; // -32767-01-01T00:00:00Z
813 const std::time_t chrono_timestamp_max =
814 971'890'963'199; // 32767-12-31T23:59:59Z
815#else
816 const std::time_t chrono_timestamp_min = -43'200; // 1969-12-31T12:00:00Z
817 const std::time_t chrono_timestamp_max =
818 32'536'850'399; // 3001-01-19T21:59:59
819#endif
820
821 const std::time_t seconds = ptr_sp->GetValueAsSigned(0);
822 if (seconds < chrono_timestamp_min || seconds > chrono_timestamp_max)
823 stream.Printf("timestamp=%" PRId64 " s", static_cast<int64_t>(seconds));
824 else {
825 std::array<char, 128> str;
826 std::size_t size =
827 std::strftime(str.data(), str.size(), fmt, gmtime(&seconds));
828 if (size == 0)
829 return false;
830
831 stream.Printf("date/time=%s timestamp=%" PRId64 " s", str.data(),
832 static_cast<int64_t>(seconds));
833 }
834
835 return true;
836}
837
839 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
840 return LibcxxChronoTimePointSecondsSummaryProvider(valobj, stream, options,
841 "%FT%H:%M:%SZ");
842}
843
845 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
846 return LibcxxChronoTimePointSecondsSummaryProvider(valobj, stream, options,
847 "%FT%H:%M:%S");
848}
849
850static bool
852 const TypeSummaryOptions &options,
853 const char *fmt) {
854 ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__d_");
855 if (!ptr_sp)
856 return false;
857 ptr_sp = ptr_sp->GetChildMemberWithName("__rep_");
858 if (!ptr_sp)
859 return false;
860
861#ifndef _WIN32
862 // The date time in the chrono library is valid in the range
863 // [-32767-01-01Z, 32767-12-31Z]. A 32-bit time_t has a larger range, the
864 // function strftime is not able to format the entire range of time_t. The
865 // exact point has not been investigated; it's limited to chrono's range.
866 const int chrono_timestamp_min = -12'687'428; // -32767-01-01Z
867 const int chrono_timestamp_max = 11'248'737; // 32767-12-31Z
868#else
869 const int chrono_timestamp_min = 0; // 1970-01-01Z
870 const int chrono_timestamp_max = 376'583; // 3001-01-19Z
871#endif
872
873 const int days = ptr_sp->GetValueAsSigned(0);
874 if (days < chrono_timestamp_min || days > chrono_timestamp_max)
875 stream.Printf("timestamp=%d days", days);
876
877 else {
878 const std::time_t seconds = std::time_t(86400) * days;
879
880 std::array<char, 128> str;
881 std::size_t size =
882 std::strftime(str.data(), str.size(), fmt, gmtime(&seconds));
883 if (size == 0)
884 return false;
885
886 stream.Printf("date=%s timestamp=%d days", str.data(), days);
887 }
888
889 return true;
890}
891
893 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
894 return LibcxxChronoTimepointDaysSummaryProvider(valobj, stream, options,
895 "%FZ");
896}
897
899 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
900 return LibcxxChronoTimepointDaysSummaryProvider(valobj, stream, options,
901 "%F");
902}
903
905 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
906 // FIXME: These are the names used in the C++20 ostream operator. Since LLVM
907 // uses C++17 it's not possible to use the ostream operator directly.
908 static const std::array<std::string_view, 12> months = {
909 "January", "February", "March", "April", "May", "June",
910 "July", "August", "September", "October", "November", "December"};
911
912 ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__m_");
913 if (!ptr_sp)
914 return false;
915
916 const unsigned month = ptr_sp->GetValueAsUnsigned(0);
917 if (month >= 1 && month <= 12)
918 stream << "month=" << months[month - 1];
919 else
920 stream.Printf("month=%u", month);
921
922 return true;
923}
924
926 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
927 // FIXME: These are the names used in the C++20 ostream operator. Since LLVM
928 // uses C++17 it's not possible to use the ostream operator directly.
929 static const std::array<std::string_view, 7> weekdays = {
930 "Sunday", "Monday", "Tuesday", "Wednesday",
931 "Thursday", "Friday", "Saturday"};
932
933 ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__wd_");
934 if (!ptr_sp)
935 return false;
936
937 const unsigned weekday = ptr_sp->GetValueAsUnsigned(0);
938 if (weekday < 7)
939 stream << "weekday=" << weekdays[weekday];
940 else
941 stream.Printf("weekday=%u", weekday);
942
943 return true;
944}
945
947 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
948 ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__y_");
949 if (!ptr_sp)
950 return false;
951 ptr_sp = ptr_sp->GetChildMemberWithName("__y_");
952 if (!ptr_sp)
953 return false;
954 int year = ptr_sp->GetValueAsSigned(0);
955
956 ptr_sp = valobj.GetChildMemberWithName("__m_");
957 if (!ptr_sp)
958 return false;
959 ptr_sp = ptr_sp->GetChildMemberWithName("__m_");
960 if (!ptr_sp)
961 return false;
962 const unsigned month = ptr_sp->GetValueAsUnsigned(0);
963
964 ptr_sp = valobj.GetChildMemberWithName("__d_");
965 if (!ptr_sp)
966 return false;
967 ptr_sp = ptr_sp->GetChildMemberWithName("__d_");
968 if (!ptr_sp)
969 return false;
970 const unsigned day = ptr_sp->GetValueAsUnsigned(0);
971
972 stream << "date=";
973 if (year < 0) {
974 stream << '-';
975 year = -year;
976 }
977 stream.Printf("%04d-%02u-%02u", year, month, day);
978
979 return true;
980}
static llvm::raw_ostream & error(Stream &strm)
static bool LibcxxChronoTimepointDaysSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options, const char *fmt)
Definition: LibCxx.cpp:851
static ValueObjectSP ExtractLibCxxStringData(ValueObject &valobj)
Definition: LibCxx.cpp:448
static bool formatStringImpl(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options, std::string prefix_token)
Definition: LibCxx.cpp:682
static std::optional< std::pair< uint64_t, ValueObjectSP > > ExtractLibcxxStringInfo(ValueObject &valobj)
Determine the size in bytes of valobj (a libc++ std::string object) and extract its data payload.
Definition: LibCxx.cpp:466
static bool formatStringViewImpl(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options, std::string prefix_token)
Definition: LibCxx.cpp:737
static bool LibcxxStringSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options, std::string prefix_token, ValueObjectSP location_sp, uint64_t size)
Definition: LibCxx.cpp:624
static std::tuple< bool, ValueObjectSP, size_t > LibcxxExtractStringViewData(ValueObject &valobj)
Definition: LibCxx.cpp:717
static bool LibcxxChronoTimePointSecondsSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options, const char *fmt)
Definition: LibCxx.cpp:795
static void consumeInlineNamespace(llvm::StringRef &name)
Definition: LibCxx.cpp:38
LibCppStdFunctionCallableInfo FindLibCppStdFunctionCallableInfo(lldb::ValueObjectSP &valobj_sp)
static CPPLanguageRuntime * Get(Process &process)
A uniqued constant string class.
Definition: ConstString.h:40
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:197
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
An data extractor class.
Definition: DataExtractor.h:48
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
Process * GetProcessPtr() const
Returns a pointer to the process object.
const ConstString & GetFilename() const
Filename string const get accessor.
Definition: FileSpec.h:240
A plug-in interface definition class for debugging a process.
Definition: Process.h:343
static lldb::TypeSystemClangSP GetForTarget(Target &target, std::optional< IsolatedASTKind > ast_kind=DefaultAST, bool create_on_demand=true)
Returns the scratch TypeSystemClang for the given target.
An error handling class.
Definition: Status.h:115
bool Success() const
Test for success condition.
Definition: Status.cpp:280
const char * GetData() const
Definition: StreamString.h:45
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
ConstString GetName() const
Definition: Symbol.cpp:548
lldb::TypeSummaryCapping GetCapping() const
Definition: TypeSummary.cpp:31
virtual lldb::ValueObjectSP GetChildAtIndex(uint32_t idx, bool can_create=true)
virtual uint64_t GetValueAsUnsigned(uint64_t fail_value, bool *success=nullptr)
virtual lldb::ValueObjectSP GetChildMemberWithName(llvm::StringRef name, bool can_create=true)
virtual ConstString GetTypeName()
Definition: ValueObject.h:365
lldb::TargetSP GetTargetSP() const
Definition: ValueObject.h:334
virtual lldb::ValueObjectSP GetNonSyntheticValue()
Definition: ValueObject.h:606
uint32_t GetNumChildrenIgnoringErrors(uint32_t max=UINT32_MAX)
Like GetNumChildren but returns 0 on error.
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override
Definition: LibCxx.cpp:264
llvm::Expected< uint32_t > CalculateNumChildren() override
Definition: LibCxx.cpp:259
lldb::ChildCacheState Update() override
This function is assumed to always succeed and if it fails, the front-end should know to deal with it...
Definition: LibCxx.cpp:294
LibcxxSharedPtrSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
Definition: LibCxx.cpp:252
size_t GetIndexOfChildWithName(ConstString name) override
Definition: LibCxx.cpp:318
llvm::Expected< uint32_t > CalculateNumChildren() override
Definition: LibCxx.cpp:354
lldb::ChildCacheState Update() override
This function is assumed to always succeed and if it fails, the front-end should know to deal with it...
Definition: LibCxx.cpp:384
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override
Definition: LibCxx.cpp:361
size_t GetIndexOfChildWithName(ConstString name) override
Definition: LibCxx.cpp:421
LibcxxUniquePtrSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
Definition: LibCxx.cpp:337
static bool ReadBufferAndDumpToStream(const ReadBufferAndDumpToStreamOptions &options)
#define LLDB_INVALID_OFFSET
Definition: lldb-defines.h:93
#define UINT32_MAX
Definition: lldb-defines.h:19
bool FormatStringRef(const llvm::StringRef &format, Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, const Address *addr, ValueObject *valobj, bool function_changed, bool initial_function)
lldb::ValueObjectSP GetChildMemberWithName(ValueObject &obj, llvm::ArrayRef< ConstString > alternative_names)
Find a child member of obj_sp, trying all alternative names in order.
Definition: LibCxx.cpp:64
bool LibcxxChronoSysSecondsSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition: LibCxx.cpp:838
bool LibcxxChronoMonthSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition: LibCxx.cpp:904
SyntheticChildrenFrontEnd * LibcxxUniquePtrSyntheticFrontEndCreator(CXXSyntheticChildren *, lldb::ValueObjectSP)
Definition: LibCxx.cpp:347
bool LibcxxUniquePointerSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition: LibCxx.cpp:196
bool LibcxxSmartPointerSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition: LibCxx.cpp:154
bool LibcxxStringViewSummaryProviderASCII(ValueObject &valueObj, Stream &stream, const TypeSummaryOptions &summary_options)
Definition: LibCxx.cpp:755
bool LibcxxStringViewSummaryProviderUTF16(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options)
Definition: LibCxx.cpp:762
SyntheticChildrenFrontEnd * LibCxxVectorIteratorSyntheticFrontEndCreator(CXXSyntheticChildren *, lldb::ValueObjectSP)
Definition: LibCxx.cpp:244
bool LibcxxStringViewSummaryProviderUTF32(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options)
Definition: LibCxx.cpp:769
bool LibcxxChronoYearMonthDaySummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition: LibCxx.cpp:946
bool LibcxxWStringSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition: LibCxx.cpp:608
bool LibcxxStringSummaryProviderASCII(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options)
Definition: LibCxx.cpp:695
bool LibcxxChronoLocalSecondsSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition: LibCxx.cpp:844
bool LibcxxWStringViewSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition: LibCxx.cpp:776
bool LibcxxChronoWeekdaySummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition: LibCxx.cpp:925
bool isStdTemplate(ConstString type_name, llvm::StringRef type)
Definition: LibCxx.cpp:55
lldb::ValueObjectSP GetFirstValueOfLibCXXCompressedPair(ValueObject &pair)
Definition: LibCxx.cpp:76
bool LibcxxStringSummaryProviderUTF16(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options)
Definition: LibCxx.cpp:702
bool LibcxxFunctionSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition: LibCxx.cpp:106
bool LibcxxStringSummaryProviderUTF32(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options)
Definition: LibCxx.cpp:709
bool LibcxxChronoLocalDaysSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition: LibCxx.cpp:898
lldb::ValueObjectSP GetSecondValueOfLibCXXCompressedPair(ValueObject &pair)
Definition: LibCxx.cpp:90
bool isOldCompressedPairLayout(ValueObject &pair_obj)
Definition: LibCxx.cpp:50
bool LibcxxContainerSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition: LibCxx.cpp:431
SyntheticChildrenFrontEnd * LibcxxSharedPtrSyntheticFrontEndCreator(CXXSyntheticChildren *, lldb::ValueObjectSP)
Definition: LibCxx.cpp:330
bool LibcxxChronoSysDaysSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition: LibCxx.cpp:892
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
ChildCacheState
Specifies if children need to be re-computed after a call to SyntheticChildrenFrontEnd::Update.
@ eRefetch
Children need to be recomputed dynamically.
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:484
std::shared_ptr< lldb_private::TypeSystemClang > TypeSystemClangSP
Definition: lldb-forward.h:470
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:448
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
Definition: LineEntry.h:147
const FileSpec & GetFile() const
Helper to access the file.
Definition: LineEntry.h:134