[Lldb-commits] [lldb] r113735 - in /lldb/trunk: include/lldb/Core/ValueObject.h include/lldb/Symbol/ClangASTContext.h source/Core/ValueObject.cpp source/Symbol/ClangASTContext.cpp
Greg Clayton
gclayton at apple.com
Sun Sep 12 20:32:57 PDT 2010
Author: gclayton
Date: Sun Sep 12 22:32:57 2010
New Revision: 113735
URL: http://llvm.org/viewvc/llvm-project?rev=113735&view=rev
Log:
Added the summary values for function pointers so we can show where they
point to.
Modified:
lldb/trunk/include/lldb/Core/ValueObject.h
lldb/trunk/include/lldb/Symbol/ClangASTContext.h
lldb/trunk/source/Core/ValueObject.cpp
lldb/trunk/source/Symbol/ClangASTContext.cpp
Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=113735&r1=113734&r2=113735&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Sun Sep 12 22:32:57 2010
@@ -223,6 +223,10 @@
void
SetValueIsValid (bool valid);
+
+ lldb::addr_t
+ GetPointerValue (lldb::AddressType &address_type,
+ bool scalar_is_load_address);
private:
//------------------------------------------------------------------
// For ValueObject only
Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=113735&r1=113734&r2=113735&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Sun Sep 12 22:32:57 2010
@@ -391,6 +391,9 @@
static bool
IsCStringType (void *clang_type, uint32_t &length);
+
+ static bool
+ IsFunctionPointerType (void *clang_type);
static bool
IsArrayType (void *clang_type, void **member_type = NULL, uint64_t *size = NULL);
Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=113735&r1=113734&r2=113735&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Sun Sep 12 22:32:57 2010
@@ -390,108 +390,134 @@
// See if this is a pointer to a C string?
uint32_t fixed_length = 0;
- if (clang_type && ClangASTContext::IsCStringType (clang_type, fixed_length))
+ if (clang_type)
{
- Process *process = exe_scope->CalculateProcess();
- if (process != NULL)
+ StreamString sstr;
+
+ if (ClangASTContext::IsCStringType (clang_type, fixed_length))
{
- StreamString sstr;
- lldb::addr_t cstr_address = LLDB_INVALID_ADDRESS;
- lldb::AddressType cstr_address_type = eAddressTypeInvalid;
- switch (GetValue().GetValueType())
+ Process *process = exe_scope->CalculateProcess();
+ if (process != NULL)
{
- case Value::eValueTypeScalar:
- cstr_address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
- cstr_address_type = eAddressTypeLoad;
- break;
-
- case Value::eValueTypeLoadAddress:
- case Value::eValueTypeFileAddress:
- case Value::eValueTypeHostAddress:
+ lldb::AddressType cstr_address_type = eAddressTypeInvalid;
+ lldb::addr_t cstr_address = GetPointerValue (cstr_address_type, true);
+
+ if (cstr_address != LLDB_INVALID_ADDRESS)
{
- uint32_t data_offset = 0;
- cstr_address = m_data.GetPointer(&data_offset);
- cstr_address_type = m_value.GetValueAddressType();
- if (cstr_address_type == eAddressTypeInvalid)
- cstr_address_type = eAddressTypeLoad;
+ DataExtractor data;
+ size_t bytes_read = 0;
+ std::vector<char> data_buffer;
+ std::vector<char> cstr_buffer;
+ size_t cstr_length;
+ Error error;
+ if (fixed_length > 0)
+ {
+ data_buffer.resize(fixed_length);
+ // Resize the formatted buffer in case every character
+ // uses the "\xXX" format and one extra byte for a NULL
+ cstr_buffer.resize(data_buffer.size() * 4 + 1);
+ data.SetData (&data_buffer.front(), data_buffer.size(), eByteOrderHost);
+ bytes_read = process->ReadMemory (cstr_address, &data_buffer.front(), fixed_length, error);
+ if (bytes_read > 0)
+ {
+ sstr << '"';
+ cstr_length = data.Dump (&sstr,
+ 0, // Start offset in "data"
+ eFormatChar, // Print as characters
+ 1, // Size of item (1 byte for a char!)
+ bytes_read, // How many bytes to print?
+ UINT32_MAX, // num per line
+ LLDB_INVALID_ADDRESS,// base address
+ 0, // bitfield bit size
+ 0); // bitfield bit offset
+ sstr << '"';
+ }
+ }
+ else
+ {
+ const size_t k_max_buf_size = 256;
+ data_buffer.resize (k_max_buf_size + 1);
+ // NULL terminate in case we don't get the entire C string
+ data_buffer.back() = '\0';
+ // Make a formatted buffer that can contain take 4
+ // bytes per character in case each byte uses the
+ // "\xXX" format and one extra byte for a NULL
+ cstr_buffer.resize (k_max_buf_size * 4 + 1);
+
+ data.SetData (&data_buffer.front(), data_buffer.size(), eByteOrderHost);
+ size_t total_cstr_len = 0;
+ while ((bytes_read = process->ReadMemory (cstr_address, &data_buffer.front(), k_max_buf_size, error)) > 0)
+ {
+ size_t len = strlen(&data_buffer.front());
+ if (len == 0)
+ break;
+ if (len > bytes_read)
+ len = bytes_read;
+ if (sstr.GetSize() == 0)
+ sstr << '"';
+
+ cstr_length = data.Dump (&sstr,
+ 0, // Start offset in "data"
+ eFormatChar, // Print as characters
+ 1, // Size of item (1 byte for a char!)
+ len, // How many bytes to print?
+ UINT32_MAX, // num per line
+ LLDB_INVALID_ADDRESS,// base address
+ 0, // bitfield bit size
+ 0); // bitfield bit offset
+
+ if (len < k_max_buf_size)
+ break;
+ cstr_address += total_cstr_len;
+ }
+ if (sstr.GetSize() > 0)
+ sstr << '"';
+ }
}
- break;
}
+
+ if (sstr.GetSize() > 0)
+ m_summary_str.assign (sstr.GetData(), sstr.GetSize());
+ }
+ else if (ClangASTContext::IsFunctionPointerType (clang_type))
+ {
+ lldb::AddressType func_ptr_address_type = eAddressTypeInvalid;
+ lldb::addr_t func_ptr_address = GetPointerValue (func_ptr_address_type, true);
- if (cstr_address != LLDB_INVALID_ADDRESS)
+ if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
{
- DataExtractor data;
- size_t bytes_read = 0;
- std::vector<char> data_buffer;
- std::vector<char> cstr_buffer;
- size_t cstr_length;
- Error error;
- if (fixed_length > 0)
+ switch (func_ptr_address_type)
{
- data_buffer.resize(fixed_length);
- // Resize the formatted buffer in case every character
- // uses the "\xXX" format and one extra byte for a NULL
- cstr_buffer.resize(data_buffer.size() * 4 + 1);
- data.SetData (&data_buffer.front(), data_buffer.size(), eByteOrderHost);
- bytes_read = process->ReadMemory (cstr_address, &data_buffer.front(), fixed_length, error);
- if (bytes_read > 0)
+ case eAddressTypeInvalid:
+ case eAddressTypeFile:
+ break;
+
+ case eAddressTypeLoad:
{
- sstr << '"';
- cstr_length = data.Dump (&sstr,
- 0, // Start offset in "data"
- eFormatChar, // Print as characters
- 1, // Size of item (1 byte for a char!)
- bytes_read, // How many bytes to print?
- UINT32_MAX, // num per line
- LLDB_INVALID_ADDRESS,// base address
- 0, // bitfield bit size
- 0); // bitfield bit offset
- sstr << '"';
+ Address so_addr;
+ Process *process = exe_scope->CalculateProcess();
+ if (process != NULL)
+ {
+ if (process->ResolveLoadAddress(func_ptr_address, so_addr))
+ {
+ so_addr.Dump (&sstr,
+ exe_scope,
+ Address::DumpStyleResolvedDescription,
+ Address::DumpStyleSectionNameOffset);
+ }
+ }
}
- }
- else
- {
- const size_t k_max_buf_size = 256;
- data_buffer.resize (k_max_buf_size + 1);
- // NULL terminate in case we don't get the entire C string
- data_buffer.back() = '\0';
- // Make a formatted buffer that can contain take 4
- // bytes per character in case each byte uses the
- // "\xXX" format and one extra byte for a NULL
- cstr_buffer.resize (k_max_buf_size * 4 + 1);
-
- data.SetData (&data_buffer.front(), data_buffer.size(), eByteOrderHost);
- size_t total_cstr_len = 0;
- while ((bytes_read = process->ReadMemory (cstr_address, &data_buffer.front(), k_max_buf_size, error)) > 0)
- {
- size_t len = strlen(&data_buffer.front());
- if (len == 0)
- break;
- if (len > bytes_read)
- len = bytes_read;
- if (sstr.GetSize() == 0)
- sstr << '"';
+ break;
- cstr_length = data.Dump (&sstr,
- 0, // Start offset in "data"
- eFormatChar, // Print as characters
- 1, // Size of item (1 byte for a char!)
- len, // How many bytes to print?
- UINT32_MAX, // num per line
- LLDB_INVALID_ADDRESS,// base address
- 0, // bitfield bit size
- 0); // bitfield bit offset
-
- if (len < k_max_buf_size)
- break;
- cstr_address += total_cstr_len;
- }
- if (sstr.GetSize() > 0)
- sstr << '"';
+ case eAddressTypeHost:
+ break;
}
-
- if (sstr.GetSize() > 0)
- m_summary_str.assign (sstr.GetData(), sstr.GetSize());
+ }
+ if (sstr.GetSize() > 0)
+ {
+ m_summary_str.assign (1, '(');
+ m_summary_str.append (sstr.GetData(), sstr.GetSize());
+ m_summary_str.append (1, ')');
}
}
}
@@ -502,6 +528,7 @@
return m_summary_str.c_str();
}
+
const char *
ValueObject::GetObjectDescription (ExecutionContextScope *exe_scope)
{
@@ -614,6 +641,36 @@
return m_value_str.c_str();
}
+addr_t
+ValueObject::GetPointerValue (lldb::AddressType &address_type, bool scalar_is_load_address)
+{
+ lldb::addr_t address = LLDB_INVALID_ADDRESS;
+ address_type = eAddressTypeInvalid;
+ switch (GetValue().GetValueType())
+ {
+ case Value::eValueTypeScalar:
+ if (scalar_is_load_address)
+ {
+ address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
+ address_type = eAddressTypeLoad;
+ }
+ break;
+
+ case Value::eValueTypeLoadAddress:
+ case Value::eValueTypeFileAddress:
+ case Value::eValueTypeHostAddress:
+ {
+ uint32_t data_offset = 0;
+ address = m_data.GetPointer(&data_offset);
+ address_type = m_value.GetValueAddressType();
+ if (address_type == eAddressTypeInvalid)
+ address_type = eAddressTypeLoad;
+ }
+ break;
+ }
+ return address;
+}
+
bool
ValueObject::SetValueFromCString (ExecutionContextScope *exe_scope, const char *value_str)
{
Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=113735&r1=113734&r2=113735&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Sun Sep 12 22:32:57 2010
@@ -1185,7 +1185,8 @@
if (qual_type->isAggregateType ())
return true;
- switch (qual_type->getTypeClass())
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
{
case clang::Type::IncompleteArray:
case clang::Type::VariableArray:
@@ -1401,7 +1402,8 @@
child_bitfield_bit_size = 0;
child_bitfield_bit_offset = 0;
QualType parent_qual_type(QualType::getFromOpaquePtr(parent_clang_type));
- switch (parent_qual_type->getTypeClass())
+ const clang::Type::TypeClass parent_type_class = parent_qual_type->getTypeClass();
+ switch (parent_type_class)
{
case clang::Type::Builtin:
switch (cast<clang::BuiltinType>(parent_qual_type)->getKind())
@@ -1897,7 +1899,8 @@
if (clang_type && name && name[0])
{
QualType qual_type(QualType::getFromOpaquePtr(clang_type));
- switch (qual_type->getTypeClass())
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
{
case clang::Type::Record:
{
@@ -2174,9 +2177,9 @@
{
QualType qual_type(QualType::getFromOpaquePtr(clang_type));
- clang::Type::TypeClass qual_type_class = qual_type->getTypeClass();
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
- switch (qual_type_class)
+ switch (type_class)
{
case clang::Type::Record:
{
@@ -2402,7 +2405,8 @@
return NULL;
QualType qual_type(QualType::getFromOpaquePtr(clang_type));
- switch (qual_type->getTypeClass())
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
{
case clang::Type::FunctionNoProto: break;
case clang::Type::FunctionProto: break;
@@ -2691,7 +2695,8 @@
{
QualType qual_type (QualType::getFromOpaquePtr(clang_type));
- switch (qual_type->getTypeClass())
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
{
case clang::Type::ObjCObject:
case clang::Type::ObjCInterface:
@@ -2743,7 +2748,8 @@
return false;
QualType qual_type (QualType::getFromOpaquePtr(clang_type));
- switch (qual_type->getTypeClass())
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
{
case clang::Type::ObjCObjectPointer:
if (target_type)
@@ -2803,7 +2809,8 @@
if (clang_type)
{
QualType qual_type (QualType::getFromOpaquePtr(clang_type));
- switch (qual_type->getTypeClass())
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
{
case clang::Type::ObjCObjectPointer:
if (target_type)
@@ -2876,7 +2883,8 @@
if (clang_type)
{
QualType qual_type (QualType::getFromOpaquePtr(clang_type));
- switch (qual_type->getTypeClass())
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
{
case clang::Type::ConstantArray:
{
@@ -2934,6 +2942,38 @@
}
bool
+ClangASTContext::IsFunctionPointerType (void *clang_type)
+{
+ if (clang_type)
+ {
+ QualType qual_type (QualType::getFromOpaquePtr(clang_type));
+
+ if (qual_type->isFunctionPointerType())
+ return true;
+
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
+ {
+ case clang::Type::Typedef:
+ return ClangASTContext::IsFunctionPointerType (cast<TypedefType>(qual_type)->LookThroughTypedefs().getAsOpaquePtr());
+
+ case clang::Type::LValueReference:
+ case clang::Type::RValueReference:
+ {
+ ReferenceType *reference_type = cast<ReferenceType>(qual_type.getTypePtr());
+ if (reference_type)
+ return ClangASTContext::IsFunctionPointerType (reference_type->getPointeeType().getAsOpaquePtr());
+ }
+ break;
+ }
+ }
+ return false;
+}
+
+
+
+
+bool
ClangASTContext::IsArrayType (void *clang_type, void **member_type, uint64_t *size)
{
if (!clang_type)
@@ -2941,7 +2981,8 @@
QualType qual_type (QualType::getFromOpaquePtr(clang_type));
- switch (qual_type->getTypeClass())
+ const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+ switch (type_class)
{
case clang::Type::ConstantArray:
if (member_type)
More information about the lldb-commits
mailing list