Make a more complete fix for always supplying an execution context when getting byte sizes from types.

There was a test in the test suite that was triggering the backtrace logging output that requested that the client pass an execution context. Sometimes we need the process for Objective C types because our static notion of the type might not align with the reality when being run in a live runtime.

Switched from an "ExecutionContext *" to an "ExecutionContextScope *" for greater ease of use.

llvm-svn: 228892
This commit is contained in:
Greg Clayton 2015-02-12 00:34:25 +00:00
parent 36f807c860
commit 526ae040ba
16 changed files with 103 additions and 65 deletions

View File

@ -640,6 +640,9 @@ private:
return m_stream_string;
}
lldb::addr_t Allocate();
lldb::TargetSP
GetTarget();
private:
lldb_private::IRExecutionUnit &m_execution_unit;
lldb_private::StreamString m_stream_string;

View File

@ -69,10 +69,18 @@ public:
// This function can return NULL.
ExecutionContextScope *GetBestExecutionContextScope() const;
lldb::TargetSP
GetTarget ()
{
return m_target_wp.lock();
}
protected:
// This function should only be used if you know you are using the JIT.
// Any other cases should use GetBestExecutionContextScope().
lldb::ProcessWP GetProcessWP ()
lldb::ProcessWP &
GetProcessWP ()
{
return m_process_wp;
}

View File

@ -351,10 +351,10 @@ public:
//----------------------------------------------------------------------
uint64_t
GetByteSize (ExecutionContext *exe_ctx) const;
GetByteSize (ExecutionContextScope *exe_scope) const;
uint64_t
GetBitSize (ExecutionContext *exe_ctx) const;
GetBitSize (ExecutionContextScope *exe_scope) const;
lldb::Encoding
GetEncoding (uint64_t &count) const;

View File

@ -973,7 +973,7 @@ ValueObject::GetPointeeData (DataExtractor& data,
ExecutionContext exe_ctx (GetExecutionContextRef());
const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize(&exe_ctx);
const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
const uint64_t bytes = item_count * item_type_size;
const uint64_t offset = item_idx * item_type_size;
@ -1049,7 +1049,7 @@ ValueObject::GetPointeeData (DataExtractor& data,
break;
case eAddressTypeHost:
{
const uint64_t max_bytes = GetClangType().GetByteSize(&exe_ctx);
const uint64_t max_bytes = GetClangType().GetByteSize(exe_ctx.GetBestExecutionContextScope());
if (max_bytes > offset)
{
size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
@ -2244,7 +2244,7 @@ ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type
ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
type,
name_const_str,
type.GetByteSize(&exe_ctx),
type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
offset,
0,
0,
@ -2287,7 +2287,7 @@ ValueObject::GetSyntheticBase (uint32_t offset, const ClangASTType& type, bool c
ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
type,
name_const_str,
type.GetByteSize(&exe_ctx),
type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
offset,
0,
0,

View File

@ -259,7 +259,7 @@ ValueObjectConstResult::GetByteSize()
ExecutionContext exe_ctx(GetExecutionContextRef());
if (m_byte_size == 0)
SetByteSize(GetClangType().GetByteSize(&exe_ctx));
SetByteSize(GetClangType().GetByteSize(exe_ctx.GetBestExecutionContextScope()));
return m_byte_size;
}

View File

@ -112,7 +112,7 @@ ValueObjectVariable::GetByteSize()
if (!type.IsValid())
return 0;
return type.GetByteSize(&exe_ctx);
return type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
}
lldb::ValueType

View File

@ -317,7 +317,7 @@ lldb_private::formatters::WCharStringSummaryProvider (ValueObject& valobj, Strea
return false;
ClangASTType wchar_clang_type = ClangASTContext::GetBasicType(ast, lldb::eBasicTypeWChar);
const uint32_t wchar_size = wchar_clang_type.GetBitSize(nullptr);
const uint32_t wchar_size = wchar_clang_type.GetBitSize(nullptr); // Safe to pass NULL for exe_scope here
ReadStringAndDumpToStreamOptions options(valobj);
options.SetLocation(data_addr);

View File

@ -59,7 +59,8 @@ IRForTarget::FunctionValueCache::~FunctionValueCache()
{
}
llvm::Value *IRForTarget::FunctionValueCache::GetValue(llvm::Function *function)
llvm::Value *
IRForTarget::FunctionValueCache::GetValue(llvm::Function *function)
{
if (!m_values.count(function))
{
@ -70,7 +71,8 @@ llvm::Value *IRForTarget::FunctionValueCache::GetValue(llvm::Function *function)
return m_values[function];
}
lldb::addr_t IRForTarget::StaticDataAllocator::Allocate()
lldb::addr_t
IRForTarget::StaticDataAllocator::Allocate()
{
lldb_private::Error err;
@ -85,7 +87,14 @@ lldb::addr_t IRForTarget::StaticDataAllocator::Allocate()
return m_allocation;
}
static llvm::Value *FindEntryInstruction (llvm::Function *function)
lldb::TargetSP
IRForTarget::StaticDataAllocator::GetTarget()
{
return m_execution_unit.GetTarget();
}
static llvm::Value *
FindEntryInstruction (llvm::Function *function)
{
if (function->empty())
return NULL;
@ -590,7 +599,10 @@ IRForTarget::CreateResultVariable (llvm::Function &llvm_function)
&result_decl->getASTContext());
}
if (m_result_type.GetBitSize(nullptr) == 0)
lldb::TargetSP target_sp (m_data_allocator.GetTarget());
lldb_private::ExecutionContext exe_ctx (target_sp.get(), true);
if (m_result_type.GetBitSize(exe_ctx.GetBestExecutionContextScope()) == 0)
{
lldb_private::StreamString type_desc_stream;
m_result_type.DumpTypeDescription(&type_desc_stream);

View File

@ -334,11 +334,11 @@ ABIMacOSX_arm::GetArgumentValues (Thread &thread,
size_t bit_width = 0;
if (clang_type.IsIntegerType (is_signed))
{
bit_width = clang_type.GetBitSize(nullptr);
bit_width = clang_type.GetBitSize(&thread);
}
else if (clang_type.IsPointerOrReferenceType ())
{
bit_width = clang_type.GetBitSize(nullptr);
bit_width = clang_type.GetBitSize(&thread);
}
else
{
@ -437,7 +437,7 @@ ABIMacOSX_arm::GetReturnValueObjectImpl (Thread &thread,
const RegisterInfo *r0_reg_info = reg_ctx->GetRegisterInfoByName("r0", 0);
if (clang_type.IsIntegerType (is_signed))
{
size_t bit_width = clang_type.GetBitSize(nullptr);
size_t bit_width = clang_type.GetBitSize(&thread);
switch (bit_width)
{

View File

@ -322,11 +322,11 @@ ABIMacOSX_arm64::GetArgumentValues (Thread &thread, ValueList &values) const
size_t bit_width = 0;
if (value_type.IsIntegerType (is_signed))
{
bit_width = value_type.GetBitSize(nullptr);
bit_width = value_type.GetBitSize(&thread);
}
else if (value_type.IsPointerOrReferenceType ())
{
bit_width = value_type.GetBitSize(nullptr);
bit_width = value_type.GetBitSize(&thread);
}
else
{

View File

@ -552,7 +552,7 @@ ABIMacOSX_i386::GetArgumentValues (Thread &thread,
if (clang_type.IsIntegerType (is_signed))
{
ReadIntegerArgument(value->GetScalar(),
clang_type.GetBitSize(nullptr),
clang_type.GetBitSize(&thread),
is_signed,
thread.GetProcess().get(),
current_stack_argument);
@ -560,7 +560,7 @@ ABIMacOSX_i386::GetArgumentValues (Thread &thread,
else if (clang_type.IsPointerType())
{
ReadIntegerArgument(value->GetScalar(),
clang_type.GetBitSize(nullptr),
clang_type.GetBitSize(&thread),
false,
thread.GetProcess().get(),
current_stack_argument);
@ -672,7 +672,7 @@ ABIMacOSX_i386::GetReturnValueObjectImpl (Thread &thread,
if (clang_type.IsIntegerType (is_signed))
{
size_t bit_width = clang_type.GetBitSize(nullptr);
size_t bit_width = clang_type.GetBitSize(&thread);
unsigned eax_id = reg_ctx->GetRegisterInfoByName("eax", 0)->kinds[eRegisterKindLLDB];
unsigned edx_id = reg_ctx->GetRegisterInfoByName("edx", 0)->kinds[eRegisterKindLLDB];

View File

@ -444,7 +444,7 @@ ABISysV_ppc::GetArgumentValues (Thread &thread,
if (clang_type.IsIntegerType (is_signed))
{
ReadIntegerArgument(value->GetScalar(),
clang_type.GetBitSize(nullptr),
clang_type.GetBitSize(&thread),
is_signed,
thread,
argument_register_ids,
@ -454,7 +454,7 @@ ABISysV_ppc::GetArgumentValues (Thread &thread,
else if (clang_type.IsPointerType ())
{
ReadIntegerArgument(value->GetScalar(),
clang_type.GetBitSize(nullptr),
clang_type.GetBitSize(&thread),
false,
thread,
argument_register_ids,
@ -524,7 +524,7 @@ ABISysV_ppc::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjec
error.SetErrorString ("We don't support returning complex values at present");
else
{
size_t bit_width = clang_type.GetBitSize(nullptr);
size_t bit_width = clang_type.GetBitSize(frame_sp.get());
if (bit_width <= 64)
{
DataExtractor data;
@ -740,7 +740,7 @@ ABISysV_ppc::GetReturnValueObjectImpl (Thread &thread, ClangASTType &return_clan
if (!reg_ctx_sp)
return return_valobj_sp;
const size_t bit_width = return_clang_type.GetBitSize(nullptr);
const size_t bit_width = return_clang_type.GetBitSize(&thread);
if (return_clang_type.IsAggregateType())
{
Target *target = exe_ctx.GetTargetPtr();
@ -782,7 +782,7 @@ ABISysV_ppc::GetReturnValueObjectImpl (Thread &thread, ClangASTType &return_clan
uint32_t count;
ClangASTType field_clang_type = return_clang_type.GetFieldAtIndex (idx, name, &field_bit_offset, NULL, NULL);
const size_t field_bit_width = field_clang_type.GetBitSize(nullptr);
const size_t field_bit_width = field_clang_type.GetBitSize(&thread);
// If there are any unaligned fields, this is stored in memory.
if (field_bit_offset % field_bit_width != 0)

View File

@ -444,7 +444,7 @@ ABISysV_ppc64::GetArgumentValues (Thread &thread,
if (clang_type.IsIntegerType (is_signed))
{
ReadIntegerArgument(value->GetScalar(),
clang_type.GetBitSize(nullptr),
clang_type.GetBitSize(&thread),
is_signed,
thread,
argument_register_ids,
@ -454,7 +454,7 @@ ABISysV_ppc64::GetArgumentValues (Thread &thread,
else if (clang_type.IsPointerType ())
{
ReadIntegerArgument(value->GetScalar(),
clang_type.GetBitSize(nullptr),
clang_type.GetBitSize(&thread),
false,
thread,
argument_register_ids,
@ -524,7 +524,7 @@ ABISysV_ppc64::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObj
error.SetErrorString ("We don't support returning complex values at present");
else
{
size_t bit_width = clang_type.GetBitSize(nullptr);
size_t bit_width = clang_type.GetBitSize(frame_sp.get());
if (bit_width <= 64)
{
DataExtractor data;
@ -740,7 +740,7 @@ ABISysV_ppc64::GetReturnValueObjectImpl (Thread &thread, ClangASTType &return_cl
if (!reg_ctx_sp)
return return_valobj_sp;
const size_t bit_width = return_clang_type.GetBitSize(nullptr);
const size_t bit_width = return_clang_type.GetBitSize(&thread);
if (return_clang_type.IsAggregateType())
{
Target *target = exe_ctx.GetTargetPtr();
@ -782,7 +782,7 @@ ABISysV_ppc64::GetReturnValueObjectImpl (Thread &thread, ClangASTType &return_cl
uint32_t count;
ClangASTType field_clang_type = return_clang_type.GetFieldAtIndex (idx, name, &field_bit_offset, NULL, NULL);
const size_t field_bit_width = field_clang_type.GetBitSize(nullptr);
const size_t field_bit_width = field_clang_type.GetBitSize(&thread);
// If there are any unaligned fields, this is stored in memory.
if (field_bit_offset % field_bit_width != 0)

View File

@ -510,7 +510,7 @@ ABISysV_x86_64::GetArgumentValues (Thread &thread,
if (clang_type.IsIntegerType (is_signed))
{
ReadIntegerArgument(value->GetScalar(),
clang_type.GetBitSize(nullptr),
clang_type.GetBitSize(&thread),
is_signed,
thread,
argument_register_ids,
@ -520,7 +520,7 @@ ABISysV_x86_64::GetArgumentValues (Thread &thread,
else if (clang_type.IsPointerType ())
{
ReadIntegerArgument(value->GetScalar(),
clang_type.GetBitSize(nullptr),
clang_type.GetBitSize(&thread),
false,
thread,
argument_register_ids,
@ -590,7 +590,7 @@ ABISysV_x86_64::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueOb
error.SetErrorString ("We don't support returning complex values at present");
else
{
size_t bit_width = clang_type.GetBitSize(nullptr);
size_t bit_width = clang_type.GetBitSize(frame_sp.get());
if (bit_width <= 64)
{
const RegisterInfo *xmm0_info = reg_ctx->GetRegisterInfoByName("xmm0", 0);
@ -821,7 +821,7 @@ ABISysV_x86_64::GetReturnValueObjectImpl (Thread &thread, ClangASTType &return_c
if (!reg_ctx_sp)
return return_valobj_sp;
const size_t bit_width = return_clang_type.GetBitSize(nullptr);
const size_t bit_width = return_clang_type.GetBitSize(&thread);
if (return_clang_type.IsAggregateType())
{
Target *target = exe_ctx.GetTargetPtr();
@ -869,7 +869,7 @@ ABISysV_x86_64::GetReturnValueObjectImpl (Thread &thread, ClangASTType &return_c
uint32_t count;
ClangASTType field_clang_type = return_clang_type.GetFieldAtIndex (idx, name, &field_bit_offset, NULL, NULL);
const size_t field_bit_width = field_clang_type.GetBitSize(nullptr);
const size_t field_bit_width = field_clang_type.GetBitSize(&thread);
// If there are any unaligned fields, this is stored in memory.
if (field_bit_offset % field_bit_width != 0)

View File

@ -2093,7 +2093,7 @@ ClangASTType::GetBasicTypeFromAST (lldb::BasicType basic_type) const
//----------------------------------------------------------------------
uint64_t
ClangASTType::GetBitSize (ExecutionContext *exe_ctx) const
ClangASTType::GetBitSize (ExecutionContextScope *exe_scope) const
{
if (GetCompleteType ())
{
@ -2102,9 +2102,12 @@ ClangASTType::GetBitSize (ExecutionContext *exe_ctx) const
{
case clang::Type::ObjCInterface:
case clang::Type::ObjCObject:
if (exe_ctx && exe_ctx->GetProcessPtr())
{
ObjCLanguageRuntime *objc_runtime = exe_ctx->GetProcessPtr()->GetObjCLanguageRuntime();
ExecutionContext exe_ctx (exe_scope);
Process *process = exe_ctx.GetProcessPtr();
if (process)
{
ObjCLanguageRuntime *objc_runtime = process->GetObjCLanguageRuntime();
if (objc_runtime)
{
uint64_t bit_size = 0;
@ -2121,11 +2124,12 @@ ClangASTType::GetBitSize (ExecutionContext *exe_ctx) const
s.Printf("warning: trying to determine the size of type ");
DumpTypeDescription(&s);
s.Printf("\n without a valid ExecutionContext. this is not reliable. please file a bug against LLDB.\nbacktrace:\n");
Host::Backtrace(s, 10);
Host::Backtrace(s, UINT32_MAX);
printf("%s\n", s.GetData());
g_printed = true;
}
}
}
// fallthrough
default:
const uint32_t bit_size = m_ast->getTypeSize (qual_type);
@ -2143,9 +2147,9 @@ ClangASTType::GetBitSize (ExecutionContext *exe_ctx) const
}
uint64_t
ClangASTType::GetByteSize (ExecutionContext *exe_ctx) const
ClangASTType::GetByteSize (ExecutionContextScope *exe_scope) const
{
return (GetBitSize (exe_ctx) + 7) / 8;
return (GetBitSize (exe_scope) + 7) / 8;
}
size_t
@ -3478,7 +3482,7 @@ ClangASTType::GetChildClangTypeAtIndex (ExecutionContext *exe_ctx,
child_byte_offset = bit_offset/8;
ClangASTType base_class_clang_type(m_ast, base_class->getType());
child_name = base_class_clang_type.GetTypeName().AsCString("");
uint64_t base_class_clang_type_bit_size = base_class_clang_type.GetBitSize(nullptr);
uint64_t base_class_clang_type_bit_size = base_class_clang_type.GetBitSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
// Base classes bit sizes should be a multiple of 8 bits in size
assert (base_class_clang_type_bit_size % 8 == 0);
@ -3506,7 +3510,7 @@ ClangASTType::GetChildClangTypeAtIndex (ExecutionContext *exe_ctx,
// alignment (field_type_info.second) from the AST context.
ClangASTType field_clang_type (m_ast, field->getType());
assert(field_idx < record_layout.getFieldCount());
child_byte_size = field_clang_type.GetByteSize(exe_ctx);
child_byte_size = field_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
// Figure out the field offset within the current struct/union/class type
bit_offset = record_layout.getFieldOffset (field_idx);
@ -3671,7 +3675,7 @@ ClangASTType::GetChildClangTypeAtIndex (ExecutionContext *exe_ctx,
// We have a pointer to an simple type
if (idx == 0 && pointee_clang_type.GetCompleteType())
{
child_byte_size = pointee_clang_type.GetByteSize(exe_ctx);
child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
child_byte_offset = 0;
return pointee_clang_type;
}
@ -3692,7 +3696,7 @@ ClangASTType::GetChildClangTypeAtIndex (ExecutionContext *exe_ctx,
char element_name[64];
::snprintf (element_name, sizeof (element_name), "[%zu]", idx);
child_name.assign(element_name);
child_byte_size = element_type.GetByteSize(exe_ctx);
child_byte_size = element_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
return element_type;
}
@ -3713,7 +3717,7 @@ ClangASTType::GetChildClangTypeAtIndex (ExecutionContext *exe_ctx,
char element_name[64];
::snprintf (element_name, sizeof (element_name), "[%zu]", idx);
child_name.assign(element_name);
child_byte_size = element_type.GetByteSize(exe_ctx);
child_byte_size = element_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
return element_type;
}
@ -3763,7 +3767,7 @@ ClangASTType::GetChildClangTypeAtIndex (ExecutionContext *exe_ctx,
// We have a pointer to an simple type
if (idx == 0)
{
child_byte_size = pointee_clang_type.GetByteSize(exe_ctx);
child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
child_byte_offset = 0;
return pointee_clang_type;
}
@ -3807,7 +3811,7 @@ ClangASTType::GetChildClangTypeAtIndex (ExecutionContext *exe_ctx,
// We have a pointer to an simple type
if (idx == 0)
{
child_byte_size = pointee_clang_type.GetByteSize(exe_ctx);
child_byte_size = pointee_clang_type.GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
child_byte_offset = 0;
return pointee_clang_type;
}
@ -6913,7 +6917,7 @@ ClangASTType::ReadFromMemory (lldb_private::ExecutionContext *exe_ctx,
if (!GetCompleteType())
return false;
const uint64_t byte_size = GetByteSize(exe_ctx);
const uint64_t byte_size = GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
if (data.GetByteSize() < byte_size)
{
lldb::DataBufferSP data_sp(new DataBufferHeap (byte_size, '\0'));
@ -6963,7 +6967,7 @@ ClangASTType::WriteToMemory (lldb_private::ExecutionContext *exe_ctx,
if (!GetCompleteType())
return false;
const uint64_t byte_size = GetByteSize(exe_ctx);
const uint64_t byte_size = GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
if (byte_size > 0)
{

View File

@ -119,12 +119,15 @@ ExecutionContext::ExecutionContext (const lldb::StackFrameWP &frame_wp) :
}
ExecutionContext::ExecutionContext (Target* t, bool fill_current_process_thread_frame) :
m_target_sp (t->shared_from_this()),
m_target_sp (),
m_process_sp (),
m_thread_sp (),
m_frame_sp ()
{
if (t && fill_current_process_thread_frame)
if (t)
{
m_target_sp = t->shared_from_this();
if (fill_current_process_thread_frame)
{
m_process_sp = t->GetProcessSP();
if (m_process_sp)
@ -134,16 +137,24 @@ ExecutionContext::ExecutionContext (Target* t, bool fill_current_process_thread_
m_frame_sp = m_thread_sp->GetSelectedFrame();
}
}
}
}
ExecutionContext::ExecutionContext(Process* process, Thread *thread, StackFrame *frame) :
m_target_sp (),
m_process_sp (process->shared_from_this()),
m_thread_sp (thread->shared_from_this()),
m_frame_sp (frame->shared_from_this())
m_process_sp (),
m_thread_sp (),
m_frame_sp ()
{
if (process)
{
m_process_sp = process->shared_from_this();
m_target_sp = process->GetTarget().shared_from_this();
}
if (thread)
m_thread_sp = thread->shared_from_this();
if (frame)
m_frame_sp = frame->shared_from_this();
}
ExecutionContext::ExecutionContext (const ExecutionContextRef &exe_ctx_ref) :