diff options
author | Enrico Granata <egranata@apple.com> | 2014-10-29 23:08:02 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2014-10-29 23:08:02 +0000 |
commit | 76b08d584bd8a72d2420cac7f3e306abaa2cb36c (patch) | |
tree | 51cd47d1eaf6fac13b09bc0a1611ba75943108b1 | |
parent | 27b6d47f36f8cd95a77bd3db9842ec2861c72c04 (diff) | |
download | bcm5719-llvm-76b08d584bd8a72d2420cac7f3e306abaa2cb36c.tar.gz bcm5719-llvm-76b08d584bd8a72d2420cac7f3e306abaa2cb36c.zip |
Fix the NSPathStore2 data formatter to actually handle the explicit length stored inside the object. The meat of this commit, however, is a nice little API for easily adding new __lldb_autogen_ helper types to an AST context
llvm-svn: 220881
-rw-r--r-- | lldb/include/lldb/Symbol/ClangASTContext.h | 6 | ||||
-rw-r--r-- | lldb/source/DataFormatters/CXXFormatterFunctions.cpp | 27 | ||||
-rw-r--r-- | lldb/source/Symbol/ClangASTContext.cpp | 15 |
3 files changed, 46 insertions, 2 deletions
diff --git a/lldb/include/lldb/Symbol/ClangASTContext.h b/lldb/include/lldb/Symbol/ClangASTContext.h index 345bcd7c284..2c49a43580f 100644 --- a/lldb/include/lldb/Symbol/ClangASTContext.h +++ b/lldb/include/lldb/Symbol/ClangASTContext.h @@ -14,8 +14,10 @@ #include <stdint.h> // C++ Includes +#include <initializer_list> #include <string> #include <vector> +#include <utility> // Other libraries and framework includes #include "llvm/ADT/SmallVector.h" @@ -243,6 +245,10 @@ public: return clang_type; } + + ClangASTType + GetOrCreateStructForIdentifier (const ConstString &type_name, + const std::initializer_list< std::pair < const char *, ClangASTType > >& type_fields); //------------------------------------------------------------------ // Structure, Unions, Classes diff --git a/lldb/source/DataFormatters/CXXFormatterFunctions.cpp b/lldb/source/DataFormatters/CXXFormatterFunctions.cpp index c8e5055d49f..9653e25e04a 100644 --- a/lldb/source/DataFormatters/CXXFormatterFunctions.cpp +++ b/lldb/source/DataFormatters/CXXFormatterFunctions.cpp @@ -23,6 +23,8 @@ #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/ProcessStructReader.h" + #include <algorithm> using namespace lldb; @@ -1037,6 +1039,26 @@ lldb_private::formatters::NSTaggedString_SummaryProvider (ObjCLanguageRuntime::C return true; } +static ClangASTType +GetNSPathStore2Type (Target &target) +{ + static ConstString g_type_name("__lldb_autogen_nspathstore2"); + + ClangASTContext *ast_ctx = target.GetScratchClangASTContext(); + + if (!ast_ctx) + return ClangASTType(); + + ClangASTType voidstar = ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType(); + ClangASTType uint32 = ast_ctx->GetIntTypeFromBitSize(32, false); + + return ast_ctx->GetOrCreateStructForIdentifier(g_type_name, { + {"isa",voidstar}, + {"lengthAndRef",uint32}, + {"buffer",voidstar} + }); +} + bool lldb_private::formatters::NSStringSummaryProvider (ValueObject& valobj, Stream& stream) { @@ -1182,7 +1204,10 @@ lldb_private::formatters::NSStringSummaryProvider (ValueObject& valobj, Stream& } else if (is_special) { - uint64_t location = valobj_addr + (ptr_size == 8 ? 12 : 8); + ProcessStructReader reader(valobj.GetProcessSP().get(), valobj.GetValueAsUnsigned(0), GetNSPathStore2Type(*valobj.GetTargetSP())); + explicit_length = reader.GetField<uint32_t>(ConstString("lengthAndRef")) >> 20; + lldb::addr_t location = valobj.GetValueAsUnsigned(0) + ptr_size + 4; + ReadUTFBufferAndDumpToStreamOptions<UTF16> options; options.SetConversionFunction(ConvertUTF16toUTF8); options.SetLocation(location); diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp index 4a7c779fc7a..8347444b273 100644 --- a/lldb/source/Symbol/ClangASTContext.cpp +++ b/lldb/source/Symbol/ClangASTContext.cpp @@ -1855,7 +1855,20 @@ ClangASTContext::CreateArrayType (const ClangASTType &element_type, return ClangASTType(); } - +ClangASTType +ClangASTContext::GetOrCreateStructForIdentifier (const ConstString &type_name, + const std::initializer_list< std::pair < const char *, ClangASTType > >& type_fields) +{ + ClangASTType type; + if ((type = GetTypeForIdentifier<clang::CXXRecordDecl>(type_name)).IsValid()) + return type; + type = CreateRecordType(nullptr, lldb::eAccessPublic, type_name.GetCString(), clang::TTK_Struct, lldb::eLanguageTypeC); + type.StartTagDeclarationDefinition(); + for (const auto& field : type_fields) + type.AddFieldToRecordType(field.first, field.second, lldb::eAccessPublic, 0); + type.CompleteTagDeclarationDefinition(); + return type; +} #pragma mark Enumeration Types |