[Lldb-commits] [lldb] r109543 - in /lldb/trunk: include/lldb/Expression/ClangExpressionDeclMap.h source/Expression/ClangExpressionDeclMap.cpp source/Expression/IRForTarget.cpp
Sean Callanan
scallanan at apple.com
Tue Jul 27 14:39:39 PDT 2010
Author: spyffe
Date: Tue Jul 27 16:39:39 2010
New Revision: 109543
URL: http://llvm.org/viewvc/llvm-project?rev=109543&view=rev
Log:
Added support for calling functions from expressions.
Right now we mock up the function as a variadic
function when generating the IR for the call; we need
to eventually make the function be the right type if
the type is available.
Modified:
lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
lldb/trunk/source/Expression/IRForTarget.cpp
Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=109543&r1=109542&r2=109543&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Tue Jul 27 16:39:39 2010
@@ -88,7 +88,9 @@
off_t &offset,
uint32_t index);
- uint64_t GetFunctionAddress (const clang::NamedDecl *decl);
+ bool GetFunctionInfo (const clang::NamedDecl *decl,
+ llvm::Value**& value,
+ uint64_t &ptr);
// Interface for DwarfExpression
Value *GetValueForIndex (uint32_t index);
@@ -119,6 +121,7 @@
TypeFromParser m_parser_type;
TypeFromUser m_user_type;
lldb_private::Value *m_value; /* owned by ClangExpressionDeclMap */
+ llvm::Value *m_llvm_value;
};
struct StructMember
Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=109543&r1=109542&r2=109543&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Tue Jul 27 16:39:39 2010
@@ -182,8 +182,10 @@
return true;
}
-uint64_t
-ClangExpressionDeclMap::GetFunctionAddress (const clang::NamedDecl *decl)
+bool
+ClangExpressionDeclMap::GetFunctionInfo (const clang::NamedDecl *decl,
+ llvm::Value**& value,
+ uint64_t &ptr)
{
TupleIterator iter;
@@ -193,11 +195,13 @@
{
if (decl == iter->m_decl)
{
- return iter->m_value->GetScalar().ULongLong();
+ value = &iter->m_llvm_value;
+ ptr = iter->m_value->GetScalar().ULongLong();
+ return true;
}
}
- return 0;
+ return false;
}
// Interface for DwarfExpression
@@ -769,6 +773,7 @@
tuple.m_value = var_location;
tuple.m_user_type = ut;
tuple.m_parser_type = pt;
+ tuple.m_llvm_value = NULL;
m_tuples.push_back(tuple);
@@ -841,6 +846,7 @@
tuple.m_decl = fun_decl;
tuple.m_value = fun_location.release();
tuple.m_user_type = TypeFromUser(fun_opaque_type, fun_ast_context);
+ tuple.m_llvm_value = NULL;
m_tuples.push_back(tuple);
Modified: lldb/trunk/source/Expression/IRForTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=109543&r1=109542&r2=109543&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRForTarget.cpp (original)
+++ lldb/trunk/source/Expression/IRForTarget.cpp Tue Jul 27 16:39:39 2010
@@ -29,7 +29,7 @@
IRForTarget::IRForTarget(const void *pid,
lldb_private::ClangExpressionDeclMap *decl_map,
- const llvm::TargetData *target_data) :
+ const TargetData *target_data) :
ModulePass(pid),
m_decl_map(decl_map),
m_target_data(target_data)
@@ -41,8 +41,8 @@
}
static clang::NamedDecl *
-DeclForGlobalValue(llvm::Module &module,
- llvm::GlobalValue *global_value)
+DeclForGlobalValue(Module &module,
+ GlobalValue *global_value)
{
NamedMDNode *named_metadata = module.getNamedMetadata("clang.global.decl.ptrs");
@@ -82,7 +82,7 @@
bool
IRForTarget::MaybeHandleVariable(Module &M,
- llvm::Value *V,
+ Value *V,
bool Store)
{
if (GlobalVariable *global_variable = dyn_cast<GlobalVariable>(V))
@@ -104,7 +104,7 @@
return false;
}
- const llvm::Type *value_type = global_variable->getType();
+ const Type *value_type = global_variable->getType();
size_t value_size = m_target_data->getTypeStoreSize(value_type);
off_t value_alignment = m_target_data->getPrefTypeAlignment(value_type);
@@ -128,7 +128,7 @@
{
lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
- llvm::Function *fun = C->getCalledFunction();
+ Function *fun = C->getCalledFunction();
if (fun == NULL)
return true;
@@ -142,9 +142,10 @@
return false;
}
- uint64_t fun_addr = m_decl_map->GetFunctionAddress(fun_decl);
+ uint64_t fun_addr;
+ Value **fun_value_ptr;
- if (fun_addr == 0)
+ if (!m_decl_map->GetFunctionInfo(fun_decl, fun_value_ptr, fun_addr))
{
if (log)
log->Printf("Function %s had no address", fun_decl->getNameAsCString());
@@ -154,6 +155,22 @@
if (log)
log->Printf("Found %s at %llx", fun_decl->getNameAsCString(), fun_addr);
+ if (!*fun_value_ptr)
+ {
+ std::vector<const Type*> params;
+
+ const IntegerType *intptr_ty = Type::getIntNTy(M.getContext(),
+ (M.getPointerSize() == Module::Pointer64) ? 64 : 32);
+
+ FunctionType *fun_ty = FunctionType::get(intptr_ty, params, true);
+ PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty);
+ Constant *fun_addr_int = ConstantInt::get(intptr_ty, fun_addr, false);
+ Constant *fun_addr_ptr = ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty);
+ *fun_value_ptr = fun_addr_ptr;
+ }
+
+ C->setCalledFunction(*fun_value_ptr);
+
return true;
}
@@ -164,7 +181,7 @@
// Prepare the current basic block for execution in the remote process
//
- llvm::BasicBlock::iterator ii;
+ BasicBlock::iterator ii;
for (ii = BB.begin();
ii != BB.end();
@@ -189,7 +206,7 @@
}
static std::string
-PrintValue(llvm::Value *V, bool truncate = false)
+PrintValue(Value *V, bool truncate = false)
{
std::string s;
raw_string_ostream rso(s);
@@ -200,7 +217,7 @@
return s;
}
-static bool isGuardVariableRef(llvm::Value *V)
+static bool isGuardVariableRef(Value *V)
{
ConstantExpr *C = dyn_cast<ConstantExpr>(V);
@@ -250,9 +267,9 @@
// Eliminate any reference to guard variables found.
//
- llvm::BasicBlock::iterator ii;
+ BasicBlock::iterator ii;
- typedef llvm::SmallVector <Instruction*, 2> InstrList;
+ typedef SmallVector <Instruction*, 2> InstrList;
typedef InstrList::iterator InstrIterator;
InstrList guard_loads;
@@ -300,7 +317,7 @@
// for those.
static bool
-UnfoldConstant(llvm::Constant *C, llvm::Value *new_value, llvm::Instruction *first_entry_instruction)
+UnfoldConstant(Constant *C, Value *new_value, Instruction *first_entry_instruction)
{
lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
@@ -415,7 +432,7 @@
if (iter == F->getArgumentList().end())
return false;
- llvm::Argument *argument = iter;
+ Argument *argument = iter;
if (!argument->getName().equals("___clang_arg"))
return false;
@@ -423,8 +440,8 @@
if (log)
log->Printf("Arg: %s", PrintValue(argument).c_str());
- llvm::BasicBlock &entry_block(F->getEntryBlock());
- llvm::Instruction *first_entry_instruction(entry_block.getFirstNonPHIOrDbg());
+ BasicBlock &entry_block(F->getEntryBlock());
+ Instruction *first_entry_instruction(entry_block.getFirstNonPHIOrDbg());
if (!first_entry_instruction)
return false;
@@ -438,7 +455,7 @@
for (element_index = 0; element_index < num_elements; ++element_index)
{
const clang::NamedDecl *decl;
- llvm::Value *value;
+ Value *value;
off_t offset;
if (!m_decl_map->GetStructElement (decl, value, offset, element_index))
@@ -471,7 +488,7 @@
{
lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
- llvm::Function* function = M.getFunction(StringRef("___clang_expr"));
+ Function* function = M.getFunction(StringRef("___clang_expr"));
if (!function)
{
@@ -481,7 +498,7 @@
return false;
}
- llvm::Function::iterator bbi;
+ Function::iterator bbi;
for (bbi = function->begin();
bbi != function->end();
More information about the lldb-commits
mailing list