[Lldb-commits] [lldb] r177799 - <rdar://problem/13315663>
Enrico Granata
egranata at apple.com
Fri Mar 22 18:12:38 PDT 2013
Author: enrico
Date: Fri Mar 22 20:12:38 2013
New Revision: 177799
URL: http://llvm.org/viewvc/llvm-project?rev=177799&view=rev
Log:
<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
Modified:
lldb/trunk/source/Core/ValueObject.cpp
Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=177799&r1=177798&r2=177799&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Fri Mar 22 20:12:38 2013
@@ -1255,17 +1255,40 @@ ValueObject::GetValueAsCString (lldb::Fo
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
More information about the lldb-commits
mailing list