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
14#include "lldb/Core/Debugger.h"
21#include "lldb/Target/Target.h"
24#include "lldb/Utility/Endian.h"
25#include "lldb/Utility/Status.h"
26#include "lldb/Utility/Stream.h"
30#include "lldb/lldb-forward.h"
31#include "llvm/Support/ErrorExtras.h"
32#include <optional>
33#include <tuple>
34
35using namespace lldb;
36using namespace lldb_private;
37using namespace lldb_private::formatters;
38
39static void consumeInlineNamespace(llvm::StringRef &name) {
40 // Delete past an inline namespace, if any: __[a-zA-Z0-9_]+::
41 auto scratch = name;
42 if (scratch.consume_front("__") &&
43 std::isalnum(static_cast<unsigned char>(scratch[0]))) {
44 scratch = scratch.drop_while(
45 [](char c) { return std::isalnum(static_cast<unsigned char>(c)); });
46 if (scratch.consume_front("::")) {
47 // Successfully consumed a namespace.
48 name = scratch;
49 }
50 }
51}
52
54 llvm::StringRef type) {
55 llvm::StringRef name = type_name.GetStringRef();
56 // The type name may be prefixed with `std::__<inline-namespace>::`.
57 if (name.consume_front("std::"))
59 return name.consume_front(type) && name.starts_with("<");
60}
61
63 ValueObject &obj, llvm::ArrayRef<ConstString> alternative_names) {
64 for (ConstString name : alternative_names) {
66
67 if (child_sp)
68 return child_sp;
69 }
70 return {};
71}
72
75 ValueObject &pair) {
76 ValueObjectSP value;
77 ValueObjectSP first_child = pair.GetChildAtIndex(0);
78 if (first_child)
79 value = first_child->GetChildMemberWithName("__value_");
80 if (!value) {
81 // pre-c88580c member name
82 value = pair.GetChildMemberWithName("__first_");
83 }
84 return value;
85}
86
89 ValueObject &pair) {
90 ValueObjectSP value;
91 if (pair.GetNumChildrenIgnoringErrors() > 1) {
92 ValueObjectSP second_child = pair.GetChildAtIndex(1);
93 if (second_child) {
94 value = second_child->GetChildMemberWithName("__value_");
95 }
96 }
97 if (!value) {
98 // pre-c88580c member name
99 value = pair.GetChildMemberWithName("__second_");
100 }
101 return value;
102}
103
104std::pair<lldb::ValueObjectSP, bool>
106 ValueObject &obj, llvm::StringRef child_name,
107 llvm::StringRef compressed_pair_name) {
108 auto is_old_compressed_pair = [](ValueObject &pair_obj) -> bool {
109 return isStdTemplate(pair_obj.GetTypeName(), "__compressed_pair");
110 };
111
112 ValueObjectSP node_sp(obj.GetChildMemberWithName(child_name));
113 if (node_sp)
114 return {node_sp, is_old_compressed_pair(*node_sp)};
115
116 // Try the even older __compressed_pair layout.
117
118 assert(!compressed_pair_name.empty());
119
120 node_sp = obj.GetChildMemberWithName(compressed_pair_name);
121
122 // Unrecognized layout (possibly older than LLDB supports).
123 if (!node_sp)
124 return {nullptr, false};
125
126 // Expected old compressed_pair layout, but got something else.
127 if (!is_old_compressed_pair(*node_sp))
128 return {nullptr, false};
129
130 return {node_sp, true};
131}
132
134 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
135
136 ValueObjectSP valobj_sp(valobj.GetNonSyntheticValue());
137
138 if (!valobj_sp)
139 return false;
140
141 ExecutionContext exe_ctx(valobj_sp->GetExecutionContextRef());
142 Process *process = exe_ctx.GetProcessPtr();
143
144 if (process == nullptr)
145 return false;
146
147 CPPLanguageRuntime *cpp_runtime = CPPLanguageRuntime::Get(*process);
148
149 if (!cpp_runtime)
150 return false;
151
153 cpp_runtime->FindLibCppStdFunctionCallableInfo(valobj_sp);
154
155 switch (callable_info.callable_case) {
157 stream.Printf(" __f_ = %" PRIu64, callable_info.member_f_pointer_value);
158 return false;
159 break;
161 stream.Printf(
162 " Lambda in File %s at Line %u",
164 callable_info.callable_line_entry.line);
165 break;
167 stream.Printf(
168 " Function in File %s at Line %u",
170 callable_info.callable_line_entry.line);
171 break;
173 stream.Printf(" Function = %s ",
174 callable_info.callable_symbol.GetName().GetCString());
175 break;
176 }
177
178 return true;
179}
180
182 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
183 ValueObjectSP valobj_sp(valobj.GetNonSyntheticValue());
184 if (!valobj_sp)
185 return false;
186
187 ValueObjectSP ptr_sp(valobj_sp->GetChildMemberWithName("__ptr_"));
188 ValueObjectSP ctrl_sp(valobj_sp->GetChildMemberWithName("__cntrl_"));
189 if (!ctrl_sp || !ptr_sp)
190 return false;
191
192 DumpCxxSmartPtrPointerSummary(stream, *ptr_sp, options);
193
194 bool success;
195 uint64_t ctrl_addr = ctrl_sp->GetValueAsUnsigned(0, &success);
196 // Empty control field. We're done.
197 if (!success || ctrl_addr == 0)
198 return true;
199
200 if (auto count_sp = ctrl_sp->GetChildMemberWithName("__shared_owners_")) {
201 bool success;
202 uint64_t count = count_sp->GetValueAsUnsigned(0, &success);
203 if (!success)
204 return false;
205
206 // std::shared_ptr releases the underlying resource when the
207 // __shared_owners_ count hits -1. So `__shared_owners_ == 0` indicates 1
208 // owner. Hence add +1 here.
209 stream.Printf(" strong=%" PRIu64, count + 1);
210 }
211
212 if (auto weak_count_sp =
213 ctrl_sp->GetChildMemberWithName("__shared_weak_owners_")) {
214 bool success;
215 uint64_t count = weak_count_sp->GetValueAsUnsigned(0, &success);
216 if (!success)
217 return false;
218
219 // Unlike __shared_owners_, __shared_weak_owners_ indicates the exact
220 // std::weak_ptr reference count.
221 stream.Printf(" weak=%" PRIu64, count);
222 }
223
224 return true;
225}
226
228 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
229 ValueObjectSP valobj_sp(valobj.GetNonSyntheticValue());
230 if (!valobj_sp)
231 return false;
232
233 auto [ptr_sp, is_compressed_pair] =
234 GetValueOrOldCompressedPair(*valobj_sp, "__ptr_", "__ptr_");
235 if (!ptr_sp)
236 return false;
237
238 if (is_compressed_pair)
239 ptr_sp = GetFirstValueOfLibCXXCompressedPair(*ptr_sp);
240
241 if (!ptr_sp)
242 return false;
243
244 DumpCxxSmartPtrPointerSummary(stream, *ptr_sp, options);
245
246 return true;
247}
248
249static std::optional<int64_t> LibcxxExtractOrderingValue(ValueObject &valobj) {
250 lldb::ValueObjectSP value_sp = valobj.GetChildMemberWithName("__value_");
251 if (!value_sp)
252 return std::nullopt;
253 bool success;
254 int64_t value = value_sp->GetValueAsSigned(0, &success);
255 if (!success)
256 return std::nullopt;
257 return value;
258}
259
261 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
262 std::optional<int64_t> value = LibcxxExtractOrderingValue(valobj);
263 if (!value)
264 return false;
265 switch (*value) {
266 case -1:
267 stream << "less";
268 break;
269 case 0:
270 stream << "equivalent";
271 break;
272 case 1:
273 stream << "greater";
274 break;
275 case -127:
276 stream << "unordered";
277 break;
278 default:
279 return false;
280 }
281 return true;
282}
283
285 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
286 std::optional<int64_t> value = LibcxxExtractOrderingValue(valobj);
287 if (!value)
288 return false;
289 switch (*value) {
290 case -1:
291 stream << "less";
292 break;
293 case 0:
294 stream << "equivalent";
295 break;
296 case 1:
297 stream << "greater";
298 break;
299 default:
300 return false;
301 }
302 return true;
303}
304
306 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
307 std::optional<int64_t> value = LibcxxExtractOrderingValue(valobj);
308 if (!value)
309 return false;
310 switch (*value) {
311 case -1:
312 stream << "less";
313 break;
314 case 0:
315 stream << "equal";
316 break;
317 case 1:
318 stream << "greater";
319 break;
320 default:
321 return false;
322 }
323 return true;
324}
325
326/*
327 (lldb) fr var ibeg --raw --ptr-depth 1 -T
328 (std::__1::__wrap_iter<int *>) ibeg = {
329 (std::__1::__wrap_iter<int *>::iterator_type) __i = 0x00000001001037a0 {
330 (int) *__i = 1
331 }
332 }
333*/
334
338 return (valobj_sp ? new VectorIteratorSyntheticFrontEnd(
339 valobj_sp, {ConstString("__i_"), ConstString("__i")})
340 : nullptr);
341}
342
350
351llvm::Expected<uint32_t> lldb_private::formatters::
353 return (m_cntrl ? 1 : 0);
354}
355
358 uint32_t idx) {
359 if (!m_cntrl || !m_ptr_obj)
360 return lldb::ValueObjectSP();
361
362 ValueObjectSP valobj_sp = m_backend.GetSP();
363 if (!valobj_sp)
364 return lldb::ValueObjectSP();
365
366 if (idx == 0)
367 return m_ptr_obj->GetSP();
368
369 if (idx == 1) {
370 Status status;
371 ValueObjectSP value_sp = m_ptr_obj->Dereference(status);
372 if (status.Success())
373 return value_sp;
374 }
375
376 return lldb::ValueObjectSP();
377}
378
381 m_cntrl = nullptr;
382 m_ptr_obj = nullptr;
383
384 ValueObjectSP valobj_sp = m_backend.GetSP();
385 if (!valobj_sp)
387
388 TargetSP target_sp(valobj_sp->GetTargetSP());
389 if (!target_sp)
391
392 auto ptr_obj_sp = valobj_sp->GetChildMemberWithName("__ptr_");
393 if (!ptr_obj_sp)
395
396 auto cast_ptr_sp = GetDesugaredSmartPointerValue(*ptr_obj_sp, *valobj_sp);
397 if (!cast_ptr_sp)
399
400 m_ptr_obj = cast_ptr_sp->Clone("pointer").get();
401
402 lldb::ValueObjectSP cntrl_sp(valobj_sp->GetChildMemberWithName("__cntrl_"));
403
404 m_cntrl = cntrl_sp.get(); // need to store the raw pointer to avoid a circular
405 // dependency
407}
408
409llvm::Expected<size_t>
412 if (name == "pointer")
413 return 0;
414
415 if (name == "object" || name == "$$dereference$$")
416 return 1;
417
418 return llvm::createStringErrorV("type has no child named '{0}'", name);
419}
420
423
427 return (valobj_sp ? new LibcxxSharedPtrSyntheticFrontEnd(valobj_sp)
428 : nullptr);
429}
430
437
440
444 return (valobj_sp ? new LibcxxUniquePtrSyntheticFrontEnd(valobj_sp)
445 : nullptr);
446}
447
448llvm::Expected<uint32_t> lldb_private::formatters::
450 if (m_value_ptr_sp)
451 return m_deleter_sp ? 2 : 1;
452 return 0;
453}
454
457 uint32_t idx) {
458 if (!m_value_ptr_sp)
459 return lldb::ValueObjectSP();
460
461 if (idx == 0)
462 return m_value_ptr_sp;
463
464 if (idx == 1)
465 return m_deleter_sp;
466
467 if (idx == 2) {
468 Status status;
469 auto value_sp = m_value_ptr_sp->Dereference(status);
470 if (status.Success()) {
471 return value_sp;
472 }
473 }
474
475 return lldb::ValueObjectSP();
476}
477
480 ValueObjectSP valobj_sp = m_backend.GetSP();
481 if (!valobj_sp)
483
484 auto [ptr_sp, is_compressed_pair] =
485 GetValueOrOldCompressedPair(*valobj_sp, "__ptr_", "__ptr_");
486 if (!ptr_sp)
488
489 // Retrieve the actual pointer and the deleter, and clone them to give them
490 // user-friendly names.
491 if (is_compressed_pair) {
492 if (ValueObjectSP value_pointer_sp =
494 m_value_ptr_sp = value_pointer_sp->Clone("pointer");
495
496 if (ValueObjectSP deleter_sp =
498 m_deleter_sp = deleter_sp->Clone("deleter");
499 } else {
500 m_value_ptr_sp = ptr_sp->Clone("pointer");
501
502 if (ValueObjectSP deleter_sp =
503 valobj_sp->GetChildMemberWithName("__deleter_"))
504 if (deleter_sp->GetNumChildrenIgnoringErrors() > 0)
505 m_deleter_sp = deleter_sp->Clone("deleter");
506 }
507
509}
510
511llvm::Expected<size_t>
514 if (name == "pointer")
515 return 0;
516 if (name == "deleter")
517 return 1;
518 if (name == "obj" || name == "object" || name == "$$dereference$$")
519 return 2;
520 return llvm::createStringErrorV("type has no child named '{0}'", name);
521}
522
523/// The field layout in a libc++ string (cap, side, data or data, size, cap).
524namespace {
525enum class StringLayout { CSD, DSC };
526}
527
529 auto [valobj_r_sp, is_compressed_pair] =
530 GetValueOrOldCompressedPair(valobj, "__rep_", "__r_");
531 if (!valobj_r_sp)
532 return nullptr;
533
534 if (is_compressed_pair)
535 return GetFirstValueOfLibCXXCompressedPair(*valobj_r_sp);
536
537 return valobj_r_sp;
538}
539
540/// Determine the size in bytes of \p valobj (a libc++ std::string object) and
541/// extract its data payload. Return the size + payload pair.
542// TODO: Support big-endian architectures.
543static std::optional<std::pair<uint64_t, ValueObjectSP>>
545 ValueObjectSP valobj_rep_sp = ExtractLibCxxStringData(valobj);
546 if (!valobj_rep_sp || !valobj_rep_sp->GetError().Success())
547 return {};
548
549 ValueObjectSP l = valobj_rep_sp->GetChildMemberWithName("__l");
550 if (!l)
551 return {};
552
553 auto index_or_err = l->GetIndexOfChildWithName("__data_");
554 if (!index_or_err) {
555 LLDB_LOG_ERROR(GetLog(LLDBLog::DataFormatters), index_or_err.takeError(),
556 "{0}");
557 return {};
558 }
559
560 StringLayout layout =
561 *index_or_err == 0 ? StringLayout::DSC : StringLayout::CSD;
562
563 bool short_mode = false; // this means the string is in short-mode and the
564 // data is stored inline
565 bool using_bitmasks = true; // Whether the class uses bitmasks for the mode
566 // flag (pre-D123580).
567 uint64_t size;
568 uint64_t size_mode_value = 0;
569
570 ValueObjectSP short_sp = valobj_rep_sp->GetChildMemberWithName("__s");
571 if (!short_sp)
572 return {};
573
574 ValueObjectSP is_long = short_sp->GetChildMemberWithName("__is_long_");
575 ValueObjectSP size_sp = short_sp->GetChildMemberWithName("__size_");
576 if (!size_sp)
577 return {};
578
579 if (is_long) {
580 using_bitmasks = false;
581 short_mode = !is_long->GetValueAsUnsigned(/*fail_value=*/0);
582 size = size_sp->GetValueAsUnsigned(/*fail_value=*/0);
583 } else {
584 // The string mode is encoded in the size field.
585 size_mode_value = size_sp->GetValueAsUnsigned(0);
586 uint8_t mode_mask = layout == StringLayout::DSC ? 0x80 : 1;
587 short_mode = (size_mode_value & mode_mask) == 0;
588 }
589
590 if (short_mode) {
591 ValueObjectSP location_sp = short_sp->GetChildMemberWithName("__data_");
592 if (using_bitmasks)
593 size = (layout == StringLayout::DSC) ? size_mode_value
594 : ((size_mode_value >> 1) % 256);
595
596 if (!location_sp)
597 return {};
598
599 // When the small-string optimization takes place, the data must fit in the
600 // inline string buffer (23 bytes on x86_64/Darwin). If it doesn't, it's
601 // likely that the string isn't initialized and we're reading garbage.
602 ExecutionContext exe_ctx(location_sp->GetExecutionContextRef());
603 const std::optional<uint64_t> max_bytes =
604 llvm::expectedToOptional(location_sp->GetCompilerType().GetByteSize(
606 if (!max_bytes || size > *max_bytes)
607 return {};
608
609 return std::make_pair(size, location_sp);
610 }
611
612 // we can use the layout_decider object as the data pointer
613 ValueObjectSP location_sp = l->GetChildMemberWithName("__data_");
614 ValueObjectSP size_vo = l->GetChildMemberWithName("__size_");
615 ValueObjectSP capacity_vo = l->GetChildMemberWithName("__cap_");
616 if (!size_vo || !location_sp || !capacity_vo)
617 return {};
618 size = size_vo->GetValueAsUnsigned(LLDB_INVALID_OFFSET);
619 uint64_t capacity = capacity_vo->GetValueAsUnsigned(LLDB_INVALID_OFFSET);
620 if (!using_bitmasks && layout == StringLayout::CSD)
621 capacity *= 2;
622 if (size == LLDB_INVALID_OFFSET || capacity == LLDB_INVALID_OFFSET ||
623 capacity < size)
624 return {};
625 return std::make_pair(size, location_sp);
626}
627
629 ValueObject &valobj, Stream &stream,
630 const TypeSummaryOptions &summary_options) {
631 auto string_info = ExtractLibcxxStringInfo(valobj);
632 if (!string_info)
633 return false;
634 uint64_t size;
635 ValueObjectSP location_sp;
636 std::tie(size, location_sp) = *string_info;
637
638 auto wchar_t_size = GetWCharByteSize(valobj);
639 if (!wchar_t_size)
640 return false;
641
642 switch (*wchar_t_size) {
643 case 1:
645 stream, summary_options, location_sp, size, "L");
646 case 2:
648 stream, summary_options, location_sp, size, "L");
649 case 4:
651 stream, summary_options, location_sp, size, "L");
652 }
653 return false;
654}
655
656template <StringPrinter::StringElementType element_type>
657static bool
659 const TypeSummaryOptions &summary_options,
660 std::string prefix_token) {
661 auto string_info = ExtractLibcxxStringInfo(valobj);
662 if (!string_info)
663 return false;
664 uint64_t size;
665 ValueObjectSP location_sp;
666 std::tie(size, location_sp) = *string_info;
667
669 stream, summary_options, location_sp, size, prefix_token);
670}
671template <StringPrinter::StringElementType element_type>
672static bool formatStringImpl(ValueObject &valobj, Stream &stream,
673 const TypeSummaryOptions &summary_options,
674 std::string prefix_token) {
675 StreamString scratch_stream;
677 valobj, scratch_stream, summary_options, prefix_token);
678 if (success)
679 stream << scratch_stream.GetData();
680 else
681 stream << "Summary Unavailable";
682 return true;
683}
684
686 ValueObject &valobj, Stream &stream,
687 const TypeSummaryOptions &summary_options) {
689 valobj, stream, summary_options, "");
690}
691
693 ValueObject &valobj, Stream &stream,
694 const TypeSummaryOptions &summary_options) {
696 valobj, stream, summary_options, "u");
697}
698
700 ValueObject &valobj, Stream &stream,
701 const TypeSummaryOptions &summary_options) {
703 valobj, stream, summary_options, "U");
704}
705
706static std::tuple<bool, ValueObjectSP, size_t>
708 auto dataobj = GetChildMemberWithName(
709 valobj, {ConstString("__data_"), ConstString("__data")});
710 auto sizeobj = GetChildMemberWithName(
711 valobj, {ConstString("__size_"), ConstString("__size")});
712 if (!dataobj || !sizeobj)
713 return std::make_tuple<bool,ValueObjectSP,size_t>(false, {}, {});
714
715 if (!dataobj->GetError().Success() || !sizeobj->GetError().Success())
716 return std::make_tuple<bool,ValueObjectSP,size_t>(false, {}, {});
717
718 bool success{false};
719 uint64_t size = sizeobj->GetValueAsUnsigned(0, &success);
720 if (!success)
721 return std::make_tuple<bool,ValueObjectSP,size_t>(false, {}, {});
722
723 return std::make_tuple(true,dataobj,size);
724}
725
726template <StringPrinter::StringElementType element_type>
727static bool formatStringViewImpl(ValueObject &valobj, Stream &stream,
728 const TypeSummaryOptions &summary_options,
729 std::string prefix_token) {
730
731 bool success;
732 ValueObjectSP dataobj;
733 size_t size;
734 std::tie(success, dataobj, size) = LibcxxExtractStringViewData(valobj);
735
736 if (!success) {
737 stream << "Summary Unavailable";
738 return true;
739 }
740
741 return StringBufferSummaryProvider<element_type>(stream, summary_options,
742 dataobj, size, prefix_token);
743}
744
746 ValueObject &valobj, Stream &stream,
747 const TypeSummaryOptions &summary_options) {
749 valobj, stream, summary_options, "");
750}
751
753 ValueObject &valobj, Stream &stream,
754 const TypeSummaryOptions &summary_options) {
756 valobj, stream, summary_options, "u");
757}
758
760 ValueObject &valobj, Stream &stream,
761 const TypeSummaryOptions &summary_options) {
763 valobj, stream, summary_options, "U");
764}
765
767 ValueObject &valobj, Stream &stream,
768 const TypeSummaryOptions &summary_options) {
769
770 bool success;
771 ValueObjectSP dataobj;
772 size_t size;
773 std::tie(success, dataobj, size) = LibcxxExtractStringViewData(valobj);
774
775 if (!success) {
776 stream << "Summary Unavailable";
777 return true;
778 }
779
780 auto wchar_t_size = GetWCharByteSize(valobj);
781 if (!wchar_t_size)
782 return false;
783
784 switch (*wchar_t_size) {
785 case 1:
787 stream, summary_options, dataobj, size, "L");
788 case 2:
790 stream, summary_options, dataobj, size, "L");
791 case 4:
793 stream, summary_options, dataobj, size, "L");
794 }
795 return false;
796}
797
798static bool
800 const TypeSummaryOptions &options,
801 const char *fmt) {
802 ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__d_");
803 if (!ptr_sp)
804 return false;
805 ptr_sp = ptr_sp->GetChildMemberWithName("__rep_");
806 if (!ptr_sp)
807 return false;
808
809#ifndef _WIN32
810 // The date time in the chrono library is valid in the range
811 // [-32767-01-01T00:00:00Z, 32767-12-31T23:59:59Z]. A 64-bit time_t has a
812 // larger range, the function strftime is not able to format the entire range
813 // of time_t. The exact point has not been investigated; it's limited to
814 // chrono's range.
815 const std::time_t chrono_timestamp_min =
816 -1'096'193'779'200; // -32767-01-01T00:00:00Z
817 const std::time_t chrono_timestamp_max =
818 971'890'963'199; // 32767-12-31T23:59:59Z
819#else
820 const std::time_t chrono_timestamp_min = -43'200; // 1969-12-31T12:00:00Z
821 const std::time_t chrono_timestamp_max =
822 32'536'850'399; // 3001-01-19T21:59:59
823#endif
824
825 const std::time_t seconds = ptr_sp->GetValueAsSigned(0);
826 if (seconds < chrono_timestamp_min || seconds > chrono_timestamp_max)
827 stream.Printf("timestamp=%" PRId64 " s", static_cast<int64_t>(seconds));
828 else {
829 std::array<char, 128> str;
830 std::size_t size =
831 std::strftime(str.data(), str.size(), fmt, gmtime(&seconds));
832 if (size == 0)
833 return false;
834
835 stream.Printf("date/time=%s timestamp=%" PRId64 " s", str.data(),
836 static_cast<int64_t>(seconds));
837 }
838
839 return true;
840}
841
843 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
844 return LibcxxChronoTimePointSecondsSummaryProvider(valobj, stream, options,
845 "%FT%H:%M:%SZ");
846}
847
849 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
850 return LibcxxChronoTimePointSecondsSummaryProvider(valobj, stream, options,
851 "%FT%H:%M:%S");
852}
853
854static bool
856 const TypeSummaryOptions &options,
857 const char *fmt) {
858 ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__d_");
859 if (!ptr_sp)
860 return false;
861 ptr_sp = ptr_sp->GetChildMemberWithName("__rep_");
862 if (!ptr_sp)
863 return false;
864
865#ifndef _WIN32
866 // The date time in the chrono library is valid in the range
867 // [-32767-01-01Z, 32767-12-31Z]. A 32-bit time_t has a larger range, the
868 // function strftime is not able to format the entire range of time_t. The
869 // exact point has not been investigated; it's limited to chrono's range.
870 const int chrono_timestamp_min = -12'687'428; // -32767-01-01Z
871 const int chrono_timestamp_max = 11'248'737; // 32767-12-31Z
872#else
873 const int chrono_timestamp_min = 0; // 1970-01-01Z
874 const int chrono_timestamp_max = 376'583; // 3001-01-19Z
875#endif
876
877 const int days = ptr_sp->GetValueAsSigned(0);
878 if (days < chrono_timestamp_min || days > chrono_timestamp_max)
879 stream.Printf("timestamp=%d days", days);
880
881 else {
882 const std::time_t seconds = std::time_t(86400) * days;
883
884 std::array<char, 128> str;
885 std::size_t size =
886 std::strftime(str.data(), str.size(), fmt, gmtime(&seconds));
887 if (size == 0)
888 return false;
889
890 stream.Printf("date=%s timestamp=%d days", str.data(), days);
891 }
892
893 return true;
894}
895
897 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
898 return LibcxxChronoTimepointDaysSummaryProvider(valobj, stream, options,
899 "%FZ");
900}
901
903 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
904 return LibcxxChronoTimepointDaysSummaryProvider(valobj, stream, options,
905 "%F");
906}
907
909 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
910 // FIXME: These are the names used in the C++20 ostream operator. Since LLVM
911 // uses C++17 it's not possible to use the ostream operator directly.
912 static const std::array<std::string_view, 12> months = {
913 "January", "February", "March", "April", "May", "June",
914 "July", "August", "September", "October", "November", "December"};
915
916 ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__m_");
917 if (!ptr_sp)
918 return false;
919
920 const unsigned month = ptr_sp->GetValueAsUnsigned(0);
921 if (month >= 1 && month <= 12)
922 stream << "month=" << months[month - 1];
923 else
924 stream.Printf("month=%u", month);
925
926 return true;
927}
928
930 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
931 // FIXME: These are the names used in the C++20 ostream operator. Since LLVM
932 // uses C++17 it's not possible to use the ostream operator directly.
933 static const std::array<std::string_view, 7> weekdays = {
934 "Sunday", "Monday", "Tuesday", "Wednesday",
935 "Thursday", "Friday", "Saturday"};
936
937 ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__wd_");
938 if (!ptr_sp)
939 return false;
940
941 const unsigned weekday = ptr_sp->GetValueAsUnsigned(0);
942 if (weekday < 7)
943 stream << "weekday=" << weekdays[weekday];
944 else
945 stream.Printf("weekday=%u", weekday);
946
947 return true;
948}
949
951 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
952 ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__y_");
953 if (!ptr_sp)
954 return false;
955 ptr_sp = ptr_sp->GetChildMemberWithName("__y_");
956 if (!ptr_sp)
957 return false;
958 int year = ptr_sp->GetValueAsSigned(0);
959
960 ptr_sp = valobj.GetChildMemberWithName("__m_");
961 if (!ptr_sp)
962 return false;
963 ptr_sp = ptr_sp->GetChildMemberWithName("__m_");
964 if (!ptr_sp)
965 return false;
966 const unsigned month = ptr_sp->GetValueAsUnsigned(0);
967
968 ptr_sp = valobj.GetChildMemberWithName("__d_");
969 if (!ptr_sp)
970 return false;
971 ptr_sp = ptr_sp->GetChildMemberWithName("__d_");
972 if (!ptr_sp)
973 return false;
974 const unsigned day = ptr_sp->GetValueAsUnsigned(0);
975
976 stream << "date=";
977 if (year < 0) {
978 stream << '-';
979 year = -year;
980 }
981 stream.Printf("%04d-%02u-%02u", year, month, day);
982
983 return true;
984}
static bool LibcxxChronoTimepointDaysSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options, const char *fmt)
Definition LibCxx.cpp:855
static ValueObjectSP ExtractLibCxxStringData(ValueObject &valobj)
Definition LibCxx.cpp:528
static bool formatStringImpl(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options, std::string prefix_token)
Definition LibCxx.cpp:672
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:544
static bool formatStringViewImpl(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options, std::string prefix_token)
Definition LibCxx.cpp:727
static std::optional< int64_t > LibcxxExtractOrderingValue(ValueObject &valobj)
Definition LibCxx.cpp:249
static std::tuple< bool, ValueObjectSP, size_t > LibcxxExtractStringViewData(ValueObject &valobj)
Definition LibCxx.cpp:707
static bool LibcxxChronoTimePointSecondsSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options, const char *fmt)
Definition LibCxx.cpp:799
static bool LibcxxStringSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options, std::string prefix_token)
Definition LibCxx.cpp:658
static void consumeInlineNamespace(llvm::StringRef &name)
Definition LibCxx.cpp:39
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:394
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.
const char * GetCString() const
Get the string value as a C string.
"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:250
A plug-in interface definition class for debugging a process.
Definition Process.h:357
An error handling class.
Definition Status.h:118
bool Success() const
Test for success condition.
Definition Status.cpp:303
const char * GetData() const
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:511
SyntheticChildrenFrontEnd(ValueObject &backend)
virtual lldb::ValueObjectSP GetChildAtIndex(uint32_t idx, bool can_create=true)
virtual lldb::ValueObjectSP GetChildMemberWithName(llvm::StringRef name, bool can_create=true)
virtual lldb::ValueObjectSP GetNonSyntheticValue()
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:357
llvm::Expected< uint32_t > CalculateNumChildren() override
Definition LibCxx.cpp:352
llvm::Expected< size_t > GetIndexOfChildWithName(ConstString name) override
Determine the index of a named child.
Definition LibCxx.cpp:411
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:380
LibcxxSharedPtrSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
Definition LibCxx.cpp:344
llvm::Expected< uint32_t > CalculateNumChildren() override
Definition LibCxx.cpp:449
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:479
llvm::Expected< size_t > GetIndexOfChildWithName(ConstString name) override
Determine the index of a named child.
Definition LibCxx.cpp:513
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override
Definition LibCxx.cpp:456
LibcxxUniquePtrSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
Definition LibCxx.cpp:432
#define LLDB_INVALID_OFFSET
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:62
bool LibcxxChronoSysSecondsSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition LibCxx.cpp:842
bool LibcxxChronoMonthSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition LibCxx.cpp:908
SyntheticChildrenFrontEnd * LibcxxUniquePtrSyntheticFrontEndCreator(CXXSyntheticChildren *, lldb::ValueObjectSP)
bool LibcxxUniquePointerSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition LibCxx.cpp:227
lldb::ValueObjectSP GetDesugaredSmartPointerValue(ValueObject &ptr, ValueObject &container)
Return the ValueObjectSP of the underlying pointer member whose type is a desugared 'std::shared_ptr:...
Definition Generic.cpp:13
bool LibcxxPartialOrderingSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition LibCxx.cpp:260
bool LibcxxSmartPointerSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition LibCxx.cpp:181
bool LibcxxStringViewSummaryProviderASCII(ValueObject &valueObj, Stream &stream, const TypeSummaryOptions &summary_options)
Definition LibCxx.cpp:745
bool LibcxxStringViewSummaryProviderUTF16(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options)
Definition LibCxx.cpp:752
std::optional< uint64_t > GetWCharByteSize(ValueObject &valobj)
SyntheticChildrenFrontEnd * LibCxxVectorIteratorSyntheticFrontEndCreator(CXXSyntheticChildren *, lldb::ValueObjectSP)
bool LibcxxStringViewSummaryProviderUTF32(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options)
Definition LibCxx.cpp:759
bool StringBufferSummaryProvider(Stream &stream, const TypeSummaryOptions &summary_options, lldb::ValueObjectSP location_sp, uint64_t size, std::string prefix_token)
Print a summary for a string buffer to stream.
bool LibcxxWeakOrderingSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition LibCxx.cpp:284
bool LibcxxChronoYearMonthDaySummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition LibCxx.cpp:950
bool LibcxxWStringSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition LibCxx.cpp:628
bool LibcxxStringSummaryProviderASCII(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options)
Definition LibCxx.cpp:685
bool LibcxxChronoLocalSecondsSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition LibCxx.cpp:848
bool LibcxxWStringViewSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition LibCxx.cpp:766
bool LibcxxChronoWeekdaySummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition LibCxx.cpp:929
bool isStdTemplate(ConstString type_name, llvm::StringRef type)
Definition LibCxx.cpp:53
lldb::ValueObjectSP GetFirstValueOfLibCXXCompressedPair(ValueObject &pair)
Definition LibCxx.cpp:74
bool LibcxxStringSummaryProviderUTF16(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options)
Definition LibCxx.cpp:692
bool LibcxxFunctionSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition LibCxx.cpp:133
bool LibcxxStringSummaryProviderUTF32(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options)
Definition LibCxx.cpp:699
std::pair< lldb::ValueObjectSP, bool > GetValueOrOldCompressedPair(ValueObject &obj, llvm::StringRef child_name, llvm::StringRef compressed_pair_name)
Returns the ValueObjectSP of the child of obj.
Definition LibCxx.cpp:105
bool LibcxxStrongOrderingSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition LibCxx.cpp:305
bool LibcxxChronoLocalDaysSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition LibCxx.cpp:902
lldb::ValueObjectSP GetSecondValueOfLibCXXCompressedPair(ValueObject &pair)
Definition LibCxx.cpp:88
SyntheticChildrenFrontEnd * LibcxxSharedPtrSyntheticFrontEndCreator(CXXSyntheticChildren *, lldb::ValueObjectSP)
bool LibcxxChronoSysDaysSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Definition LibCxx.cpp:896
void DumpCxxSmartPtrPointerSummary(Stream &stream, ValueObject &ptr, const TypeSummaryOptions &options)
Prints the summary for the pointer value of a C++ std::unique_ptr/stdshared_ptr/stdweak_ptr.
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:327
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
std::shared_ptr< lldb_private::Target > TargetSP
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
Definition LineEntry.h:151
const FileSpec & GetFile() const
Helper to access the file.
Definition LineEntry.h:134