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"
35#include "lldb/Target/Process.h"
40#include "lldb/Target/Target.h"
41#include "lldb/Target/Thread.h"
48#include "lldb/Utility/Log.h"
50#include "lldb/Utility/Status.h"
51#include "lldb/Utility/Stream.h"
55#include "lldb/lldb-defines.h"
56#include "lldb/lldb-forward.h"
57#include "llvm/ADT/STLExtras.h"
58#include "llvm/ADT/StringRef.h"
59#include "llvm/Support/Compiler.h"
60#include "llvm/Support/Regex.h"
61#include "llvm/TargetParser/Triple.h"
62
63#include <cctype>
64#include <cinttypes>
65#include <cstdio>
66#include <cstdlib>
67#include <cstring>
68#include <memory>
69#include <type_traits>
70#include <utility>
71
72namespace lldb_private {
74}
75namespace lldb_private {
76struct RegisterInfo;
77}
78
79using namespace lldb;
80using namespace lldb_private;
81
85
87
89 Definition("*", EntryType::ParentString)};
90
92 Definition("load", EntryType::AddressLoad),
93 Definition("file", EntryType::AddressFile)};
94
96 Definition("basename", EntryType::ParentNumber, FileKind::Basename),
97 Definition("dirname", EntryType::ParentNumber, FileKind::Dirname),
98 Definition("fullpath", EntryType::ParentNumber, FileKind::Fullpath)};
99
101 Definition("index", EntryType::FrameIndex),
102 Definition("pc", EntryType::FrameRegisterPC),
103 Definition("fp", EntryType::FrameRegisterFP),
104 Definition("sp", EntryType::FrameRegisterSP),
105 Definition("flags", EntryType::FrameRegisterFlags),
106 Definition("no-debug", EntryType::FrameNoDebug),
107 Entry::DefinitionWithChildren("reg", EntryType::FrameRegisterByName,
109 Definition("is-artificial", EntryType::FrameIsArtificial),
110};
111
113 Definition("id", EntryType::FunctionID),
114 Definition("name", EntryType::FunctionName),
115 Definition("name-without-args", EntryType::FunctionNameNoArgs),
116 Definition("name-with-args", EntryType::FunctionNameWithArgs),
117 Definition("mangled-name", EntryType::FunctionMangledName),
118 Definition("addr-offset", EntryType::FunctionAddrOffset),
119 Definition("concrete-only-addr-offset-no-padding",
120 EntryType::FunctionAddrOffsetConcrete),
121 Definition("line-offset", EntryType::FunctionLineOffset),
122 Definition("pc-offset", EntryType::FunctionPCOffset),
123 Definition("initial-function", EntryType::FunctionInitial),
124 Definition("changed", EntryType::FunctionChanged),
125 Definition("is-optimized", EntryType::FunctionIsOptimized)};
126
128 Entry::DefinitionWithChildren("file", EntryType::LineEntryFile,
130 Definition("number", EntryType::LineEntryLineNumber),
131 Definition("column", EntryType::LineEntryColumn),
132 Definition("start-addr", EntryType::LineEntryStartAddress),
133 Definition("end-addr", EntryType::LineEntryEndAddress),
134};
135
137 "file", EntryType::ModuleFile, g_file_child_entries)};
138
140 Definition("id", EntryType::ProcessID),
141 Definition("name", EntryType::ProcessFile, FileKind::Basename),
142 Entry::DefinitionWithChildren("file", EntryType::ProcessFile,
144
146 Definition("*", EntryType::ParentString)};
147
149 Definition("*", EntryType::ParentString)};
150
152 Definition("id", EntryType::ThreadID),
153 Definition("protocol_id", EntryType::ThreadProtocolID),
154 Definition("index", EntryType::ThreadIndexID),
155 Entry::DefinitionWithChildren("info", EntryType::ThreadInfo,
157 Definition("queue", EntryType::ThreadQueue),
158 Definition("name", EntryType::ThreadName),
159 Definition("stop-reason", EntryType::ThreadStopReason),
160 Definition("stop-reason-raw", EntryType::ThreadStopReasonRaw),
161 Definition("return-value", EntryType::ThreadReturnValue),
162 Definition("completed-expression", EntryType::ThreadCompletedExpression)};
163
165 Definition("arch", EntryType::TargetArch)};
166
167#define _TO_STR2(_val) #_val
168#define _TO_STR(_val) _TO_STR2(_val)
169
171 Definition("black",
174 Definition("green",
176 Definition("yellow",
179 Definition("purple",
182 Definition("white",
184};
185
187 Definition("black",
190 Definition("green",
192 Definition("yellow",
195 Definition("purple",
198 Definition("white",
200};
201
203 Entry::DefinitionWithChildren("fg", EntryType::Invalid, g_ansi_fg_entries),
204 Entry::DefinitionWithChildren("bg", EntryType::Invalid, g_ansi_bg_entries),
209 Definition("underline",
211 Definition("slow-blink",
213 Definition("fast-blink",
215 Definition("negative",
217 Definition("conceal",
219 Definition("crossed-out",
221};
222
224 Definition("frame", EntryType::ScriptFrame),
225 Definition("process", EntryType::ScriptProcess),
226 Definition("target", EntryType::ScriptTarget),
227 Definition("thread", EntryType::ScriptThread),
228 Definition("var", EntryType::ScriptVariable),
229 Definition("svar", EntryType::ScriptVariableSynthetic),
230 Definition("thread", EntryType::ScriptThread)};
231
233 Entry::DefinitionWithChildren("addr", EntryType::AddressLoadOrFile,
235 Definition("addr-file-or-load", EntryType::AddressLoadOrFile),
236 Entry::DefinitionWithChildren("ansi", EntryType::Invalid, g_ansi_entries),
237 Definition("current-pc-arrow", EntryType::CurrentPCArrow),
238 Entry::DefinitionWithChildren("file", EntryType::File,
240 Definition("language", EntryType::Lang),
241 Entry::DefinitionWithChildren("frame", EntryType::Invalid,
243 Entry::DefinitionWithChildren("function", EntryType::Invalid,
245 Entry::DefinitionWithChildren("line", EntryType::Invalid,
247 Entry::DefinitionWithChildren("module", EntryType::Invalid,
249 Entry::DefinitionWithChildren("process", EntryType::Invalid,
251 Entry::DefinitionWithChildren("script", EntryType::Invalid,
253 Entry::DefinitionWithChildren("svar", EntryType::VariableSynthetic,
255 Entry::DefinitionWithChildren("thread", EntryType::Invalid,
257 Entry::DefinitionWithChildren("target", EntryType::Invalid,
259 Entry::DefinitionWithChildren("var", EntryType::Variable,
260 g_var_child_entries, true)};
261
263 "<root>", EntryType::Root, g_top_level_entries);
264
266 : string(s.data(), s.size()), printf_format(), children(),
267 type(Type::String) {}
268
270 : string(1, ch), printf_format(), children(), type(Type::String) {}
271
273 if (children.empty() || children.back().type != Entry::Type::String)
274 children.push_back(Entry(ch));
275 else
276 children.back().string.append(1, ch);
277}
278
279void FormatEntity::Entry::AppendText(const llvm::StringRef &s) {
280 if (children.empty() || children.back().type != Entry::Type::String)
281 children.push_back(Entry(s));
282 else
283 children.back().string.append(s.data(), s.size());
284}
285
286void FormatEntity::Entry::AppendText(const char *cstr) {
287 return AppendText(llvm::StringRef(cstr));
288}
289
290#define ENUM_TO_CSTR(eee) \
291 case FormatEntity::Entry::Type::eee: \
292 return #eee
293
295 switch (t) {
297 ENUM_TO_CSTR(ParentNumber);
298 ENUM_TO_CSTR(ParentString);
299 ENUM_TO_CSTR(EscapeCode);
300 ENUM_TO_CSTR(Root);
301 ENUM_TO_CSTR(String);
302 ENUM_TO_CSTR(Scope);
304 ENUM_TO_CSTR(VariableSynthetic);
305 ENUM_TO_CSTR(ScriptVariable);
306 ENUM_TO_CSTR(ScriptVariableSynthetic);
307 ENUM_TO_CSTR(AddressLoad);
308 ENUM_TO_CSTR(AddressFile);
309 ENUM_TO_CSTR(AddressLoadOrFile);
310 ENUM_TO_CSTR(ProcessID);
311 ENUM_TO_CSTR(ProcessFile);
312 ENUM_TO_CSTR(ScriptProcess);
313 ENUM_TO_CSTR(ThreadID);
314 ENUM_TO_CSTR(ThreadProtocolID);
315 ENUM_TO_CSTR(ThreadIndexID);
316 ENUM_TO_CSTR(ThreadName);
317 ENUM_TO_CSTR(ThreadQueue);
318 ENUM_TO_CSTR(ThreadStopReason);
319 ENUM_TO_CSTR(ThreadStopReasonRaw);
320 ENUM_TO_CSTR(ThreadReturnValue);
321 ENUM_TO_CSTR(ThreadCompletedExpression);
322 ENUM_TO_CSTR(ScriptThread);
323 ENUM_TO_CSTR(ThreadInfo);
324 ENUM_TO_CSTR(TargetArch);
325 ENUM_TO_CSTR(ScriptTarget);
326 ENUM_TO_CSTR(ModuleFile);
328 ENUM_TO_CSTR(Lang);
329 ENUM_TO_CSTR(FrameIndex);
330 ENUM_TO_CSTR(FrameNoDebug);
331 ENUM_TO_CSTR(FrameRegisterPC);
332 ENUM_TO_CSTR(FrameRegisterSP);
333 ENUM_TO_CSTR(FrameRegisterFP);
334 ENUM_TO_CSTR(FrameRegisterFlags);
335 ENUM_TO_CSTR(FrameRegisterByName);
336 ENUM_TO_CSTR(FrameIsArtificial);
337 ENUM_TO_CSTR(ScriptFrame);
338 ENUM_TO_CSTR(FunctionID);
339 ENUM_TO_CSTR(FunctionDidChange);
340 ENUM_TO_CSTR(FunctionInitialFunction);
341 ENUM_TO_CSTR(FunctionName);
342 ENUM_TO_CSTR(FunctionNameWithArgs);
343 ENUM_TO_CSTR(FunctionNameNoArgs);
344 ENUM_TO_CSTR(FunctionMangledName);
345 ENUM_TO_CSTR(FunctionAddrOffset);
346 ENUM_TO_CSTR(FunctionAddrOffsetConcrete);
347 ENUM_TO_CSTR(FunctionLineOffset);
348 ENUM_TO_CSTR(FunctionPCOffset);
349 ENUM_TO_CSTR(FunctionInitial);
350 ENUM_TO_CSTR(FunctionChanged);
351 ENUM_TO_CSTR(FunctionIsOptimized);
352 ENUM_TO_CSTR(LineEntryFile);
353 ENUM_TO_CSTR(LineEntryLineNumber);
354 ENUM_TO_CSTR(LineEntryColumn);
355 ENUM_TO_CSTR(LineEntryStartAddress);
356 ENUM_TO_CSTR(LineEntryEndAddress);
357 ENUM_TO_CSTR(CurrentPCArrow);
358 }
359 return "???";
360}
361
362#undef ENUM_TO_CSTR
363
364void FormatEntity::Entry::Dump(Stream &s, int depth) const {
365 s.Printf("%*.*s%-20s: ", depth * 2, depth * 2, "", TypeToCString(type));
366 if (fmt != eFormatDefault)
367 s.Printf("lldb-format = %s, ", FormatManager::GetFormatAsCString(fmt));
368 if (!string.empty())
369 s.Printf("string = \"%s\"", string.c_str());
370 if (!printf_format.empty())
371 s.Printf("printf_format = \"%s\"", printf_format.c_str());
372 if (number != 0)
373 s.Printf("number = %" PRIu64 " (0x%" PRIx64 "), ", number, number);
374 if (deref)
375 s.Printf("deref = true, ");
376 s.EOL();
377 for (const auto &child : children) {
378 child.Dump(s, depth + 1);
379 }
380}
381
382template <typename T>
384 const ExecutionContext *exe_ctx, T t,
385 const char *script_function_name) {
386 Target *target = Target::GetTargetFromContexts(exe_ctx, sc);
387
388 if (target) {
389 ScriptInterpreter *script_interpreter =
391 if (script_interpreter) {
393 std::string script_output;
394
395 if (script_interpreter->RunScriptFormatKeyword(script_function_name, t,
396 script_output, error) &&
397 error.Success()) {
398 s.Printf("%s", script_output.c_str());
399 return true;
400 } else {
401 s.Printf("<error: %s>", error.AsCString());
402 }
403 }
404 }
405 return false;
406}
407
409 const ExecutionContext *exe_ctx,
410 const Address &addr,
411 bool print_file_addr_or_load_addr) {
412 Target *target = Target::GetTargetFromContexts(exe_ctx, sc);
414 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
415 vaddr = addr.GetLoadAddress(target);
416 if (vaddr == LLDB_INVALID_ADDRESS)
417 vaddr = addr.GetFileAddress();
418
419 if (vaddr != LLDB_INVALID_ADDRESS) {
420 int addr_width = 0;
421 if (exe_ctx && target) {
422 addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
423 }
424 if (addr_width == 0)
425 addr_width = 16;
426 if (print_file_addr_or_load_addr) {
427 ExecutionContextScope *exe_scope = nullptr;
428 if (exe_ctx)
429 exe_scope = exe_ctx->GetBestExecutionContextScope();
430 addr.Dump(&s, exe_scope, Address::DumpStyleLoadAddress,
432 } else {
433 s.Printf("0x%*.*" PRIx64, addr_width, addr_width, vaddr);
434 }
435 return true;
436 }
437 return false;
438}
439
441 const ExecutionContext *exe_ctx,
442 const Address &format_addr,
443 bool concrete_only, bool no_padding,
444 bool print_zero_offsets) {
445 if (format_addr.IsValid()) {
446 Address func_addr;
447
448 if (sc) {
449 if (sc->function) {
450 func_addr = sc->function->GetAddressRange().GetBaseAddress();
451 if (sc->block && !concrete_only) {
452 // Check to make sure we aren't in an inline function. If we are, use
453 // the inline block range that contains "format_addr" since blocks
454 // can be discontiguous.
455 Block *inline_block = sc->block->GetContainingInlinedBlock();
456 AddressRange inline_range;
457 if (inline_block && inline_block->GetRangeContainingAddress(
458 format_addr, inline_range))
459 func_addr = inline_range.GetBaseAddress();
460 }
461 } else if (sc->symbol && sc->symbol->ValueIsAddress())
462 func_addr = sc->symbol->GetAddressRef();
463 }
464
465 if (func_addr.IsValid()) {
466 const char *addr_offset_padding = no_padding ? "" : " ";
467
468 if (func_addr.GetSection() == format_addr.GetSection()) {
469 addr_t func_file_addr = func_addr.GetFileAddress();
470 addr_t addr_file_addr = format_addr.GetFileAddress();
471 if (addr_file_addr > func_file_addr ||
472 (addr_file_addr == func_file_addr && print_zero_offsets)) {
473 s.Printf("%s+%s%" PRIu64, addr_offset_padding, addr_offset_padding,
474 addr_file_addr - func_file_addr);
475 } else if (addr_file_addr < func_file_addr) {
476 s.Printf("%s-%s%" PRIu64, addr_offset_padding, addr_offset_padding,
477 func_file_addr - addr_file_addr);
478 }
479 return true;
480 } else {
481 Target *target = Target::GetTargetFromContexts(exe_ctx, sc);
482 if (target) {
483 addr_t func_load_addr = func_addr.GetLoadAddress(target);
484 addr_t addr_load_addr = format_addr.GetLoadAddress(target);
485 if (addr_load_addr > func_load_addr ||
486 (addr_load_addr == func_load_addr && print_zero_offsets)) {
487 s.Printf("%s+%s%" PRIu64, addr_offset_padding, addr_offset_padding,
488 addr_load_addr - func_load_addr);
489 } else if (addr_load_addr < func_load_addr) {
490 s.Printf("%s-%s%" PRIu64, addr_offset_padding, addr_offset_padding,
491 func_load_addr - addr_load_addr);
492 }
493 return true;
494 }
495 }
496 }
497 }
498 return false;
499}
500
501static bool ScanBracketedRange(llvm::StringRef subpath,
502 size_t &close_bracket_index,
503 const char *&var_name_final_if_array_range,
504 int64_t &index_lower, int64_t &index_higher) {
506 close_bracket_index = llvm::StringRef::npos;
507 const size_t open_bracket_index = subpath.find('[');
508 if (open_bracket_index == llvm::StringRef::npos) {
509 LLDB_LOGF(log,
510 "[ScanBracketedRange] no bracketed range, skipping entirely");
511 return false;
512 }
513
514 close_bracket_index = subpath.find(']', open_bracket_index + 1);
515
516 if (close_bracket_index == llvm::StringRef::npos) {
517 LLDB_LOGF(log,
518 "[ScanBracketedRange] no bracketed range, skipping entirely");
519 return false;
520 } else {
521 var_name_final_if_array_range = subpath.data() + open_bracket_index;
522
523 if (close_bracket_index - open_bracket_index == 1) {
524 LLDB_LOGF(
525 log,
526 "[ScanBracketedRange] '[]' detected.. going from 0 to end of data");
527 index_lower = 0;
528 } else {
529 const size_t separator_index = subpath.find('-', open_bracket_index + 1);
530
531 if (separator_index == llvm::StringRef::npos) {
532 const char *index_lower_cstr = subpath.data() + open_bracket_index + 1;
533 index_lower = ::strtoul(index_lower_cstr, nullptr, 0);
534 index_higher = index_lower;
535 LLDB_LOGF(log,
536 "[ScanBracketedRange] [%" PRId64
537 "] detected, high index is same",
538 index_lower);
539 } else {
540 const char *index_lower_cstr = subpath.data() + open_bracket_index + 1;
541 const char *index_higher_cstr = subpath.data() + separator_index + 1;
542 index_lower = ::strtoul(index_lower_cstr, nullptr, 0);
543 index_higher = ::strtoul(index_higher_cstr, nullptr, 0);
544 LLDB_LOGF(log,
545 "[ScanBracketedRange] [%" PRId64 "-%" PRId64 "] detected",
546 index_lower, index_higher);
547 }
548 if (index_lower > index_higher && index_higher > 0) {
549 LLDB_LOGF(log, "[ScanBracketedRange] swapping indices");
550 const int64_t temp = index_lower;
551 index_lower = index_higher;
552 index_higher = temp;
553 }
554 }
555 }
556 return true;
557}
558
559static bool DumpFile(Stream &s, const FileSpec &file, FileKind file_kind) {
560 switch (file_kind) {
561 case FileKind::FileError:
562 break;
563
564 case FileKind::Basename:
565 if (file.GetFilename()) {
566 s << file.GetFilename();
567 return true;
568 }
569 break;
570
571 case FileKind::Dirname:
572 if (file.GetDirectory()) {
573 s << file.GetDirectory();
574 return true;
575 }
576 break;
577
578 case FileKind::Fullpath:
579 if (file) {
580 s << file;
581 return true;
582 }
583 break;
584 }
585 return false;
586}
587
588static bool DumpRegister(Stream &s, StackFrame *frame, RegisterKind reg_kind,
589 uint32_t reg_num, Format format) {
590 if (frame) {
591 RegisterContext *reg_ctx = frame->GetRegisterContext().get();
592
593 if (reg_ctx) {
594 const uint32_t lldb_reg_num =
595 reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
596 if (lldb_reg_num != LLDB_INVALID_REGNUM) {
597 const RegisterInfo *reg_info =
598 reg_ctx->GetRegisterInfoAtIndex(lldb_reg_num);
599 if (reg_info) {
600 RegisterValue reg_value;
601 if (reg_ctx->ReadRegister(reg_info, reg_value)) {
602 DumpRegisterValue(reg_value, s, *reg_info, false, false, format);
603 return true;
604 }
605 }
606 }
607 }
608 }
609 return false;
610}
611
613 bool deref_pointer) {
615 std::string name_to_deref = llvm::formatv("[{0}]", index);
616 LLDB_LOG(log, "[ExpandIndexedExpression] name to deref: {0}", name_to_deref);
624 name_to_deref, &reason_to_stop, &final_value_type, options, &what_next);
625 if (!item) {
626 LLDB_LOGF(log,
627 "[ExpandIndexedExpression] ERROR: why stopping = %d,"
628 " final_value_type %d",
629 reason_to_stop, final_value_type);
630 } else {
631 LLDB_LOGF(log,
632 "[ExpandIndexedExpression] ALL RIGHT: why stopping = %d,"
633 " final_value_type %d",
634 reason_to_stop, final_value_type);
635 }
636 return item;
637}
638
641 switch (style) {
643 return '@';
645 return 'V';
647 return 'L';
649 return 'S';
651 return '#';
653 return 'T';
655 return 'N';
657 return '>';
658 }
659 return '\0';
660}
661
662/// Options supported by format_provider<T> for integral arithmetic types.
663/// See table in FormatProviders.h.
664static llvm::Regex LLVMFormatPattern{"x[-+]?\\d*|n|d", llvm::Regex::IgnoreCase};
665
666static bool DumpValueWithLLVMFormat(Stream &s, llvm::StringRef options,
667 ValueObject &valobj) {
668 std::string formatted;
669 std::string llvm_format = ("{0:" + options + "}").str();
670
671 auto type_info = valobj.GetTypeInfo();
672 if ((type_info & eTypeIsInteger) && LLVMFormatPattern.match(options)) {
673 if (type_info & eTypeIsSigned) {
674 bool success = false;
675 int64_t integer = valobj.GetValueAsSigned(0, &success);
676 if (success)
677 formatted = llvm::formatv(llvm_format.data(), integer);
678 } else {
679 bool success = false;
680 uint64_t integer = valobj.GetValueAsUnsigned(0, &success);
681 if (success)
682 formatted = llvm::formatv(llvm_format.data(), integer);
683 }
684 }
685
686 if (formatted.empty())
687 return false;
688
689 s.Write(formatted.data(), formatted.size());
690 return true;
691}
692
693static bool DumpValue(Stream &s, const SymbolContext *sc,
694 const ExecutionContext *exe_ctx,
695 const FormatEntity::Entry &entry, ValueObject *valobj) {
696 if (valobj == nullptr)
697 return false;
698
700 Format custom_format = eFormatInvalid;
702 entry.string.empty()
705
706 bool do_deref_pointer = entry.deref;
707 bool is_script = false;
708 switch (entry.type) {
710 is_script = true;
711 break;
712
714 custom_format = entry.fmt;
716 break;
717
719 is_script = true;
720 [[fallthrough]];
722 custom_format = entry.fmt;
724 if (!valobj->IsSynthetic()) {
725 valobj = valobj->GetSyntheticValue().get();
726 if (valobj == nullptr)
727 return false;
728 }
729 break;
730
731 default:
732 return false;
733 }
734
744 SyntheticChildrenTraversal::Both);
745 ValueObject *target = nullptr;
746 const char *var_name_final_if_array_range = nullptr;
747 size_t close_bracket_index = llvm::StringRef::npos;
748 int64_t index_lower = -1;
749 int64_t index_higher = -1;
750 bool is_array_range = false;
751 bool was_plain_var = false;
752 bool was_var_format = false;
753 bool was_var_indexed = false;
758
759 if (is_script) {
760 return RunScriptFormatKeyword(s, sc, exe_ctx, valobj, entry.string.c_str());
761 }
762
763 auto split = llvm::StringRef(entry.string).split(':');
764 auto subpath = split.first;
765 auto llvm_format = split.second;
766
767 // simplest case ${var}, just print valobj's value
768 if (subpath.empty()) {
769 if (entry.printf_format.empty() && entry.fmt == eFormatDefault &&
771 was_plain_var = true;
772 else
773 was_var_format = true;
774 target = valobj;
775 } else // this is ${var.something} or multiple .something nested
776 {
777 if (subpath[0] == '[')
778 was_var_indexed = true;
779 ScanBracketedRange(subpath, close_bracket_index,
780 var_name_final_if_array_range, index_lower,
781 index_higher);
782
784
785 LLDB_LOG(log, "[Debugger::FormatPrompt] symbol to expand: {0}", subpath);
786
787 target =
788 valobj
789 ->GetValueForExpressionPath(subpath, &reason_to_stop,
790 &final_value_type, options, &what_next)
791 .get();
792
793 if (!target) {
794 LLDB_LOGF(log,
795 "[Debugger::FormatPrompt] ERROR: why stopping = %d,"
796 " final_value_type %d",
797 reason_to_stop, final_value_type);
798 return false;
799 } else {
800 LLDB_LOGF(log,
801 "[Debugger::FormatPrompt] ALL RIGHT: why stopping = %d,"
802 " final_value_type %d",
803 reason_to_stop, final_value_type);
804 target = target
806 target->GetDynamicValueType(), true)
807 .get();
808 }
809 }
810
811 is_array_range =
812 (final_value_type ==
814 final_value_type ==
816
817 do_deref_pointer =
819
820 if (do_deref_pointer && !is_array_range) {
821 // I have not deref-ed yet, let's do it
822 // this happens when we are not going through
823 // GetValueForVariableExpressionPath to get to the target ValueObject
825 target = target->Dereference(error).get();
826 if (error.Fail()) {
827 LLDB_LOGF(log, "[Debugger::FormatPrompt] ERROR: %s\n",
828 error.AsCString("unknown"));
829 return false;
830 }
831 do_deref_pointer = false;
832 }
833
834 if (!target) {
835 LLDB_LOGF(log, "[Debugger::FormatPrompt] could not calculate target for "
836 "prompt expression");
837 return false;
838 }
839
840 // we do not want to use the summary for a bitfield of type T:n if we were
841 // originally dealing with just a T - that would get us into an endless
842 // recursion
843 if (target->IsBitfield() && was_var_indexed) {
844 // TODO: check for a (T:n)-specific summary - we should still obey that
845 StreamString bitfield_name;
846 bitfield_name.Printf("%s:%d", target->GetTypeName().AsCString(),
847 target->GetBitfieldBitSize());
848 auto type_sp = std::make_shared<TypeNameSpecifierImpl>(
849 bitfield_name.GetString(), lldb::eFormatterMatchExact);
850 if (val_obj_display ==
854 }
855
856 // TODO use flags for these
857 const uint32_t type_info_flags =
858 target->GetCompilerType().GetTypeInfo(nullptr);
859 bool is_array = (type_info_flags & eTypeIsArray) != 0;
860 bool is_pointer = (type_info_flags & eTypeIsPointer) != 0;
861 bool is_aggregate = target->GetCompilerType().IsAggregateType();
862
863 if ((is_array || is_pointer) && (!is_array_range) &&
864 val_obj_display ==
866 // wrong, but there
867 // are some
868 // exceptions
869 {
870 StreamString str_temp;
871 LLDB_LOGF(log,
872 "[Debugger::FormatPrompt] I am into array || pointer && !range");
873
874 if (target->HasSpecialPrintableRepresentation(val_obj_display,
875 custom_format)) {
876 // try to use the special cases
877 bool success = target->DumpPrintableRepresentation(
878 str_temp, val_obj_display, custom_format);
879 LLDB_LOGF(log, "[Debugger::FormatPrompt] special cases did%s match",
880 success ? "" : "n't");
881
882 // should not happen
883 if (success)
884 s << str_temp.GetString();
885 return true;
886 } else {
887 if (was_plain_var) // if ${var}
888 {
889 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
890 } else if (is_pointer) // if pointer, value is the address stored
891 {
893 s, val_obj_display, custom_format,
895 }
896 return true;
897 }
898 }
899
900 // if directly trying to print ${var}, and this is an aggregate, display a
901 // nice type @ location message
902 if (is_aggregate && was_plain_var) {
903 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
904 return true;
905 }
906
907 // if directly trying to print ${var%V}, and this is an aggregate, do not let
908 // the user do it
909 if (is_aggregate &&
910 ((was_var_format &&
911 val_obj_display ==
913 s << "<invalid use of aggregate type>";
914 return true;
915 }
916
917 if (!is_array_range) {
918 if (!llvm_format.empty()) {
919 if (DumpValueWithLLVMFormat(s, llvm_format, *target)) {
920 LLDB_LOGF(log, "dumping using llvm format");
921 return true;
922 } else {
923 LLDB_LOG(
924 log,
925 "empty output using llvm format '{0}' - with type info flags {1}",
926 entry.printf_format, target->GetTypeInfo());
927 }
928 }
929 LLDB_LOGF(log, "dumping ordinary printable output");
930 return target->DumpPrintableRepresentation(s, val_obj_display,
931 custom_format);
932 } else {
933 LLDB_LOGF(log,
934 "[Debugger::FormatPrompt] checking if I can handle as array");
935 if (!is_array && !is_pointer)
936 return false;
937 LLDB_LOGF(log, "[Debugger::FormatPrompt] handle as array");
938 StreamString special_directions_stream;
939 llvm::StringRef special_directions;
940 if (close_bracket_index != llvm::StringRef::npos &&
941 subpath.size() > close_bracket_index) {
942 ConstString additional_data(subpath.drop_front(close_bracket_index + 1));
943 special_directions_stream.Printf("${%svar%s", do_deref_pointer ? "*" : "",
944 additional_data.GetCString());
945
946 if (entry.fmt != eFormatDefault) {
947 const char format_char =
949 if (format_char != '\0')
950 special_directions_stream.Printf("%%%c", format_char);
951 else {
952 const char *format_cstr =
954 special_directions_stream.Printf("%%%s", format_cstr);
955 }
956 } else if (entry.number != 0) {
957 const char style_char = ConvertValueObjectStyleToChar(
959 if (style_char)
960 special_directions_stream.Printf("%%%c", style_char);
961 }
962 special_directions_stream.PutChar('}');
963 special_directions =
964 llvm::StringRef(special_directions_stream.GetString());
965 }
966
967 // let us display items index_lower thru index_higher of this array
968 s.PutChar('[');
969
970 if (index_higher < 0)
971 index_higher = valobj->GetNumChildrenIgnoringErrors() - 1;
972
973 uint32_t max_num_children =
974 target->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
975
976 bool success = true;
977 for (int64_t index = index_lower; index <= index_higher; ++index) {
978 ValueObject *item = ExpandIndexedExpression(target, index, false).get();
979
980 if (!item) {
981 LLDB_LOGF(log,
982 "[Debugger::FormatPrompt] ERROR in getting child item at "
983 "index %" PRId64,
984 index);
985 } else {
986 LLDB_LOGF(
987 log,
988 "[Debugger::FormatPrompt] special_directions for child item: %s",
989 special_directions.data() ? special_directions.data() : "");
990 }
991
992 if (special_directions.empty()) {
993 success &= item->DumpPrintableRepresentation(s, val_obj_display,
994 custom_format);
995 } else {
997 special_directions, s, sc, exe_ctx, nullptr, item, false, false);
998 }
999
1000 if (--max_num_children == 0) {
1001 s.PutCString(", ...");
1002 break;
1003 }
1004
1005 if (index < index_higher)
1006 s.PutChar(',');
1007 }
1008 s.PutChar(']');
1009 return success;
1010 }
1011}
1012
1013static bool DumpRegister(Stream &s, StackFrame *frame, const char *reg_name,
1014 Format format) {
1015 if (frame) {
1016 RegisterContext *reg_ctx = frame->GetRegisterContext().get();
1017
1018 if (reg_ctx) {
1019 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(reg_name);
1020 if (reg_info) {
1021 RegisterValue reg_value;
1022 if (reg_ctx->ReadRegister(reg_info, reg_value)) {
1023 DumpRegisterValue(reg_value, s, *reg_info, false, false, format);
1024 return true;
1025 }
1026 }
1027 }
1028 }
1029 return false;
1030}
1031
1033 const FormatEntity::Entry &entry,
1034 const StructuredData::ObjectSP &thread_info_dictionary,
1035 const SymbolContext *sc, const ExecutionContext *exe_ctx, Stream &s) {
1036 llvm::StringRef path(entry.string);
1037
1039 thread_info_dictionary->GetObjectForDotSeparatedPath(path);
1040
1041 if (value) {
1042 if (value->GetType() == eStructuredDataTypeInteger) {
1043 const char *token_format = "0x%4.4" PRIx64;
1044 if (!entry.printf_format.empty())
1045 token_format = entry.printf_format.c_str();
1046 s.Printf(token_format, value->GetUnsignedIntegerValue());
1047 return true;
1048 } else if (value->GetType() == eStructuredDataTypeFloat) {
1049 s.Printf("%f", value->GetAsFloat()->GetValue());
1050 return true;
1051 } else if (value->GetType() == eStructuredDataTypeString) {
1052 s.Format("{0}", value->GetAsString()->GetValue());
1053 return true;
1054 } else if (value->GetType() == eStructuredDataTypeArray) {
1055 if (value->GetAsArray()->GetSize() > 0) {
1056 s.Printf("%zu", value->GetAsArray()->GetSize());
1057 return true;
1058 }
1059 } else if (value->GetType() == eStructuredDataTypeDictionary) {
1060 s.Printf("%zu",
1061 value->GetAsDictionary()->GetKeys()->GetAsArray()->GetSize());
1062 return true;
1063 }
1064 }
1065
1066 return false;
1067}
1068
1069static inline bool IsToken(const char *var_name_begin, const char *var) {
1070 return (::strncmp(var_name_begin, var, strlen(var)) == 0);
1071}
1072
1073/// Parses the basename out of a demangled function name
1074/// that may include function arguments. Supports
1075/// template functions.
1076///
1077/// Returns pointers to the opening and closing parenthesis of
1078/// `full_name`. Can return nullptr for either parenthesis if
1079/// none is exists.
1080static std::pair<char const *, char const *>
1081ParseBaseName(char const *full_name) {
1082 const char *open_paren = strchr(full_name, '(');
1083 const char *close_paren = nullptr;
1084 const char *generic = strchr(full_name, '<');
1085 // if before the arguments list begins there is a template sign
1086 // then scan to the end of the generic args before you try to find
1087 // the arguments list
1088 if (generic && open_paren && generic < open_paren) {
1089 int generic_depth = 1;
1090 ++generic;
1091 for (; *generic && generic_depth > 0; generic++) {
1092 if (*generic == '<')
1093 generic_depth++;
1094 if (*generic == '>')
1095 generic_depth--;
1096 }
1097 if (*generic)
1098 open_paren = strchr(generic, '(');
1099 else
1100 open_paren = nullptr;
1101 }
1102
1103 if (open_paren) {
1104 if (IsToken(open_paren, "(anonymous namespace)")) {
1105 open_paren = strchr(open_paren + strlen("(anonymous namespace)"), '(');
1106 if (open_paren)
1107 close_paren = strchr(open_paren, ')');
1108 } else
1109 close_paren = strchr(open_paren, ')');
1110 }
1111
1112 return {open_paren, close_paren};
1113}
1114
1115/// Writes out the function name in 'full_name' to 'out_stream'
1116/// but replaces each argument type with the variable name
1117/// and the corresponding pretty-printed value
1119 char const *full_name,
1120 ExecutionContextScope *exe_scope,
1121 VariableList const &args) {
1122 auto [open_paren, close_paren] = ParseBaseName(full_name);
1123 if (open_paren)
1124 out_stream.Write(full_name, open_paren - full_name + 1);
1125 else {
1126 out_stream.PutCString(full_name);
1127 out_stream.PutChar('(');
1128 }
1129
1130 FormatEntity::PrettyPrintFunctionArguments(out_stream, args, exe_scope);
1131
1132 if (close_paren)
1133 out_stream.PutCString(close_paren);
1134 else
1135 out_stream.PutChar(')');
1136}
1137
1138static void FormatInlinedBlock(Stream &out_stream, Block *block) {
1139 if (!block)
1140 return;
1141 Block *inline_block = block->GetContainingInlinedBlock();
1142 if (inline_block) {
1143 if (const InlineFunctionInfo *inline_info =
1144 inline_block->GetInlinedFunctionInfo()) {
1145 out_stream.PutCString(" [inlined] ");
1146 inline_info->GetName().Dump(&out_stream);
1147 }
1148 }
1149}
1150
1151bool FormatEntity::FormatStringRef(const llvm::StringRef &format_str, Stream &s,
1152 const SymbolContext *sc,
1153 const ExecutionContext *exe_ctx,
1154 const Address *addr, ValueObject *valobj,
1155 bool function_changed,
1156 bool initial_function) {
1157 if (!format_str.empty()) {
1159 Status error = FormatEntity::Parse(format_str, root);
1160 if (error.Success()) {
1161 return FormatEntity::Format(root, s, sc, exe_ctx, addr, valobj,
1162 function_changed, initial_function);
1163 }
1164 }
1165 return false;
1166}
1167
1168bool FormatEntity::FormatCString(const char *format, Stream &s,
1169 const SymbolContext *sc,
1170 const ExecutionContext *exe_ctx,
1171 const Address *addr, ValueObject *valobj,
1172 bool function_changed, bool initial_function) {
1173 if (format && format[0]) {
1175 llvm::StringRef format_str(format);
1176 Status error = FormatEntity::Parse(format_str, root);
1177 if (error.Success()) {
1178 return FormatEntity::Format(root, s, sc, exe_ctx, addr, valobj,
1179 function_changed, initial_function);
1180 }
1181 }
1182 return false;
1183}
1184
1185bool FormatEntity::Format(const Entry &entry, Stream &s,
1186 const SymbolContext *sc,
1187 const ExecutionContext *exe_ctx, const Address *addr,
1188 ValueObject *valobj, bool function_changed,
1189 bool initial_function) {
1190 switch (entry.type) {
1192 case Entry::Type::ParentNumber: // Only used for
1193 // FormatEntity::Entry::Definition encoding
1194 case Entry::Type::ParentString: // Only used for
1195 // FormatEntity::Entry::Definition encoding
1196 return false;
1198 if (exe_ctx) {
1199 if (Target *target = exe_ctx->GetTargetPtr()) {
1200 Debugger &debugger = target->GetDebugger();
1201 if (debugger.GetUseColor()) {
1202 s.PutCString(entry.string);
1203 }
1204 }
1205 }
1206 // Always return true, so colors being disabled is transparent.
1207 return true;
1208
1209 case Entry::Type::Root:
1210 for (const auto &child : entry.children) {
1211 if (!Format(child, s, sc, exe_ctx, addr, valobj, function_changed,
1212 initial_function)) {
1213 return false; // If any item of root fails, then the formatting fails
1214 }
1215 }
1216 return true; // Only return true if all items succeeded
1217
1219 s.PutCString(entry.string);
1220 return true;
1221
1222 case Entry::Type::Scope: {
1223 StreamString scope_stream;
1224 bool success = false;
1225 for (const auto &child : entry.children) {
1226 success = Format(child, scope_stream, sc, exe_ctx, addr, valobj,
1227 function_changed, initial_function);
1228 if (!success)
1229 break;
1230 }
1231 // Only if all items in a scope succeed, then do we print the output into
1232 // the main stream
1233 if (success)
1234 s.Write(scope_stream.GetString().data(), scope_stream.GetString().size());
1235 }
1236 return true; // Scopes always successfully print themselves
1237
1242 return DumpValue(s, sc, exe_ctx, entry, valobj);
1243
1247 return (
1248 addr != nullptr && addr->IsValid() &&
1249 DumpAddressAndContent(s, sc, exe_ctx, *addr,
1251
1253 if (exe_ctx) {
1254 Process *process = exe_ctx->GetProcessPtr();
1255 if (process) {
1256 const char *format = "%" PRIu64;
1257 if (!entry.printf_format.empty())
1258 format = entry.printf_format.c_str();
1259 s.Printf(format, process->GetID());
1260 return true;
1261 }
1262 }
1263 return false;
1264
1266 if (exe_ctx) {
1267 Process *process = exe_ctx->GetProcessPtr();
1268 if (process) {
1269 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
1270 if (exe_module) {
1271 if (DumpFile(s, exe_module->GetFileSpec(), (FileKind)entry.number))
1272 return true;
1273 }
1274 }
1275 }
1276 return false;
1277
1279 if (exe_ctx) {
1280 Process *process = exe_ctx->GetProcessPtr();
1281 if (process)
1282 return RunScriptFormatKeyword(s, sc, exe_ctx, process,
1283 entry.string.c_str());
1284 }
1285 return false;
1286
1288 if (exe_ctx) {
1289 Thread *thread = exe_ctx->GetThreadPtr();
1290 if (thread) {
1291 const char *format = "0x%4.4" PRIx64;
1292 if (!entry.printf_format.empty()) {
1293 // Watch for the special "tid" format...
1294 if (entry.printf_format == "tid") {
1295 // TODO(zturner): Rather than hardcoding this to be platform
1296 // specific, it should be controlled by a setting and the default
1297 // value of the setting can be different depending on the platform.
1298 Target &target = thread->GetProcess()->GetTarget();
1299 ArchSpec arch(target.GetArchitecture());
1300 llvm::Triple::OSType ostype = arch.IsValid()
1301 ? arch.GetTriple().getOS()
1302 : llvm::Triple::UnknownOS;
1303 if (ostype == llvm::Triple::FreeBSD ||
1304 ostype == llvm::Triple::Linux ||
1305 ostype == llvm::Triple::NetBSD ||
1306 ostype == llvm::Triple::OpenBSD) {
1307 format = "%" PRIu64;
1308 }
1309 } else {
1310 format = entry.printf_format.c_str();
1311 }
1312 }
1313 s.Printf(format, thread->GetID());
1314 return true;
1315 }
1316 }
1317 return false;
1318
1320 if (exe_ctx) {
1321 Thread *thread = exe_ctx->GetThreadPtr();
1322 if (thread) {
1323 const char *format = "0x%4.4" PRIx64;
1324 if (!entry.printf_format.empty())
1325 format = entry.printf_format.c_str();
1326 s.Printf(format, thread->GetProtocolID());
1327 return true;
1328 }
1329 }
1330 return false;
1331
1333 if (exe_ctx) {
1334 Thread *thread = exe_ctx->GetThreadPtr();
1335 if (thread) {
1336 const char *format = "%" PRIu32;
1337 if (!entry.printf_format.empty())
1338 format = entry.printf_format.c_str();
1339 s.Printf(format, thread->GetIndexID());
1340 return true;
1341 }
1342 }
1343 return false;
1344
1346 if (exe_ctx) {
1347 Thread *thread = exe_ctx->GetThreadPtr();
1348 if (thread) {
1349 const char *cstr = thread->GetName();
1350 if (cstr && cstr[0]) {
1351 s.PutCString(cstr);
1352 return true;
1353 }
1354 }
1355 }
1356 return false;
1357
1359 if (exe_ctx) {
1360 Thread *thread = exe_ctx->GetThreadPtr();
1361 if (thread) {
1362 const char *cstr = thread->GetQueueName();
1363 if (cstr && cstr[0]) {
1364 s.PutCString(cstr);
1365 return true;
1366 }
1367 }
1368 }
1369 return false;
1370
1372 if (exe_ctx) {
1373 if (Thread *thread = exe_ctx->GetThreadPtr()) {
1374 std::string stop_description = thread->GetStopDescription();
1375 if (!stop_description.empty()) {
1376 s.PutCString(stop_description);
1377 return true;
1378 }
1379 }
1380 }
1381 return false;
1382
1384 if (exe_ctx) {
1385 if (Thread *thread = exe_ctx->GetThreadPtr()) {
1386 std::string stop_description = thread->GetStopDescriptionRaw();
1387 if (!stop_description.empty()) {
1388 s.PutCString(stop_description);
1389 return true;
1390 }
1391 }
1392 }
1393 return false;
1394
1396 if (exe_ctx) {
1397 Thread *thread = exe_ctx->GetThreadPtr();
1398 if (thread) {
1399 StopInfoSP stop_info_sp = thread->GetStopInfo();
1400 if (stop_info_sp && stop_info_sp->IsValid()) {
1401 ValueObjectSP return_valobj_sp =
1402 StopInfo::GetReturnValueObject(stop_info_sp);
1403 if (return_valobj_sp) {
1404 return_valobj_sp->Dump(s);
1405 return true;
1406 }
1407 }
1408 }
1409 }
1410 return false;
1411
1413 if (exe_ctx) {
1414 Thread *thread = exe_ctx->GetThreadPtr();
1415 if (thread) {
1416 StopInfoSP stop_info_sp = thread->GetStopInfo();
1417 if (stop_info_sp && stop_info_sp->IsValid()) {
1418 ExpressionVariableSP expression_var_sp =
1419 StopInfo::GetExpressionVariable(stop_info_sp);
1420 if (expression_var_sp && expression_var_sp->GetValueObject()) {
1421 expression_var_sp->GetValueObject()->Dump(s);
1422 return true;
1423 }
1424 }
1425 }
1426 }
1427 return false;
1428
1430 if (exe_ctx) {
1431 Thread *thread = exe_ctx->GetThreadPtr();
1432 if (thread)
1433 return RunScriptFormatKeyword(s, sc, exe_ctx, thread,
1434 entry.string.c_str());
1435 }
1436 return false;
1437
1439 if (exe_ctx) {
1440 Thread *thread = exe_ctx->GetThreadPtr();
1441 if (thread) {
1442 StructuredData::ObjectSP object_sp = thread->GetExtendedInfo();
1443 if (object_sp &&
1444 object_sp->GetType() == eStructuredDataTypeDictionary) {
1445 if (FormatThreadExtendedInfoRecurse(entry, object_sp, sc, exe_ctx, s))
1446 return true;
1447 }
1448 }
1449 }
1450 return false;
1451
1453 if (exe_ctx) {
1454 Target *target = exe_ctx->GetTargetPtr();
1455 if (target) {
1456 const ArchSpec &arch = target->GetArchitecture();
1457 if (arch.IsValid()) {
1459 return true;
1460 }
1461 }
1462 }
1463 return false;
1464
1466 if (exe_ctx) {
1467 Target *target = exe_ctx->GetTargetPtr();
1468 if (target)
1469 return RunScriptFormatKeyword(s, sc, exe_ctx, target,
1470 entry.string.c_str());
1471 }
1472 return false;
1473
1475 if (sc) {
1476 Module *module = sc->module_sp.get();
1477 if (module) {
1478 if (DumpFile(s, module->GetFileSpec(), (FileKind)entry.number))
1479 return true;
1480 }
1481 }
1482 return false;
1483
1484 case Entry::Type::File:
1485 if (sc) {
1486 CompileUnit *cu = sc->comp_unit;
1487 if (cu) {
1488 if (DumpFile(s, cu->GetPrimaryFile(), (FileKind)entry.number))
1489 return true;
1490 }
1491 }
1492 return false;
1493
1494 case Entry::Type::Lang:
1495 if (sc) {
1496 CompileUnit *cu = sc->comp_unit;
1497 if (cu) {
1498 const char *lang_name =
1500 if (lang_name) {
1501 s.PutCString(lang_name);
1502 return true;
1503 }
1504 }
1505 }
1506 return false;
1507
1509 if (exe_ctx) {
1510 StackFrame *frame = exe_ctx->GetFramePtr();
1511 if (frame) {
1512 const char *format = "%" PRIu32;
1513 if (!entry.printf_format.empty())
1514 format = entry.printf_format.c_str();
1515 s.Printf(format, frame->GetFrameIndex());
1516 return true;
1517 }
1518 }
1519 return false;
1520
1522 if (exe_ctx) {
1523 StackFrame *frame = exe_ctx->GetFramePtr();
1524 if (frame) {
1525 const Address &pc_addr = frame->GetFrameCodeAddress();
1526 if (pc_addr.IsValid()) {
1527 if (DumpAddressAndContent(s, sc, exe_ctx, pc_addr, false))
1528 return true;
1529 }
1530 }
1531 }
1532 return false;
1533
1535 if (exe_ctx) {
1536 StackFrame *frame = exe_ctx->GetFramePtr();
1537 if (frame) {
1539 (lldb::Format)entry.number))
1540 return true;
1541 }
1542 }
1543 return false;
1544
1546 if (exe_ctx) {
1547 StackFrame *frame = exe_ctx->GetFramePtr();
1548 if (frame) {
1550 (lldb::Format)entry.number))
1551 return true;
1552 }
1553 }
1554 return false;
1555
1557 if (exe_ctx) {
1558 StackFrame *frame = exe_ctx->GetFramePtr();
1559 if (frame) {
1560 if (DumpRegister(s, frame, eRegisterKindGeneric,
1562 return true;
1563 }
1564 }
1565 return false;
1566
1568 if (exe_ctx) {
1569 StackFrame *frame = exe_ctx->GetFramePtr();
1570 if (frame) {
1571 return !frame->HasDebugInformation();
1572 }
1573 }
1574 return true;
1575
1577 if (exe_ctx) {
1578 StackFrame *frame = exe_ctx->GetFramePtr();
1579 if (frame) {
1580 if (DumpRegister(s, frame, entry.string.c_str(),
1581 (lldb::Format)entry.number))
1582 return true;
1583 }
1584 }
1585 return false;
1586
1588 if (exe_ctx)
1589 if (StackFrame *frame = exe_ctx->GetFramePtr())
1590 return frame->IsArtificial();
1591 return false;
1592 }
1593
1595 if (exe_ctx) {
1596 StackFrame *frame = exe_ctx->GetFramePtr();
1597 if (frame)
1598 return RunScriptFormatKeyword(s, sc, exe_ctx, frame,
1599 entry.string.c_str());
1600 }
1601 return false;
1602
1604 if (sc) {
1605 if (sc->function) {
1606 s.Printf("function{0x%8.8" PRIx64 "}", sc->function->GetID());
1607 return true;
1608 } else if (sc->symbol) {
1609 s.Printf("symbol[%u]", sc->symbol->GetID());
1610 return true;
1611 }
1612 }
1613 return false;
1614
1616 return function_changed;
1617
1619 return initial_function;
1620
1622 if (!sc)
1623 return false;
1624
1625 Language *language_plugin = nullptr;
1626 bool language_plugin_handled = false;
1627 StreamString ss;
1628
1629 if (sc->function)
1630 language_plugin = Language::FindPlugin(sc->function->GetLanguage());
1631 else if (sc->symbol)
1632 language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
1633
1634 if (language_plugin)
1635 language_plugin_handled = language_plugin->GetFunctionDisplayName(
1637
1638 if (language_plugin_handled) {
1639 s << ss.GetString();
1640 return true;
1641 } else {
1642 const char *name = nullptr;
1643 if (sc->function)
1644 name = sc->function->GetName().AsCString(nullptr);
1645 else if (sc->symbol)
1646 name = sc->symbol->GetName().AsCString(nullptr);
1647
1648 if (name) {
1649 s.PutCString(name);
1650 FormatInlinedBlock(s, sc->block);
1651 return true;
1652 }
1653 }
1654 }
1655 return false;
1656
1658 if (!sc)
1659 return false;
1660
1661 Language *language_plugin = nullptr;
1662 bool language_plugin_handled = false;
1663 StreamString ss;
1664 if (sc->function)
1665 language_plugin = Language::FindPlugin(sc->function->GetLanguage());
1666 else if (sc->symbol)
1667 language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
1668
1669 if (language_plugin)
1670 language_plugin_handled = language_plugin->GetFunctionDisplayName(
1672 ss);
1673
1674 if (language_plugin_handled) {
1675 s << ss.GetString();
1676 return true;
1677 } else {
1678 ConstString name;
1679 if (sc->function)
1680 name = sc->function->GetNameNoArguments();
1681 else if (sc->symbol)
1682 name = sc->symbol->GetNameNoArguments();
1683 if (name) {
1684 s.PutCString(name.GetCString());
1685 FormatInlinedBlock(s, sc->block);
1686 return true;
1687 }
1688 }
1689 }
1690 return false;
1691
1693 if (!sc)
1694 return false;
1695
1696 Language *language_plugin = nullptr;
1697 bool language_plugin_handled = false;
1698 StreamString ss;
1699 if (sc->function)
1700 language_plugin = Language::FindPlugin(sc->function->GetLanguage());
1701 else if (sc->symbol)
1702 language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
1703
1704 if (language_plugin)
1705 language_plugin_handled = language_plugin->GetFunctionDisplayName(
1707
1708 if (language_plugin_handled) {
1709 s << ss.GetString();
1710 return true;
1711 } else {
1712 // Print the function name with arguments in it
1713 if (sc->function) {
1714 ExecutionContextScope *exe_scope =
1715 exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr;
1716 const char *cstr = sc->function->GetName().AsCString(nullptr);
1717 if (cstr) {
1718 const InlineFunctionInfo *inline_info = nullptr;
1719 VariableListSP variable_list_sp;
1720 bool get_function_vars = true;
1721 if (sc->block) {
1722 Block *inline_block = sc->block->GetContainingInlinedBlock();
1723
1724 if (inline_block) {
1725 get_function_vars = false;
1726 inline_info = inline_block->GetInlinedFunctionInfo();
1727 if (inline_info)
1728 variable_list_sp = inline_block->GetBlockVariableList(true);
1729 }
1730 }
1731
1732 if (get_function_vars) {
1733 variable_list_sp =
1734 sc->function->GetBlock(true).GetBlockVariableList(true);
1735 }
1736
1737 if (inline_info) {
1738 s.PutCString(cstr);
1739 s.PutCString(" [inlined] ");
1740 cstr = inline_info->GetName().GetCString();
1741 }
1742
1743 VariableList args;
1744 if (variable_list_sp)
1745 variable_list_sp->AppendVariablesWithScope(
1747 if (args.GetSize() > 0) {
1748 PrettyPrintFunctionNameWithArgs(s, cstr, exe_scope, args);
1749 } else {
1750 s.PutCString(cstr);
1751 }
1752 return true;
1753 }
1754 } else if (sc->symbol) {
1755 const char *cstr = sc->symbol->GetName().AsCString(nullptr);
1756 if (cstr) {
1757 s.PutCString(cstr);
1758 return true;
1759 }
1760 }
1761 }
1762 }
1763 return false;
1764
1766 if (!sc)
1767 return false;
1768
1769 const char *name = nullptr;
1770 if (sc->symbol)
1771 name =
1773 else if (sc->function)
1774 name = sc->function->GetMangled()
1776 .AsCString();
1777
1778 if (!name)
1779 return false;
1780 s.PutCString(name);
1781 FormatInlinedBlock(s, sc->block);
1782 return true;
1783 }
1785 if (addr) {
1786 if (DumpAddressOffsetFromFunction(s, sc, exe_ctx, *addr, false, false,
1787 false))
1788 return true;
1789 }
1790 return false;
1791
1793 if (addr) {
1794 if (DumpAddressOffsetFromFunction(s, sc, exe_ctx, *addr, true, true,
1795 true))
1796 return true;
1797 }
1798 return false;
1799
1801 if (sc)
1803 s, sc, exe_ctx, sc->line_entry.range.GetBaseAddress(), false, false,
1804 false));
1805 return false;
1806
1808 if (exe_ctx) {
1809 StackFrame *frame = exe_ctx->GetFramePtr();
1810 if (frame) {
1811 if (DumpAddressOffsetFromFunction(s, sc, exe_ctx,
1812 frame->GetFrameCodeAddress(), false,
1813 false, false))
1814 return true;
1815 }
1816 }
1817 return false;
1818
1820 return function_changed;
1821
1823 bool is_optimized = false;
1824 if (sc && sc->function && sc->function->GetIsOptimized()) {
1825 is_optimized = true;
1826 }
1827 return is_optimized;
1828 }
1829
1831 return initial_function;
1832
1834 if (sc && sc->line_entry.IsValid()) {
1835 Module *module = sc->module_sp.get();
1836 if (module) {
1837 if (DumpFile(s, sc->line_entry.GetFile(), (FileKind)entry.number))
1838 return true;
1839 }
1840 }
1841 return false;
1842
1844 if (sc && sc->line_entry.IsValid()) {
1845 const char *format = "%" PRIu32;
1846 if (!entry.printf_format.empty())
1847 format = entry.printf_format.c_str();
1848 s.Printf(format, sc->line_entry.line);
1849 return true;
1850 }
1851 return false;
1852
1854 if (sc && sc->line_entry.IsValid() && sc->line_entry.column) {
1855 const char *format = "%" PRIu32;
1856 if (!entry.printf_format.empty())
1857 format = entry.printf_format.c_str();
1858 s.Printf(format, sc->line_entry.column);
1859 return true;
1860 }
1861 return false;
1862
1865 if (sc && sc->line_entry.range.GetBaseAddress().IsValid()) {
1867
1869 addr.Slide(sc->line_entry.range.GetByteSize());
1870 if (DumpAddressAndContent(s, sc, exe_ctx, addr, false))
1871 return true;
1872 }
1873 return false;
1874
1876 if (addr && exe_ctx && exe_ctx->GetFramePtr()) {
1877 RegisterContextSP reg_ctx =
1878 exe_ctx->GetFramePtr()->GetRegisterContextSP();
1879 if (reg_ctx) {
1880 addr_t pc_loadaddr = reg_ctx->GetPC();
1881 if (pc_loadaddr != LLDB_INVALID_ADDRESS) {
1882 Address pc;
1883 pc.SetLoadAddress(pc_loadaddr, exe_ctx->GetTargetPtr());
1884 if (pc == *addr) {
1885 s.Printf("-> ");
1886 return true;
1887 }
1888 }
1889 }
1890 s.Printf(" ");
1891 return true;
1892 }
1893 return false;
1894 }
1895 return false;
1896}
1897
1899 const Definition *parent) {
1900 if (parent->children) {
1901 const size_t n = parent->num_children;
1902 for (size_t i = 0; i < n; ++i) {
1903 if (i > 0)
1904 s.PutCString(", ");
1905 s.Printf("\"%s\"", parent->children[i].name);
1906 }
1907 return true;
1908 }
1909 return false;
1910}
1911
1912static Status ParseEntry(const llvm::StringRef &format_str,
1913 const Definition *parent, FormatEntity::Entry &entry) {
1914 Status error;
1915
1916 const size_t sep_pos = format_str.find_first_of(".[:");
1917 const char sep_char =
1918 (sep_pos == llvm::StringRef::npos) ? '\0' : format_str[sep_pos];
1919 llvm::StringRef key = format_str.substr(0, sep_pos);
1920
1921 const size_t n = parent->num_children;
1922 for (size_t i = 0; i < n; ++i) {
1923 const Definition *entry_def = parent->children + i;
1924 if (key == entry_def->name || entry_def->name[0] == '*') {
1925 llvm::StringRef value;
1926 if (sep_char)
1927 value =
1928 format_str.substr(sep_pos + (entry_def->keep_separator ? 0 : 1));
1929 switch (entry_def->type) {
1931 entry.string = format_str.str();
1932 return error; // Success
1933
1935 entry.number = entry_def->data;
1936 return error; // Success
1937
1939 entry.type = entry_def->type;
1940 entry.string = entry_def->string;
1941 return error; // Success
1942
1943 default:
1944 entry.type = entry_def->type;
1945 break;
1946 }
1947
1948 if (value.empty()) {
1949 if (entry_def->type == FormatEntity::Entry::Type::Invalid) {
1950 if (entry_def->children) {
1951 StreamString error_strm;
1952 error_strm.Printf("'%s' can't be specified on its own, you must "
1953 "access one of its children: ",
1954 entry_def->name);
1955 DumpCommaSeparatedChildEntryNames(error_strm, entry_def);
1956 error.SetErrorStringWithFormat("%s", error_strm.GetData());
1957 } else if (sep_char == ':') {
1958 // Any value whose separator is a with a ':' means this value has a
1959 // string argument that needs to be stored in the entry (like
1960 // "${script.var:}"). In this case the string value is the empty
1961 // string which is ok.
1962 } else {
1963 error.SetErrorStringWithFormat("%s", "invalid entry definitions");
1964 }
1965 }
1966 } else {
1967 if (entry_def->children) {
1968 error = ParseEntry(value, entry_def, entry);
1969 } else if (sep_char == ':') {
1970 // Any value whose separator is a with a ':' means this value has a
1971 // string argument that needs to be stored in the entry (like
1972 // "${script.var:modulename.function}")
1973 entry.string = value.str();
1974 } else {
1975 error.SetErrorStringWithFormat(
1976 "'%s' followed by '%s' but it has no children", key.str().c_str(),
1977 value.str().c_str());
1978 }
1979 }
1980 return error;
1981 }
1982 }
1983 StreamString error_strm;
1985 error_strm.Printf(
1986 "invalid top level item '%s'. Valid top level items are: ",
1987 key.str().c_str());
1988 else
1989 error_strm.Printf("invalid member '%s' in '%s'. Valid members are: ",
1990 key.str().c_str(), parent->name);
1991 DumpCommaSeparatedChildEntryNames(error_strm, parent);
1992 error.SetErrorStringWithFormat("%s", error_strm.GetData());
1993 return error;
1994}
1995
1996static const Definition *FindEntry(const llvm::StringRef &format_str,
1997 const Definition *parent,
1998 llvm::StringRef &remainder) {
1999 Status error;
2000
2001 std::pair<llvm::StringRef, llvm::StringRef> p = format_str.split('.');
2002 const size_t n = parent->num_children;
2003 for (size_t i = 0; i < n; ++i) {
2004 const Definition *entry_def = parent->children + i;
2005 if (p.first == entry_def->name || entry_def->name[0] == '*') {
2006 if (p.second.empty()) {
2007 if (format_str.back() == '.')
2008 remainder = format_str.drop_front(format_str.size() - 1);
2009 else
2010 remainder = llvm::StringRef(); // Exact match
2011 return entry_def;
2012 } else {
2013 if (entry_def->children) {
2014 return FindEntry(p.second, entry_def, remainder);
2015 } else {
2016 remainder = p.second;
2017 return entry_def;
2018 }
2019 }
2020 }
2021 }
2022 remainder = format_str;
2023 return parent;
2024}
2025
2026static Status ParseInternal(llvm::StringRef &format, Entry &parent_entry,
2027 uint32_t depth) {
2028 Status error;
2029 while (!format.empty() && error.Success()) {
2030 const size_t non_special_chars = format.find_first_of("${}\\");
2031
2032 if (non_special_chars == llvm::StringRef::npos) {
2033 // No special characters, just string bytes so add them and we are done
2034 parent_entry.AppendText(format);
2035 return error;
2036 }
2037
2038 if (non_special_chars > 0) {
2039 // We have a special character, so add all characters before these as a
2040 // plain string
2041 parent_entry.AppendText(format.substr(0, non_special_chars));
2042 format = format.drop_front(non_special_chars);
2043 }
2044
2045 switch (format[0]) {
2046 case '\0':
2047 return error;
2048
2049 case '{': {
2050 format = format.drop_front(); // Skip the '{'
2051 Entry scope_entry(Entry::Type::Scope);
2052 error = ParseInternal(format, scope_entry, depth + 1);
2053 if (error.Fail())
2054 return error;
2055 parent_entry.AppendEntry(std::move(scope_entry));
2056 } break;
2057
2058 case '}':
2059 if (depth == 0)
2060 error.SetErrorString("unmatched '}' character");
2061 else
2062 format =
2063 format
2064 .drop_front(); // Skip the '}' as we are at the end of the scope
2065 return error;
2066
2067 case '\\': {
2068 format = format.drop_front(); // Skip the '\' character
2069 if (format.empty()) {
2070 error.SetErrorString(
2071 "'\\' character was not followed by another character");
2072 return error;
2073 }
2074
2075 const char desens_char = format[0];
2076 format = format.drop_front(); // Skip the desensitized char character
2077 switch (desens_char) {
2078 case 'a':
2079 parent_entry.AppendChar('\a');
2080 break;
2081 case 'b':
2082 parent_entry.AppendChar('\b');
2083 break;
2084 case 'f':
2085 parent_entry.AppendChar('\f');
2086 break;
2087 case 'n':
2088 parent_entry.AppendChar('\n');
2089 break;
2090 case 'r':
2091 parent_entry.AppendChar('\r');
2092 break;
2093 case 't':
2094 parent_entry.AppendChar('\t');
2095 break;
2096 case 'v':
2097 parent_entry.AppendChar('\v');
2098 break;
2099 case '\'':
2100 parent_entry.AppendChar('\'');
2101 break;
2102 case '\\':
2103 parent_entry.AppendChar('\\');
2104 break;
2105 case '0':
2106 // 1 to 3 octal chars
2107 {
2108 // Make a string that can hold onto the initial zero char, up to 3
2109 // octal digits, and a terminating NULL.
2110 char oct_str[5] = {0, 0, 0, 0, 0};
2111
2112 int i;
2113 for (i = 0; (format[i] >= '0' && format[i] <= '7') && i < 4; ++i)
2114 oct_str[i] = format[i];
2115
2116 // We don't want to consume the last octal character since the main
2117 // for loop will do this for us, so we advance p by one less than i
2118 // (even if i is zero)
2119 format = format.drop_front(i);
2120 unsigned long octal_value = ::strtoul(oct_str, nullptr, 8);
2121 if (octal_value <= UINT8_MAX) {
2122 parent_entry.AppendChar((char)octal_value);
2123 } else {
2124 error.SetErrorString("octal number is larger than a single byte");
2125 return error;
2126 }
2127 }
2128 break;
2129
2130 case 'x':
2131 // hex number in the format
2132 if (isxdigit(format[0])) {
2133 // Make a string that can hold onto two hex chars plus a
2134 // NULL terminator
2135 char hex_str[3] = {0, 0, 0};
2136 hex_str[0] = format[0];
2137
2138 format = format.drop_front();
2139
2140 if (isxdigit(format[0])) {
2141 hex_str[1] = format[0];
2142 format = format.drop_front();
2143 }
2144
2145 unsigned long hex_value = strtoul(hex_str, nullptr, 16);
2146 if (hex_value <= UINT8_MAX) {
2147 parent_entry.AppendChar((char)hex_value);
2148 } else {
2149 error.SetErrorString("hex number is larger than a single byte");
2150 return error;
2151 }
2152 } else {
2153 parent_entry.AppendChar(desens_char);
2154 }
2155 break;
2156
2157 default:
2158 // Just desensitize any other character by just printing what came
2159 // after the '\'
2160 parent_entry.AppendChar(desens_char);
2161 break;
2162 }
2163 } break;
2164
2165 case '$':
2166 if (format.size() == 1) {
2167 // '$' at the end of a format string, just print the '$'
2168 parent_entry.AppendText("$");
2169 } else {
2170 format = format.drop_front(); // Skip the '$'
2171
2172 if (format[0] == '{') {
2173 format = format.drop_front(); // Skip the '{'
2174
2175 llvm::StringRef variable, variable_format;
2176 error = FormatEntity::ExtractVariableInfo(format, variable,
2177 variable_format);
2178 if (error.Fail())
2179 return error;
2180 bool verify_is_thread_id = false;
2181 Entry entry;
2182 if (!variable_format.empty()) {
2183 entry.printf_format = variable_format.str();
2184
2185 // If the format contains a '%' we are going to assume this is a
2186 // printf style format. So if you want to format your thread ID
2187 // using "0x%llx" you can use: ${thread.id%0x%llx}
2188 //
2189 // If there is no '%' in the format, then it is assumed to be a
2190 // LLDB format name, or one of the extended formats specified in
2191 // the switch statement below.
2192
2193 if (entry.printf_format.find('%') == std::string::npos) {
2194 bool clear_printf = false;
2195
2196 if (entry.printf_format.size() == 1) {
2197 switch (entry.printf_format[0]) {
2198 case '@': // if this is an @ sign, print ObjC description
2199 entry.number = ValueObject::
2201 clear_printf = true;
2202 break;
2203 case 'V': // if this is a V, print the value using the default
2204 // format
2205 entry.number =
2207 clear_printf = true;
2208 break;
2209 case 'L': // if this is an L, print the location of the value
2210 entry.number =
2212 clear_printf = true;
2213 break;
2214 case 'S': // if this is an S, print the summary after all
2215 entry.number =
2217 clear_printf = true;
2218 break;
2219 case '#': // if this is a '#', print the number of children
2220 entry.number =
2222 clear_printf = true;
2223 break;
2224 case 'T': // if this is a 'T', print the type
2225 entry.number =
2227 clear_printf = true;
2228 break;
2229 case 'N': // if this is a 'N', print the name
2230 entry.number =
2232 clear_printf = true;
2233 break;
2234 case '>': // if this is a '>', print the expression path
2235 entry.number = ValueObject::
2237 clear_printf = true;
2238 break;
2239 }
2240 }
2241
2242 if (entry.number == 0) {
2244 entry.printf_format.c_str(), entry.fmt)) {
2245 clear_printf = true;
2246 } else if (entry.printf_format == "tid") {
2247 verify_is_thread_id = true;
2248 } else {
2249 error.SetErrorStringWithFormat("invalid format: '%s'",
2250 entry.printf_format.c_str());
2251 return error;
2252 }
2253 }
2254
2255 // Our format string turned out to not be a printf style format
2256 // so lets clear the string
2257 if (clear_printf)
2258 entry.printf_format.clear();
2259 }
2260 }
2261
2262 // Check for dereferences
2263 if (variable[0] == '*') {
2264 entry.deref = true;
2265 variable = variable.drop_front();
2266 }
2267
2268 error = ParseEntry(variable, &g_root, entry);
2269 if (error.Fail())
2270 return error;
2271
2272 llvm::StringRef entry_string(entry.string);
2273 if (entry_string.contains(':')) {
2274 auto [_, llvm_format] = entry_string.split(':');
2275 if (!llvm_format.empty() && !LLVMFormatPattern.match(llvm_format)) {
2276 error.SetErrorStringWithFormat("invalid llvm format: '%s'",
2277 llvm_format.data());
2278 return error;
2279 }
2280 }
2281
2282 if (verify_is_thread_id) {
2283 if (entry.type != Entry::Type::ThreadID &&
2285 error.SetErrorString("the 'tid' format can only be used on "
2286 "${thread.id} and ${thread.protocol_id}");
2287 }
2288 }
2289
2290 switch (entry.type) {
2293 if (entry.number == 0) {
2294 if (entry.string.empty())
2295 entry.number =
2297 else
2298 entry.number =
2300 }
2301 break;
2302 default:
2303 // Make sure someone didn't try to dereference anything but ${var}
2304 // or ${svar}
2305 if (entry.deref) {
2306 error.SetErrorStringWithFormat(
2307 "${%s} can't be dereferenced, only ${var} and ${svar} can.",
2308 variable.str().c_str());
2309 return error;
2310 }
2311 }
2312 parent_entry.AppendEntry(std::move(entry));
2313 }
2314 }
2315 break;
2316 }
2317 }
2318 return error;
2319}
2320
2321Status FormatEntity::ExtractVariableInfo(llvm::StringRef &format_str,
2322 llvm::StringRef &variable_name,
2323 llvm::StringRef &variable_format) {
2324 Status error;
2325 variable_name = llvm::StringRef();
2326 variable_format = llvm::StringRef();
2327
2328 const size_t paren_pos = format_str.find('}');
2329 if (paren_pos != llvm::StringRef::npos) {
2330 const size_t percent_pos = format_str.find('%');
2331 if (percent_pos < paren_pos) {
2332 if (percent_pos > 0) {
2333 if (percent_pos > 1)
2334 variable_name = format_str.substr(0, percent_pos);
2335 variable_format =
2336 format_str.substr(percent_pos + 1, paren_pos - (percent_pos + 1));
2337 }
2338 } else {
2339 variable_name = format_str.substr(0, paren_pos);
2340 }
2341 // Strip off elements and the formatting and the trailing '}'
2342 format_str = format_str.substr(paren_pos + 1);
2343 } else {
2344 error.SetErrorStringWithFormat(
2345 "missing terminating '}' character for '${%s'",
2346 format_str.str().c_str());
2347 }
2348 return error;
2349}
2350
2352 llvm::StringRef variable_name,
2353 llvm::StringRef variable_format) {
2354 if (variable_name.empty() || variable_name == ".fullpath") {
2355 file_spec.Dump(s.AsRawOstream());
2356 return true;
2357 } else if (variable_name == ".basename") {
2358 s.PutCString(file_spec.GetFilename().GetStringRef());
2359 return true;
2360 } else if (variable_name == ".dirname") {
2361 s.PutCString(file_spec.GetFilename().GetStringRef());
2362 return true;
2363 }
2364 return false;
2365}
2366
2367static std::string MakeMatch(const llvm::StringRef &prefix,
2368 const char *suffix) {
2369 std::string match(prefix.str());
2370 match.append(suffix);
2371 return match;
2372}
2373
2374static void AddMatches(const Definition *def, const llvm::StringRef &prefix,
2375 const llvm::StringRef &match_prefix,
2376 StringList &matches) {
2377 const size_t n = def->num_children;
2378 if (n > 0) {
2379 for (size_t i = 0; i < n; ++i) {
2380 std::string match = prefix.str();
2381 if (match_prefix.empty())
2382 matches.AppendString(MakeMatch(prefix, def->children[i].name));
2383 else if (strncmp(def->children[i].name, match_prefix.data(),
2384 match_prefix.size()) == 0)
2385 matches.AppendString(
2386 MakeMatch(prefix, def->children[i].name + match_prefix.size()));
2387 }
2388 }
2389}
2390
2392 llvm::StringRef str = request.GetCursorArgumentPrefix();
2393
2394 const size_t dollar_pos = str.rfind('$');
2395 if (dollar_pos == llvm::StringRef::npos)
2396 return;
2397
2398 // Hitting TAB after $ at the end of the string add a "{"
2399 if (dollar_pos == str.size() - 1) {
2400 std::string match = str.str();
2401 match.append("{");
2402 request.AddCompletion(match);
2403 return;
2404 }
2405
2406 if (str[dollar_pos + 1] != '{')
2407 return;
2408
2409 const size_t close_pos = str.find('}', dollar_pos + 2);
2410 if (close_pos != llvm::StringRef::npos)
2411 return;
2412
2413 const size_t format_pos = str.find('%', dollar_pos + 2);
2414 if (format_pos != llvm::StringRef::npos)
2415 return;
2416
2417 llvm::StringRef partial_variable(str.substr(dollar_pos + 2));
2418 if (partial_variable.empty()) {
2419 // Suggest all top level entities as we are just past "${"
2420 StringList new_matches;
2421 AddMatches(&g_root, str, llvm::StringRef(), new_matches);
2422 request.AddCompletions(new_matches);
2423 return;
2424 }
2425
2426 // We have a partially specified variable, find it
2427 llvm::StringRef remainder;
2428 const Definition *entry_def = FindEntry(partial_variable, &g_root, remainder);
2429 if (!entry_def)
2430 return;
2431
2432 const size_t n = entry_def->num_children;
2433
2434 if (remainder.empty()) {
2435 // Exact match
2436 if (n > 0) {
2437 // "${thread.info" <TAB>
2438 request.AddCompletion(MakeMatch(str, "."));
2439 } else {
2440 // "${thread.id" <TAB>
2441 request.AddCompletion(MakeMatch(str, "}"));
2442 }
2443 } else if (remainder == ".") {
2444 // "${thread." <TAB>
2445 StringList new_matches;
2446 AddMatches(entry_def, str, llvm::StringRef(), new_matches);
2447 request.AddCompletions(new_matches);
2448 } else {
2449 // We have a partial match
2450 // "${thre" <TAB>
2451 StringList new_matches;
2452 AddMatches(entry_def, str, remainder, new_matches);
2453 request.AddCompletions(new_matches);
2454 }
2455}
2456
2458 Stream &out_stream, VariableList const &args,
2459 ExecutionContextScope *exe_scope) {
2460 const size_t num_args = args.GetSize();
2461 for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx) {
2462 std::string buffer;
2463
2464 VariableSP var_sp(args.GetVariableAtIndex(arg_idx));
2465 ValueObjectSP var_value_sp(ValueObjectVariable::Create(exe_scope, var_sp));
2466 StreamString ss;
2467 llvm::StringRef var_representation;
2468 const char *var_name = var_value_sp->GetName().GetCString();
2469 if (var_value_sp->GetCompilerType().IsValid()) {
2470 if (exe_scope && exe_scope->CalculateTarget())
2471 var_value_sp = var_value_sp->GetQualifiedRepresentationIfAvailable(
2472 exe_scope->CalculateTarget()
2473 ->TargetProperties::GetPreferDynamicValue(),
2474 exe_scope->CalculateTarget()
2475 ->TargetProperties::GetEnableSyntheticValue());
2476 if (var_value_sp->GetCompilerType().IsAggregateType() &&
2479 .SetHideItemNames(false)
2480 .SetShowMembersOneLiner(true),
2481 "");
2482 format.FormatObject(var_value_sp.get(), buffer, TypeSummaryOptions());
2483 var_representation = buffer;
2484 } else
2485 var_value_sp->DumpPrintableRepresentation(
2486 ss,
2488 eValueObjectRepresentationStyleSummary,
2491 }
2492
2493 if (!ss.GetString().empty())
2494 var_representation = ss.GetString();
2495 if (arg_idx > 0)
2496 out_stream.PutCString(", ");
2497 if (var_value_sp->GetError().Success()) {
2498 if (!var_representation.empty())
2499 out_stream.Printf("%s=%s", var_name, var_representation.str().c_str());
2500 else
2501 out_stream.Printf("%s=%s at %s", var_name,
2502 var_value_sp->GetTypeName().GetCString(),
2503 var_value_sp->GetLocationAsCString());
2504 } else
2505 out_stream.Printf("%s=<unavailable>", var_name);
2506 }
2507}
2508
2509Status FormatEntity::Parse(const llvm::StringRef &format_str, Entry &entry) {
2510 entry.Clear();
2511 entry.type = Entry::Type::Root;
2512 llvm::StringRef modifiable_format(format_str);
2513 return ParseInternal(modifiable_format, entry, 0);
2514}
#define ANSI_ESC_START
Definition: AnsiTerminal.h:62
#define ANSI_BG_COLOR_PURPLE
Definition: AnsiTerminal.h:35
#define ANSI_CTRL_UNDERLINE
Definition: AnsiTerminal.h:55
#define ANSI_BG_COLOR_RED
Definition: AnsiTerminal.h:31
#define ANSI_FG_COLOR_BLACK
Definition: AnsiTerminal.h:12
#define ANSI_BG_COLOR_YELLOW
Definition: AnsiTerminal.h:33
#define ANSI_BG_COLOR_BLACK
Definition: AnsiTerminal.h:30
#define ANSI_FG_COLOR_YELLOW
Definition: AnsiTerminal.h:15
#define ANSI_FG_COLOR_PURPLE
Definition: AnsiTerminal.h:17
#define ANSI_BG_COLOR_CYAN
Definition: AnsiTerminal.h:36
#define ANSI_BG_COLOR_GREEN
Definition: AnsiTerminal.h:32
#define ANSI_CTRL_SLOW_BLINK
Definition: AnsiTerminal.h:56
#define ANSI_FG_COLOR_RED
Definition: AnsiTerminal.h:13
#define ANSI_BG_COLOR_BLUE
Definition: AnsiTerminal.h:34
#define ANSI_CTRL_ITALIC
Definition: AnsiTerminal.h:54
#define ANSI_FG_COLOR_CYAN
Definition: AnsiTerminal.h:18
#define ANSI_CTRL_FAST_BLINK
Definition: AnsiTerminal.h:57
#define ANSI_CTRL_CROSSED_OUT
Definition: AnsiTerminal.h:60
#define ANSI_CTRL_IMAGE_NEGATIVE
Definition: AnsiTerminal.h:58
#define ANSI_BG_COLOR_WHITE
Definition: AnsiTerminal.h:37
#define ANSI_CTRL_CONCEAL
Definition: AnsiTerminal.h:59
#define ANSI_FG_COLOR_GREEN
Definition: AnsiTerminal.h:14
#define ANSI_CTRL_FAINT
Definition: AnsiTerminal.h:53
#define ANSI_FG_COLOR_BLUE
Definition: AnsiTerminal.h:16
#define ANSI_CTRL_NORMAL
Definition: AnsiTerminal.h:51
#define ANSI_CTRL_BOLD
Definition: AnsiTerminal.h:52
#define ANSI_FG_COLOR_WHITE
Definition: AnsiTerminal.h:19
#define ANSI_ESC_END
Definition: AnsiTerminal.h:63
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 void FormatInlinedBlock(Stream &out_stream, Block *block)
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)
constexpr Definition g_string_entry[]
constexpr Definition g_root
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[]
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)
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)
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[]
static bool DumpValue(Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, const FormatEntity::Entry &entry, ValueObject *valobj)
#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:359
#define LLDB_LOGF(log,...)
Definition: Log.h:366
A section + offset based address range class.
Definition: AddressRange.h:25
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:211
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
Definition: AddressRange.h:223
A section + offset based address class.
Definition: Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition: Address.cpp:313
lldb::SectionSP GetSection() const
Get const accessor for the section.
Definition: Address.h:439
@ 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:459
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:408
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:293
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:355
An architecture specification class.
Definition: ArchSpec.h:31
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition: ArchSpec.cpp:691
bool IsValid() const
Tests if this ArchSpec is valid.
Definition: ArchSpec.h:348
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:450
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition: ArchSpec.cpp:552
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:415
Block * GetContainingInlinedBlock()
Get the inlined block that contains this block.
Definition: Block.cpp:208
const InlineFunctionInfo * GetInlinedFunctionInfo() const
Get const accessor for any inlined function information.
Definition: Block.h:276
bool GetRangeContainingAddress(const Address &addr, AddressRange &range)
Definition: Block.cpp:250
A class that describes a compilation unit.
Definition: CompileUnit.h:41
const FileSpec & GetPrimaryFile() const
Return the primary source spec associated with this compile unit.
Definition: CompileUnit.h:230
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
A uniqued constant string class.
Definition: ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:188
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:197
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
static bool ShouldPrintAsOneLiner(ValueObject &valobj)
static lldb::TypeSummaryImplSP GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp)
A class to manage flag bits.
Definition: Debugger.h:80
bool GetUseColor() const
Definition: Debugger.cpp:403
ScriptInterpreter * GetScriptInterpreter(bool can_create=true, std::optional< lldb::ScriptLanguage > language={})
Definition: Debugger.cpp:1684
"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
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
Target * GetTargetPtr() const
Returns a pointer to the target object.
Process * GetProcessPtr() const
Returns a pointer to the process object.
Thread * GetThreadPtr() const
Returns a pointer to the thread object.
A file utility class.
Definition: FileSpec.h:56
const ConstString & GetFilename() const
Filename string const get accessor.
Definition: FileSpec.h:240
const ConstString & GetDirectory() const
Directory string const get accessor.
Definition: FileSpec.h:223
void Dump(llvm::raw_ostream &s) const
Dump this object to a Stream.
Definition: FileSpec.cpp:325
An abstract base class for files.
Definition: File.h:36
static const char * GetFormatAsCString(lldb::Format format)
static bool GetFormatFromCString(const char *format_cstr, lldb::Format &format)
static char GetFormatAsFormatChar(lldb::Format format)
bool GetIsOptimized()
Get whether compiler optimizations were enabled for this function.
Definition: Function.cpp:501
const AddressRange & GetAddressRange()
Definition: Function.h:447
ConstString GetName() const
Definition: Function.cpp:693
const Mangled & GetMangled() const
Definition: Function.h:528
lldb::LanguageType GetLanguage() const
Definition: Function.cpp:682
ConstString GetNameNoArguments() const
Definition: Function.cpp:697
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition: Function.cpp:371
A class that describes information for an inlined function.
Definition: Function.h:125
ConstString GetName() const
Definition: Function.cpp:96
static Language * FindPlugin(lldb::LanguageType language)
Definition: Language.cpp:84
static const char * GetNameForLanguageType(lldb::LanguageType language)
Definition: Language.cpp:266
virtual bool GetFunctionDisplayName(const SymbolContext *sc, const ExecutionContext *exe_ctx, FunctionNameRepresentation representation, Stream &s)
Definition: Language.cpp:513
ConstString GetName(NamePreference preference=ePreferDemangled) const
Best name get accessor.
Definition: Mangled.cpp:335
A class that describes an executable image and its associated object and symbol files.
Definition: Module.h:88
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition: Module.h:452
A plug-in interface definition class for debugging a process.
Definition: Process.h:341
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:538
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1277
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:43
lldb::RegisterContextSP GetRegisterContext()
Get the RegisterContext for this frame, if possible.
uint32_t GetFrameIndex() const
Query this frame to find what frame it is in this Thread's StackFrameList.
Definition: StackFrame.cpp:175
bool HasDebugInformation()
Determine whether this StackFrame has debug information available or not.
const lldb::RegisterContextSP & GetRegisterContextSP() const
Definition: StackFrame.h:243
const Address & GetFrameCodeAddress()
Get an Address for the current pc value in this StackFrame.
Definition: StackFrame.cpp:190
An error handling class.
Definition: Status.h:44
static lldb::ExpressionVariableSP GetExpressionVariable(lldb::StopInfoSP &stop_info_sp)
Definition: StopInfo.cpp:1445
static lldb::ValueObjectSP GetReturnValueObject(lldb::StopInfoSP &stop_info_sp)
Definition: StopInfo.cpp:1435
const char * GetData() const
Definition: StreamString.h:43
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)
Definition: Stream.h:353
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
Definition: Stream.h:112
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:401
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:65
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)
Definition: StringList.cpp:43
std::shared_ptr< Object > ObjectSP
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:34
Function * function
The Function for a given query.
Block * block
The Block for a given query.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
Symbol * symbol
The Symbol for a given query.
LineEntry line_entry
The LineEntry for a given query.
uint32_t GetID() const
Definition: Symbol.h:136
bool ValueIsAddress() const
Definition: Symbol.cpp:165
Mangled & GetMangled()
Definition: Symbol.h:146
lldb::LanguageType GetLanguage() const
Definition: Symbol.h:138
Address & GetAddressRef()
Definition: Symbol.h:72
ConstString GetName() const
Definition: Symbol.cpp:548
ConstString GetNameNoArguments() const
Definition: Symbol.cpp:550
Module * GetExecutableModulePointer()
Definition: Target.cpp:1436
static Target * GetTargetFromContexts(const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
Definition: Target.cpp:2636
SectionLoadList & GetSectionLoadList()
Definition: Target.h:1138
Debugger & GetDebugger()
Definition: Target.h:1064
const ArchSpec & GetArchitecture() const
Definition: Target.h:1023
virtual lldb::user_id_t GetProtocolID() const
Definition: Thread.h:1110
virtual const char * GetQueueName()
Retrieve the Queue name for the queue currently using this Thread.
Definition: Thread.h:332
uint32_t GetIndexID() const
Definition: Thread.cpp:1388
StructuredData::ObjectSP GetExtendedInfo()
Retrieve a dictionary of information about this thread.
Definition: Thread.h:272
virtual const char * GetName()
Definition: Thread.h:280
lldb::ProcessSP GetProcess() const
Definition: Thread.h:154
lldb::StopInfoSP GetStopInfo()
Definition: Thread.cpp:341
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp)
virtual uint32_t GetBitfieldBitSize()
Definition: ValueObject.h:424
bool DumpPrintableRepresentation(Stream &s, ValueObjectRepresentationStyle val_obj_display=eValueObjectRepresentationStyleSummary, lldb::Format custom_format=lldb::eFormatInvalid, PrintableRepresentationSpecialCases special=PrintableRepresentationSpecialCases::eAllow, bool do_dump_error=true)
CompilerType GetCompilerType()
Definition: ValueObject.h:352
lldb::ValueObjectSP GetSyntheticValue()
@ eExpressionPathScanEndReasonEndOfString
Out of data to parse.
Definition: ValueObject.h:125
@ eExpressionPathAftermathNothing
Just return it.
Definition: ValueObject.h:175
@ eExpressionPathAftermathDereference
Dereference the target.
Definition: ValueObject.h:177
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()
Definition: ValueObject.h:365
lldb::DynamicValueType GetDynamicValueType()
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr)
Definition: ValueObject.h:378
lldb::ValueObjectSP GetQualifiedRepresentationIfAvailable(lldb::DynamicValueType dynValue, bool synthValue)
lldb::TargetSP GetTargetSP() const
Definition: ValueObject.h:334
@ eExpressionPathEndResultTypePlain
Anything but...
Definition: ValueObject.h:161
@ eExpressionPathEndResultTypeBoundedRange
A range [low-high].
Definition: ValueObject.h:165
@ eExpressionPathEndResultTypeUnboundedRange
A range [].
Definition: ValueObject.h:167
virtual lldb::ValueObjectSP Dereference(Status &error)
bool HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display, lldb::Format custom_format)
virtual const char * GetLocationAsCString()
Definition: ValueObject.h:522
virtual int64_t GetValueAsSigned(int64_t fail_value, bool *success=nullptr)
@ eValueObjectRepresentationStyleLanguageSpecific
Definition: ValueObject.h:115
virtual bool IsSynthetic()
Definition: ValueObject.h:612
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)
#define LLDB_REGNUM_GENERIC_SP
Definition: lldb-defines.h:57
#define LLDB_REGNUM_GENERIC_FLAGS
Definition: lldb-defines.h:60
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:87
#define LLDB_REGNUM_GENERIC_FP
Definition: lldb-defines.h:58
bool FormatFileSpec(const FileSpec &file, Stream &s, llvm::StringRef elements, llvm::StringRef element_format)
Status Parse(const llvm::StringRef &format, Entry &entry)
bool Format(const Entry &entry, Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, const Address *addr, ValueObject *valobj, bool function_changed, bool initial_function)
bool FormatCString(const char *format, Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, const Address *addr, ValueObject *valobj, bool function_changed, bool initial_function)
Status ExtractVariableInfo(llvm::StringRef &format_str, llvm::StringRef &variable_name, llvm::StringRef &variable_format)
bool FormatStringRef(const llvm::StringRef &format, Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, const Address *addr, ValueObject *valobj, bool function_changed, bool initial_function)
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)
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:331
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_flags=false, lldb::TargetSP target_sp=nullptr)
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:475
std::shared_ptr< lldb_private::ExpressionVariable > ExpressionVariableSP
Definition: lldb-forward.h:346
Format
Display format definitions.
@ eFormatterMatchExact
std::shared_ptr< lldb_private::VariableList > VariableListSP
Definition: lldb-forward.h:478
std::shared_ptr< lldb_private::Variable > VariableSP
Definition: lldb-forward.h:477
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
Definition: lldb-forward.h:422
uint64_t addr_t
Definition: lldb-types.h:80
@ eStructuredDataTypeFloat
@ eStructuredDataTypeDictionary
@ eStructuredDataTypeInteger
@ eStructuredDataTypeArray
@ eStructuredDataTypeString
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
Definition: lldb-forward.h:389
@ eValueTypeVariableArgument
function argument variables
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.
Definition: FormatEntity.h:107
const Definition * children
An array of "num_children" Definition entries.
Definition: FormatEntity.h:117
const bool keep_separator
Whether the separator is kept during parsing or not.
Definition: FormatEntity.h:120
const char * string
Insert this exact string into the output.
Definition: FormatEntity.h:109
const uint64_t data
Data that is returned as the value of the format string.
Definition: FormatEntity.h:113
const uint32_t num_children
The number of children of this node in the tree of format strings.
Definition: FormatEntity.h:115
const Entry::Type type
Entry::Type corresponding to this definition.
Definition: FormatEntity.h:111
void Dump(Stream &s, int depth=0) const
std::vector< Entry > children
Definition: FormatEntity.h:201
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)
Definition: FormatEntity.h:142
void AppendEntry(const Entry &&entry)
Definition: FormatEntity.h:161
static const char * TypeToCString(Type t)
Entry(Type t=Type::Invalid, const char *s=nullptr, const char *f=nullptr)
Definition: FormatEntity.h:148
uint16_t column
The column number of the source line, or zero if there is no column information.
Definition: LineEntry.h:151
bool IsValid() const
Check if a line entry object is valid.
Definition: LineEntry.cpp:35
AddressRange range
The section offset address range for this line entry.
Definition: LineEntry.h:137
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
Definition: LineEntry.h:147
const FileSpec & GetFile() const
Helper to access the file.
Definition: LineEntry.h:134
Every register is described in detail including its name, alternate name (optional),...
llvm::ArrayRef< uint8_t > data(const uint8_t *context_base) const
bool FormatObject(ValueObject *valobj, std::string &dest, const TypeSummaryOptions &options) override
Definition: TypeSummary.cpp:68
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47
GetValueForExpressionPathOptions & SetSyntheticChildrenTraversal(SyntheticChildrenTraversal traverse)
Definition: ValueObject.h:248
GetValueForExpressionPathOptions & DoAllowFragileIVar()
Definition: ValueObject.h:227
GetValueForExpressionPathOptions & DontCheckDotVsArrowSyntax()
Definition: ValueObject.h:222
GetValueForExpressionPathOptions & DoAllowBitfieldSyntax()
Definition: ValueObject.h:237