LLDB mainline
FormatEntity.cpp
Go to the documentation of this file.
1//===-- FormatEntity.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
10
11#include "lldb/Core/Address.h"
13#include "lldb/Core/Debugger.h"
15#include "lldb/Core/Module.h"
24#include "lldb/Symbol/Block.h"
29#include "lldb/Symbol/Symbol.h"
36#include "lldb/Target/Process.h"
41#include "lldb/Target/Target.h"
42#include "lldb/Target/Thread.h"
48#include "lldb/Utility/Log.h"
50#include "lldb/Utility/Status.h"
51#include "lldb/Utility/Stream.h"
57#include "lldb/lldb-defines.h"
58#include "lldb/lldb-forward.h"
59#include "llvm/ADT/STLExtras.h"
60#include "llvm/ADT/StringRef.h"
61#include "llvm/Support/Compiler.h"
62#include "llvm/Support/Regex.h"
63#include "llvm/TargetParser/Triple.h"
64
65#include <cassert>
66#include <cctype>
67#include <cinttypes>
68#include <cstdio>
69#include <cstdlib>
70#include <cstring>
71#include <memory>
72#include <type_traits>
73#include <utility>
74
75namespace lldb_private {
77}
78namespace lldb_private {
79struct RegisterInfo;
80}
81
82using namespace lldb;
83using namespace lldb_private;
84
88
90
92 Definition("*", EntryType::ParentString)};
93
95 Definition("load", EntryType::AddressLoad),
96 Definition("file", EntryType::AddressFile)};
97
99 Definition("basename", EntryType::ParentNumber, FileKind::Basename),
100 Definition("dirname", EntryType::ParentNumber, FileKind::Dirname),
101 Definition("fullpath", EntryType::ParentNumber, FileKind::Fullpath)};
102
104 Definition("index", EntryType::FrameIndex),
105 Definition("pc", EntryType::FrameRegisterPC),
106 Definition("fp", EntryType::FrameRegisterFP),
107 Definition("sp", EntryType::FrameRegisterSP),
108 Definition("flags", EntryType::FrameRegisterTypeFlags),
109 Definition("no-debug", EntryType::FrameNoDebug),
110 Entry::DefinitionWithChildren("reg", EntryType::FrameRegisterByName,
112 Definition("is-artificial", EntryType::FrameIsArtificial),
113 Definition("kind", EntryType::FrameKind),
114 Definition("borrowed-info", EntryType::FrameBorrowedInfo),
115};
116
118 Definition("id", EntryType::FunctionID),
119 Definition("name", EntryType::FunctionName),
120 Definition("name-without-args", EntryType::FunctionNameNoArgs),
121 Definition("name-with-args", EntryType::FunctionNameWithArgs),
122 Definition("mangled-name", EntryType::FunctionMangledName),
123 Definition("addr-offset", EntryType::FunctionAddrOffset),
124 Definition("concrete-only-addr-offset-no-padding",
125 EntryType::FunctionAddrOffsetConcrete),
126 Definition("line-offset", EntryType::FunctionLineOffset),
127 Definition("pc-offset", EntryType::FunctionPCOffset),
128 Definition("initial-function", EntryType::FunctionInitial),
129 Definition("changed", EntryType::FunctionChanged),
130 Definition("is-optimized", EntryType::FunctionIsOptimized),
131 Definition("is-inlined", EntryType::FunctionIsInlined),
132 Definition("prefix", EntryType::FunctionPrefix),
133 Definition("scope", EntryType::FunctionScope),
134 Definition("basename", EntryType::FunctionBasename),
135 Definition("name-qualifiers", EntryType::FunctionNameQualifiers),
136 Definition("template-arguments", EntryType::FunctionTemplateArguments),
137 Definition("formatted-arguments", EntryType::FunctionFormattedArguments),
138 Definition("return-left", EntryType::FunctionReturnLeft),
139 Definition("return-right", EntryType::FunctionReturnRight),
140 Definition("qualifiers", EntryType::FunctionQualifiers),
141 Definition("suffix", EntryType::FunctionSuffix),
142};
143
145 Entry::DefinitionWithChildren("file", EntryType::LineEntryFile,
147 Definition("number", EntryType::LineEntryLineNumber),
148 Definition("column", EntryType::LineEntryColumn),
149 Definition("start-addr", EntryType::LineEntryStartAddress),
150 Definition("end-addr", EntryType::LineEntryEndAddress),
151};
152
154 "file", EntryType::ModuleFile, g_file_child_entries)};
155
157 Definition("id", EntryType::ProcessID),
158 Definition("name", EntryType::ProcessFile, FileKind::Basename),
159 Entry::DefinitionWithChildren("file", EntryType::ProcessFile,
161
163 Definition("*", EntryType::ParentString)};
164
166 Definition("*", EntryType::ParentString)};
167
169 Definition("id", EntryType::ThreadID),
170 Definition("protocol_id", EntryType::ThreadProtocolID),
171 Definition("index", EntryType::ThreadIndexID),
172 Entry::DefinitionWithChildren("info", EntryType::ThreadInfo,
174 Definition("queue", EntryType::ThreadQueue),
175 Definition("name", EntryType::ThreadName),
176 Definition("stop-reason", EntryType::ThreadStopReason),
177 Definition("stop-reason-raw", EntryType::ThreadStopReasonRaw),
178 Definition("return-value", EntryType::ThreadReturnValue),
179 Definition("completed-expression", EntryType::ThreadCompletedExpression)};
180
182 Definition("arch", EntryType::TargetArch),
183 Entry::DefinitionWithChildren("file", EntryType::TargetFile,
185
187 Definition("count", EntryType::ProgressCount),
188 Definition("message", EntryType::ProgressMessage)};
189
190#define _TO_STR2(_val) #_val
191#define _TO_STR(_val) _TO_STR2(_val)
192
208
224
245
247 Definition("frame", EntryType::ScriptFrame),
248 Definition("process", EntryType::ScriptProcess),
249 Definition("target", EntryType::ScriptTarget),
250 Definition("thread", EntryType::ScriptThread),
251 Definition("var", EntryType::ScriptVariable),
252 Definition("svar", EntryType::ScriptVariableSynthetic),
253 Definition("thread", EntryType::ScriptThread)};
254
256 Entry::DefinitionWithChildren("addr", EntryType::AddressLoadOrFile,
258 Definition("addr-file-or-load", EntryType::AddressLoadOrFile),
259 Entry::DefinitionWithChildren("ansi", EntryType::Invalid, g_ansi_entries),
260 Definition("current-pc-arrow", EntryType::CurrentPCArrow),
261 Entry::DefinitionWithChildren("file", EntryType::File,
263 Definition("language", EntryType::Lang),
264 Entry::DefinitionWithChildren("frame", EntryType::Invalid,
266 Entry::DefinitionWithChildren("function", EntryType::Invalid,
268 Entry::DefinitionWithChildren("line", EntryType::Invalid,
270 Entry::DefinitionWithChildren("module", EntryType::Invalid,
272 Entry::DefinitionWithChildren("process", EntryType::Invalid,
274 Entry::DefinitionWithChildren("script", EntryType::Invalid,
276 Entry::DefinitionWithChildren("svar", EntryType::VariableSynthetic,
278 Entry::DefinitionWithChildren("thread", EntryType::Invalid,
280 Entry::DefinitionWithChildren("target", EntryType::Invalid,
282 Entry::DefinitionWithChildren("var", EntryType::Variable,
283 g_var_child_entries, true),
284 Entry::DefinitionWithChildren("progress", EntryType::Invalid,
286 Definition("separator", EntryType::Separator),
287};
288
290 "<root>", EntryType::Root, g_top_level_entries);
291
292FormatEntity::Entry::Entry(Type t, const char *s, const char *f)
293 : string(s ? s : ""), printf_format(f ? f : ""), children_stack({{}}),
294 type(t) {}
295
297 : string(s.data(), s.size()), children_stack({{}}), type(Type::String) {}
298
300 : string(1, ch), printf_format(), children_stack({{}}), type(Type::String) {
301}
302
303std::vector<Entry> &FormatEntity::Entry::GetChildren() {
304 assert(level < children_stack.size());
305 return children_stack[level];
306}
307
309 auto &entries = GetChildren();
310 if (entries.empty() || entries.back().type != Entry::Type::String)
311 entries.push_back(Entry(ch));
312 else
313 entries.back().string.append(1, ch);
314}
315
316void FormatEntity::Entry::AppendText(const llvm::StringRef &s) {
317 auto &entries = GetChildren();
318 if (entries.empty() || entries.back().type != Entry::Type::String)
319 entries.push_back(Entry(s));
320 else
321 entries.back().string.append(s.data(), s.size());
322}
323
324void FormatEntity::Entry::AppendText(const char *cstr) {
325 return AppendText(llvm::StringRef(cstr));
326}
327
329 auto &entries = GetChildren();
330 entries.push_back(entry);
331}
332
334 assert(type == Entry::Type::Scope);
335 children_stack.emplace_back();
336 level++;
337}
338
339#define ENUM_TO_CSTR(eee) \
340 case FormatEntity::Entry::Type::eee: \
341 return #eee
342
344 switch (t) {
424 }
425 return "???";
426}
427
428#undef ENUM_TO_CSTR
429
430void FormatEntity::Entry::Dump(Stream &s, int depth) const {
431 s.Printf("%*.*s%-20s: ", depth * 2, depth * 2, "", TypeToCString(type));
432 if (fmt != eFormatDefault)
433 s.Printf("lldb-format = %s, ", FormatManager::GetFormatAsCString(fmt));
434 if (!string.empty())
435 s.Printf("string = \"%s\"", string.c_str());
436 if (!printf_format.empty())
437 s.Printf("printf_format = \"%s\"", printf_format.c_str());
438 if (number != 0)
439 s.Printf("number = %" PRIu64 " (0x%" PRIx64 "), ", number, number);
440 if (deref)
441 s.PutCString("deref = true, ");
442 s.EOL();
443 for (const auto &children : children_stack) {
444 for (const auto &child : children)
445 child.Dump(s, depth + 1);
446 }
447}
448
449template <typename T>
451 const ExecutionContext *exe_ctx, T t,
452 const char *script_function_name) {
453 Target *target = Target::GetTargetFromContexts(exe_ctx, sc);
454
455 if (target) {
456 ScriptInterpreter *script_interpreter =
458 if (script_interpreter) {
460 std::string script_output;
461
462 if (script_interpreter->RunScriptFormatKeyword(script_function_name, t,
463 script_output, error) &&
464 error.Success()) {
465 s.PutCString(script_output.c_str());
466 return true;
467 } else {
468 s.Printf("<error: %s>", error.AsCString());
469 }
470 }
471 }
472 return false;
473}
474
476 const ExecutionContext *exe_ctx,
477 const Address &addr,
478 bool print_file_addr_or_load_addr) {
479 Target *target = Target::GetTargetFromContexts(exe_ctx, sc);
480
481 addr_t vaddr = addr.GetLoadAddress(target);
482 if (vaddr == LLDB_INVALID_ADDRESS)
483 vaddr = addr.GetFileAddress();
484 if (vaddr == LLDB_INVALID_ADDRESS)
485 return false;
486
487 int addr_width = 0;
488 if (target)
489 addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
490 if (addr_width == 0)
491 addr_width = 16;
492
493 if (print_file_addr_or_load_addr) {
494 ExecutionContextScope *exe_scope =
495 exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr;
496 addr.Dump(&s, exe_scope, Address::DumpStyleLoadAddress,
498 } else {
499 s.Printf("0x%*.*" PRIx64, addr_width, addr_width, vaddr);
500 }
501
502 return true;
503}
504
506 const ExecutionContext *exe_ctx,
507 const Address &format_addr,
508 bool concrete_only, bool no_padding,
509 bool print_zero_offsets) {
510 if (format_addr.IsValid()) {
511 Address func_addr;
512
513 if (sc) {
514 if (sc->function) {
515 func_addr = sc->function->GetAddress();
516 if (sc->block && !concrete_only) {
517 // Check to make sure we aren't in an inline function. If we are, use
518 // the inline block range that contains "format_addr" since blocks
519 // can be discontiguous.
520 Block *inline_block = sc->block->GetContainingInlinedBlock();
521 AddressRange inline_range;
522 if (inline_block && inline_block->GetRangeContainingAddress(
523 format_addr, inline_range))
524 func_addr = inline_range.GetBaseAddress();
525 }
526 } else if (sc->symbol && sc->symbol->ValueIsAddress())
527 func_addr = sc->symbol->GetAddressRef();
528 }
529
530 if (func_addr.IsValid()) {
531 const char *addr_offset_padding = no_padding ? "" : " ";
532
533 if (func_addr.GetModule() == format_addr.GetModule()) {
534 addr_t func_file_addr = func_addr.GetFileAddress();
535 addr_t addr_file_addr = format_addr.GetFileAddress();
536 if (addr_file_addr > func_file_addr ||
537 (addr_file_addr == func_file_addr && print_zero_offsets)) {
538 s.Printf("%s+%s%" PRIu64, addr_offset_padding, addr_offset_padding,
539 addr_file_addr - func_file_addr);
540 } else if (addr_file_addr < func_file_addr) {
541 s.Printf("%s-%s%" PRIu64, addr_offset_padding, addr_offset_padding,
542 func_file_addr - addr_file_addr);
543 }
544 return true;
545 } else {
546 Target *target = Target::GetTargetFromContexts(exe_ctx, sc);
547 if (target) {
548 addr_t func_load_addr = func_addr.GetLoadAddress(target);
549 addr_t addr_load_addr = format_addr.GetLoadAddress(target);
550 if (addr_load_addr > func_load_addr ||
551 (addr_load_addr == func_load_addr && print_zero_offsets)) {
552 s.Printf("%s+%s%" PRIu64, addr_offset_padding, addr_offset_padding,
553 addr_load_addr - func_load_addr);
554 } else if (addr_load_addr < func_load_addr) {
555 s.Printf("%s-%s%" PRIu64, addr_offset_padding, addr_offset_padding,
556 func_load_addr - addr_load_addr);
557 }
558 return true;
559 }
560 }
561 }
562 }
563 return false;
564}
565
566static bool ScanBracketedRange(llvm::StringRef subpath,
567 size_t &close_bracket_index,
568 const char *&var_name_final_if_array_range,
569 int64_t &index_lower, int64_t &index_higher) {
571 close_bracket_index = llvm::StringRef::npos;
572 const size_t open_bracket_index = subpath.find('[');
573 if (open_bracket_index == llvm::StringRef::npos) {
574 LLDB_LOGF(log,
575 "[ScanBracketedRange] no bracketed range, skipping entirely");
576 return false;
577 }
578
579 close_bracket_index = subpath.find(']', open_bracket_index + 1);
580
581 if (close_bracket_index == llvm::StringRef::npos) {
582 LLDB_LOGF(log,
583 "[ScanBracketedRange] no bracketed range, skipping entirely");
584 return false;
585 } else {
586 var_name_final_if_array_range = subpath.data() + open_bracket_index;
587
588 if (close_bracket_index - open_bracket_index == 1) {
589 LLDB_LOGF(
590 log,
591 "[ScanBracketedRange] '[]' detected.. going from 0 to end of data");
592 index_lower = 0;
593 } else {
594 const size_t separator_index = subpath.find('-', open_bracket_index + 1);
595
596 if (separator_index == llvm::StringRef::npos) {
597 const char *index_lower_cstr = subpath.data() + open_bracket_index + 1;
598 index_lower = ::strtoul(index_lower_cstr, nullptr, 0);
599 index_higher = index_lower;
600 LLDB_LOGF(log,
601 "[ScanBracketedRange] [%" PRId64
602 "] detected, high index is same",
603 index_lower);
604 } else {
605 const char *index_lower_cstr = subpath.data() + open_bracket_index + 1;
606 const char *index_higher_cstr = subpath.data() + separator_index + 1;
607 index_lower = ::strtoul(index_lower_cstr, nullptr, 0);
608 index_higher = ::strtoul(index_higher_cstr, nullptr, 0);
609 LLDB_LOGF(log,
610 "[ScanBracketedRange] [%" PRId64 "-%" PRId64 "] detected",
611 index_lower, index_higher);
612 }
613 if (index_lower > index_higher && index_higher > 0) {
614 LLDB_LOGF(log, "[ScanBracketedRange] swapping indices");
615 const int64_t temp = index_lower;
616 index_lower = index_higher;
617 index_higher = temp;
618 }
619 }
620 }
621 return true;
622}
623
624/// Dump a string set by the inferior. Non-printable characters are escaped so
625/// the string cannot send control sequences to the terminal.
626static void DumpEscaped(Stream &s, llvm::StringRef str) {
628 options.SetData(DataExtractor(str.data(), str.size(),
629 endian::InlHostByteOrder(), sizeof(void *)));
630 options.SetSourceSize(str.size());
631 options.SetStream(&s);
632 options.SetQuote('\0');
634 formatters::StringPrinter::StringElementType::UTF8>(options);
635}
636
637static bool DumpFile(Stream &s, const FileSpec &file, FileKind file_kind) {
638 switch (file_kind) {
640 break;
641
643 if (!file.GetFilename().empty()) {
644 s << file.GetFilename();
645 return true;
646 }
647 break;
648
650 if (!file.GetDirectory().empty()) {
651 s << file.GetDirectory();
652 return true;
653 }
654 break;
655
657 if (file) {
658 s << file;
659 return true;
660 }
661 break;
662 }
663 return false;
664}
665
666static bool DumpRegister(Stream &s, StackFrame *frame, RegisterKind reg_kind,
667 uint32_t reg_num, Format format) {
668 if (frame) {
669 RegisterContext *reg_ctx = frame->GetRegisterContext().get();
670
671 if (reg_ctx) {
672 const uint32_t lldb_reg_num =
673 reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
674 if (lldb_reg_num != LLDB_INVALID_REGNUM) {
675 const RegisterInfo *reg_info =
676 reg_ctx->GetRegisterInfoAtIndex(lldb_reg_num);
677 if (reg_info) {
678 RegisterValue reg_value;
679 if (reg_ctx->ReadRegister(reg_info, reg_value)) {
680 DumpRegisterValue(reg_value, s, *reg_info, false, false, format);
681 return true;
682 }
683 }
684 }
685 }
686 }
687 return false;
688}
689
691 bool deref_pointer) {
693 std::string name_to_deref = llvm::formatv("[{0}]", index);
694 LLDB_LOG(log, "[ExpandIndexedExpression] name to deref: {0}", name_to_deref);
702 name_to_deref, &reason_to_stop, &final_value_type, options, &what_next);
703 if (!item) {
704 LLDB_LOGF(log,
705 "[ExpandIndexedExpression] ERROR: why stopping = %d,"
706 " final_value_type %d",
707 reason_to_stop, final_value_type);
708 } else {
709 LLDB_LOGF(log,
710 "[ExpandIndexedExpression] ALL RIGHT: why stopping = %d,"
711 " final_value_type %d",
712 reason_to_stop, final_value_type);
713 }
714 return item;
715}
716
739
740/// Options supported by format_provider<T> for integral arithmetic types.
741/// See table in FormatProviders.h.
742static llvm::Regex LLVMFormatPattern{"x[-+]?\\d*|n|d", llvm::Regex::IgnoreCase};
743
744static bool DumpValueWithLLVMFormat(Stream &s, llvm::StringRef options,
745 ValueObject &valobj) {
746 std::string formatted;
747 std::string llvm_format = ("{0:" + options + "}").str();
748
749 auto type_info = valobj.GetTypeInfo();
750 if ((type_info & eTypeIsInteger) && LLVMFormatPattern.match(options)) {
751 if (type_info & eTypeIsSigned) {
752 bool success = false;
753 int64_t integer = valobj.GetValueAsSigned(0, &success);
754 if (success)
755 formatted = llvm::formatv(llvm_format.data(), integer);
756 } else {
757 bool success = false;
758 uint64_t integer = valobj.GetValueAsUnsigned(0, &success);
759 if (success)
760 formatted = llvm::formatv(llvm_format.data(), integer);
761 }
762 }
763
764 if (formatted.empty())
765 return false;
766
767 s.Write(formatted.data(), formatted.size());
768 return true;
769}
770
772 const FormatEntity::Entry &entry,
773 ValueObject *valobj) {
774 if (valobj == nullptr)
775 return false;
776
778 enum Format custom_format = eFormatInvalid;
780 entry.string.empty()
783
784 bool do_deref_pointer = entry.deref;
785 bool is_script = false;
786 switch (entry.type) {
788 is_script = true;
789 break;
790
792 custom_format = entry.fmt;
794 break;
795
797 is_script = true;
798 [[fallthrough]];
800 custom_format = entry.fmt;
802 if (!valobj->IsSynthetic()) {
803 valobj = valobj->GetSyntheticValue().get();
804 if (valobj == nullptr)
805 return false;
806 }
807 break;
808
809 default:
810 return false;
811 }
812
822 SyntheticChildrenTraversal::Both);
823 ValueObject *target = nullptr;
824 const char *var_name_final_if_array_range = nullptr;
825 size_t close_bracket_index = llvm::StringRef::npos;
826 int64_t index_lower = -1;
827 int64_t index_higher = -1;
828 bool is_array_range = false;
829 bool was_plain_var = false;
830 bool was_var_format = false;
831 bool was_var_indexed = false;
836
837 if (is_script) {
838 return RunScriptFormatKeyword(s, m_sc, m_exe_ctx, valobj,
839 entry.string.c_str());
840 }
841
842 auto split = llvm::StringRef(entry.string).split(':');
843 auto subpath = split.first;
844 auto llvm_format = split.second;
845
846 // simplest case ${var}, just print valobj's value
847 if (subpath.empty()) {
848 if (entry.printf_format.empty() && entry.fmt == eFormatDefault &&
850 was_plain_var = true;
851 else
852 was_var_format = true;
853 target = valobj;
854 } else // this is ${var.something} or multiple .something nested
855 {
856 if (subpath[0] == '[')
857 was_var_indexed = true;
858 ScanBracketedRange(subpath, close_bracket_index,
859 var_name_final_if_array_range, index_lower,
860 index_higher);
861
863
864 LLDB_LOG(log, "[Debugger::FormatPrompt] symbol to expand: {0}", subpath);
865
866 target =
867 valobj
868 ->GetValueForExpressionPath(subpath, &reason_to_stop,
869 &final_value_type, options, &what_next)
870 .get();
871
872 if (!target) {
873 LLDB_LOGF(log,
874 "[Debugger::FormatPrompt] ERROR: why stopping = %d,"
875 " final_value_type %d",
876 reason_to_stop, final_value_type);
877 return false;
878 } else {
879 LLDB_LOGF(log,
880 "[Debugger::FormatPrompt] ALL RIGHT: why stopping = %d,"
881 " final_value_type %d",
882 reason_to_stop, final_value_type);
883 target = target
885 target->GetDynamicValueType(), true)
886 .get();
887 }
888 }
889
890 is_array_range =
891 (final_value_type ==
893 final_value_type ==
895
896 do_deref_pointer =
898
899 if (do_deref_pointer && !is_array_range) {
900 // I have not deref-ed yet, let's do it
901 // this happens when we are not going through
902 // GetValueForVariableExpressionPath to get to the target ValueObject
904 target = target->Dereference(error).get();
905 if (error.Fail()) {
906 LLDB_LOGF(log, "[Debugger::FormatPrompt] ERROR: %s\n",
907 error.AsCString("unknown"));
908 return false;
909 }
910 do_deref_pointer = false;
911 }
912
913 if (!target) {
914 LLDB_LOGF(log, "[Debugger::FormatPrompt] could not calculate target for "
915 "prompt expression");
916 return false;
917 }
918
919 // we do not want to use the summary for a bitfield of type T:n if we were
920 // originally dealing with just a T - that would get us into an endless
921 // recursion
922 if (target->IsBitfield() && was_var_indexed) {
923 // TODO: check for a (T:n)-specific summary - we should still obey that
924 StreamString bitfield_name;
925 bitfield_name.Format("{0}:{1}", target->GetTypeName(),
926 target->GetBitfieldBitSize());
927 auto type_sp = std::make_shared<TypeNameSpecifierImpl>(
928 bitfield_name.GetString(), lldb::eFormatterMatchExact);
929 if (val_obj_display ==
933 }
934
935 // TODO use flags for these
936 const uint32_t type_info_flags =
937 target->GetCompilerType().GetTypeInfo(nullptr);
938 bool is_array = (type_info_flags & eTypeIsArray) != 0;
939 bool is_pointer = (type_info_flags & eTypeIsPointer) != 0;
940 bool is_aggregate = target->GetCompilerType().IsAggregateType();
941
942 if ((is_array || is_pointer) && (!is_array_range) &&
943 val_obj_display ==
945 // wrong, but there
946 // are some
947 // exceptions
948 {
949 StreamString str_temp;
950 LLDB_LOGF(log,
951 "[Debugger::FormatPrompt] I am into array || pointer && !range");
952
953 if (target->HasSpecialPrintableRepresentation(val_obj_display,
954 custom_format)) {
955 // try to use the special cases
956 bool success = target->DumpPrintableRepresentation(
957 str_temp, val_obj_display, custom_format);
958 LLDB_LOGF(log, "[Debugger::FormatPrompt] special cases did%s match",
959 success ? "" : "n't");
960
961 // should not happen
962 if (success)
963 s << str_temp.GetString();
964 return true;
965 } else {
966 if (was_plain_var) // if ${var}
967 {
968 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
969 } else if (is_pointer) // if pointer, value is the address stored
970 {
972 s, val_obj_display, custom_format,
974 }
975 return true;
976 }
977 }
978
979 // if directly trying to print ${var}, and this is an aggregate, display a
980 // nice type @ location message
981 if (is_aggregate && was_plain_var) {
982 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
983 return true;
984 }
985
986 // if directly trying to print ${var%V}, and this is an aggregate, do not let
987 // the user do it
988 if (is_aggregate &&
989 ((was_var_format &&
990 val_obj_display ==
992 s << "<invalid use of aggregate type>";
993 return true;
994 }
995
996 if (!is_array_range) {
997 if (!llvm_format.empty()) {
998 if (DumpValueWithLLVMFormat(s, llvm_format, *target)) {
999 LLDB_LOGF(log, "dumping using llvm format");
1000 return true;
1001 } else {
1002 LLDB_LOG(
1003 log,
1004 "empty output using llvm format '{0}' - with type info flags {1}",
1005 entry.printf_format, target->GetTypeInfo());
1006 }
1007 }
1008 LLDB_LOGF(log, "dumping ordinary printable output");
1009 return target->DumpPrintableRepresentation(s, val_obj_display,
1010 custom_format);
1011 } else {
1012 LLDB_LOGF(log,
1013 "[Debugger::FormatPrompt] checking if I can handle as array");
1014 if (!is_array && !is_pointer)
1015 return false;
1016 LLDB_LOGF(log, "[Debugger::FormatPrompt] handle as array");
1017 StreamString special_directions_stream;
1018 llvm::StringRef special_directions;
1019 if (close_bracket_index != llvm::StringRef::npos &&
1020 subpath.size() > close_bracket_index) {
1021 llvm::StringRef additional_data(
1022 subpath.drop_front(close_bracket_index + 1));
1023 special_directions_stream
1024 << "${"
1025 << llvm::formatv("{0}var{1}", do_deref_pointer ? "*" : "",
1026 additional_data);
1027
1028 if (entry.fmt != eFormatDefault) {
1029 const char format_char =
1031 if (format_char != '\0')
1032 special_directions_stream.Printf("%%%c", format_char);
1033 else {
1034 const char *format_cstr =
1036 special_directions_stream.Printf("%%%s", format_cstr);
1037 }
1038 } else if (entry.number != 0) {
1039 const char style_char = ConvertValueObjectStyleToChar(
1041 if (style_char)
1042 special_directions_stream.Printf("%%%c", style_char);
1043 }
1044 special_directions_stream.PutChar('}');
1045 special_directions =
1046 llvm::StringRef(special_directions_stream.GetString());
1047 }
1048
1049 // let us display items index_lower thru index_higher of this array
1050 s.PutChar('[');
1051
1052 if (index_higher < 0)
1053 index_higher = valobj->GetNumChildrenIgnoringErrors() - 1;
1054
1055 uint32_t max_num_children =
1056 target->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
1057
1058 bool success = true;
1059 for (int64_t index = index_lower; index <= index_higher; ++index) {
1060 ValueObject *item = ExpandIndexedExpression(target, index, false).get();
1061
1062 if (!item) {
1063 LLDB_LOGF(log,
1064 "[Debugger::FormatPrompt] ERROR in getting child item at "
1065 "index %" PRId64,
1066 index);
1067 } else {
1068 LLDB_LOGF(
1069 log,
1070 "[Debugger::FormatPrompt] special_directions for child item: %s",
1071 special_directions.data() ? special_directions.data() : "");
1072 }
1073
1074 if (special_directions.empty()) {
1075 success &= item->DumpPrintableRepresentation(s, val_obj_display,
1076 custom_format);
1077 } else {
1078 success &= FormatStringRef(special_directions, s, item);
1079 }
1080
1081 if (--max_num_children == 0) {
1082 s.PutCString(", ...");
1083 break;
1084 }
1085
1086 if (index < index_higher)
1087 s.PutChar(',');
1088 }
1089 s.PutChar(']');
1090 return success;
1091 }
1092}
1093
1094static bool DumpRegister(Stream &s, StackFrame *frame, const char *reg_name,
1095 Format format) {
1096 if (frame) {
1097 RegisterContext *reg_ctx = frame->GetRegisterContext().get();
1098
1099 if (reg_ctx) {
1100 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(reg_name);
1101 if (reg_info) {
1102 RegisterValue reg_value;
1103 if (reg_ctx->ReadRegister(reg_info, reg_value)) {
1104 DumpRegisterValue(reg_value, s, *reg_info, false, false, format);
1105 return true;
1106 }
1107 }
1108 }
1109 }
1110 return false;
1111}
1112
1114 const FormatEntity::Entry &entry,
1115 const StructuredData::ObjectSP &thread_info_dictionary,
1116 const SymbolContext *sc, const ExecutionContext *exe_ctx, Stream &s) {
1117 llvm::StringRef path(entry.string);
1118
1120 thread_info_dictionary->GetObjectForDotSeparatedPath(path);
1121
1122 if (value) {
1123 if (value->GetType() == eStructuredDataTypeInteger) {
1124 const char *token_format = "0x%4.4" PRIx64;
1125 if (!entry.printf_format.empty())
1126 token_format = entry.printf_format.c_str();
1127 s.Printf(token_format, value->GetUnsignedIntegerValue());
1128 return true;
1129 } else if (value->GetType() == eStructuredDataTypeFloat) {
1130 s.Printf("%f", value->GetAsFloat()->GetValue());
1131 return true;
1132 } else if (value->GetType() == eStructuredDataTypeString) {
1133 s.Format("{0}", value->GetAsString()->GetValue());
1134 return true;
1135 } else if (value->GetType() == eStructuredDataTypeArray) {
1136 if (value->GetAsArray()->GetSize() > 0) {
1137 s.Printf("%zu", value->GetAsArray()->GetSize());
1138 return true;
1139 }
1140 } else if (value->GetType() == eStructuredDataTypeDictionary) {
1141 s.Printf("%zu",
1142 value->GetAsDictionary()->GetKeys()->GetAsArray()->GetSize());
1143 return true;
1144 }
1145 }
1146
1147 return false;
1148}
1149
1150static inline bool IsToken(const char *var_name_begin, const char *var) {
1151 return (::strncmp(var_name_begin, var, strlen(var)) == 0);
1152}
1153
1154/// Parses the basename out of a demangled function name
1155/// that may include function arguments. Supports
1156/// template functions.
1157///
1158/// Returns pointers to the opening and closing parenthesis of
1159/// `full_name`. Can return nullptr for either parenthesis if
1160/// none is exists.
1161static std::pair<char const *, char const *>
1162ParseBaseName(char const *full_name) {
1163 const char *open_paren = strchr(full_name, '(');
1164 const char *close_paren = nullptr;
1165 const char *generic = strchr(full_name, '<');
1166 // if before the arguments list begins there is a template sign
1167 // then scan to the end of the generic args before you try to find
1168 // the arguments list
1169 if (generic && open_paren && generic < open_paren) {
1170 int generic_depth = 1;
1171 ++generic;
1172 for (; *generic && generic_depth > 0; generic++) {
1173 if (*generic == '<')
1174 generic_depth++;
1175 if (*generic == '>')
1176 generic_depth--;
1177 }
1178 if (*generic)
1179 open_paren = strchr(generic, '(');
1180 else
1181 open_paren = nullptr;
1182 }
1183
1184 if (open_paren) {
1185 if (IsToken(open_paren, "(anonymous namespace)")) {
1186 open_paren = strchr(open_paren + strlen("(anonymous namespace)"), '(');
1187 if (open_paren)
1188 close_paren = strchr(open_paren, ')');
1189 } else
1190 close_paren = strchr(open_paren, ')');
1191 }
1192
1193 return {open_paren, close_paren};
1194}
1195
1196/// Writes out the function name in 'full_name' to 'out_stream'
1197/// but replaces each argument type with the variable name
1198/// and the corresponding pretty-printed value
1200 char const *full_name,
1201 ExecutionContextScope *exe_scope,
1202 VariableList const &args) {
1203 auto [open_paren, close_paren] = ParseBaseName(full_name);
1204 if (open_paren)
1205 out_stream.Write(full_name, open_paren - full_name + 1);
1206 else {
1207 out_stream.PutCString(full_name);
1208 out_stream.PutChar('(');
1209 }
1210
1211 FormatEntity::PrettyPrintFunctionArguments(out_stream, args, exe_scope);
1212
1213 if (close_paren)
1214 out_stream.PutCString(close_paren);
1215 else
1216 out_stream.PutChar(')');
1217}
1218
1220 assert(sc.function);
1221
1222 if (sc.block)
1223 if (Block *inline_block = sc.block->GetContainingInlinedBlock())
1224 return inline_block->GetBlockVariableList(true);
1225
1226 return sc.function->GetBlock(true).GetBlockVariableList(true);
1227}
1228
1230 const ExecutionContext *exe_ctx,
1231 const SymbolContext &sc) {
1232 assert(sc.function);
1233
1234 ExecutionContextScope *exe_scope =
1235 exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr;
1236
1237 const char *cstr = sc.GetPossiblyInlinedFunctionName()
1239 .AsCString(nullptr);
1240 if (!cstr)
1241 return false;
1242
1243 VariableList args;
1244 if (auto variable_list_sp = GetFunctionVariableList(sc))
1246 args);
1247
1248 if (args.GetSize() > 0) {
1249 PrettyPrintFunctionNameWithArgs(s, cstr, exe_scope, args);
1250 } else {
1251 s.PutCString(cstr);
1252 }
1253
1254 return true;
1255}
1256
1258 const ExecutionContext *exe_ctx,
1259 const SymbolContext &sc) {
1260 Language *language_plugin = nullptr;
1261 bool language_plugin_handled = false;
1262 StreamString ss;
1263 if (sc.function)
1264 language_plugin = Language::FindPlugin(sc.function->GetLanguage());
1265 else if (sc.symbol)
1266 language_plugin = Language::FindPlugin(sc.symbol->GetLanguage());
1267
1268 if (language_plugin)
1269 language_plugin_handled = language_plugin->GetFunctionDisplayName(
1271
1272 if (language_plugin_handled) {
1273 s << ss.GetString();
1274 return true;
1275 }
1276
1277 if (sc.function)
1278 return PrintFunctionNameWithArgs(s, exe_ctx, sc);
1279
1280 if (!sc.symbol)
1281 return false;
1282
1283 const char *cstr = sc.symbol->GetName().AsCString(nullptr);
1284 if (!cstr)
1285 return false;
1286
1287 s.PutCString(cstr);
1288
1289 return true;
1290}
1291
1293 assert(m_sc);
1294
1295 Language *language_plugin = nullptr;
1296 if (m_sc->function)
1297 language_plugin = Language::FindPlugin(m_sc->function->GetLanguage());
1298 else if (m_sc->symbol)
1299 language_plugin = Language::FindPlugin(m_sc->symbol->GetLanguage());
1300
1301 if (!language_plugin)
1302 return false;
1303
1304 FormatEntity::Entry format = language_plugin->GetFunctionNameFormat();
1305
1306 // Bail on invalid or empty format.
1307 if (!format || format == FormatEntity::Entry(Entry::Type::Root))
1308 return false;
1309
1310 StreamString name_stream;
1311 const bool success = Format(format, name_stream, /*valobj=*/nullptr);
1312 if (success)
1313 s << name_stream.GetString();
1314
1315 return success;
1316}
1317
1318bool FormatEntity::Formatter::FormatStringRef(const llvm::StringRef &format_str,
1319 Stream &s, ValueObject *valobj) {
1320 if (!format_str.empty()) {
1322 Status error = FormatEntity::Parse(format_str, root);
1323 if (error.Success()) {
1324 return Format(root, s, valobj);
1325 }
1326 }
1327 return false;
1328}
1329
1331 ValueObject *valobj) {
1332 if (IsInvalidRecursiveFormat(entry.type)) {
1334 "Error: detected recursive format entity: {0}",
1336 return false;
1337 }
1338
1339 auto entry_stack_guard = PushEntryType(entry.type);
1340
1341 switch (entry.type) {
1343 case Entry::Type::ParentNumber: // Only used for
1344 // FormatEntity::Entry::Definition encoding
1345 case Entry::Type::ParentString: // Only used for
1346 // FormatEntity::Entry::Definition encoding
1347 return false;
1350 Debugger &debugger = target->GetDebugger();
1351 if (debugger.GetUseColor()) {
1352 s.PutCString(entry.string);
1353 }
1354 }
1355 // Always return true, so colors being disabled is transparent.
1356 return true;
1357
1358 case Entry::Type::Root:
1359 for (const auto &child : entry.children_stack[0]) {
1360 if (!Format(child, s, valobj)) {
1361 return false; // If any item of root fails, then the formatting fails
1362 }
1363 }
1364 return true; // Only return true if all items succeeded
1365
1367 s.PutCString(entry.string);
1368 return true;
1369
1370 case Entry::Type::Scope: {
1371 StreamString scope_stream;
1372 auto format_children = [&](const std::vector<Entry> &children) {
1373 scope_stream.Clear();
1374 for (const auto &child : children) {
1375 if (!Format(child, scope_stream, valobj))
1376 return false;
1377 }
1378 return true;
1379 };
1380
1381 for (auto &children : entry.children_stack) {
1382 if (format_children(children)) {
1383 s.Write(scope_stream.GetString().data(),
1384 scope_stream.GetString().size());
1385 return true;
1386 }
1387 }
1388
1389 return true; // Scopes always successfully print themselves
1390 }
1391
1396 return DumpValue(s, entry, valobj);
1397
1401 return (
1402 m_addr != nullptr && m_addr->IsValid() &&
1405
1407 if (m_exe_ctx) {
1408 Process *process = m_exe_ctx->GetProcessPtr();
1409 if (process) {
1410 const char *format = "%" PRIu64;
1411 if (!entry.printf_format.empty())
1412 format = entry.printf_format.c_str();
1413 s.Printf(format, process->GetID());
1414 return true;
1415 }
1416 }
1417 return false;
1418
1420 if (m_exe_ctx) {
1421 Process *process = m_exe_ctx->GetProcessPtr();
1422 if (process) {
1423 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
1424 if (exe_module) {
1425 if (DumpFile(s, exe_module->GetFileSpec(), (FileKind)entry.number))
1426 return true;
1427 }
1428 }
1429 }
1430 return false;
1431
1433 if (m_exe_ctx) {
1434 Process *process = m_exe_ctx->GetProcessPtr();
1435 if (process)
1436 return RunScriptFormatKeyword(s, m_sc, m_exe_ctx, process,
1437 entry.string.c_str());
1438 }
1439 return false;
1440
1442 if (m_exe_ctx) {
1443 Thread *thread = m_exe_ctx->GetThreadPtr();
1444 if (thread) {
1445 const char *format = "0x%4.4" PRIx64;
1446 if (!entry.printf_format.empty()) {
1447 // Watch for the special "tid" format...
1448 if (entry.printf_format == "tid") {
1449 // TODO(zturner): Rather than hardcoding this to be platform
1450 // specific, it should be controlled by a setting and the default
1451 // value of the setting can be different depending on the platform.
1452 Target &target = thread->GetProcess()->GetTarget();
1453 ArchSpec arch(target.GetArchitecture());
1454 llvm::Triple::OSType ostype = arch.IsValid()
1455 ? arch.GetTriple().getOS()
1456 : llvm::Triple::UnknownOS;
1457 if (ostype == llvm::Triple::FreeBSD ||
1458 ostype == llvm::Triple::Linux ||
1459 ostype == llvm::Triple::NetBSD ||
1460 ostype == llvm::Triple::OpenBSD) {
1461 format = "%" PRIu64;
1462 }
1463 } else {
1464 format = entry.printf_format.c_str();
1465 }
1466 }
1467 s.Printf(format, thread->GetID());
1468 return true;
1469 }
1470 }
1471 return false;
1472
1474 if (m_exe_ctx) {
1475 Thread *thread = m_exe_ctx->GetThreadPtr();
1476 if (thread) {
1477 const char *format = "0x%4.4" PRIx64;
1478 if (!entry.printf_format.empty())
1479 format = entry.printf_format.c_str();
1480 s.Printf(format, thread->GetProtocolID());
1481 return true;
1482 }
1483 }
1484 return false;
1485
1487 if (m_exe_ctx) {
1488 Thread *thread = m_exe_ctx->GetThreadPtr();
1489 if (thread) {
1490 const char *format = "%" PRIu32;
1491 if (!entry.printf_format.empty())
1492 format = entry.printf_format.c_str();
1493 s.Printf(format, thread->GetIndexID());
1494 return true;
1495 }
1496 }
1497 return false;
1498
1500 if (m_exe_ctx) {
1501 Thread *thread = m_exe_ctx->GetThreadPtr();
1502 if (thread) {
1503 const char *cstr = thread->GetName();
1504 if (cstr && cstr[0]) {
1505 DumpEscaped(s, cstr);
1506 return true;
1507 }
1508 }
1509 }
1510 return false;
1511
1513 if (m_exe_ctx) {
1514 Thread *thread = m_exe_ctx->GetThreadPtr();
1515 if (thread) {
1516 const char *cstr = thread->GetQueueName();
1517 if (cstr && cstr[0]) {
1518 DumpEscaped(s, cstr);
1519 return true;
1520 }
1521 }
1522 }
1523 return false;
1524
1526 if (m_exe_ctx) {
1527 if (Thread *thread = m_exe_ctx->GetThreadPtr()) {
1528 std::string stop_description = thread->GetStopDescription();
1529 if (!stop_description.empty()) {
1530 s.PutCString(stop_description);
1531 return true;
1532 }
1533 }
1534 }
1535 return false;
1536
1538 if (m_exe_ctx) {
1539 if (Thread *thread = m_exe_ctx->GetThreadPtr()) {
1540 std::string stop_description = thread->GetStopDescriptionRaw();
1541 if (!stop_description.empty()) {
1542 s.PutCString(stop_description);
1543 return true;
1544 }
1545 }
1546 }
1547 return false;
1548
1550 if (m_exe_ctx) {
1551 Thread *thread = m_exe_ctx->GetThreadPtr();
1552 if (thread) {
1553 StopInfoSP stop_info_sp = thread->GetStopInfo();
1554 if (stop_info_sp && stop_info_sp->IsValid()) {
1555 ThreadPlanReturnValue return_value =
1556 StopInfo::GetReturnValue(stop_info_sp);
1557 ValueObjectSP return_valobj_sp;
1558 if (auto *returned = std::get_if<ReturnedValue>(&return_value))
1559 return_valobj_sp = returned->valobj_sp;
1560 else if (auto *thrown = std::get_if<ThrownError>(&return_value))
1561 return_valobj_sp = thrown->valobj_sp;
1562 if (return_valobj_sp) {
1563 DumpValueObjectOptions options;
1564 if (return_valobj_sp->IsDynamic())
1566 if (return_valobj_sp->DoesProvideSyntheticValue())
1567 options.SetUseSyntheticValue(true);
1568 if (llvm::Error error = return_valobj_sp->Dump(s, options)) {
1569 s << "error: " << toString(std::move(error));
1570 return false;
1571 }
1572 return true;
1573 }
1574 }
1575 }
1576 }
1577 return false;
1578
1580 if (m_exe_ctx) {
1581 Thread *thread = m_exe_ctx->GetThreadPtr();
1582 if (thread) {
1583 StopInfoSP stop_info_sp = thread->GetStopInfo();
1584 if (stop_info_sp && stop_info_sp->IsValid()) {
1585 ExpressionVariableSP expression_var_sp =
1586 StopInfo::GetExpressionVariable(stop_info_sp);
1587 if (expression_var_sp && expression_var_sp->GetValueObject()) {
1588 if (llvm::Error error =
1589 expression_var_sp->GetValueObject()->Dump(s)) {
1590 s << "error: " << toString(std::move(error));
1591 return false;
1592 }
1593 return true;
1594 }
1595 }
1596 }
1597 }
1598 return false;
1599
1601 if (m_exe_ctx) {
1602 Thread *thread = m_exe_ctx->GetThreadPtr();
1603 if (thread)
1604 return RunScriptFormatKeyword(s, m_sc, m_exe_ctx, thread,
1605 entry.string.c_str());
1606 }
1607 return false;
1608
1610 if (m_exe_ctx) {
1611 Thread *thread = m_exe_ctx->GetThreadPtr();
1612 if (thread) {
1613 StructuredData::ObjectSP object_sp = thread->GetExtendedInfo();
1614 if (object_sp &&
1615 object_sp->GetType() == eStructuredDataTypeDictionary) {
1616 if (FormatThreadExtendedInfoRecurse(entry, object_sp, m_sc, m_exe_ctx,
1617 s))
1618 return true;
1619 }
1620 }
1621 }
1622 return false;
1623
1625 if (m_exe_ctx) {
1626 Target *target = m_exe_ctx->GetTargetPtr();
1627 if (target) {
1628 const ArchSpec &arch = target->GetArchitecture();
1629 if (arch.IsValid()) {
1631 return true;
1632 }
1633 }
1634 }
1635 return false;
1636
1638 if (m_exe_ctx) {
1639 if (Target *target = m_exe_ctx->GetTargetPtr()) {
1640 if (Module *exe_module = target->GetExecutableModulePointer()) {
1641 if (DumpFile(s, exe_module->GetFileSpec(), (FileKind)entry.number))
1642 return true;
1643 }
1644 }
1645 }
1646 return false;
1647
1649 if (m_exe_ctx) {
1650 Target *target = m_exe_ctx->GetTargetPtr();
1651 if (target)
1652 return RunScriptFormatKeyword(s, m_sc, m_exe_ctx, target,
1653 entry.string.c_str());
1654 }
1655 return false;
1656
1658 if (m_sc) {
1659 Module *module = m_sc->module_sp.get();
1660 if (module) {
1661 if (DumpFile(s, module->GetFileSpec(), (FileKind)entry.number))
1662 return true;
1663 }
1664 }
1665 return false;
1666
1667 case Entry::Type::File:
1668 if (m_sc) {
1669 CompileUnit *cu = m_sc->comp_unit;
1670 if (cu) {
1671 if (DumpFile(s, cu->GetPrimaryFile(), (FileKind)entry.number))
1672 return true;
1673 }
1674 }
1675 return false;
1676
1677 case Entry::Type::Lang:
1678 if (m_sc) {
1679 CompileUnit *cu = m_sc->comp_unit;
1680 if (cu) {
1681 const char *lang_name =
1683 if (lang_name) {
1684 s.PutCString(lang_name);
1685 return true;
1686 }
1687 }
1688 }
1689 return false;
1690
1692 if (m_exe_ctx) {
1693 StackFrame *frame = m_exe_ctx->GetFramePtr();
1694 if (frame) {
1695 const char *format = "%" PRIu32;
1696 if (!entry.printf_format.empty())
1697 format = entry.printf_format.c_str();
1698 s.Printf(format, frame->GetFrameIndex());
1699 return true;
1700 }
1701 }
1702 return false;
1703
1705 if (m_exe_ctx) {
1706 StackFrame *frame = m_exe_ctx->GetFramePtr();
1707 if (frame) {
1708 const Address &pc_addr = frame->GetFrameCodeAddress();
1709 if (pc_addr.IsValid())
1710 if (DumpAddressAndContent(s, m_sc, m_exe_ctx, pc_addr, false))
1711 return true;
1712 }
1713 }
1714 return false;
1715
1717 if (m_exe_ctx) {
1718 StackFrame *frame = m_exe_ctx->GetFramePtr();
1719 if (frame) {
1721 (lldb::Format)entry.number))
1722 return true;
1723 }
1724 }
1725 return false;
1726
1728 if (m_exe_ctx) {
1729 StackFrame *frame = m_exe_ctx->GetFramePtr();
1730 if (frame) {
1732 (lldb::Format)entry.number))
1733 return true;
1734 }
1735 }
1736 return false;
1737
1739 if (m_exe_ctx) {
1740 StackFrame *frame = m_exe_ctx->GetFramePtr();
1741 if (frame) {
1742 if (DumpRegister(s, frame, eRegisterKindGeneric,
1744 return true;
1745 }
1746 }
1747 return false;
1748
1750 if (m_exe_ctx) {
1751 StackFrame *frame = m_exe_ctx->GetFramePtr();
1752 if (frame) {
1753 return !frame->HasDebugInformation();
1754 }
1755 }
1756 return true;
1757
1759 if (m_exe_ctx) {
1760 StackFrame *frame = m_exe_ctx->GetFramePtr();
1761 if (frame) {
1762 if (DumpRegister(s, frame, entry.string.c_str(),
1763 (lldb::Format)entry.number))
1764 return true;
1765 }
1766 }
1767 return false;
1768
1770 if (m_exe_ctx)
1771 if (StackFrame *frame = m_exe_ctx->GetFramePtr())
1772 return frame->IsArtificial();
1773 return false;
1774 }
1775
1777 if (m_exe_ctx)
1778 if (StackFrame *frame = m_exe_ctx->GetFramePtr()) {
1779 if (frame->IsSynthetic())
1780 s.PutCString(" [synthetic]");
1781 else if (frame->IsHistorical())
1782 s.PutCString(" [history]");
1783 return true;
1784 }
1785 return false;
1786 }
1787
1789 if (m_exe_ctx)
1790 if (StackFrame *frame = m_exe_ctx->GetFramePtr()) {
1791 if (BorrowedStackFrame *borrowed_frame =
1792 llvm::dyn_cast<BorrowedStackFrame>(frame)) {
1793 if (lldb::StackFrameSP borrowed_from_sp =
1794 borrowed_frame->GetBorrowedFrame()) {
1795 s.Printf(" [borrowed from frame #%u]",
1796 borrowed_from_sp->GetFrameIndex());
1797 return true;
1798 }
1799 }
1800 }
1801 return false;
1802 }
1803
1805 if (m_exe_ctx) {
1806 StackFrame *frame = m_exe_ctx->GetFramePtr();
1807 if (frame)
1808 return RunScriptFormatKeyword(s, m_sc, m_exe_ctx, frame,
1809 entry.string.c_str());
1810 }
1811 return false;
1812
1814 if (m_sc) {
1815 if (m_sc->function) {
1816 s.Printf("function{0x%8.8" PRIx64 "}", m_sc->function->GetID());
1817 return true;
1818 } else if (m_sc->symbol) {
1819 s.Printf("symbol[%u]", m_sc->symbol->GetID());
1820 return true;
1821 }
1822 }
1823 return false;
1824
1826 return m_function_changed;
1827
1829 return m_initial_function;
1830
1832 if (m_sc) {
1833 Language *language_plugin = nullptr;
1834 bool language_plugin_handled = false;
1835 StreamString ss;
1836
1837 if (m_sc->function)
1838 language_plugin = Language::FindPlugin(m_sc->function->GetLanguage());
1839 else if (m_sc->symbol)
1840 language_plugin = Language::FindPlugin(m_sc->symbol->GetLanguage());
1841
1842 if (language_plugin)
1843 language_plugin_handled = language_plugin->GetFunctionDisplayName(
1845
1846 if (language_plugin_handled) {
1847 s << ss.GetString();
1848 return true;
1849 }
1850
1851 const char *name = m_sc->GetPossiblyInlinedFunctionName()
1853 .AsCString(nullptr);
1854 if (name) {
1855 s.PutCString(name);
1856 return true;
1857 }
1858 }
1859
1860 // Fallback to frame methods if available.
1861 if (m_exe_ctx) {
1862 StackFrame *frame = m_exe_ctx->GetFramePtr();
1863 if (frame) {
1864 const char *name = frame->GetFunctionName();
1865 if (name) {
1866 s.PutCString(name);
1867 return true;
1868 }
1869 }
1870 }
1871 return false;
1872 }
1873
1875 if (m_sc) {
1876 Language *language_plugin = nullptr;
1877 bool language_plugin_handled = false;
1878 StreamString ss;
1879 if (m_sc->function)
1880 language_plugin = Language::FindPlugin(m_sc->function->GetLanguage());
1881 else if (m_sc->symbol)
1882 language_plugin = Language::FindPlugin(m_sc->symbol->GetLanguage());
1883
1884 if (language_plugin)
1885 language_plugin_handled = language_plugin->GetFunctionDisplayName(
1886 *m_sc, m_exe_ctx,
1888
1889 if (language_plugin_handled) {
1890 s << ss.GetString();
1891 return true;
1892 }
1893
1894 const char *name =
1895 m_sc->GetPossiblyInlinedFunctionName()
1896 .GetName(
1898 .AsCString(nullptr);
1899 if (name) {
1900 s.PutCString(name);
1901 return true;
1902 }
1903 }
1904
1905 // Fallback to frame methods if available.
1906 if (m_exe_ctx) {
1907 StackFrame *frame = m_exe_ctx->GetFramePtr();
1908 if (frame) {
1909 const char *name = frame->GetFunctionName();
1910 if (name) {
1911 s.PutCString(name);
1912 return true;
1913 }
1914 }
1915 }
1916 return false;
1917 }
1918
1929 Language *language_plugin = nullptr;
1930 if (m_sc->function)
1931 language_plugin = Language::FindPlugin(m_sc->function->GetLanguage());
1932 else if (m_sc->symbol)
1933 language_plugin = Language::FindPlugin(m_sc->symbol->GetLanguage());
1934
1935 if (!language_plugin)
1936 return false;
1937
1938 return language_plugin->HandleFrameFormatVariable(*m_sc, m_exe_ctx,
1939 entry.type, s);
1940 }
1941
1943 if (m_sc) {
1945 return true;
1946
1948 return true;
1949 }
1950
1951 // Fallback to frame methods if available.
1952 if (m_exe_ctx) {
1953 StackFrame *frame = m_exe_ctx->GetFramePtr();
1954 if (frame) {
1955 const char *name = frame->GetDisplayFunctionName();
1956 if (name) {
1957 s.PutCString(name);
1958 return true;
1959 }
1960 }
1961 }
1962 return false;
1963 }
1965 if (!m_sc)
1966 return false;
1967
1968 const char *name = m_sc->GetPossiblyInlinedFunctionName()
1970 .AsCString(nullptr);
1971 if (!name)
1972 return false;
1973
1974 s.PutCString(name);
1975
1976 return true;
1977 }
1979 if (m_addr) {
1981 false, false))
1982 return true;
1983 }
1984 return false;
1985
1987 if (m_addr) {
1988 if (DumpAddressOffsetFromFunction(s, m_sc, m_exe_ctx, *m_addr, true, true,
1989 true))
1990 return true;
1991 }
1992 return false;
1993
1995 if (m_sc)
1997 s, m_sc, m_exe_ctx, m_sc->line_entry.range.GetBaseAddress(), false,
1998 false, false));
1999 return false;
2000
2002 if (m_exe_ctx) {
2003 StackFrame *frame = m_exe_ctx->GetFramePtr();
2004 if (frame)
2006 frame->GetFrameCodeAddress(), false,
2007 false, false))
2008 return true;
2009 }
2010 return false;
2011
2013 return m_function_changed;
2014
2016 bool is_optimized = false;
2017 if (m_sc && m_sc->function && m_sc->function->GetIsOptimized()) {
2018 is_optimized = true;
2019 }
2020 return is_optimized;
2021 }
2022
2024 return m_sc && m_sc->block && m_sc->block->GetInlinedFunctionInfo();
2025 }
2026
2028 return m_initial_function;
2029
2031 if (m_sc && m_sc->line_entry.IsValid()) {
2032 if (DumpFile(s, m_sc->line_entry.GetFile(), (FileKind)entry.number))
2033 return true;
2034 }
2035 return false;
2036
2038 if (m_sc && m_sc->line_entry.IsValid()) {
2039 const char *format = "%" PRIu32;
2040 if (!entry.printf_format.empty())
2041 format = entry.printf_format.c_str();
2042 s.Printf(format, m_sc->line_entry.line);
2043 return true;
2044 }
2045 return false;
2046
2048 if (m_sc && m_sc->line_entry.IsValid() && m_sc->line_entry.column) {
2049 const char *format = "%" PRIu32;
2050 if (!entry.printf_format.empty())
2051 format = entry.printf_format.c_str();
2052 s.Printf(format, m_sc->line_entry.column);
2053 return true;
2054 }
2055 return false;
2056
2059 if (m_sc && m_sc->line_entry.range.GetBaseAddress().IsValid()) {
2060 Address addr = m_sc->line_entry.range.GetBaseAddress();
2061
2063 addr.Slide(m_sc->line_entry.range.GetByteSize());
2064 if (DumpAddressAndContent(s, m_sc, m_exe_ctx, addr, false))
2065 return true;
2066 }
2067 return false;
2068
2070 if (m_addr && m_exe_ctx && m_exe_ctx->GetFramePtr()) {
2071 RegisterContextSP reg_ctx =
2072 m_exe_ctx->GetFramePtr()->GetRegisterContextSP();
2073 if (reg_ctx) {
2074 addr_t pc_loadaddr = reg_ctx->GetPC();
2075 if (pc_loadaddr != LLDB_INVALID_ADDRESS) {
2076 Address pc;
2077 pc.SetLoadAddress(pc_loadaddr, m_exe_ctx->GetTargetPtr());
2078 if (pc == *m_addr) {
2079 s.PutCString("-> ");
2080 return true;
2081 }
2082 }
2083 }
2084 s.PutCString(" ");
2085 return true;
2086 }
2087 return false;
2088
2091 if (auto progress = target->GetDebugger().GetCurrentProgressReport()) {
2092 if (progress->total != UINT64_MAX) {
2093 s.Format("[{0:N}/{1:N}]", progress->completed, progress->total);
2094 return true;
2095 }
2096 }
2097 }
2098 return false;
2099
2102 if (auto progress = target->GetDebugger().GetCurrentProgressReport()) {
2103 s.PutCString(progress->message);
2104 return true;
2105 }
2106 }
2107 return false;
2108
2111 s << target->GetDebugger().GetSeparator();
2112 return true;
2113 }
2114 return false;
2115 }
2116
2117 return false;
2118}
2119
2121 const Definition *parent) {
2122 if (parent->children) {
2123 const size_t n = parent->num_children;
2124 for (size_t i = 0; i < n; ++i) {
2125 if (i > 0)
2126 s.PutCString(", ");
2127 s.Printf("\"%s\"", parent->children[i].name);
2128 }
2129 return true;
2130 }
2131 return false;
2132}
2133
2134static Status ParseEntry(const llvm::StringRef &format_str,
2135 const Definition *parent, FormatEntity::Entry &entry) {
2136 Status error;
2137
2138 const size_t sep_pos = format_str.find_first_of(".[:");
2139 const char sep_char =
2140 (sep_pos == llvm::StringRef::npos) ? '\0' : format_str[sep_pos];
2141 llvm::StringRef key = format_str.substr(0, sep_pos);
2142
2143 const size_t n = parent->num_children;
2144 for (size_t i = 0; i < n; ++i) {
2145 const Definition *entry_def = parent->children + i;
2146 if (key == entry_def->name || entry_def->name[0] == '*') {
2147 llvm::StringRef value;
2148 if (sep_char)
2149 value =
2150 format_str.substr(sep_pos + (entry_def->keep_separator ? 0 : 1));
2151 switch (entry_def->type) {
2153 entry.string = format_str.str();
2154 return error; // Success
2155
2157 entry.number = entry_def->data;
2158 return error; // Success
2159
2161 entry.type = entry_def->type;
2162 entry.string = entry_def->string;
2163 return error; // Success
2164
2165 default:
2166 entry.type = entry_def->type;
2167 break;
2168 }
2169
2170 if (value.empty()) {
2171 if (entry_def->type == FormatEntity::Entry::Type::Invalid) {
2172 if (entry_def->children) {
2173 StreamString error_strm;
2174 error_strm.Printf("'%s' can't be specified on its own, you must "
2175 "access one of its children: ",
2176 entry_def->name);
2177 DumpCommaSeparatedChildEntryNames(error_strm, entry_def);
2178 error =
2179 Status::FromErrorStringWithFormat("%s", error_strm.GetData());
2180 } else if (sep_char == ':') {
2181 // Any value whose separator is a with a ':' means this value has a
2182 // string argument that needs to be stored in the entry (like
2183 // "${script.var:}"). In this case the string value is the empty
2184 // string which is ok.
2185 } else {
2187 "%s", "invalid entry definitions");
2188 }
2189 }
2190 } else {
2191 if (entry_def->children) {
2192 error = ParseEntry(value, entry_def, entry);
2193 } else if (sep_char == ':') {
2194 // Any value whose separator is a with a ':' means this value has a
2195 // string argument that needs to be stored in the entry (like
2196 // "${script.var:modulename.function}")
2197 entry.string = value.str();
2198 } else {
2200 "'%s' followed by '%s' but it has no children", key.str().c_str(),
2201 value.str().c_str());
2202 }
2203 }
2204 return error;
2205 }
2206 }
2207 StreamString error_strm;
2209 error_strm.Printf(
2210 "invalid top level item '%s'. Valid top level items are: ",
2211 key.str().c_str());
2212 else
2213 error_strm.Printf("invalid member '%s' in '%s'. Valid members are: ",
2214 key.str().c_str(), parent->name);
2215 DumpCommaSeparatedChildEntryNames(error_strm, parent);
2216 error = Status::FromErrorStringWithFormat("%s", error_strm.GetData());
2217 return error;
2218}
2219
2220static const Definition *FindEntry(const llvm::StringRef &format_str,
2221 const Definition *parent,
2222 llvm::StringRef &remainder) {
2223 Status error;
2224
2225 std::pair<llvm::StringRef, llvm::StringRef> p = format_str.split('.');
2226 const size_t n = parent->num_children;
2227 for (size_t i = 0; i < n; ++i) {
2228 const Definition *entry_def = parent->children + i;
2229 if (p.first == entry_def->name || entry_def->name[0] == '*') {
2230 if (p.second.empty()) {
2231 if (format_str.back() == '.')
2232 remainder = format_str.drop_front(format_str.size() - 1);
2233 else
2234 remainder = llvm::StringRef(); // Exact match
2235 return entry_def;
2236 } else {
2237 if (entry_def->children) {
2238 return FindEntry(p.second, entry_def, remainder);
2239 } else {
2240 remainder = p.second;
2241 return entry_def;
2242 }
2243 }
2244 }
2245 }
2246 remainder = format_str;
2247 return parent;
2248}
2249
2250static Status ParseInternal(llvm::StringRef &format, Entry &parent_entry,
2251 uint32_t depth) {
2252 Status error;
2253 while (!format.empty() && error.Success()) {
2254 const size_t non_special_chars = format.find_first_of("${}\\|");
2255
2256 if (non_special_chars == llvm::StringRef::npos) {
2257 // No special characters, just string bytes so add them and we are done
2258 parent_entry.AppendText(format);
2259 return error;
2260 }
2261
2262 if (non_special_chars > 0) {
2263 // We have a special character, so add all characters before these as a
2264 // plain string
2265 parent_entry.AppendText(format.substr(0, non_special_chars));
2266 format = format.drop_front(non_special_chars);
2267 }
2268
2269 switch (format[0]) {
2270 case '\0':
2271 return error;
2272
2273 case '{': {
2274 format = format.drop_front(); // Skip the '{'
2275 Entry scope_entry(Entry::Type::Scope);
2276 error = ParseInternal(format, scope_entry, depth + 1);
2277 if (error.Fail())
2278 return error;
2279 parent_entry.AppendEntry(std::move(scope_entry));
2280 } break;
2281
2282 case '}':
2283 if (depth == 0)
2284 error = Status::FromErrorString("unmatched '}' character");
2285 else
2286 format =
2287 format
2288 .drop_front(); // Skip the '}' as we are at the end of the scope
2289 return error;
2290
2291 case '|':
2292 format = format.drop_front(); // Skip the '|'
2293 if (parent_entry.type == Entry::Type::Scope)
2294 parent_entry.StartAlternative();
2295 else
2296 parent_entry.AppendChar('|');
2297 break;
2298
2299 case '\\': {
2300 format = format.drop_front(); // Skip the '\' character
2301 if (format.empty()) {
2303 "'\\' character was not followed by another character");
2304 return error;
2305 }
2306
2307 const char desens_char = format[0];
2308 format = format.drop_front(); // Skip the desensitized char character
2309 switch (desens_char) {
2310 case 'a':
2311 parent_entry.AppendChar('\a');
2312 break;
2313 case 'b':
2314 parent_entry.AppendChar('\b');
2315 break;
2316 case 'f':
2317 parent_entry.AppendChar('\f');
2318 break;
2319 case 'n':
2320 parent_entry.AppendChar('\n');
2321 break;
2322 case 'r':
2323 parent_entry.AppendChar('\r');
2324 break;
2325 case 't':
2326 parent_entry.AppendChar('\t');
2327 break;
2328 case 'v':
2329 parent_entry.AppendChar('\v');
2330 break;
2331 case '\'':
2332 parent_entry.AppendChar('\'');
2333 break;
2334 case '\\':
2335 parent_entry.AppendChar('\\');
2336 break;
2337 case '0':
2338 // 1 to 3 octal chars
2339 {
2340 // Make a string that can hold onto the initial zero char, up to 3
2341 // octal digits, and a terminating NULL.
2342 char oct_str[5] = {0, 0, 0, 0, 0};
2343
2344 int i;
2345 for (i = 0; (format[i] >= '0' && format[i] <= '7') && i < 4; ++i)
2346 oct_str[i] = format[i];
2347
2348 // We don't want to consume the last octal character since the main
2349 // for loop will do this for us, so we advance p by one less than i
2350 // (even if i is zero)
2351 format = format.drop_front(i);
2352 unsigned long octal_value = ::strtoul(oct_str, nullptr, 8);
2353 if (octal_value <= UINT8_MAX) {
2354 parent_entry.AppendChar((char)octal_value);
2355 } else {
2357 "octal number is larger than a single byte");
2358 return error;
2359 }
2360 }
2361 break;
2362
2363 case 'x':
2364 // hex number in the format
2365 if (isxdigit(format[0])) {
2366 // Make a string that can hold onto two hex chars plus a
2367 // null terminator
2368 char hex_str[3] = {0, 0, 0};
2369 hex_str[0] = format[0];
2370
2371 format = format.drop_front();
2372
2373 if (isxdigit(format[0])) {
2374 hex_str[1] = format[0];
2375 format = format.drop_front();
2376 }
2377
2378 unsigned long hex_value = strtoul(hex_str, nullptr, 16);
2379 if (hex_value <= UINT8_MAX) {
2380 parent_entry.AppendChar((char)hex_value);
2381 } else {
2383 "hex number is larger than a single byte");
2384 return error;
2385 }
2386 } else {
2387 parent_entry.AppendChar(desens_char);
2388 }
2389 break;
2390
2391 default:
2392 // Just desensitize any other character by just printing what came
2393 // after the '\'
2394 parent_entry.AppendChar(desens_char);
2395 break;
2396 }
2397 } break;
2398
2399 case '$':
2400 format = format.drop_front(); // Skip the '$'
2401 if (format.empty() || format.front() != '{') {
2402 // Print '$' when not followed by '{'.
2403 parent_entry.AppendText("$");
2404 } else {
2405 format = format.drop_front(); // Skip the '{'
2406
2407 llvm::StringRef variable, variable_format;
2408 error = FormatEntity::ExtractVariableInfo(format, variable,
2409 variable_format);
2410 if (error.Fail())
2411 return error;
2412 bool verify_is_thread_id = false;
2413 Entry entry;
2414 if (!variable_format.empty()) {
2415 entry.printf_format = variable_format.str();
2416
2417 // If the format contains a '%' we are going to assume this is a
2418 // printf style format. So if you want to format your thread ID
2419 // using "0x%llx" you can use: ${thread.id%0x%llx}
2420 //
2421 // If there is no '%' in the format, then it is assumed to be a
2422 // LLDB format name, or one of the extended formats specified in
2423 // the switch statement below.
2424
2425 if (entry.printf_format.find('%') == std::string::npos) {
2426 bool clear_printf = false;
2427
2428 if (entry.printf_format.size() == 1) {
2429 switch (entry.printf_format[0]) {
2430 case '@': // if this is an @ sign, print ObjC description
2431 entry.number = ValueObject::
2432 eValueObjectRepresentationStyleLanguageSpecific;
2433 clear_printf = true;
2434 break;
2435 case 'V': // if this is a V, print the value using the default
2436 // format
2437 entry.number =
2439 clear_printf = true;
2440 break;
2441 case 'L': // if this is an L, print the location of the value
2442 entry.number =
2444 clear_printf = true;
2445 break;
2446 case 'S': // if this is an S, print the summary after all
2447 entry.number =
2449 clear_printf = true;
2450 break;
2451 case '#': // if this is a '#', print the number of children
2452 entry.number =
2454 clear_printf = true;
2455 break;
2456 case 'T': // if this is a 'T', print the type
2458 clear_printf = true;
2459 break;
2460 case 'N': // if this is a 'N', print the name
2462 clear_printf = true;
2463 break;
2464 case '>': // if this is a '>', print the expression path
2465 entry.number =
2467 clear_printf = true;
2468 break;
2469 }
2470 }
2471
2472 if (entry.number == 0) {
2474 entry.printf_format.c_str(), entry.fmt)) {
2475 clear_printf = true;
2476 } else if (entry.printf_format == "tid") {
2477 verify_is_thread_id = true;
2478 } else {
2480 "invalid format: '%s'", entry.printf_format.c_str());
2481 return error;
2482 }
2483 }
2484
2485 // Our format string turned out to not be a printf style format
2486 // so lets clear the string
2487 if (clear_printf)
2488 entry.printf_format.clear();
2489 }
2490 }
2491
2492 // Check for dereferences
2493 if (variable[0] == '*') {
2494 entry.deref = true;
2495 variable = variable.drop_front();
2496 }
2497
2498 error = ParseEntry(variable, &g_root, entry);
2499 if (error.Fail())
2500 return error;
2501
2502 llvm::StringRef entry_string(entry.string);
2503 if (entry_string.contains(':')) {
2504 auto [_, llvm_format] = entry_string.split(':');
2505 if (!llvm_format.empty() && !LLVMFormatPattern.match(llvm_format)) {
2507 "invalid llvm format: '%s'", llvm_format.data());
2508 return error;
2509 }
2510 }
2511
2512 if (verify_is_thread_id) {
2513 if (entry.type != Entry::Type::ThreadID &&
2516 "the 'tid' format can only be used on "
2517 "${thread.id} and ${thread.protocol_id}");
2518 }
2519 }
2520
2521 switch (entry.type) {
2524 if (entry.number == 0) {
2525 if (entry.string.empty())
2527 else
2528 entry.number =
2530 }
2531 break;
2532 default:
2533 // Make sure someone didn't try to dereference anything but ${var}
2534 // or ${svar}
2535 if (entry.deref) {
2537 "${%s} can't be dereferenced, only ${var} and ${svar} can.",
2538 variable.str().c_str());
2539 return error;
2540 }
2541 }
2542 parent_entry.AppendEntry(std::move(entry));
2543 }
2544 break;
2545 }
2546 }
2547 return error;
2548}
2549
2550Status FormatEntity::ExtractVariableInfo(llvm::StringRef &format_str,
2551 llvm::StringRef &variable_name,
2552 llvm::StringRef &variable_format) {
2553 Status error;
2554 variable_name = llvm::StringRef();
2555 variable_format = llvm::StringRef();
2556
2557 const size_t paren_pos = format_str.find('}');
2558 if (paren_pos != llvm::StringRef::npos) {
2559 const size_t percent_pos = format_str.find('%');
2560 if (percent_pos < paren_pos) {
2561 if (percent_pos > 0) {
2562 if (percent_pos > 1)
2563 variable_name = format_str.substr(0, percent_pos);
2564 variable_format =
2565 format_str.substr(percent_pos + 1, paren_pos - (percent_pos + 1));
2566 }
2567 } else {
2568 variable_name = format_str.substr(0, paren_pos);
2569 }
2570 // Strip off elements and the formatting and the trailing '}'
2571 format_str = format_str.substr(paren_pos + 1);
2572 } else {
2574 "missing terminating '}' character for '${%s'",
2575 format_str.str().c_str());
2576 }
2577 return error;
2578}
2579
2581 llvm::StringRef variable_name,
2582 llvm::StringRef variable_format) {
2583 if (variable_name.empty() || variable_name == ".fullpath") {
2584 file_spec.Dump(s.AsRawOstream());
2585 return true;
2586 } else if (variable_name == ".basename") {
2587 s.PutCString(file_spec.GetFilename());
2588 return true;
2589 } else if (variable_name == ".dirname") {
2590 s.PutCString(file_spec.GetFilename());
2591 return true;
2592 }
2593 return false;
2594}
2595
2596static std::string MakeMatch(const llvm::StringRef &prefix,
2597 const char *suffix) {
2598 std::string match(prefix.str());
2599 match.append(suffix);
2600 return match;
2601}
2602
2603static void AddMatches(const Definition *def, const llvm::StringRef &prefix,
2604 const llvm::StringRef &match_prefix,
2605 StringList &matches) {
2606 const size_t n = def->num_children;
2607 if (n > 0) {
2608 for (size_t i = 0; i < n; ++i) {
2609 if (match_prefix.empty())
2610 matches.AppendString(MakeMatch(prefix, def->children[i].name));
2611 else if (strncmp(def->children[i].name, match_prefix.data(),
2612 match_prefix.size()) == 0)
2613 matches.AppendString(
2614 MakeMatch(prefix, def->children[i].name + match_prefix.size()));
2615 }
2616 }
2617}
2618
2620 llvm::StringRef str = request.GetCursorArgumentPrefix();
2621
2622 const size_t dollar_pos = str.rfind('$');
2623 if (dollar_pos == llvm::StringRef::npos)
2624 return;
2625
2626 // Hitting TAB after $ at the end of the string add a "{"
2627 if (dollar_pos == str.size() - 1) {
2628 std::string match = str.str();
2629 match.append("{");
2630 request.AddCompletion(match);
2631 return;
2632 }
2633
2634 if (str[dollar_pos + 1] != '{')
2635 return;
2636
2637 const size_t close_pos = str.find('}', dollar_pos + 2);
2638 if (close_pos != llvm::StringRef::npos)
2639 return;
2640
2641 const size_t format_pos = str.find('%', dollar_pos + 2);
2642 if (format_pos != llvm::StringRef::npos)
2643 return;
2644
2645 llvm::StringRef partial_variable(str.substr(dollar_pos + 2));
2646 if (partial_variable.empty()) {
2647 // Suggest all top level entities as we are just past "${"
2648 StringList new_matches;
2649 AddMatches(&g_root, str, llvm::StringRef(), new_matches);
2650 request.AddCompletions(new_matches);
2651 return;
2652 }
2653
2654 // We have a partially specified variable, find it
2655 llvm::StringRef remainder;
2656 const Definition *entry_def = FindEntry(partial_variable, &g_root, remainder);
2657 if (!entry_def)
2658 return;
2659
2660 const size_t n = entry_def->num_children;
2661
2662 if (remainder.empty()) {
2663 // Exact match
2664 if (n > 0) {
2665 // "${thread.info" <TAB>
2666 request.AddCompletion(MakeMatch(str, "."));
2667 } else {
2668 // "${thread.id" <TAB>
2669 request.AddCompletion(MakeMatch(str, "}"));
2670 }
2671 } else if (remainder == ".") {
2672 // "${thread." <TAB>
2673 StringList new_matches;
2674 AddMatches(entry_def, str, llvm::StringRef(), new_matches);
2675 request.AddCompletions(new_matches);
2676 } else {
2677 // We have a partial match
2678 // "${thre" <TAB>
2679 StringList new_matches;
2680 AddMatches(entry_def, str, remainder, new_matches);
2681 request.AddCompletions(new_matches);
2682 }
2683}
2684
2686 Stream &out_stream, VariableList const &args,
2687 ExecutionContextScope *exe_scope) {
2688 const size_t num_args = args.GetSize();
2689 for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx) {
2690 std::string buffer;
2691
2692 VariableSP var_sp(args.GetVariableAtIndex(arg_idx));
2693 ValueObjectSP var_value_sp(ValueObjectVariable::Create(exe_scope, var_sp));
2694 StreamString ss;
2695 llvm::StringRef var_representation;
2696 const char *var_name = var_value_sp->GetName().GetCString();
2697 if (var_value_sp->GetCompilerType().IsValid()) {
2698 if (exe_scope && exe_scope->CalculateTarget())
2699 var_value_sp = var_value_sp->GetQualifiedRepresentationIfAvailable(
2700 exe_scope->CalculateTarget()
2701 ->TargetProperties::GetPreferDynamicValue(),
2702 exe_scope->CalculateTarget()
2703 ->TargetProperties::GetEnableSyntheticValue());
2704 if (var_value_sp->GetCompilerType().IsAggregateType() &&
2707 .SetHideItemNames(false)
2708 .SetShowMembersOneLiner(true),
2709 "");
2710 format.FormatObject(var_value_sp.get(), buffer, TypeSummaryOptions());
2711 var_representation = buffer;
2712 } else
2713 var_value_sp->DumpPrintableRepresentation(
2714 ss,
2716 eValueObjectRepresentationStyleSummary,
2719 }
2720
2721 if (!ss.GetString().empty())
2722 var_representation = ss.GetString();
2723 if (arg_idx > 0)
2724 out_stream.PutCString(", ");
2725 if (var_value_sp->GetError().Success()) {
2726 if (!var_representation.empty())
2727 out_stream.Printf("%s=%s", var_name, var_representation.str().c_str());
2728 else
2729 out_stream.Printf("%s=%s at %s", var_name,
2730 var_value_sp->GetTypeName().GetCString(),
2731 var_value_sp->GetLocationAsCString());
2732 } else
2733 out_stream.Printf("%s=<unavailable>", var_name);
2734 }
2735}
2736
2737Status FormatEntity::Parse(const llvm::StringRef &format_str, Entry &entry) {
2738 entry.Clear();
2739 entry.type = Entry::Type::Root;
2740 llvm::StringRef modifiable_format(format_str);
2741 return ParseInternal(modifiable_format, entry, 0);
2742}
2743
2745 // It is expected that Scope and Root format entities recursively call Format.
2746 //
2747 // Variable may also be formatted recursively in some special cases. The main
2748 // use-case being array summary strings, in which case Format will call itself
2749 // with the subrange ValueObject and apply a freshly created Variable entry.
2750 // E.g., ${var[1-3]} will format the [1-3] range with ${var%S}.
2751 static constexpr std::array s_permitted_recursive_entities = {
2753
2754 if (llvm::is_contained(s_permitted_recursive_entities, type))
2755 return false;
2756
2757 return llvm::is_contained(m_entry_type_stack, type);
2758}
#define ANSI_ESC_START
#define ANSI_BG_COLOR_PURPLE
#define ANSI_CTRL_UNDERLINE
#define ANSI_BG_COLOR_RED
#define ANSI_FG_COLOR_BLACK
#define ANSI_BG_COLOR_YELLOW
#define ANSI_BG_COLOR_BLACK
#define ANSI_FG_COLOR_YELLOW
#define ANSI_FG_COLOR_PURPLE
#define ANSI_BG_COLOR_CYAN
#define ANSI_BG_COLOR_GREEN
#define ANSI_CTRL_SLOW_BLINK
#define ANSI_FG_COLOR_RED
#define ANSI_BG_COLOR_BLUE
#define ANSI_CTRL_ITALIC
#define ANSI_FG_COLOR_CYAN
#define ANSI_CTRL_FAST_BLINK
#define ANSI_CTRL_CROSSED_OUT
#define ANSI_CTRL_IMAGE_NEGATIVE
#define ANSI_BG_COLOR_WHITE
#define ANSI_CTRL_CONCEAL
#define ANSI_FG_COLOR_GREEN
#define ANSI_CTRL_FAINT
#define ANSI_FG_COLOR_BLUE
#define ANSI_CTRL_NORMAL
#define ANSI_CTRL_BOLD
#define ANSI_FG_COLOR_WHITE
#define ANSI_ESC_END
static llvm::raw_ostream & error(Stream &strm)
#define integer
#define ENUM_TO_CSTR(eee)
static void AddMatches(const Definition *def, const llvm::StringRef &prefix, const llvm::StringRef &match_prefix, StringList &matches)
static std::pair< char const *, char const * > ParseBaseName(char const *full_name)
Parses the basename out of a demangled function name that may include function arguments.
static const Definition * FindEntry(const llvm::StringRef &format_str, const Definition *parent, llvm::StringRef &remainder)
constexpr Definition g_frame_child_entries[]
constexpr Definition g_ansi_bg_entries[]
static bool ScanBracketedRange(llvm::StringRef subpath, size_t &close_bracket_index, const char *&var_name_final_if_array_range, int64_t &index_lower, int64_t &index_higher)
static bool RunScriptFormatKeyword(Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, T t, const char *script_function_name)
static bool DumpFile(Stream &s, const FileSpec &file, FileKind file_kind)
lldb_private::FormatEntity::Entry::Definition Definition
constexpr Definition g_script_child_entries[]
static Status ParseInternal(llvm::StringRef &format, Entry &parent_entry, uint32_t depth)
constexpr Definition g_file_child_entries[]
static Status ParseEntry(const llvm::StringRef &format_str, const Definition *parent, FormatEntity::Entry &entry)
static std::string MakeMatch(const llvm::StringRef &prefix, const char *suffix)
static ValueObjectSP ExpandIndexedExpression(ValueObject *valobj, size_t index, bool deref_pointer)
static bool HandleFunctionNameWithArgs(Stream &s, const ExecutionContext *exe_ctx, const SymbolContext &sc)
constexpr Definition g_string_entry[]
constexpr Definition g_root
static bool PrintFunctionNameWithArgs(Stream &s, const ExecutionContext *exe_ctx, const SymbolContext &sc)
static bool DumpCommaSeparatedChildEntryNames(Stream &s, const Definition *parent)
constexpr Definition g_svar_child_entries[]
constexpr Definition g_var_child_entries[]
static bool IsToken(const char *var_name_begin, const char *var)
static llvm::Regex LLVMFormatPattern
Options supported by format_provider<T> for integral arithmetic types.
constexpr Definition g_top_level_entries[]
static char ConvertValueObjectStyleToChar(ValueObject::ValueObjectRepresentationStyle style)
constexpr Definition g_line_child_entries[]
static void PrettyPrintFunctionNameWithArgs(Stream &out_stream, char const *full_name, ExecutionContextScope *exe_scope, VariableList const &args)
Writes out the function name in 'full_name' to 'out_stream' but replaces each argument type with the ...
constexpr Definition g_function_child_entries[]
static void DumpEscaped(Stream &s, llvm::StringRef str)
Dump a string set by the inferior.
FileKind
@ FileError
@ Dirname
@ Basename
@ Fullpath
constexpr Definition g_module_child_entries[]
constexpr Definition g_ansi_entries[]
constexpr Definition g_process_child_entries[]
static bool DumpValueWithLLVMFormat(Stream &s, llvm::StringRef options, ValueObject &valobj)
static bool DumpAddressAndContent(Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, const Address &addr, bool print_file_addr_or_load_addr)
FormatEntity::Entry::Type EntryType
static VariableListSP GetFunctionVariableList(const SymbolContext &sc)
static bool DumpAddressOffsetFromFunction(Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, const Address &format_addr, bool concrete_only, bool no_padding, bool print_zero_offsets)
constexpr Definition g_progress_child_entries[]
static bool DumpRegister(Stream &s, StackFrame *frame, RegisterKind reg_kind, uint32_t reg_num, Format format)
constexpr Definition g_ansi_fg_entries[]
constexpr Definition g_addr_entries[]
constexpr Definition g_target_child_entries[]
constexpr Definition g_thread_child_entries[]
#define _TO_STR(_val)
static bool FormatThreadExtendedInfoRecurse(const FormatEntity::Entry &entry, const StructuredData::ObjectSP &thread_info_dictionary, const SymbolContext *sc, const ExecutionContext *exe_ctx, Stream &s)
FormatEntity::Entry Entry
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:375
#define LLDB_LOGF(log,...)
Definition Log.h:389
A section + offset based address range class.
Address & GetBaseAddress()
Get accessor for the base address of the range.
A section + offset based address class.
Definition Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition Address.cpp:303
@ DumpStyleModuleWithFileAddress
Display as the file address with the module name prepended (if any).
Definition Address.h:93
@ DumpStyleLoadAddress
Display as the load address (if resolved).
Definition Address.h:99
bool Slide(int64_t offset)
Definition Address.h:446
bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style=DumpStyleInvalid, uint32_t addr_byte_size=UINT32_MAX, bool all_ranges=false, std::optional< Stream::HighlightSettings > settings=std::nullopt) const
Dump a description of this object to a Stream.
Definition Address.cpp:398
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition Address.cpp:275
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:283
bool IsValid() const
Check if the object state is valid.
Definition Address.h:355
An architecture specification class.
Definition ArchSpec.h:32
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition ArchSpec.cpp:710
bool IsValid() const
Tests if this ArchSpec is valid.
Definition ArchSpec.h:375
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:465
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition ArchSpec.cpp:568
A class that describes a single lexical block.
Definition Block.h:41
lldb::VariableListSP GetBlockVariableList(bool can_create)
Get the variable list for this block only.
Definition Block.cpp:382
Block * GetContainingInlinedBlock()
Get the inlined block that contains this block.
Definition Block.cpp:206
bool GetRangeContainingAddress(const Address &addr, AddressRange &range)
Definition Block.cpp:248
"lldb/Target/BorrowedStackFrame.h"
A class that describes a compilation unit.
Definition CompileUnit.h:43
const FileSpec & GetPrimaryFile() const
Return the primary source spec associated with this compile unit.
lldb::LanguageType GetLanguage()
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
"lldb/Utility/ArgCompletionRequest.h"
void AddCompletion(llvm::StringRef completion, llvm::StringRef description="", CompletionMode mode=CompletionMode::Normal)
Adds a possible completion string.
void AddCompletions(const StringList &completions)
Adds multiple possible completion strings.
llvm::StringRef GetCursorArgumentPrefix() const
const char * AsCString(const char *value_if_empty) const
Get the string value as a C string.
An data extractor class.
static bool ShouldPrintAsOneLiner(ValueObject &valobj)
static lldb::TypeSummaryImplSP GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp)
A class to manage flag bits.
Definition Debugger.h:106
bool GetUseColor() const
Definition Debugger.cpp:544
ScriptInterpreter * GetScriptInterpreter(bool can_create=true, std::optional< lldb::ScriptLanguage > language={})
DumpValueObjectOptions & SetUseSyntheticValue(bool use_synthetic=true)
DumpValueObjectOptions & SetUseDynamicType(lldb::DynamicValueType dyn=lldb::eNoDynamicValues)
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
virtual lldb::TargetSP CalculateTarget()=0
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
A file utility class.
Definition FileSpec.h:56
llvm::StringRef GetFilename() const
Filename string const get accessor.
Definition FileSpec.h:248
llvm::StringRef GetDirectory() const
Directory string const get accessor.
Definition FileSpec.h:233
void Dump(llvm::raw_ostream &s) const
Dump this object to a Stream.
Definition FileSpec.cpp:341
const SymbolContext *const m_sc
auto PushEntryType(Entry::Type type)
While the returned llvm::scope_exit is alive, the specified type is tracked by this Formatter object ...
const ExecutionContext *const m_exe_ctx
llvm::SmallVector< Entry::Type, 1 > m_entry_type_stack
bool Format(const Entry &entry, Stream &s, ValueObject *valobj=nullptr)
bool FormatStringRef(const llvm::StringRef &format, Stream &s, ValueObject *valobj)
bool IsInvalidRecursiveFormat(Entry::Type type)
Returns true if Format has been called for an Entry with the specified type recusrively.
bool DumpValue(Stream &s, const FormatEntity::Entry &entry, ValueObject *valobj)
static const char * GetFormatAsCString(lldb::Format format)
static bool GetFormatFromCString(const char *format_cstr, lldb::Format &format)
static char GetFormatAsFormatChar(lldb::Format format)
const Address & GetAddress() const
Return the address of the function (its entry point).
Definition Function.h:439
lldb::LanguageType GetLanguage() const
Definition Function.cpp:712
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition Function.cpp:400
virtual bool HandleFrameFormatVariable(const SymbolContext &sc, const ExecutionContext *exe_ctx, FormatEntity::Entry::Type type, Stream &s)
Definition Language.h:451
static Language * FindPlugin(lldb::LanguageType language)
Definition Language.cpp:61
static const char * GetNameForLanguageType(lldb::LanguageType language)
Returns the internal LLDB name for the specified language.
Definition Language.cpp:292
virtual bool GetFunctionDisplayName(const SymbolContext &sc, const ExecutionContext *exe_ctx, FunctionNameRepresentation representation, Stream &s)
Definition Language.cpp:561
virtual FormatEntity::Entry GetFunctionNameFormat() const
Definition Language.h:595
@ ePreferDemangledWithoutArguments
Definition Mangled.h:41
ConstString GetName(NamePreference preference=ePreferDemangled) const
Best name get accessor.
Definition Mangled.cpp:297
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:92
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition Module.h:448
A plug-in interface definition class for debugging a process.
Definition Process.h:370
lldb::pid_t GetID() const
Returns the pid of the process or LLDB_INVALID_PROCESS_ID if there is no known pid.
Definition Process.h:555
Target & GetTarget()
Get the target object pointer for this module.
Definition Process.h:1271
virtual uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num)
Convert from a given register numbering scheme to the lldb register numbering scheme.
virtual const RegisterInfo * GetRegisterInfoAtIndex(size_t reg)=0
const RegisterInfo * GetRegisterInfoByName(llvm::StringRef reg_name, uint32_t start_idx=0)
virtual bool ReadRegister(const RegisterInfo *reg_info, RegisterValue &reg_value)=0
virtual bool RunScriptFormatKeyword(const char *impl_function, Process *process, std::string &output, Status &error)
This base class provides an interface to stack frames.
Definition StackFrame.h:44
virtual const char * GetFunctionName()
Get the frame's demangled name.
virtual lldb::RegisterContextSP GetRegisterContext()
Get the RegisterContext for this frame, if possible.
virtual const char * GetDisplayFunctionName()
Get the frame's demangled display name.
virtual uint32_t GetFrameIndex() const
Query this frame to find what frame it is in this Thread's StackFrameList.
virtual bool HasDebugInformation()
Determine whether this StackFrame has debug information available or not.
virtual const Address & GetFrameCodeAddress()
Get an Address for the current pc value in this StackFrame.
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
static ThreadPlanReturnValue GetReturnValue(lldb::StopInfoSP &stop_info_sp)
static lldb::ExpressionVariableSP GetExpressionVariable(lldb::StopInfoSP &stop_info_sp)
const char * GetData() const
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition Stream.h:28
void Format(const char *format, Args &&... args)
Forwards the arguments to llvm::formatv and writes to the stream.
Definition Stream.h:370
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
Definition Stream.h:111
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition Stream.h:405
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
size_t PutChar(char ch)
Definition Stream.cpp:131
size_t EOL()
Output and End of Line character to the stream.
Definition Stream.cpp:155
void AppendString(const std::string &s)
std::shared_ptr< Object > ObjectSP
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
Block * block
The Block for a given query.
Symbol * symbol
The Symbol for a given query.
Mangled GetPossiblyInlinedFunctionName() const
If available, will return the function name according to the specified mangling preference.
bool ValueIsAddress() const
Definition Symbol.cpp:192
lldb::LanguageType GetLanguage() const
Definition Symbol.h:154
Address & GetAddressRef()
Definition Symbol.h:78
ConstString GetName() const
Definition Symbol.cpp:615
Module * GetExecutableModulePointer()
Definition Target.cpp:1668
static Target * GetTargetFromContexts(const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
Definition Target.cpp:3015
Debugger & GetDebugger() const
Definition Target.h:1378
const ArchSpec & GetArchitecture() const
Definition Target.h:1337
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp)
virtual uint32_t GetBitfieldBitSize()
bool DumpPrintableRepresentation(Stream &s, ValueObjectRepresentationStyle val_obj_display=eValueObjectRepresentationStyleSummary, lldb::Format custom_format=lldb::eFormatInvalid, PrintableRepresentationSpecialCases special=PrintableRepresentationSpecialCases::eAllow, bool do_dump_error=true)
lldb::ValueObjectSP GetSyntheticValue()
@ eExpressionPathScanEndReasonEndOfString
Out of data to parse.
@ eExpressionPathAftermathNothing
Just return it.
@ eExpressionPathAftermathDereference
Dereference the target.
lldb::ValueObjectSP GetValueForExpressionPath(llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop=nullptr, ExpressionPathEndResultType *final_value_type=nullptr, const GetValueForExpressionPathOptions &options=GetValueForExpressionPathOptions::DefaultOptions(), ExpressionPathAftermath *final_task_on_target=nullptr)
virtual uint64_t GetValueAsUnsigned(uint64_t fail_value, bool *success=nullptr)
virtual ConstString GetTypeName()
lldb::DynamicValueType GetDynamicValueType()
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr)
lldb::ValueObjectSP GetQualifiedRepresentationIfAvailable(lldb::DynamicValueType dynValue, bool synthValue)
lldb::TargetSP GetTargetSP() const
@ eExpressionPathEndResultTypePlain
Anything but...
@ eExpressionPathEndResultTypeBoundedRange
A range [low-high].
@ eExpressionPathEndResultTypeUnboundedRange
A range [].
virtual lldb::ValueObjectSP Dereference(Status &error)
CompilerType GetCompilerType()
bool HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display, lldb::Format custom_format)
virtual const char * GetLocationAsCString()
virtual int64_t GetValueAsSigned(int64_t fail_value, bool *success=nullptr)
virtual bool IsSynthetic()
uint32_t GetNumChildrenIgnoringErrors(uint32_t max=UINT32_MAX)
Like GetNumChildren but returns 0 on error.
lldb::VariableSP GetVariableAtIndex(size_t idx) const
size_t AppendVariablesWithScope(lldb::ValueType type, VariableList &var_list, bool if_unique=true)
static bool ReadBufferAndDumpToStream(const ReadBufferAndDumpToStreamOptions &options)
#define UINT64_MAX
#define LLDB_REGNUM_GENERIC_SP
#define LLDB_REGNUM_GENERIC_FLAGS
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_REGNUM
#define LLDB_REGNUM_GENERIC_FP
bool FormatFileSpec(const FileSpec &file, Stream &s, llvm::StringRef elements, llvm::StringRef element_format)
Status Parse(const llvm::StringRef &format, Entry &entry)
Status ExtractVariableInfo(llvm::StringRef &format_str, llvm::StringRef &variable_name, llvm::StringRef &variable_format)
void PrettyPrintFunctionArguments(Stream &out_stream, VariableList const &args, ExecutionContextScope *exe_scope)
For each variable in 'args' this function writes the variable name and it's pretty-printed value repr...
void AutoComplete(lldb_private::CompletionRequest &request)
lldb::ByteOrder InlHostByteOrder()
Definition Endian.h:25
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:338
void DumpRegisterValue(const RegisterValue &reg_val, Stream &s, const RegisterInfo &reg_info, bool prefix_with_name, bool prefix_with_alt_name, lldb::Format format, uint32_t reg_name_right_align_at=0, ExecutionContextScope *exe_scope=nullptr, bool print_type=false, lldb::TargetSP target_sp=nullptr)
std::variant< std::monostate, ReturnedValue, ThrownError > ThreadPlanReturnValue
What a completed thread plan computed for the function it stepped out of or called: nothing,...
Definition Thread.h:82
std::string toString(FormatterBytecode::OpCodes op)
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::ExpressionVariable > ExpressionVariableSP
Format
Display format definitions.
std::shared_ptr< lldb_private::VariableList > VariableListSP
std::shared_ptr< lldb_private::Variable > VariableSP
@ eValueTypeVariableArgument
function argument variables
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
uint64_t addr_t
Definition lldb-types.h:80
@ eDynamicCanRunTarget
@ eStructuredDataTypeFloat
@ eStructuredDataTypeDictionary
@ eStructuredDataTypeInteger
@ eStructuredDataTypeArray
@ eStructuredDataTypeString
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
RegisterKind
Register numbering types.
@ eRegisterKindGeneric
insn ptr reg, stack ptr reg, etc not specific to any particular target
const char * name
The name/string placeholder that corresponds to this definition.
const Definition * children
An array of "num_children" Definition entries.
const bool keep_separator
Whether the separator is kept during parsing or not.
const char * string
Insert this exact string into the output.
const uint64_t data
Data that is returned as the value of the format string.
const uint32_t num_children
The number of children of this node in the tree of format strings.
const Entry::Type type
Entry::Type corresponding to this definition.
void Dump(Stream &s, int depth=0) const
Entry(Type t=Type::Invalid, const char *s=nullptr, const char *f=nullptr)
void AppendText(const llvm::StringRef &s)
static constexpr Definition DefinitionWithChildren(const char *name, const FormatEntity::Entry::Type t, const Definition(&children)[N], bool keep_separator=false)
llvm::SmallVector< std::vector< Entry >, 1 > children_stack
A stack of children entries, used by Scope entries to provide alterantive children.
std::vector< Entry > & GetChildren()
static const char * TypeToCString(Type t)
void AppendEntry(const Entry &&entry)
Every register is described in detail including its name, alternate name (optional),...
bool FormatObject(ValueObject *valobj, std::string &dest, const TypeSummaryOptions &options) override
GetValueForExpressionPathOptions & SetSyntheticChildrenTraversal(SyntheticChildrenTraversal traverse)
GetValueForExpressionPathOptions & DoAllowFragileIVar()
GetValueForExpressionPathOptions & DontCheckDotVsArrowSyntax()
GetValueForExpressionPathOptions & DoAllowBitfieldSyntax()