From 852cce7c1fc91acae0ebae7e7ed16181c7e94976 Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Sat, 23 Mar 2013 01:12:38 +0000 Subject: commands of the form frame variable -f c-string foo where foo is an arbitrary pointer (e.g. void*) now do the right thing, i.e. they deref the pointer and try to get a c-string at the pointed address instead of dumping the pointer bytes as a string. the old behavior is used as a fallback if things don’t go well MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit llvm-svn: 177799 --- lldb/source/Core/ValueObject.cpp | 41 +++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'lldb/source/Core/ValueObject.cpp') diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index 031d7546339..279f92c3b63 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -1255,17 +1255,40 @@ ValueObject::GetValueAsCString (lldb::Format format, clang_type_t clang_type = GetClangType (); if (clang_type) { + // put custom bytes to display in this DataExtractor to override the default value logic + lldb_private::DataExtractor special_format_data; + clang::ASTContext* ast = GetClangAST(); + Flags type_flags(ClangASTContext::GetTypeInfo(clang_type, ast, NULL)); + if (type_flags.Test(ClangASTContext::eTypeIsPointer) && !type_flags.Test(ClangASTContext::eTypeIsObjC)) + { + if (format == eFormatCString) + { + // if we are dumping a pointer as a c-string, get the pointee data as a string + TargetSP target_sp(GetTargetSP()); + if (target_sp) + { + size_t max_len = target_sp->GetMaximumSizeOfStringSummary(); + Error error; + DataBufferSP buffer_sp(new DataBufferHeap(max_len+1,0)); + Address address(GetPointerValue()); + if (target_sp->ReadCStringFromMemory(address, (char*)buffer_sp->GetBytes(), max_len, error) && error.Success()) + special_format_data.SetData(buffer_sp); + } + } + } + StreamString sstr; ExecutionContext exe_ctx (GetExecutionContextRef()); - ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST - clang_type, // The clang type to display - &sstr, - format, // Format to display this type with - m_data, // Data to extract from - 0, // Byte offset into "m_data" - GetByteSize(), // Byte size of item in "m_data" - GetBitfieldBitSize(), // Bitfield bit size - GetBitfieldBitOffset(), // Bitfield bit offset + ClangASTType::DumpTypeValue (ast, // The clang AST + clang_type, // The clang type to display + &sstr, // The stream to use for display + format, // Format to display this type with + special_format_data.GetByteSize() ? + special_format_data: m_data, // Data to extract from + 0, // Byte offset into "m_data" + GetByteSize(), // Byte size of item in "m_data" + GetBitfieldBitSize(), // Bitfield bit size + GetBitfieldBitOffset(), // Bitfield bit offset exe_ctx.GetBestExecutionContextScope()); // Don't set the m_error to anything here otherwise // we won't be able to re-format as anything else. The -- cgit v1.2.3