diff options
| author | Enrico Granata <egranata@apple.com> | 2013-03-23 01:12:38 +0000 |
|---|---|---|
| committer | Enrico Granata <egranata@apple.com> | 2013-03-23 01:12:38 +0000 |
| commit | 852cce7c1fc91acae0ebae7e7ed16181c7e94976 (patch) | |
| tree | 01f77e36e2cf9f9b1a7cd7f77200545f395e3404 /lldb/source/Core/ValueObject.cpp | |
| parent | 7670bb5c3199b8c5409145c80768d2dfe46a1609 (diff) | |
| download | bcm5719-llvm-852cce7c1fc91acae0ebae7e7ed16181c7e94976.tar.gz bcm5719-llvm-852cce7c1fc91acae0ebae7e7ed16181c7e94976.zip | |
<rdar://problem/13315663>
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
llvm-svn: 177799
Diffstat (limited to 'lldb/source/Core/ValueObject.cpp')
| -rw-r--r-- | lldb/source/Core/ValueObject.cpp | 41 |
1 files changed, 32 insertions, 9 deletions
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 |

