31#include "llvm/Support/ErrorExtras.h"
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(
"::")) {
54 llvm::StringRef type) {
57 if (name.consume_front(
"std::"))
59 return name.consume_front(type) && name.starts_with(
"<");
63 ValueObject &obj, llvm::ArrayRef<ConstString> alternative_names) {
79 value = first_child->GetChildMemberWithName(
"__value_");
94 value = second_child->GetChildMemberWithName(
"__value_");
104std::pair<lldb::ValueObjectSP, bool>
107 llvm::StringRef compressed_pair_name) {
108 auto is_old_compressed_pair = [](
ValueObject &pair_obj) ->
bool {
109 return isStdTemplate(pair_obj.GetTypeName(),
"__compressed_pair");
114 return {node_sp, is_old_compressed_pair(*node_sp)};
118 assert(!compressed_pair_name.empty());
124 return {
nullptr,
false};
127 if (!is_old_compressed_pair(*node_sp))
128 return {
nullptr,
false};
130 return {node_sp,
true};
144 if (process ==
nullptr)
161 stream.
Format(
" Lambda in File {0} at Line {1}",
166 stream.
Format(
" Function in File {0} at Line {1}",
171 stream.
Printf(
" Function = %s ",
185 ValueObjectSP ptr_sp(valobj_sp->GetChildMemberWithName(
"__ptr_"));
186 ValueObjectSP ctrl_sp(valobj_sp->GetChildMemberWithName(
"__cntrl_"));
187 if (!ctrl_sp || !ptr_sp)
193 uint64_t ctrl_addr = ctrl_sp->GetValueAsUnsigned(0, &success);
195 if (!success || ctrl_addr == 0)
198 if (
auto count_sp = ctrl_sp->GetChildMemberWithName(
"__shared_owners_")) {
200 uint64_t count = count_sp->GetValueAsUnsigned(0, &success);
207 stream.
Printf(
" strong=%" PRIu64, count + 1);
210 if (
auto weak_count_sp =
211 ctrl_sp->GetChildMemberWithName(
"__shared_weak_owners_")) {
213 uint64_t count = weak_count_sp->GetValueAsUnsigned(0, &success);
219 stream.
Printf(
" weak=%" PRIu64, count);
231 auto [ptr_sp, is_compressed_pair] =
236 if (is_compressed_pair)
252 int64_t value = value_sp->GetValueAsSigned(0, &success);
268 stream <<
"equivalent";
274 stream <<
"unordered";
292 stream <<
"equivalent";
386 TargetSP target_sp(valobj_sp->GetTargetSP());
390 auto ptr_obj_sp = valobj_sp->GetChildMemberWithName(
"__ptr_");
398 m_ptr_obj = cast_ptr_sp->Clone(
"pointer").get();
407llvm::Expected<size_t>
410 if (name ==
"pointer")
413 if (name ==
"object" || name ==
"$$dereference$$")
416 return llvm::createStringErrorV(
"type has no child named '{0}'", name);
482 auto [ptr_sp, is_compressed_pair] =
489 if (is_compressed_pair) {
501 valobj_sp->GetChildMemberWithName(
"__deleter_"))
502 if (deleter_sp->GetNumChildrenIgnoringErrors() > 0)
509llvm::Expected<size_t>
512 if (name ==
"pointer")
514 if (name ==
"deleter")
516 if (name ==
"obj" || name ==
"object" || name ==
"$$dereference$$")
518 return llvm::createStringErrorV(
"type has no child named '{0}'", name);
523enum class StringLayout { CSD, DSC };
527 auto [valobj_r_sp, is_compressed_pair] =
532 if (is_compressed_pair)
541static std::optional<std::pair<uint64_t, ValueObjectSP>>
544 if (!valobj_rep_sp || !valobj_rep_sp->GetError().Success())
551 auto index_or_err =
l->GetIndexOfChildWithName(
"__data_");
558 StringLayout layout =
559 *index_or_err == 0 ? StringLayout::DSC : StringLayout::CSD;
561 bool short_mode =
false;
563 bool using_bitmasks =
true;
566 uint64_t size_mode_value = 0;
568 ValueObjectSP short_sp = valobj_rep_sp->GetChildMemberWithName(
"__s");
572 ValueObjectSP is_long = short_sp->GetChildMemberWithName(
"__is_long_");
573 ValueObjectSP size_sp = short_sp->GetChildMemberWithName(
"__size_");
578 using_bitmasks =
false;
579 short_mode = !is_long->GetValueAsUnsigned(0);
580 size = size_sp->GetValueAsUnsigned(0);
583 size_mode_value = size_sp->GetValueAsUnsigned(0);
584 uint8_t mode_mask = layout == StringLayout::DSC ? 0x80 : 1;
585 short_mode = (size_mode_value & mode_mask) == 0;
589 ValueObjectSP location_sp = short_sp->GetChildMemberWithName(
"__data_");
591 size = (layout == StringLayout::DSC) ? size_mode_value
592 : ((size_mode_value >> 1) % 256);
601 const std::optional<uint64_t> max_bytes =
602 llvm::expectedToOptional(location_sp->GetCompilerType().GetByteSize(
604 if (!max_bytes || size > *max_bytes)
607 return std::make_pair(size, location_sp);
614 if (!size_vo || !location_sp || !capacity_vo)
618 if (!using_bitmasks && layout == StringLayout::CSD)
623 return std::make_pair(size, location_sp);
634 std::tie(size, location_sp) = *string_info;
640 switch (*wchar_t_size) {
643 stream, summary_options, location_sp, size,
"L");
646 stream, summary_options, location_sp, size,
"L");
649 stream, summary_options, location_sp, size,
"L");
654template <StringPr
inter::StringElementType element_type>
658 std::string prefix_token) {
664 std::tie(size, location_sp) = *string_info;
667 stream, summary_options, location_sp, size, prefix_token);
669template <StringPr
inter::StringElementType element_type>
672 std::string prefix_token) {
675 valobj, scratch_stream, summary_options, prefix_token);
677 stream << scratch_stream.
GetData();
679 stream <<
"Summary Unavailable";
687 valobj, stream, summary_options,
"");
694 valobj, stream, summary_options,
"u");
701 valobj, stream, summary_options,
"U");
704static std::tuple<bool, ValueObjectSP, size_t>
710 if (!dataobj || !sizeobj)
711 return std::make_tuple<bool,ValueObjectSP,size_t>(
false, {}, {});
713 if (!dataobj->GetError().Success() || !sizeobj->GetError().Success())
714 return std::make_tuple<bool,ValueObjectSP,size_t>(
false, {}, {});
717 uint64_t size = sizeobj->GetValueAsUnsigned(0, &success);
719 return std::make_tuple<bool,ValueObjectSP,size_t>(
false, {}, {});
721 return std::make_tuple(
true,dataobj,size);
724template <StringPr
inter::StringElementType element_type>
727 std::string prefix_token) {
735 stream <<
"Summary Unavailable";
740 dataobj, size, prefix_token);
747 valobj, stream, summary_options,
"");
754 valobj, stream, summary_options,
"u");
761 valobj, stream, summary_options,
"U");
774 stream <<
"Summary Unavailable";
782 switch (*wchar_t_size) {
785 stream, summary_options, dataobj, size,
"L");
788 stream, summary_options, dataobj, size,
"L");
791 stream, summary_options, dataobj, size,
"L");
803 ptr_sp = ptr_sp->GetChildMemberWithName(
"__rep_");
813 const std::time_t chrono_timestamp_min =
815 const std::time_t chrono_timestamp_max =
818 const std::time_t chrono_timestamp_min = -43'200;
819 const std::time_t chrono_timestamp_max =
823 const std::time_t seconds = ptr_sp->GetValueAsSigned(0);
824 if (seconds < chrono_timestamp_min || seconds > chrono_timestamp_max)
825 stream.
Printf(
"timestamp=%" PRId64
" s",
static_cast<int64_t
>(seconds));
827 std::array<char, 128> str;
829 std::strftime(str.data(), str.size(), fmt, gmtime(&seconds));
833 stream.
Printf(
"date/time=%s timestamp=%" PRId64
" s", str.data(),
834 static_cast<int64_t
>(seconds));
859 ptr_sp = ptr_sp->GetChildMemberWithName(
"__rep_");
868 const int chrono_timestamp_min = -12'687'428;
869 const int chrono_timestamp_max = 11'248'737;
871 const int chrono_timestamp_min = 0;
872 const int chrono_timestamp_max = 376'583;
875 const int days = ptr_sp->GetValueAsSigned(0);
876 if (days < chrono_timestamp_min || days > chrono_timestamp_max)
877 stream.
Printf(
"timestamp=%d days", days);
880 const std::time_t seconds = std::time_t(86400) * days;
882 std::array<char, 128> str;
884 std::strftime(str.data(), str.size(), fmt, gmtime(&seconds));
888 stream.
Printf(
"date=%s timestamp=%d days", str.data(), days);
910 static const std::array<std::string_view, 12> months = {
911 "January",
"February",
"March",
"April",
"May",
"June",
912 "July",
"August",
"September",
"October",
"November",
"December"};
918 const unsigned month = ptr_sp->GetValueAsUnsigned(0);
919 if (month >= 1 && month <= 12)
920 stream <<
"month=" << months[month - 1];
922 stream.
Printf(
"month=%u", month);
931 static const std::array<std::string_view, 7> weekdays = {
932 "Sunday",
"Monday",
"Tuesday",
"Wednesday",
933 "Thursday",
"Friday",
"Saturday"};
939 const unsigned weekday = ptr_sp->GetValueAsUnsigned(0);
941 stream <<
"weekday=" << weekdays[weekday];
943 stream.
Printf(
"weekday=%u", weekday);
953 ptr_sp = ptr_sp->GetChildMemberWithName(
"__y_");
956 int year = ptr_sp->GetValueAsSigned(0);
961 ptr_sp = ptr_sp->GetChildMemberWithName(
"__m_");
964 const unsigned month = ptr_sp->GetValueAsUnsigned(0);
969 ptr_sp = ptr_sp->GetChildMemberWithName(
"__d_");
972 const unsigned day = ptr_sp->GetValueAsUnsigned(0);
979 stream.
Printf(
"%04d-%02u-%02u", year, month, day);
990 ValueObjectSP file_sp = ptr_sp->GetChildMemberWithName(
"_M_file_name");
992 ptr_sp->GetChildMemberWithName(
"_M_function_name");
993 ValueObjectSP line_sp = ptr_sp->GetChildMemberWithName(
"_M_line");
994 ValueObjectSP column_sp = ptr_sp->GetChildMemberWithName(
"_M_column");
996 if (!file_sp || !function_sp || !line_sp || !column_sp)
999 bool success =
false;
1000 uint64_t line = line_sp->GetValueAsUnsigned(0, &success);
1004 uint64_t column = column_sp->GetValueAsUnsigned(0, &success);
1008 const char *file = file_sp->GetSummaryAsCString();
1009 stream.
Format(
"{0}:{1}:{2}", file ? file :
"<unknown>", line, column);
1011 if (
const char *function = function_sp->GetSummaryAsCString())
1012 stream.
Printf(
" (%s)", function);
static bool LibcxxChronoTimepointDaysSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options, const char *fmt)
static ValueObjectSP ExtractLibCxxStringData(ValueObject &valobj)
static bool formatStringImpl(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options, std::string prefix_token)
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.
static bool formatStringViewImpl(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options, std::string prefix_token)
static std::optional< int64_t > LibcxxExtractOrderingValue(ValueObject &valobj)
static std::tuple< bool, ValueObjectSP, size_t > LibcxxExtractStringViewData(ValueObject &valobj)
static bool LibcxxChronoTimePointSecondsSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options, const char *fmt)
static bool LibcxxStringSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &summary_options, std::string prefix_token)
static void consumeInlineNamespace(llvm::StringRef &name)
#define LLDB_LOG_ERROR(log, error,...)
LibCppStdFunctionCallableInfo FindLibCppStdFunctionCallableInfo(lldb::ValueObjectSP &valobj_sp)
static CPPLanguageRuntime * Get(Process &process)
A uniqued constant string class.
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.
llvm::StringRef GetFilename() const
Filename string const get accessor.
A plug-in interface definition class for debugging a process.
bool Success() const
Test for success condition.
const char * GetData() const
A stream class that can stream formatted output to a file.
void Format(const char *format, Args &&... args)
Forwards the arguments to llvm::formatv and writes to the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
ConstString GetName() const
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.
#define LLDB_INVALID_OFFSET
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.
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
lldb::addr_t member_f_pointer_value
LineEntry callable_line_entry
LibCppStdFunctionCallableCase callable_case
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
const FileSpec & GetFile() const
Helper to access the file.