Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@@ -0,0 +1,6 @@
add_subdirectory(CPlusPlus)
add_subdirectory(Go)
add_subdirectory(Java)
add_subdirectory(ObjC)
add_subdirectory(ObjCPlusPlus)
add_subdirectory(OCaml)

View File

@@ -0,0 +1,211 @@
//===-- BlockPointer.cpp ----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "BlockPointer.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/DataFormatters/FormattersHelpers.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/ClangASTImporter.h"
#include "lldb/Symbol/CompilerType.h"
#include "lldb/Symbol/TypeSystem.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/LLDBAssert.h"
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::formatters;
namespace lldb_private {
namespace formatters {
class BlockPointerSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
BlockPointerSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
: SyntheticChildrenFrontEnd(*valobj_sp), m_block_struct_type() {
CompilerType block_pointer_type(m_backend.GetCompilerType());
CompilerType function_pointer_type;
block_pointer_type.IsBlockPointerType(&function_pointer_type);
TargetSP target_sp(m_backend.GetTargetSP());
if (!target_sp) {
return;
}
Status err;
TypeSystem *type_system = target_sp->GetScratchTypeSystemForLanguage(
&err, lldb::eLanguageTypeC_plus_plus);
if (!err.Success() || !type_system) {
return;
}
ClangASTContext *clang_ast_context =
llvm::dyn_cast<ClangASTContext>(type_system);
if (!clang_ast_context) {
return;
}
ClangASTImporterSP clang_ast_importer = target_sp->GetClangASTImporter();
if (!clang_ast_importer) {
return;
}
const char *const isa_name("__isa");
const CompilerType isa_type =
clang_ast_context->GetBasicType(lldb::eBasicTypeObjCClass);
const char *const flags_name("__flags");
const CompilerType flags_type =
clang_ast_context->GetBasicType(lldb::eBasicTypeInt);
const char *const reserved_name("__reserved");
const CompilerType reserved_type =
clang_ast_context->GetBasicType(lldb::eBasicTypeInt);
const char *const FuncPtr_name("__FuncPtr");
const CompilerType FuncPtr_type =
clang_ast_importer->CopyType(*clang_ast_context, function_pointer_type);
m_block_struct_type = clang_ast_context->CreateStructForIdentifier(
ConstString(), {{isa_name, isa_type},
{flags_name, flags_type},
{reserved_name, reserved_type},
{FuncPtr_name, FuncPtr_type}});
}
~BlockPointerSyntheticFrontEnd() override = default;
size_t CalculateNumChildren() override {
const bool omit_empty_base_classes = false;
return m_block_struct_type.GetNumChildren(omit_empty_base_classes);
}
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override {
if (!m_block_struct_type.IsValid()) {
return lldb::ValueObjectSP();
}
if (idx >= CalculateNumChildren()) {
return lldb::ValueObjectSP();
}
const bool thread_and_frame_only_if_stopped = true;
ExecutionContext exe_ctx = m_backend.GetExecutionContextRef().Lock(
thread_and_frame_only_if_stopped);
const bool transparent_pointers = false;
const bool omit_empty_base_classes = false;
const bool ignore_array_bounds = false;
ValueObject *value_object = nullptr;
std::string child_name;
uint32_t child_byte_size = 0;
int32_t child_byte_offset = 0;
uint32_t child_bitfield_bit_size = 0;
uint32_t child_bitfield_bit_offset = 0;
bool child_is_base_class = false;
bool child_is_deref_of_parent = false;
uint64_t language_flags = 0;
const CompilerType child_type =
m_block_struct_type.GetChildCompilerTypeAtIndex(
&exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
child_bitfield_bit_size, child_bitfield_bit_offset,
child_is_base_class, child_is_deref_of_parent, value_object,
language_flags);
ValueObjectSP struct_pointer_sp =
m_backend.Cast(m_block_struct_type.GetPointerType());
if (!struct_pointer_sp) {
return lldb::ValueObjectSP();
}
Status err;
ValueObjectSP struct_sp = struct_pointer_sp->Dereference(err);
if (!struct_sp || !err.Success()) {
return lldb::ValueObjectSP();
}
ValueObjectSP child_sp(struct_sp->GetSyntheticChildAtOffset(
child_byte_offset, child_type, true,
ConstString(child_name.c_str(), child_name.size())));
return child_sp;
}
// return true if this object is now safe to use forever without
// ever updating again; the typical (and tested) answer here is
// 'false'
bool Update() override { return false; }
// maybe return false if the block pointer is, say, null
bool MightHaveChildren() override { return true; }
size_t GetIndexOfChildWithName(const ConstString &name) override {
if (!m_block_struct_type.IsValid())
return UINT32_MAX;
const bool omit_empty_base_classes = false;
return m_block_struct_type.GetIndexOfChildWithName(name.AsCString(),
omit_empty_base_classes);
}
private:
CompilerType m_block_struct_type;
};
} // namespace formatters
} // namespace lldb_private
bool lldb_private::formatters::BlockPointerSummaryProvider(
ValueObject &valobj, Stream &s, const TypeSummaryOptions &) {
lldb_private::SyntheticChildrenFrontEnd *synthetic_children =
BlockPointerSyntheticFrontEndCreator(nullptr, valobj.GetSP());
if (!synthetic_children) {
return false;
}
synthetic_children->Update();
static const ConstString s_FuncPtr_name("__FuncPtr");
lldb::ValueObjectSP child_sp = synthetic_children->GetChildAtIndex(
synthetic_children->GetIndexOfChildWithName(s_FuncPtr_name));
if (!child_sp) {
return false;
}
lldb::ValueObjectSP qualified_child_representation_sp =
child_sp->GetQualifiedRepresentationIfAvailable(
lldb::eDynamicDontRunTarget, true);
const char *child_value =
qualified_child_representation_sp->GetValueAsCString();
s.Printf("%s", child_value);
return true;
}
lldb_private::SyntheticChildrenFrontEnd *
lldb_private::formatters::BlockPointerSyntheticFrontEndCreator(
CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
if (!valobj_sp)
return nullptr;
return new BlockPointerSyntheticFrontEnd(valobj_sp);
}

View File

@@ -0,0 +1,26 @@
//===-- BlockPointer.h ------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_BlockPointer_h_
#define liblldb_BlockPointer_h_
#include "lldb/lldb-forward.h"
namespace lldb_private {
namespace formatters {
bool BlockPointerSummaryProvider(ValueObject &, Stream &,
const TypeSummaryOptions &);
SyntheticChildrenFrontEnd *
BlockPointerSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
} // namespace formatters
} // namespace lldb_private
#endif // liblldb_BlockPointer_h_

View File

@@ -0,0 +1,29 @@
add_lldb_library(lldbPluginCPlusPlusLanguage PLUGIN
BlockPointer.cpp
CPlusPlusLanguage.cpp
CPlusPlusNameParser.cpp
CxxStringTypes.cpp
LibCxx.cpp
LibCxxAtomic.cpp
LibCxxBitset.cpp
LibCxxInitializerList.cpp
LibCxxList.cpp
LibCxxMap.cpp
LibCxxQueue.cpp
LibCxxTuple.cpp
LibCxxUnorderedMap.cpp
LibCxxVector.cpp
LibStdcpp.cpp
LibStdcppTuple.cpp
LibStdcppUniquePointer.cpp
LINK_LIBS
lldbCore
lldbDataFormatters
lldbHost
lldbSymbol
lldbTarget
lldbUtility
LINK_COMPONENTS
Support
)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,138 @@
//===-- CPlusPlusLanguage.h -------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_CPlusPlusLanguage_h_
#define liblldb_CPlusPlusLanguage_h_
// C Includes
// C++ Includes
#include <set>
#include <vector>
// Other libraries and framework includes
#include "llvm/ADT/StringRef.h"
// Project includes
#include "lldb/Target/Language.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/lldb-private.h"
namespace lldb_private {
class CPlusPlusLanguage : public Language {
public:
class MethodName {
public:
MethodName()
: m_full(), m_basename(), m_context(), m_arguments(), m_qualifiers(),
m_parsed(false), m_parse_error(false) {}
MethodName(const ConstString &s)
: m_full(s), m_basename(), m_context(), m_arguments(), m_qualifiers(),
m_parsed(false), m_parse_error(false) {}
void Clear();
bool IsValid() {
if (!m_parsed)
Parse();
if (m_parse_error)
return false;
return (bool)m_full;
}
const ConstString &GetFullName() const { return m_full; }
std::string GetScopeQualifiedName();
llvm::StringRef GetBasename();
llvm::StringRef GetContext();
llvm::StringRef GetArguments();
llvm::StringRef GetQualifiers();
protected:
void Parse();
bool TrySimplifiedParse();
ConstString m_full; // Full name:
// "lldb::SBTarget::GetBreakpointAtIndex(unsigned int)
// const"
llvm::StringRef m_basename; // Basename: "GetBreakpointAtIndex"
llvm::StringRef m_context; // Decl context: "lldb::SBTarget"
llvm::StringRef m_arguments; // Arguments: "(unsigned int)"
llvm::StringRef m_qualifiers; // Qualifiers: "const"
bool m_parsed;
bool m_parse_error;
};
CPlusPlusLanguage() = default;
~CPlusPlusLanguage() override = default;
lldb::LanguageType GetLanguageType() const override {
return lldb::eLanguageTypeC_plus_plus;
}
std::unique_ptr<TypeScavenger> GetTypeScavenger() override;
lldb::TypeCategoryImplSP GetFormatters() override;
HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries() override;
HardcodedFormatters::HardcodedSyntheticFinder
GetHardcodedSynthetics() override;
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
static void Initialize();
static void Terminate();
static lldb_private::Language *CreateInstance(lldb::LanguageType language);
static lldb_private::ConstString GetPluginNameStatic();
static bool IsCPPMangledName(const char *name);
// Extract C++ context and identifier from a string using heuristic matching
// (as opposed to
// CPlusPlusLanguage::MethodName which has to have a fully qualified C++ name
// with parens and arguments.
// If the name is a lone C identifier (e.g. C) or a qualified C identifier
// (e.g. A::B::C) it will return true,
// and identifier will be the identifier (C and C respectively) and the
// context will be "" and "A::B" respectively.
// If the name fails the heuristic matching for a qualified or unqualified
// C/C++ identifier, then it will return false
// and identifier and context will be unchanged.
static bool ExtractContextAndIdentifier(const char *name,
llvm::StringRef &context,
llvm::StringRef &identifier);
// Given a mangled function name, calculates some alternative manglings since
// the compiler mangling may not line up with the symbol we are expecting
static uint32_t
FindAlternateFunctionManglings(const ConstString mangled,
std::set<ConstString> &candidates);
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
ConstString GetPluginName() override;
uint32_t GetPluginVersion() override;
};
} // namespace lldb_private
#endif // liblldb_CPlusPlusLanguage_h_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,182 @@
//===-- CPlusPlusNameParser.h -----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_CPlusPlusNameParser_h_
#define liblldb_CPlusPlusNameParser_h_
// C Includes
// C++ Includes
// Other libraries and framework includes
#include "clang/Lex/Lexer.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
// Project includes
#include "lldb/Utility/ConstString.h"
#include "lldb/lldb-private.h"
namespace lldb_private {
// Helps to validate and obtain various parts of C++ definitions.
class CPlusPlusNameParser {
public:
CPlusPlusNameParser(llvm::StringRef text) : m_text(text) { ExtractTokens(); }
struct ParsedName {
llvm::StringRef basename;
llvm::StringRef context;
};
struct ParsedFunction {
ParsedName name;
llvm::StringRef arguments;
llvm::StringRef qualifiers;
};
// Treats given text as a function definition and parses it.
// Function definition might or might not have a return type and this should
// change parsing result.
// Examples:
// main(int, chat const*)
// T fun(int, bool)
// std::vector<int>::push_back(int)
// int& map<int, pair<short, int>>::operator[](short) const
// int (*get_function(const chat *))()
llvm::Optional<ParsedFunction> ParseAsFunctionDefinition();
// Treats given text as a potentially nested name of C++ entity (function,
// class, field) and parses it.
// Examples:
// main
// fun
// std::vector<int>::push_back
// map<int, pair<short, int>>::operator[]
// func<C>(int, C&)::nested_class::method
llvm::Optional<ParsedName> ParseAsFullName();
private:
// A C++ definition to parse.
llvm::StringRef m_text;
// Tokens extracted from m_text.
llvm::SmallVector<clang::Token, 30> m_tokens;
// Index of the next token to look at from m_tokens.
size_t m_next_token_index = 0;
// Range of tokens saved in m_next_token_index.
struct Range {
size_t begin_index = 0;
size_t end_index = 0;
Range() {}
Range(size_t begin, size_t end) : begin_index(begin), end_index(end) {
assert(end >= begin);
}
size_t size() const { return end_index - begin_index; }
bool empty() const { return size() == 0; }
};
struct ParsedNameRanges {
Range basename_range;
Range context_range;
};
// Bookmark automatically restores parsing position (m_next_token_index)
// when destructed unless it's manually removed with Remove().
class Bookmark {
public:
Bookmark(size_t &position)
: m_position(position), m_position_value(position) {}
Bookmark(const Bookmark &) = delete;
Bookmark(Bookmark &&b)
: m_position(b.m_position), m_position_value(b.m_position_value),
m_restore(b.m_restore) {
b.Remove();
}
Bookmark &operator=(Bookmark &&) = delete;
Bookmark &operator=(const Bookmark &) = delete;
void Remove() { m_restore = false; }
size_t GetSavedPosition() { return m_position_value; }
~Bookmark() {
if (m_restore) {
m_position = m_position_value;
}
}
private:
size_t &m_position;
size_t m_position_value;
bool m_restore = true;
};
bool HasMoreTokens();
void Advance();
void TakeBack();
bool ConsumeToken(clang::tok::TokenKind kind);
template <typename... Ts> bool ConsumeToken(Ts... kinds);
Bookmark SetBookmark();
size_t GetCurrentPosition();
clang::Token &Peek();
bool ConsumeBrackets(clang::tok::TokenKind left, clang::tok::TokenKind right);
llvm::Optional<ParsedFunction> ParseFunctionImpl(bool expect_return_type);
// Parses functions returning function pointers 'string (*f(int x))(float y)'
llvm::Optional<ParsedFunction> ParseFuncPtr(bool expect_return_type);
// Consumes function arguments enclosed within '(' ... ')'
bool ConsumeArguments();
// Consumes template arguments enclosed within '<' ... '>'
bool ConsumeTemplateArgs();
// Consumes '(anonymous namespace)'
bool ConsumeAnonymousNamespace();
// Consumes '{lambda ...}'
bool ConsumeLambda();
// Consumes operator declaration like 'operator *' or 'operator delete []'
bool ConsumeOperator();
// Skips 'const' and 'volatile'
void SkipTypeQualifiers();
// Skips 'const', 'volatile', '&', '&&' in the end of the function.
void SkipFunctionQualifiers();
// Consumes built-in types like 'int' or 'unsigned long long int'
bool ConsumeBuiltinType();
// Consumes types defined via decltype keyword.
bool ConsumeDecltype();
// Skips 'const' and 'volatile'
void SkipPtrsAndRefs();
// Consumes things like 'const * const &'
bool ConsumePtrsAndRefs();
// Consumes full type name like 'Namespace::Class<int>::Method()::InnerClass'
bool ConsumeTypename();
llvm::Optional<ParsedNameRanges> ParseFullNameImpl();
llvm::StringRef GetTextForRange(const Range &range);
// Populate m_tokens by calling clang lexer on m_text.
void ExtractTokens();
};
} // namespace lldb_private
#endif // liblldb_CPlusPlusNameParser_h_

View File

@@ -0,0 +1,223 @@
//===-- CxxStringTypes.cpp --------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "CxxStringTypes.h"
#include "llvm/Support/ConvertUTF.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/Core/ValueObjectConstResult.h"
#include "lldb/DataFormatters/FormattersHelpers.h"
#include "lldb/DataFormatters/StringPrinter.h"
#include "lldb/DataFormatters/TypeSummary.h"
#include "lldb/Host/Time.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Target/ProcessStructReader.h"
#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/Endian.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/Stream.h"
#include <algorithm>
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::formatters;
bool lldb_private::formatters::Char16StringSummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &) {
ProcessSP process_sp = valobj.GetProcessSP();
if (!process_sp)
return false;
lldb::addr_t valobj_addr = GetArrayAddressOrPointerValue(valobj);
if (valobj_addr == 0 || valobj_addr == LLDB_INVALID_ADDRESS)
return false;
StringPrinter::ReadStringAndDumpToStreamOptions options(valobj);
options.SetLocation(valobj_addr);
options.SetProcessSP(process_sp);
options.SetStream(&stream);
options.SetPrefixToken("u");
if (!StringPrinter::ReadStringAndDumpToStream<
StringPrinter::StringElementType::UTF16>(options)) {
stream.Printf("Summary Unavailable");
return true;
}
return true;
}
bool lldb_private::formatters::Char32StringSummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &) {
ProcessSP process_sp = valobj.GetProcessSP();
if (!process_sp)
return false;
lldb::addr_t valobj_addr = GetArrayAddressOrPointerValue(valobj);
if (valobj_addr == 0 || valobj_addr == LLDB_INVALID_ADDRESS)
return false;
StringPrinter::ReadStringAndDumpToStreamOptions options(valobj);
options.SetLocation(valobj_addr);
options.SetProcessSP(process_sp);
options.SetStream(&stream);
options.SetPrefixToken("U");
if (!StringPrinter::ReadStringAndDumpToStream<
StringPrinter::StringElementType::UTF32>(options)) {
stream.Printf("Summary Unavailable");
return true;
}
return true;
}
bool lldb_private::formatters::WCharStringSummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &) {
ProcessSP process_sp = valobj.GetProcessSP();
if (!process_sp)
return false;
lldb::addr_t valobj_addr = GetArrayAddressOrPointerValue(valobj);
if (valobj_addr == 0 || valobj_addr == LLDB_INVALID_ADDRESS)
return false;
// Get a wchar_t basic type from the current type system
CompilerType wchar_compiler_type =
valobj.GetCompilerType().GetBasicTypeFromAST(lldb::eBasicTypeWChar);
if (!wchar_compiler_type)
return false;
const uint32_t wchar_size = wchar_compiler_type.GetBitSize(
nullptr); // Safe to pass NULL for exe_scope here
StringPrinter::ReadStringAndDumpToStreamOptions options(valobj);
options.SetLocation(valobj_addr);
options.SetProcessSP(process_sp);
options.SetStream(&stream);
options.SetPrefixToken("L");
switch (wchar_size) {
case 8:
return StringPrinter::ReadStringAndDumpToStream<
StringPrinter::StringElementType::UTF8>(options);
case 16:
return StringPrinter::ReadStringAndDumpToStream<
StringPrinter::StringElementType::UTF16>(options);
case 32:
return StringPrinter::ReadStringAndDumpToStream<
StringPrinter::StringElementType::UTF32>(options);
default:
stream.Printf("size for wchar_t is not valid");
return true;
}
return true;
}
bool lldb_private::formatters::Char16SummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &) {
DataExtractor data;
Status error;
valobj.GetData(data, error);
if (error.Fail())
return false;
std::string value;
valobj.GetValueAsCString(lldb::eFormatUnicode16, value);
if (!value.empty())
stream.Printf("%s ", value.c_str());
StringPrinter::ReadBufferAndDumpToStreamOptions options(valobj);
options.SetData(data);
options.SetStream(&stream);
options.SetPrefixToken("u");
options.SetQuote('\'');
options.SetSourceSize(1);
options.SetBinaryZeroIsTerminator(false);
return StringPrinter::ReadBufferAndDumpToStream<
StringPrinter::StringElementType::UTF16>(options);
}
bool lldb_private::formatters::Char32SummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &) {
DataExtractor data;
Status error;
valobj.GetData(data, error);
if (error.Fail())
return false;
std::string value;
valobj.GetValueAsCString(lldb::eFormatUnicode32, value);
if (!value.empty())
stream.Printf("%s ", value.c_str());
StringPrinter::ReadBufferAndDumpToStreamOptions options(valobj);
options.SetData(data);
options.SetStream(&stream);
options.SetPrefixToken("U");
options.SetQuote('\'');
options.SetSourceSize(1);
options.SetBinaryZeroIsTerminator(false);
return StringPrinter::ReadBufferAndDumpToStream<
StringPrinter::StringElementType::UTF32>(options);
}
bool lldb_private::formatters::WCharSummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &) {
DataExtractor data;
Status error;
valobj.GetData(data, error);
if (error.Fail())
return false;
// Get a wchar_t basic type from the current type system
CompilerType wchar_compiler_type =
valobj.GetCompilerType().GetBasicTypeFromAST(lldb::eBasicTypeWChar);
if (!wchar_compiler_type)
return false;
const uint32_t wchar_size = wchar_compiler_type.GetBitSize(
nullptr); // Safe to pass NULL for exe_scope here
StringPrinter::ReadBufferAndDumpToStreamOptions options(valobj);
options.SetData(data);
options.SetStream(&stream);
options.SetPrefixToken("L");
options.SetQuote('\'');
options.SetSourceSize(1);
options.SetBinaryZeroIsTerminator(false);
switch (wchar_size) {
case 8:
return StringPrinter::ReadBufferAndDumpToStream<
StringPrinter::StringElementType::UTF8>(options);
case 16:
return StringPrinter::ReadBufferAndDumpToStream<
StringPrinter::StringElementType::UTF16>(options);
case 32:
return StringPrinter::ReadBufferAndDumpToStream<
StringPrinter::StringElementType::UTF32>(options);
default:
stream.Printf("size for wchar_t is not valid");
return true;
}
return true;
}

View File

@@ -0,0 +1,44 @@
//===-- CxxStringTypes.h ----------------------------------------------*- C++
//-*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_CxxStringTypes_h_
#define liblldb_CxxStringTypes_h_
#include "lldb/Core/ValueObject.h"
#include "lldb/DataFormatters/TypeSummary.h"
#include "lldb/Utility/Stream.h"
namespace lldb_private {
namespace formatters {
bool Char16StringSummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // char16_t* and unichar*
bool Char32StringSummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // char32_t*
bool WCharStringSummaryProvider(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // wchar_t*
bool Char16SummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // char16_t and unichar
bool Char32SummaryProvider(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // char32_t
bool WCharSummaryProvider(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // wchar_t
} // namespace formatters
} // namespace lldb_private
#endif // liblldb_CxxStringTypes_h_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,139 @@
//===-- LibCxx.h ---------------------------------------------------*- C++
//-*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_LibCxx_h_
#define liblldb_LibCxx_h_
#include "lldb/Core/ValueObject.h"
#include "lldb/DataFormatters/TypeSummary.h"
#include "lldb/DataFormatters/TypeSynthetic.h"
#include "lldb/Utility/Stream.h"
namespace lldb_private {
namespace formatters {
bool LibcxxStringSummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // libc++ std::string
bool LibcxxWStringSummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options); // libc++ std::wstring
bool LibcxxSmartPointerSummaryProvider(
ValueObject &valobj, Stream &stream,
const TypeSummaryOptions
&options); // libc++ std::shared_ptr<> and std::weak_ptr<>
SyntheticChildrenFrontEnd *
LibcxxVectorBoolSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
bool LibcxxContainerSummaryProvider(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options);
class LibCxxMapIteratorSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
LibCxxMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
size_t CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
bool Update() override;
bool MightHaveChildren() override;
size_t GetIndexOfChildWithName(const ConstString &name) override;
~LibCxxMapIteratorSyntheticFrontEnd() override;
private:
ValueObject *m_pair_ptr;
lldb::ValueObjectSP m_pair_sp;
};
SyntheticChildrenFrontEnd *
LibCxxMapIteratorSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
SyntheticChildrenFrontEnd *
LibCxxVectorIteratorSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
class LibcxxSharedPtrSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
LibcxxSharedPtrSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
size_t CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
bool Update() override;
bool MightHaveChildren() override;
size_t GetIndexOfChildWithName(const ConstString &name) override;
~LibcxxSharedPtrSyntheticFrontEnd() override;
private:
ValueObject *m_cntrl;
lldb::ValueObjectSP m_count_sp;
lldb::ValueObjectSP m_weak_count_sp;
uint8_t m_ptr_size;
lldb::ByteOrder m_byte_order;
};
SyntheticChildrenFrontEnd *
LibcxxBitsetSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
SyntheticChildrenFrontEnd *
LibcxxSharedPtrSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
SyntheticChildrenFrontEnd *
LibcxxStdVectorSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
SyntheticChildrenFrontEnd *
LibcxxStdListSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
SyntheticChildrenFrontEnd *
LibcxxStdForwardListSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
SyntheticChildrenFrontEnd *
LibcxxStdMapSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
SyntheticChildrenFrontEnd *
LibcxxStdUnorderedMapSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
SyntheticChildrenFrontEnd *
LibcxxInitializerListSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
SyntheticChildrenFrontEnd *LibcxxFunctionFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
SyntheticChildrenFrontEnd *LibcxxQueueFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
SyntheticChildrenFrontEnd *LibcxxTupleFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
} // namespace formatters
} // namespace lldb_private
#endif // liblldb_LibCxx_h_

View File

@@ -0,0 +1,105 @@
//===-- LibCxxAtomic.cpp ------------------------------------------*- C++
//-*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "LibCxxAtomic.h"
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::formatters;
bool lldb_private::formatters::LibCxxAtomicSummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
static ConstString g___a_("__a_");
if (ValueObjectSP child = valobj.GetChildMemberWithName(g___a_, true)) {
std::string summary;
if (child->GetSummaryAsCString(summary, options) && summary.size() > 0) {
stream.Printf("%s", summary.c_str());
return true;
}
}
return false;
}
namespace lldb_private {
namespace formatters {
class LibcxxStdAtomicSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
LibcxxStdAtomicSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
~LibcxxStdAtomicSyntheticFrontEnd() override = default;
size_t CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
bool Update() override;
bool MightHaveChildren() override;
size_t GetIndexOfChildWithName(const ConstString &name) override;
lldb::ValueObjectSP GetSyntheticValue() override;
private:
ValueObject *m_real_child;
};
} // namespace formatters
} // namespace lldb_private
lldb_private::formatters::LibcxxStdAtomicSyntheticFrontEnd::
LibcxxStdAtomicSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
: SyntheticChildrenFrontEnd(*valobj_sp), m_real_child(nullptr) {}
bool lldb_private::formatters::LibcxxStdAtomicSyntheticFrontEnd::Update() {
static ConstString g___a_("__a_");
m_real_child = m_backend.GetChildMemberWithName(g___a_, true).get();
return false;
}
bool lldb_private::formatters::LibcxxStdAtomicSyntheticFrontEnd::
MightHaveChildren() {
return true;
}
size_t lldb_private::formatters::LibcxxStdAtomicSyntheticFrontEnd::
CalculateNumChildren() {
return m_real_child ? m_real_child->GetNumChildren() : 0;
}
lldb::ValueObjectSP
lldb_private::formatters::LibcxxStdAtomicSyntheticFrontEnd::GetChildAtIndex(
size_t idx) {
return m_real_child ? m_real_child->GetChildAtIndex(idx, true) : nullptr;
}
size_t lldb_private::formatters::LibcxxStdAtomicSyntheticFrontEnd::
GetIndexOfChildWithName(const ConstString &name) {
return m_real_child ? m_real_child->GetIndexOfChildWithName(name)
: UINT32_MAX;
}
lldb::ValueObjectSP lldb_private::formatters::LibcxxStdAtomicSyntheticFrontEnd::
GetSyntheticValue() {
if (m_real_child && m_real_child->CanProvideValue())
return m_real_child->GetSP();
return nullptr;
}
SyntheticChildrenFrontEnd *
lldb_private::formatters::LibcxxAtomicSyntheticFrontEndCreator(
CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
if (valobj_sp)
return new LibcxxStdAtomicSyntheticFrontEnd(valobj_sp);
return nullptr;
}

View File

@@ -0,0 +1,31 @@
//===-- LibCxxAtomic.h -------------------------------------------*- C++
//-*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_LibCxxAtomic_h_
#define liblldb_LibCxxAtomic_h_
#include "lldb/Core/ValueObject.h"
#include "lldb/DataFormatters/TypeSummary.h"
#include "lldb/DataFormatters/TypeSynthetic.h"
#include "lldb/Utility/Stream.h"
namespace lldb_private {
namespace formatters {
bool LibCxxAtomicSummaryProvider(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options);
SyntheticChildrenFrontEnd *
LibcxxAtomicSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP);
} // namespace formatters
} // namespace lldb_private
#endif // liblldb_LibCxxAtomic_h_

View File

@@ -0,0 +1,107 @@
//===-- LibCxxBitset.cpp ----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "LibCxx.h"
#include "lldb/DataFormatters/FormattersHelpers.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Target/Target.h"
using namespace lldb;
using namespace lldb_private;
namespace {
class BitsetFrontEnd : public SyntheticChildrenFrontEnd {
public:
BitsetFrontEnd(ValueObject &valobj);
size_t GetIndexOfChildWithName(const ConstString &name) override {
return formatters::ExtractIndexFromString(name.GetCString());
}
bool MightHaveChildren() override { return true; }
bool Update() override;
size_t CalculateNumChildren() override { return m_elements.size(); }
ValueObjectSP GetChildAtIndex(size_t idx) override;
private:
std::vector<ValueObjectSP> m_elements;
ValueObjectSP m_first;
CompilerType m_bool_type;
ByteOrder m_byte_order = eByteOrderInvalid;
uint8_t m_byte_size = 0;
};
} // namespace
BitsetFrontEnd::BitsetFrontEnd(ValueObject &valobj)
: SyntheticChildrenFrontEnd(valobj) {
m_bool_type = valobj.GetCompilerType().GetBasicTypeFromAST(eBasicTypeBool);
if (auto target_sp = m_backend.GetTargetSP()) {
m_byte_order = target_sp->GetArchitecture().GetByteOrder();
m_byte_size = target_sp->GetArchitecture().GetAddressByteSize();
Update();
}
}
bool BitsetFrontEnd::Update() {
m_elements.clear();
m_first.reset();
TargetSP target_sp = m_backend.GetTargetSP();
if (!target_sp)
return false;
size_t capping_size = target_sp->GetMaximumNumberOfChildrenToDisplay();
size_t size = 0;
if (auto arg = m_backend.GetCompilerType().GetIntegralTemplateArgument(0))
size = arg->value.getLimitedValue(capping_size);
m_elements.assign(size, ValueObjectSP());
m_first = m_backend.GetChildMemberWithName(ConstString("__first_"), true);
return false;
}
ValueObjectSP BitsetFrontEnd::GetChildAtIndex(size_t idx) {
if (idx >= m_elements.size() || !m_first)
return ValueObjectSP();
if (m_elements[idx])
return m_elements[idx];
ExecutionContext ctx = m_backend.GetExecutionContextRef().Lock(false);
CompilerType type;
ValueObjectSP chunk;
// For small bitsets __first_ is not an array, but a plain size_t.
if (m_first->GetCompilerType().IsArrayType(&type, nullptr, nullptr))
chunk = m_first->GetChildAtIndex(
idx / type.GetBitSize(ctx.GetBestExecutionContextScope()), true);
else {
type = m_first->GetCompilerType();
chunk = m_first;
}
if (!type || !chunk)
return ValueObjectSP();
size_t chunk_idx = idx % type.GetBitSize(ctx.GetBestExecutionContextScope());
uint8_t value = !!(chunk->GetValueAsUnsigned(0) & (uint64_t(1) << chunk_idx));
DataExtractor data(&value, sizeof(value), m_byte_order, m_byte_size);
m_elements[idx] = CreateValueObjectFromData(llvm::formatv("[{0}]", idx).str(),
data, ctx, m_bool_type);
return m_elements[idx];
}
SyntheticChildrenFrontEnd *formatters::LibcxxBitsetSyntheticFrontEndCreator(
CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
if (valobj_sp)
return new BitsetFrontEnd(*valobj_sp);
return nullptr;
}

View File

@@ -0,0 +1,128 @@
//===-- LibCxxInitializerList.cpp -------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "LibCxx.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/DataFormatters/FormattersHelpers.h"
#include "lldb/Utility/ConstString.h"
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::formatters;
namespace lldb_private {
namespace formatters {
class LibcxxInitializerListSyntheticFrontEnd
: public SyntheticChildrenFrontEnd {
public:
LibcxxInitializerListSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
~LibcxxInitializerListSyntheticFrontEnd() override;
size_t CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
bool Update() override;
bool MightHaveChildren() override;
size_t GetIndexOfChildWithName(const ConstString &name) override;
private:
ValueObject *m_start;
CompilerType m_element_type;
uint32_t m_element_size;
size_t m_num_elements;
};
} // namespace formatters
} // namespace lldb_private
lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
LibcxxInitializerListSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
: SyntheticChildrenFrontEnd(*valobj_sp), m_start(nullptr), m_element_type(),
m_element_size(0), m_num_elements(0) {
if (valobj_sp)
Update();
}
lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
~LibcxxInitializerListSyntheticFrontEnd() {
// this needs to stay around because it's a child object who will follow its
// parent's life cycle
// delete m_start;
}
size_t lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
CalculateNumChildren() {
static ConstString g___size_("__size_");
m_num_elements = 0;
ValueObjectSP size_sp(m_backend.GetChildMemberWithName(g___size_, true));
if (size_sp)
m_num_elements = size_sp->GetValueAsUnsigned(0);
return m_num_elements;
}
lldb::ValueObjectSP lldb_private::formatters::
LibcxxInitializerListSyntheticFrontEnd::GetChildAtIndex(size_t idx) {
if (!m_start)
return lldb::ValueObjectSP();
uint64_t offset = idx * m_element_size;
offset = offset + m_start->GetValueAsUnsigned(0);
StreamString name;
name.Printf("[%" PRIu64 "]", (uint64_t)idx);
return CreateValueObjectFromAddress(name.GetString(), offset,
m_backend.GetExecutionContextRef(),
m_element_type);
}
bool lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
Update() {
static ConstString g___begin_("__begin_");
m_start = nullptr;
m_num_elements = 0;
m_element_type = m_backend.GetCompilerType().GetTypeTemplateArgument(0);
if (!m_element_type.IsValid())
return false;
m_element_size = m_element_type.GetByteSize(nullptr);
if (m_element_size > 0)
m_start =
m_backend.GetChildMemberWithName(g___begin_, true)
.get(); // store raw pointers or end up with a circular dependency
return false;
}
bool lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
MightHaveChildren() {
return true;
}
size_t lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
GetIndexOfChildWithName(const ConstString &name) {
if (!m_start)
return UINT32_MAX;
return ExtractIndexFromString(name.GetCString());
}
lldb_private::SyntheticChildrenFrontEnd *
lldb_private::formatters::LibcxxInitializerListSyntheticFrontEndCreator(
CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
return (valobj_sp ? new LibcxxInitializerListSyntheticFrontEnd(valobj_sp)
: nullptr);
}

View File

@@ -0,0 +1,449 @@
//===-- LibCxxList.cpp ------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "LibCxx.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/Core/ValueObjectConstResult.h"
#include "lldb/DataFormatters/FormattersHelpers.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/Endian.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/Stream.h"
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::formatters;
namespace {
class ListEntry {
public:
ListEntry() = default;
ListEntry(ValueObjectSP entry_sp) : m_entry_sp(entry_sp) {}
ListEntry(const ListEntry &rhs) = default;
ListEntry(ValueObject *entry)
: m_entry_sp(entry ? entry->GetSP() : ValueObjectSP()) {}
ListEntry next() {
static ConstString g_next("__next_");
if (!m_entry_sp)
return ListEntry();
return ListEntry(m_entry_sp->GetChildMemberWithName(g_next, true));
}
ListEntry prev() {
static ConstString g_prev("__prev_");
if (!m_entry_sp)
return ListEntry();
return ListEntry(m_entry_sp->GetChildMemberWithName(g_prev, true));
}
uint64_t value() const {
if (!m_entry_sp)
return 0;
return m_entry_sp->GetValueAsUnsigned(0);
}
bool null() { return (value() == 0); }
explicit operator bool() { return GetEntry() && !null(); }
ValueObjectSP GetEntry() { return m_entry_sp; }
void SetEntry(ValueObjectSP entry) { m_entry_sp = entry; }
bool operator==(const ListEntry &rhs) const { return value() == rhs.value(); }
bool operator!=(const ListEntry &rhs) const { return !(*this == rhs); }
private:
ValueObjectSP m_entry_sp;
};
class ListIterator {
public:
ListIterator() = default;
ListIterator(ListEntry entry) : m_entry(entry) {}
ListIterator(ValueObjectSP entry) : m_entry(entry) {}
ListIterator(const ListIterator &rhs) = default;
ListIterator(ValueObject *entry) : m_entry(entry) {}
ValueObjectSP value() { return m_entry.GetEntry(); }
ValueObjectSP advance(size_t count) {
if (count == 0)
return m_entry.GetEntry();
if (count == 1) {
next();
return m_entry.GetEntry();
}
while (count > 0) {
next();
count--;
if (m_entry.null())
return lldb::ValueObjectSP();
}
return m_entry.GetEntry();
}
bool operator==(const ListIterator &rhs) const {
return (rhs.m_entry == m_entry);
}
protected:
void next() { m_entry = m_entry.next(); }
void prev() { m_entry = m_entry.prev(); }
private:
ListEntry m_entry;
};
class AbstractListFrontEnd : public SyntheticChildrenFrontEnd {
public:
size_t GetIndexOfChildWithName(const ConstString &name) override {
return ExtractIndexFromString(name.GetCString());
}
bool MightHaveChildren() override { return true; }
bool Update() override;
protected:
AbstractListFrontEnd(ValueObject &valobj)
: SyntheticChildrenFrontEnd(valobj) {}
size_t m_count;
ValueObject *m_head;
static constexpr bool g_use_loop_detect = true;
size_t m_loop_detected; // The number of elements that have had loop detection
// run over them.
ListEntry m_slow_runner; // Used for loop detection
ListEntry m_fast_runner; // Used for loop detection
size_t m_list_capping_size;
CompilerType m_element_type;
std::map<size_t, ListIterator> m_iterators;
bool HasLoop(size_t count);
ValueObjectSP GetItem(size_t idx);
};
class ForwardListFrontEnd : public AbstractListFrontEnd {
public:
ForwardListFrontEnd(ValueObject &valobj);
size_t CalculateNumChildren() override;
ValueObjectSP GetChildAtIndex(size_t idx) override;
bool Update() override;
};
class ListFrontEnd : public AbstractListFrontEnd {
public:
ListFrontEnd(lldb::ValueObjectSP valobj_sp);
~ListFrontEnd() override = default;
size_t CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
bool Update() override;
private:
lldb::addr_t m_node_address;
ValueObject *m_tail;
};
} // end anonymous namespace
bool AbstractListFrontEnd::Update() {
m_loop_detected = 0;
m_count = UINT32_MAX;
m_head = nullptr;
m_list_capping_size = 0;
m_slow_runner.SetEntry(nullptr);
m_fast_runner.SetEntry(nullptr);
m_iterators.clear();
if (m_backend.GetTargetSP())
m_list_capping_size =
m_backend.GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
if (m_list_capping_size == 0)
m_list_capping_size = 255;
CompilerType list_type = m_backend.GetCompilerType();
if (list_type.IsReferenceType())
list_type = list_type.GetNonReferenceType();
if (list_type.GetNumTemplateArguments() == 0)
return false;
m_element_type = list_type.GetTypeTemplateArgument(0);
return false;
}
bool AbstractListFrontEnd::HasLoop(size_t count) {
if (!g_use_loop_detect)
return false;
// don't bother checking for a loop if we won't actually need to jump nodes
if (m_count < 2)
return false;
if (m_loop_detected == 0) {
// This is the first time we are being run (after the last update). Set up
// the loop
// invariant for the first element.
m_slow_runner = ListEntry(m_head).next();
m_fast_runner = m_slow_runner.next();
m_loop_detected = 1;
}
// Loop invariant:
// Loop detection has been run over the first m_loop_detected elements. If
// m_slow_runner ==
// m_fast_runner then the loop has been detected after m_loop_detected
// elements.
const size_t steps_to_run = std::min(count, m_count);
while (m_loop_detected < steps_to_run && m_slow_runner && m_fast_runner &&
m_slow_runner != m_fast_runner) {
m_slow_runner = m_slow_runner.next();
m_fast_runner = m_fast_runner.next().next();
m_loop_detected++;
}
if (count <= m_loop_detected)
return false; // No loop in the first m_loop_detected elements.
if (!m_slow_runner || !m_fast_runner)
return false; // Reached the end of the list. Definitely no loops.
return m_slow_runner == m_fast_runner;
}
ValueObjectSP AbstractListFrontEnd::GetItem(size_t idx) {
size_t advance = idx;
ListIterator current(m_head);
if (idx > 0) {
auto cached_iterator = m_iterators.find(idx - 1);
if (cached_iterator != m_iterators.end()) {
current = cached_iterator->second;
advance = 1;
}
}
ValueObjectSP value_sp = current.advance(advance);
m_iterators[idx] = current;
return value_sp;
}
ForwardListFrontEnd::ForwardListFrontEnd(ValueObject &valobj)
: AbstractListFrontEnd(valobj) {
Update();
}
size_t ForwardListFrontEnd::CalculateNumChildren() {
if (m_count != UINT32_MAX)
return m_count;
ListEntry current(m_head);
m_count = 0;
while (current && m_count < m_list_capping_size) {
++m_count;
current = current.next();
}
return m_count;
}
ValueObjectSP ForwardListFrontEnd::GetChildAtIndex(size_t idx) {
if (idx >= CalculateNumChildren())
return nullptr;
if (!m_head)
return nullptr;
if (HasLoop(idx + 1))
return nullptr;
ValueObjectSP current_sp = GetItem(idx);
if (!current_sp)
return nullptr;
current_sp = current_sp->GetChildAtIndex(1, true); // get the __value_ child
if (!current_sp)
return nullptr;
// we need to copy current_sp into a new object otherwise we will end up with
// all items named __value_
DataExtractor data;
Status error;
current_sp->GetData(data, error);
if (error.Fail())
return nullptr;
return CreateValueObjectFromData(llvm::formatv("[{0}]", idx).str(), data,
m_backend.GetExecutionContextRef(),
m_element_type);
}
static ValueObjectSP GetValueOfCompressedPair(ValueObject &pair) {
ValueObjectSP value = pair.GetChildMemberWithName(ConstString("__value_"), true);
if (! value) {
// pre-r300140 member name
value = pair.GetChildMemberWithName(ConstString("__first_"), true);
}
return value;
}
bool ForwardListFrontEnd::Update() {
AbstractListFrontEnd::Update();
Status err;
ValueObjectSP backend_addr(m_backend.AddressOf(err));
if (err.Fail() || !backend_addr)
return false;
ValueObjectSP impl_sp(
m_backend.GetChildMemberWithName(ConstString("__before_begin_"), true));
if (!impl_sp)
return false;
impl_sp = GetValueOfCompressedPair(*impl_sp);
if (!impl_sp)
return false;
m_head = impl_sp->GetChildMemberWithName(ConstString("__next_"), true).get();
return false;
}
ListFrontEnd::ListFrontEnd(lldb::ValueObjectSP valobj_sp)
: AbstractListFrontEnd(*valobj_sp), m_node_address(), m_tail(nullptr) {
if (valobj_sp)
Update();
}
size_t ListFrontEnd::CalculateNumChildren() {
if (m_count != UINT32_MAX)
return m_count;
if (!m_head || !m_tail || m_node_address == 0)
return 0;
ValueObjectSP size_alloc(
m_backend.GetChildMemberWithName(ConstString("__size_alloc_"), true));
if (size_alloc) {
ValueObjectSP value = GetValueOfCompressedPair(*size_alloc);
if (value) {
m_count = value->GetValueAsUnsigned(UINT32_MAX);
}
}
if (m_count != UINT32_MAX) {
return m_count;
} else {
uint64_t next_val = m_head->GetValueAsUnsigned(0);
uint64_t prev_val = m_tail->GetValueAsUnsigned(0);
if (next_val == 0 || prev_val == 0)
return 0;
if (next_val == m_node_address)
return 0;
if (next_val == prev_val)
return 1;
uint64_t size = 2;
ListEntry current(m_head);
while (current.next() && current.next().value() != m_node_address) {
size++;
current = current.next();
if (size > m_list_capping_size)
break;
}
return m_count = (size - 1);
}
}
lldb::ValueObjectSP ListFrontEnd::GetChildAtIndex(size_t idx) {
static ConstString g_value("__value_");
static ConstString g_next("__next_");
if (idx >= CalculateNumChildren())
return lldb::ValueObjectSP();
if (!m_head || !m_tail || m_node_address == 0)
return lldb::ValueObjectSP();
if (HasLoop(idx + 1))
return lldb::ValueObjectSP();
ValueObjectSP current_sp = GetItem(idx);
if (!current_sp)
return lldb::ValueObjectSP();
current_sp = current_sp->GetChildAtIndex(1, true); // get the __value_ child
if (!current_sp)
return lldb::ValueObjectSP();
if (current_sp->GetName() == g_next) {
ProcessSP process_sp(current_sp->GetProcessSP());
if (!process_sp)
return nullptr;
// if we grabbed the __next_ pointer, then the child is one pointer deep-er
lldb::addr_t addr = current_sp->GetParent()->GetPointerValue();
addr = addr + 2 * process_sp->GetAddressByteSize();
ExecutionContext exe_ctx(process_sp);
current_sp =
CreateValueObjectFromAddress("__value_", addr, exe_ctx, m_element_type);
}
// we need to copy current_sp into a new object otherwise we will end up with
// all items named __value_
DataExtractor data;
Status error;
current_sp->GetData(data, error);
if (error.Fail())
return lldb::ValueObjectSP();
StreamString name;
name.Printf("[%" PRIu64 "]", (uint64_t)idx);
return CreateValueObjectFromData(name.GetString(), data,
m_backend.GetExecutionContextRef(),
m_element_type);
}
bool ListFrontEnd::Update() {
AbstractListFrontEnd::Update();
m_tail = nullptr;
m_node_address = 0;
Status err;
ValueObjectSP backend_addr(m_backend.AddressOf(err));
if (err.Fail() || !backend_addr)
return false;
m_node_address = backend_addr->GetValueAsUnsigned(0);
if (!m_node_address || m_node_address == LLDB_INVALID_ADDRESS)
return false;
ValueObjectSP impl_sp(
m_backend.GetChildMemberWithName(ConstString("__end_"), true));
if (!impl_sp)
return false;
m_head = impl_sp->GetChildMemberWithName(ConstString("__next_"), true).get();
m_tail = impl_sp->GetChildMemberWithName(ConstString("__prev_"), true).get();
return false;
}
SyntheticChildrenFrontEnd *formatters::LibcxxStdListSyntheticFrontEndCreator(
CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
return (valobj_sp ? new ListFrontEnd(valobj_sp) : nullptr);
}
SyntheticChildrenFrontEnd *
formatters::LibcxxStdForwardListSyntheticFrontEndCreator(
CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
return valobj_sp ? new ForwardListFrontEnd(*valobj_sp) : nullptr;
}

View File

@@ -0,0 +1,468 @@
//===-- LibCxxMap.cpp -------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "LibCxx.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/Core/ValueObjectConstResult.h"
#include "lldb/DataFormatters/FormattersHelpers.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/Endian.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/Stream.h"
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::formatters;
class MapEntry {
public:
MapEntry() = default;
explicit MapEntry(ValueObjectSP entry_sp) : m_entry_sp(entry_sp) {}
MapEntry(const MapEntry &rhs) = default;
explicit MapEntry(ValueObject *entry)
: m_entry_sp(entry ? entry->GetSP() : ValueObjectSP()) {}
ValueObjectSP left() const {
static ConstString g_left("__left_");
if (!m_entry_sp)
return m_entry_sp;
return m_entry_sp->GetSyntheticChildAtOffset(
0, m_entry_sp->GetCompilerType(), true);
}
ValueObjectSP right() const {
static ConstString g_right("__right_");
if (!m_entry_sp)
return m_entry_sp;
return m_entry_sp->GetSyntheticChildAtOffset(
m_entry_sp->GetProcessSP()->GetAddressByteSize(),
m_entry_sp->GetCompilerType(), true);
}
ValueObjectSP parent() const {
static ConstString g_parent("__parent_");
if (!m_entry_sp)
return m_entry_sp;
return m_entry_sp->GetSyntheticChildAtOffset(
2 * m_entry_sp->GetProcessSP()->GetAddressByteSize(),
m_entry_sp->GetCompilerType(), true);
}
uint64_t value() const {
if (!m_entry_sp)
return 0;
return m_entry_sp->GetValueAsUnsigned(0);
}
bool error() const {
if (!m_entry_sp)
return true;
return m_entry_sp->GetError().Fail();
}
bool null() const { return (value() == 0); }
ValueObjectSP GetEntry() const { return m_entry_sp; }
void SetEntry(ValueObjectSP entry) { m_entry_sp = entry; }
bool operator==(const MapEntry &rhs) const {
return (rhs.m_entry_sp.get() == m_entry_sp.get());
}
private:
ValueObjectSP m_entry_sp;
};
class MapIterator {
public:
MapIterator() = default;
MapIterator(MapEntry entry, size_t depth = 0)
: m_entry(entry), m_max_depth(depth), m_error(false) {}
MapIterator(ValueObjectSP entry, size_t depth = 0)
: m_entry(entry), m_max_depth(depth), m_error(false) {}
MapIterator(const MapIterator &rhs)
: m_entry(rhs.m_entry), m_max_depth(rhs.m_max_depth), m_error(false) {}
MapIterator(ValueObject *entry, size_t depth = 0)
: m_entry(entry), m_max_depth(depth), m_error(false) {}
ValueObjectSP value() { return m_entry.GetEntry(); }
ValueObjectSP advance(size_t count) {
ValueObjectSP fail;
if (m_error)
return fail;
size_t steps = 0;
while (count > 0) {
next();
count--, steps++;
if (m_error || m_entry.null() || (steps > m_max_depth))
return fail;
}
return m_entry.GetEntry();
}
protected:
void next() {
if (m_entry.null())
return;
MapEntry right(m_entry.right());
if (!right.null()) {
m_entry = tree_min(std::move(right));
return;
}
size_t steps = 0;
while (!is_left_child(m_entry)) {
if (m_entry.error()) {
m_error = true;
return;
}
m_entry.SetEntry(m_entry.parent());
steps++;
if (steps > m_max_depth) {
m_entry = MapEntry();
return;
}
}
m_entry = MapEntry(m_entry.parent());
}
private:
MapEntry tree_min(MapEntry &&x) {
if (x.null())
return MapEntry();
MapEntry left(x.left());
size_t steps = 0;
while (!left.null()) {
if (left.error()) {
m_error = true;
return MapEntry();
}
x = left;
left.SetEntry(x.left());
steps++;
if (steps > m_max_depth)
return MapEntry();
}
return x;
}
bool is_left_child(const MapEntry &x) {
if (x.null())
return false;
MapEntry rhs(x.parent());
rhs.SetEntry(rhs.left());
return x.value() == rhs.value();
}
MapEntry m_entry;
size_t m_max_depth;
bool m_error;
};
namespace lldb_private {
namespace formatters {
class LibcxxStdMapSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
LibcxxStdMapSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
~LibcxxStdMapSyntheticFrontEnd() override = default;
size_t CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
bool Update() override;
bool MightHaveChildren() override;
size_t GetIndexOfChildWithName(const ConstString &name) override;
private:
bool GetDataType();
void GetValueOffset(const lldb::ValueObjectSP &node);
ValueObject *m_tree;
ValueObject *m_root_node;
CompilerType m_element_type;
uint32_t m_skip_size;
size_t m_count;
std::map<size_t, MapIterator> m_iterators;
};
} // namespace formatters
} // namespace lldb_private
lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::
LibcxxStdMapSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
: SyntheticChildrenFrontEnd(*valobj_sp), m_tree(nullptr),
m_root_node(nullptr), m_element_type(), m_skip_size(UINT32_MAX),
m_count(UINT32_MAX), m_iterators() {
if (valobj_sp)
Update();
}
size_t lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::
CalculateNumChildren() {
static ConstString g___pair3_("__pair3_");
static ConstString g___first_("__first_");
static ConstString g___value_("__value_");
if (m_count != UINT32_MAX)
return m_count;
if (m_tree == nullptr)
return 0;
ValueObjectSP m_item(m_tree->GetChildMemberWithName(g___pair3_, true));
if (!m_item)
return 0;
switch (m_item->GetCompilerType().GetNumDirectBaseClasses()) {
case 1:
// Assume a pre llvm r300140 __compressed_pair implementation:
m_item = m_item->GetChildMemberWithName(g___first_, true);
break;
case 2: {
// Assume a post llvm r300140 __compressed_pair implementation:
ValueObjectSP first_elem_parent = m_item->GetChildAtIndex(0, true);
m_item = first_elem_parent->GetChildMemberWithName(g___value_, true);
break;
}
default:
return false;
}
if (!m_item)
return 0;
m_count = m_item->GetValueAsUnsigned(0);
return m_count;
}
bool lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetDataType() {
static ConstString g___value_("__value_");
static ConstString g_tree_("__tree_");
static ConstString g_pair3("__pair3_");
if (m_element_type.GetOpaqueQualType() && m_element_type.GetTypeSystem())
return true;
m_element_type.Clear();
ValueObjectSP deref;
Status error;
deref = m_root_node->Dereference(error);
if (!deref || error.Fail())
return false;
deref = deref->GetChildMemberWithName(g___value_, true);
if (deref) {
m_element_type = deref->GetCompilerType();
return true;
}
deref = m_backend.GetChildAtNamePath({g_tree_, g_pair3});
if (!deref)
return false;
m_element_type = deref->GetCompilerType()
.GetTypeTemplateArgument(1)
.GetTypeTemplateArgument(1);
if (m_element_type) {
std::string name;
uint64_t bit_offset_ptr;
uint32_t bitfield_bit_size_ptr;
bool is_bitfield_ptr;
m_element_type = m_element_type.GetFieldAtIndex(
0, name, &bit_offset_ptr, &bitfield_bit_size_ptr, &is_bitfield_ptr);
m_element_type = m_element_type.GetTypedefedType();
return m_element_type.IsValid();
} else {
m_element_type = m_backend.GetCompilerType().GetTypeTemplateArgument(0);
return m_element_type.IsValid();
}
}
void lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetValueOffset(
const lldb::ValueObjectSP &node) {
if (m_skip_size != UINT32_MAX)
return;
if (!node)
return;
CompilerType node_type(node->GetCompilerType());
uint64_t bit_offset;
if (node_type.GetIndexOfFieldWithName("__value_", nullptr, &bit_offset) !=
UINT32_MAX) {
m_skip_size = bit_offset / 8u;
} else {
ClangASTContext *ast_ctx =
llvm::dyn_cast_or_null<ClangASTContext>(node_type.GetTypeSystem());
if (!ast_ctx)
return;
CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier(
ConstString(),
{{"ptr0", ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
{"ptr1", ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
{"ptr2", ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()},
{"cw", ast_ctx->GetBasicType(lldb::eBasicTypeBool)},
{"payload", (m_element_type.GetCompleteType(), m_element_type)}});
std::string child_name;
uint32_t child_byte_size;
int32_t child_byte_offset = 0;
uint32_t child_bitfield_bit_size;
uint32_t child_bitfield_bit_offset;
bool child_is_base_class;
bool child_is_deref_of_parent;
uint64_t language_flags;
if (tree_node_type
.GetChildCompilerTypeAtIndex(
nullptr, 4, true, true, true, child_name, child_byte_size,
child_byte_offset, child_bitfield_bit_size,
child_bitfield_bit_offset, child_is_base_class,
child_is_deref_of_parent, nullptr, language_flags)
.IsValid())
m_skip_size = (uint32_t)child_byte_offset;
}
}
lldb::ValueObjectSP
lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetChildAtIndex(
size_t idx) {
static ConstString g___cc("__cc");
static ConstString g___nc("__nc");
static ConstString g___value_("__value_");
if (idx >= CalculateNumChildren())
return lldb::ValueObjectSP();
if (m_tree == nullptr || m_root_node == nullptr)
return lldb::ValueObjectSP();
MapIterator iterator(m_root_node, CalculateNumChildren());
const bool need_to_skip = (idx > 0);
size_t actual_advancde = idx;
if (need_to_skip) {
auto cached_iterator = m_iterators.find(idx - 1);
if (cached_iterator != m_iterators.end()) {
iterator = cached_iterator->second;
actual_advancde = 1;
}
}
ValueObjectSP iterated_sp(iterator.advance(actual_advancde));
if (!iterated_sp) {
// this tree is garbage - stop
m_tree =
nullptr; // this will stop all future searches until an Update() happens
return iterated_sp;
}
if (GetDataType()) {
if (!need_to_skip) {
Status error;
iterated_sp = iterated_sp->Dereference(error);
if (!iterated_sp || error.Fail()) {
m_tree = nullptr;
return lldb::ValueObjectSP();
}
GetValueOffset(iterated_sp);
auto child_sp = iterated_sp->GetChildMemberWithName(g___value_, true);
if (child_sp)
iterated_sp = child_sp;
else
iterated_sp = iterated_sp->GetSyntheticChildAtOffset(
m_skip_size, m_element_type, true);
if (!iterated_sp) {
m_tree = nullptr;
return lldb::ValueObjectSP();
}
} else {
// because of the way our debug info is made, we need to read item 0 first
// so that we can cache information used to generate other elements
if (m_skip_size == UINT32_MAX)
GetChildAtIndex(0);
if (m_skip_size == UINT32_MAX) {
m_tree = nullptr;
return lldb::ValueObjectSP();
}
iterated_sp = iterated_sp->GetSyntheticChildAtOffset(
m_skip_size, m_element_type, true);
if (!iterated_sp) {
m_tree = nullptr;
return lldb::ValueObjectSP();
}
}
} else {
m_tree = nullptr;
return lldb::ValueObjectSP();
}
// at this point we have a valid
// we need to copy current_sp into a new object otherwise we will end up with
// all items named __value_
DataExtractor data;
Status error;
iterated_sp->GetData(data, error);
if (error.Fail()) {
m_tree = nullptr;
return lldb::ValueObjectSP();
}
StreamString name;
name.Printf("[%" PRIu64 "]", (uint64_t)idx);
auto potential_child_sp = CreateValueObjectFromData(
name.GetString(), data, m_backend.GetExecutionContextRef(),
m_element_type);
if (potential_child_sp) {
switch (potential_child_sp->GetNumChildren()) {
case 1: {
auto child0_sp = potential_child_sp->GetChildAtIndex(0, true);
if (child0_sp && child0_sp->GetName() == g___cc)
potential_child_sp = child0_sp->Clone(ConstString(name.GetString()));
break;
}
case 2: {
auto child0_sp = potential_child_sp->GetChildAtIndex(0, true);
auto child1_sp = potential_child_sp->GetChildAtIndex(1, true);
if (child0_sp && child0_sp->GetName() == g___cc && child1_sp &&
child1_sp->GetName() == g___nc)
potential_child_sp = child0_sp->Clone(ConstString(name.GetString()));
break;
}
}
}
m_iterators[idx] = iterator;
return potential_child_sp;
}
bool lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::Update() {
static ConstString g___tree_("__tree_");
static ConstString g___begin_node_("__begin_node_");
m_count = UINT32_MAX;
m_tree = m_root_node = nullptr;
m_iterators.clear();
m_tree = m_backend.GetChildMemberWithName(g___tree_, true).get();
if (!m_tree)
return false;
m_root_node = m_tree->GetChildMemberWithName(g___begin_node_, true).get();
return false;
}
bool lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::
MightHaveChildren() {
return true;
}
size_t lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::
GetIndexOfChildWithName(const ConstString &name) {
return ExtractIndexFromString(name.GetCString());
}
SyntheticChildrenFrontEnd *
lldb_private::formatters::LibcxxStdMapSyntheticFrontEndCreator(
CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
return (valobj_sp ? new LibcxxStdMapSyntheticFrontEnd(valobj_sp) : nullptr);
}

View File

@@ -0,0 +1,61 @@
//===-- LibCxxQueue.cpp -----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "LibCxx.h"
#include "lldb/DataFormatters/FormattersHelpers.h"
using namespace lldb;
using namespace lldb_private;
namespace {
class QueueFrontEnd : public SyntheticChildrenFrontEnd {
public:
QueueFrontEnd(ValueObject &valobj) : SyntheticChildrenFrontEnd(valobj) {
Update();
}
size_t GetIndexOfChildWithName(const ConstString &name) override {
return m_container_sp ? m_container_sp->GetIndexOfChildWithName(name)
: UINT32_MAX;
}
bool MightHaveChildren() override { return true; }
bool Update() override;
size_t CalculateNumChildren() override {
return m_container_sp ? m_container_sp->GetNumChildren() : 0;
}
ValueObjectSP GetChildAtIndex(size_t idx) override {
return m_container_sp ? m_container_sp->GetChildAtIndex(idx, true)
: nullptr;
}
private:
ValueObjectSP m_container_sp;
};
} // namespace
bool QueueFrontEnd::Update() {
m_container_sp.reset();
ValueObjectSP c_sp = m_backend.GetChildMemberWithName(ConstString("c"), true);
if (!c_sp)
return false;
m_container_sp = c_sp->GetSyntheticValue();
return false;
}
SyntheticChildrenFrontEnd *
formatters::LibcxxQueueFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP valobj_sp) {
if (valobj_sp)
return new QueueFrontEnd(*valobj_sp);
return nullptr;
}

View File

@@ -0,0 +1,83 @@
//===-- LibCxxTuple.cpp -----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "LibCxx.h"
#include "lldb/DataFormatters/FormattersHelpers.h"
using namespace lldb;
using namespace lldb_private;
namespace {
class TupleFrontEnd: public SyntheticChildrenFrontEnd {
public:
TupleFrontEnd(ValueObject &valobj) : SyntheticChildrenFrontEnd(valobj) {
Update();
}
size_t GetIndexOfChildWithName(const ConstString &name) override {
return formatters::ExtractIndexFromString(name.GetCString());
}
bool MightHaveChildren() override { return true; }
bool Update() override;
size_t CalculateNumChildren() override { return m_elements.size(); }
ValueObjectSP GetChildAtIndex(size_t idx) override;
private:
std::vector<ValueObjectSP> m_elements;
ValueObjectSP m_base_sp;
};
}
bool TupleFrontEnd::Update() {
m_elements.clear();
m_base_sp = m_backend.GetChildMemberWithName(ConstString("__base_"), true);
if (! m_base_sp) {
// Pre r304382 name of the base element.
m_base_sp = m_backend.GetChildMemberWithName(ConstString("base_"), true);
}
if (! m_base_sp)
return false;
m_elements.assign(m_base_sp->GetCompilerType().GetNumDirectBaseClasses(),
ValueObjectSP());
return false;
}
ValueObjectSP TupleFrontEnd::GetChildAtIndex(size_t idx) {
if (idx >= m_elements.size())
return ValueObjectSP();
if (!m_base_sp)
return ValueObjectSP();
if (m_elements[idx])
return m_elements[idx];
CompilerType holder_type =
m_base_sp->GetCompilerType().GetDirectBaseClassAtIndex(idx, nullptr);
if (!holder_type)
return ValueObjectSP();
ValueObjectSP holder_sp = m_base_sp->GetChildAtIndex(idx, true);
if (!holder_sp)
return ValueObjectSP();
ValueObjectSP elem_sp = holder_sp->GetChildAtIndex(0, true);
if (elem_sp)
m_elements[idx] =
elem_sp->Clone(ConstString(llvm::formatv("[{0}]", idx).str()));
return m_elements[idx];
}
SyntheticChildrenFrontEnd *
formatters::LibcxxTupleFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP valobj_sp) {
if (valobj_sp)
return new TupleFrontEnd(*valobj_sp);
return nullptr;
}

Some files were not shown because too many files have changed in this diff Show More