2010-06-09 00:52:24 +08:00
|
|
|
//===-- ABI.cpp -------------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Target/ABI.h"
|
|
|
|
#include "lldb/Core/PluginManager.h"
|
2011-12-17 09:35:57 +08:00
|
|
|
#include "lldb/Core/Value.h"
|
|
|
|
#include "lldb/Core/ValueObjectConstResult.h"
|
|
|
|
#include "lldb/Symbol/ClangASTType.h"
|
2011-12-23 03:12:40 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2011-12-17 09:35:57 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2011-05-12 02:39:18 +08:00
|
|
|
ABISP
|
2011-02-16 05:59:32 +08:00
|
|
|
ABI::FindPlugin (const ArchSpec &arch)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-05-12 02:39:18 +08:00
|
|
|
ABISP abi_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
ABICreateInstance create_callback;
|
|
|
|
|
|
|
|
for (uint32_t idx = 0;
|
|
|
|
(create_callback = PluginManager::GetABICreateCallbackAtIndex(idx)) != NULL;
|
|
|
|
++idx)
|
|
|
|
{
|
2011-05-12 02:39:18 +08:00
|
|
|
abi_sp = create_callback(arch);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-05-12 02:39:18 +08:00
|
|
|
if (abi_sp)
|
|
|
|
return abi_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2011-05-12 02:39:18 +08:00
|
|
|
abi_sp.reset();
|
|
|
|
return abi_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Constructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
ABI::ABI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
ABI::~ABI()
|
|
|
|
{
|
|
|
|
}
|
2011-08-22 10:49:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
ABI::GetRegisterInfoByName (const ConstString &name, RegisterInfo &info)
|
|
|
|
{
|
|
|
|
uint32_t count = 0;
|
|
|
|
const RegisterInfo *register_info_array = GetRegisterInfoArray (count);
|
|
|
|
if (register_info_array)
|
|
|
|
{
|
|
|
|
const char *unique_name_cstr = name.GetCString();
|
|
|
|
uint32_t i;
|
|
|
|
for (i=0; i<count; ++i)
|
|
|
|
{
|
|
|
|
if (register_info_array[i].name == unique_name_cstr)
|
|
|
|
{
|
|
|
|
info = register_info_array[i];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0; i<count; ++i)
|
|
|
|
{
|
|
|
|
if (register_info_array[i].alt_name == unique_name_cstr)
|
|
|
|
{
|
|
|
|
info = register_info_array[i];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ABI::GetRegisterInfoByKind (RegisterKind reg_kind, uint32_t reg_num, RegisterInfo &info)
|
|
|
|
{
|
|
|
|
if (reg_kind < eRegisterKindGCC || reg_kind >= kNumRegisterKinds)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
uint32_t count = 0;
|
|
|
|
const RegisterInfo *register_info_array = GetRegisterInfoArray (count);
|
|
|
|
if (register_info_array)
|
|
|
|
{
|
|
|
|
for (uint32_t i=0; i<count; ++i)
|
|
|
|
{
|
|
|
|
if (register_info_array[i].kinds[reg_kind] == reg_num)
|
|
|
|
{
|
|
|
|
info = register_info_array[i];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-12-17 09:35:57 +08:00
|
|
|
|
|
|
|
ValueObjectSP
|
|
|
|
ABI::GetReturnValueObject (Thread &thread,
|
2012-02-21 08:09:25 +08:00
|
|
|
ClangASTType &ast_type,
|
|
|
|
bool persistent) const
|
2011-12-17 09:35:57 +08:00
|
|
|
{
|
|
|
|
if (!ast_type.IsValid())
|
|
|
|
return ValueObjectSP();
|
|
|
|
|
2011-12-23 03:12:40 +08:00
|
|
|
ValueObjectSP return_valobj_sp;
|
|
|
|
|
|
|
|
return_valobj_sp = GetReturnValueObjectImpl(thread, ast_type);
|
|
|
|
if (!return_valobj_sp)
|
|
|
|
return return_valobj_sp;
|
|
|
|
|
|
|
|
// Now turn this into a persistent variable.
|
|
|
|
// FIXME: This code is duplicated from Target::EvaluateExpression, and it is used in similar form in a couple
|
|
|
|
// of other places. Figure out the correct Create function to do all this work.
|
|
|
|
|
|
|
|
if (persistent)
|
2011-12-17 09:35:57 +08:00
|
|
|
{
|
2012-02-21 08:09:25 +08:00
|
|
|
ClangPersistentVariables& persistent_variables = thread.CalculateTarget()->GetPersistentVariables();
|
2011-12-23 03:12:40 +08:00
|
|
|
ConstString persistent_variable_name (persistent_variables.GetNextPersistentVariableName());
|
|
|
|
|
|
|
|
lldb::ValueObjectSP const_valobj_sp;
|
|
|
|
|
|
|
|
// Check in case our value is already a constant value
|
|
|
|
if (return_valobj_sp->GetIsConstant())
|
|
|
|
{
|
|
|
|
const_valobj_sp = return_valobj_sp;
|
|
|
|
const_valobj_sp->SetName (persistent_variable_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
const_valobj_sp = return_valobj_sp->CreateConstantValue (persistent_variable_name);
|
|
|
|
|
|
|
|
lldb::ValueObjectSP live_valobj_sp = return_valobj_sp;
|
|
|
|
|
|
|
|
return_valobj_sp = const_valobj_sp;
|
|
|
|
|
|
|
|
ClangExpressionVariableSP clang_expr_variable_sp(persistent_variables.CreatePersistentVariable(return_valobj_sp));
|
|
|
|
|
|
|
|
assert (clang_expr_variable_sp.get());
|
|
|
|
|
|
|
|
// Set flags and live data as appropriate
|
|
|
|
|
|
|
|
const Value &result_value = live_valobj_sp->GetValue();
|
|
|
|
|
|
|
|
switch (result_value.GetValueType())
|
|
|
|
{
|
|
|
|
case Value::eValueTypeHostAddress:
|
|
|
|
case Value::eValueTypeFileAddress:
|
|
|
|
// we don't do anything with these for now
|
|
|
|
break;
|
|
|
|
case Value::eValueTypeScalar:
|
2012-10-31 07:56:14 +08:00
|
|
|
case Value::eValueTypeVector:
|
2012-01-05 09:11:09 +08:00
|
|
|
clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsFreezeDried;
|
2011-12-23 03:12:40 +08:00
|
|
|
clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
|
|
|
|
clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
|
|
|
|
break;
|
|
|
|
case Value::eValueTypeLoadAddress:
|
|
|
|
clang_expr_variable_sp->m_live_sp = live_valobj_sp;
|
|
|
|
clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
|
|
|
|
break;
|
|
|
|
}
|
2012-01-05 09:11:09 +08:00
|
|
|
|
2011-12-23 03:12:40 +08:00
|
|
|
return_valobj_sp = clang_expr_variable_sp->GetValueObject();
|
2011-12-17 09:35:57 +08:00
|
|
|
}
|
2011-12-23 03:12:40 +08:00
|
|
|
return return_valobj_sp;
|
2011-12-17 09:35:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|