Print better error messages when memory reads fail when displaying variable

values.

Always show the variable types for the top level items when dumping program
variables.

llvm-svn: 117999
This commit is contained in:
Greg Clayton 2010-11-02 01:50:16 +00:00
parent 07072664c4
commit 7c8a966442
3 changed files with 47 additions and 24 deletions

View File

@ -498,7 +498,7 @@ Value::GetValueAsData (ExecutionContext *exe_ctx, clang::ASTContext *ast_context
switch (m_value_type) switch (m_value_type)
{ {
default: default:
error.SetErrorStringWithFormat("Invalid value type %i.\n", m_value_type); error.SetErrorStringWithFormat("invalid value type %i", m_value_type);
break; break;
case eValueTypeScalar: case eValueTypeScalar:
@ -506,17 +506,17 @@ Value::GetValueAsData (ExecutionContext *exe_ctx, clang::ASTContext *ast_context
data.SetAddressByteSize(sizeof(void *)); data.SetAddressByteSize(sizeof(void *));
if (m_value.GetData (data)) if (m_value.GetData (data))
return error; // Success; return error; // Success;
error.SetErrorStringWithFormat("Extracting data from value failed.\n"); error.SetErrorStringWithFormat("extracting data from value failed");
break; break;
case eValueTypeLoadAddress: case eValueTypeLoadAddress:
if (exe_ctx == NULL) if (exe_ctx == NULL)
{ {
error.SetErrorString ("Can't read memory (no execution context)."); error.SetErrorString ("can't read memory (no execution context)");
} }
else if (exe_ctx->process == NULL) else if (exe_ctx->process == NULL)
{ {
error.SetErrorString ("Can't read memory (invalid process)."); error.SetErrorString ("can't read memory (invalid process)");
} }
else else
{ {
@ -564,7 +564,7 @@ Value::GetValueAsData (ExecutionContext *exe_ctx, clang::ASTContext *ast_context
} }
else else
{ {
error.SetErrorStringWithFormat ("Unable to resolve the module for file address 0x%llx for variable '%s'.\n", file_addr, variable->GetName().AsCString("")); error.SetErrorStringWithFormat ("unable to resolve the module for file address 0x%llx for variable '%s'", file_addr, variable->GetName().AsCString(""));
} }
} }
else else
@ -576,7 +576,7 @@ Value::GetValueAsData (ExecutionContext *exe_ctx, clang::ASTContext *ast_context
{ {
// Can't convert a file address to anything valid without more // Can't convert a file address to anything valid without more
// context (which Module it came from) // context (which Module it came from)
error.SetErrorString ("Can't read memory from file address without more context."); error.SetErrorString ("can't read memory from file address without more context");
} }
} }
break; break;
@ -595,7 +595,7 @@ Value::GetValueAsData (ExecutionContext *exe_ctx, clang::ASTContext *ast_context
if (address == LLDB_INVALID_ADDRESS) if (address == LLDB_INVALID_ADDRESS)
{ {
error.SetErrorStringWithFormat ("Invalid %s address.\n", address_type == eAddressTypeHost ? "host" : "load"); error.SetErrorStringWithFormat ("invalid %s address", address_type == eAddressTypeHost ? "host" : "load");
return error; return error;
} }
@ -628,16 +628,18 @@ Value::GetValueAsData (ExecutionContext *exe_ctx, clang::ASTContext *ast_context
{ {
if (error.Success()) if (error.Success())
error.SetErrorStringWithFormat("read %u bytes of memory from 0x%llx failed", (uint64_t)address, byte_size); error.SetErrorStringWithFormat("read %u bytes of memory from 0x%llx failed", (uint64_t)address, byte_size);
else
error.SetErrorStringWithFormat("read memory from 0x%llx failed", (uint64_t)address);
} }
} }
else else
{ {
error.SetErrorStringWithFormat ("Unsupported lldb::AddressType value (%i).\n", address_type); error.SetErrorStringWithFormat ("unsupported lldb::AddressType value (%i)", address_type);
} }
} }
else else
{ {
error.SetErrorStringWithFormat ("Out of memory.\n"); error.SetErrorStringWithFormat ("out of memory");
} }
return error; return error;

View File

@ -990,7 +990,8 @@ ValueObject::DumpValueObject
s.Indent(); s.Indent();
if (show_types) // Always show the type for the top level items.
if (show_types || curr_depth == 0)
s.Printf("(%s) ", valobj->GetTypeName().AsCString()); s.Printf("(%s) ", valobj->GetTypeName().AsCString());
@ -1021,7 +1022,7 @@ ValueObject::DumpValueObject
if (err_cstr) if (err_cstr)
{ {
s.Printf (" %s\n", err_cstr); s.Printf (" error: %s\n", err_cstr);
} }
else else
{ {

View File

@ -146,6 +146,19 @@ ValueObjectChild::UpdateValue (ExecutionContextScope *exe_scope)
{ {
uint32_t offset = 0; uint32_t offset = 0;
m_value.GetScalar() = parent->GetDataExtractor().GetPointer(&offset); m_value.GetScalar() = parent->GetDataExtractor().GetPointer(&offset);
lldb::addr_t addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
if (addr == LLDB_INVALID_ADDRESS)
{
m_error.SetErrorString ("parent address is invalid.");
}
else if (addr == 0)
{
m_error.SetErrorString ("parent is NULL");
}
else
{
// For pointers, m_byte_offset should only ever be set if we // For pointers, m_byte_offset should only ever be set if we
// ValueObject::GetSyntheticArrayMemberFromPointer() was called // ValueObject::GetSyntheticArrayMemberFromPointer() was called
if (ClangASTContext::IsPointerType (parent->GetClangType()) && m_byte_offset) if (ClangASTContext::IsPointerType (parent->GetClangType()) && m_byte_offset)
@ -154,6 +167,7 @@ ValueObjectChild::UpdateValue (ExecutionContextScope *exe_scope)
value_type == Value::eValueTypeFileAddress) value_type == Value::eValueTypeFileAddress)
m_value.SetValueType (Value::eValueTypeLoadAddress); m_value.SetValueType (Value::eValueTypeLoadAddress);
} }
}
else else
{ {
switch (value_type) switch (value_type)
@ -163,15 +177,21 @@ ValueObjectChild::UpdateValue (ExecutionContextScope *exe_scope)
case Value::eValueTypeHostAddress: case Value::eValueTypeHostAddress:
{ {
lldb::addr_t addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); lldb::addr_t addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
if (addr == LLDB_INVALID_ADDRESS || addr == 0) if (addr == LLDB_INVALID_ADDRESS)
{ {
m_error.SetErrorStringWithFormat("Parent address is invalid: 0x%llx.\n", addr); m_error.SetErrorString ("parent address is invalid.");
break;
} }
else if (addr == 0)
{
m_error.SetErrorString ("parent is NULL");
}
else
{
// Set this object's scalar value to the address of its // Set this object's scalar value to the address of its
// value be adding its byte offset to the parent address // value be adding its byte offset to the parent address
m_value.GetScalar() += GetByteOffset(); m_value.GetScalar() += GetByteOffset();
} }
}
break; break;
case Value::eValueTypeScalar: case Value::eValueTypeScalar: