2010-09-01 08:58:00 +08:00
|
|
|
//===-- IRDynamicChecks.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/Expression/IRDynamicChecks.h"
|
|
|
|
|
2010-09-14 05:34:21 +08:00
|
|
|
#include "lldb/Core/ConstString.h"
|
2010-09-01 08:58:00 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
2010-09-14 05:34:21 +08:00
|
|
|
#include "lldb/Expression/ClangUtilityFunction.h"
|
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
2010-11-04 09:51:38 +08:00
|
|
|
#include "lldb/Target/ObjCLanguageRuntime.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
2010-09-14 05:34:21 +08:00
|
|
|
#include "lldb/Target/StackFrame.h"
|
2010-09-01 08:58:00 +08:00
|
|
|
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include "llvm/Function.h"
|
2010-09-02 08:37:32 +08:00
|
|
|
#include "llvm/Instructions.h"
|
2010-09-01 08:58:00 +08:00
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/Value.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
static char ID;
|
|
|
|
|
2010-10-16 06:48:33 +08:00
|
|
|
#define VALID_POINTER_CHECK_NAME "$__lldb_valid_pointer_check"
|
|
|
|
#define VALID_OBJC_OBJECT_CHECK_NAME "$__lldb_objc_object_check"
|
2010-09-14 05:34:21 +08:00
|
|
|
|
2010-10-16 06:48:33 +08:00
|
|
|
static const char g_valid_pointer_check_text[] =
|
|
|
|
"extern \"C\" void\n"
|
2010-10-17 05:09:32 +08:00
|
|
|
"$__lldb_valid_pointer_check (unsigned char *$__lldb_arg_ptr)\n"
|
2010-10-16 06:48:33 +08:00
|
|
|
"{\n"
|
Added a new Host call to find LLDB related paths:
static bool
Host::GetLLDBPath (lldb::PathType path_type, FileSpec &file_spec);
This will fill in "file_spec" with an appropriate path that is appropriate
for the current Host OS. MacOSX will return paths within the LLDB.framework,
and other unixes will return the paths they want. The current PathType
enums are:
typedef enum PathType
{
ePathTypeLLDBShlibDir, // The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists
ePathTypeSupportExecutableDir, // Find LLDB support executable directory (debugserver, etc)
ePathTypeHeaderDir, // Find LLDB header file directory
ePathTypePythonDir // Find Python modules (PYTHONPATH) directory
} PathType;
All places that were finding executables are and python paths are now updated
to use this Host call.
Added another new host call to launch the inferior in a terminal. This ability
will be very host specific and doesn't need to be supported on all systems.
MacOSX currently will create a new .command file and tell Terminal.app to open
the .command file. It also uses the new "darwin-debug" app which is a small
app that uses posix to exec (no fork) and stop at the entry point of the
program. The GDB remote plug-in is almost able launch a process and attach to
it, it currently will spawn the process, but it won't attach to it just yet.
This will let LLDB not have to share the terminal with another process and a
new terminal window will pop up when you launch. This won't get hooked up
until we work out all of the kinks. The new Host function is:
static lldb::pid_t
Host::LaunchInNewTerminal (
const char **argv, // argv[0] is executable
const char **envp,
const ArchSpec *arch_spec,
bool stop_at_entry,
bool disable_aslr);
Cleaned up FileSpec::GetPath to not use strncpy() as it was always zero
filling the entire path buffer.
Fixed an issue with the dynamic checker function where I missed a '$' prefix
that should have been added.
llvm-svn: 116690
2010-10-18 06:03:32 +08:00
|
|
|
" unsigned char $__lldb_local_val = *$__lldb_arg_ptr;\n"
|
2010-10-16 06:48:33 +08:00
|
|
|
"}";
|
2010-09-14 05:34:21 +08:00
|
|
|
|
2010-09-01 08:58:00 +08:00
|
|
|
DynamicCheckerFunctions::DynamicCheckerFunctions ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DynamicCheckerFunctions::~DynamicCheckerFunctions ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DynamicCheckerFunctions::Install(Stream &error_stream,
|
|
|
|
ExecutionContext &exe_ctx)
|
|
|
|
{
|
2010-10-16 06:48:33 +08:00
|
|
|
m_valid_pointer_check.reset(new ClangUtilityFunction(g_valid_pointer_check_text,
|
|
|
|
VALID_POINTER_CHECK_NAME));
|
2010-09-01 08:58:00 +08:00
|
|
|
if (!m_valid_pointer_check->Install(error_stream, exe_ctx))
|
|
|
|
return false;
|
2010-11-04 09:51:38 +08:00
|
|
|
|
|
|
|
if (exe_ctx.process)
|
|
|
|
{
|
|
|
|
ObjCLanguageRuntime *objc_language_runtime = exe_ctx.process->GetObjCLanguageRuntime();
|
|
|
|
|
|
|
|
if (objc_language_runtime)
|
|
|
|
{
|
|
|
|
m_objc_object_check.reset(objc_language_runtime->CreateObjectChecker(VALID_OBJC_OBJECT_CHECK_NAME));
|
|
|
|
|
|
|
|
if (!m_objc_object_check->Install(error_stream, exe_ctx))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-09-01 08:58:00 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string
|
|
|
|
PrintValue(llvm::Value *V, bool truncate = false)
|
|
|
|
{
|
|
|
|
std::string s;
|
|
|
|
raw_string_ostream rso(s);
|
|
|
|
V->print(rso);
|
|
|
|
rso.flush();
|
|
|
|
if (truncate)
|
|
|
|
s.resize(s.length() - 1);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2010-09-02 08:37:32 +08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
/// @class Instrumenter IRDynamicChecks.cpp
|
|
|
|
/// @brief Finds and instruments individual LLVM IR instructions
|
|
|
|
///
|
|
|
|
/// When instrumenting LLVM IR, it is frequently desirable to first search
|
|
|
|
/// for instructions, and then later modify them. This way iterators
|
|
|
|
/// remain intact, and multiple passes can look at the same code base without
|
|
|
|
/// treading on each other's toes.
|
|
|
|
///
|
|
|
|
/// The Instrumenter class implements this functionality. A client first
|
|
|
|
/// calls Inspect on a function, which populates a list of instructions to
|
|
|
|
/// be instrumented. Then, later, when all passes' Inspect functions have
|
|
|
|
/// been called, the client calls Instrument, which adds the desired
|
|
|
|
/// instrumentation.
|
|
|
|
///
|
|
|
|
/// A subclass of Instrumenter must override InstrumentInstruction, which
|
|
|
|
/// is responsible for adding whatever instrumentation is necessary.
|
|
|
|
///
|
|
|
|
/// A subclass of Instrumenter may override:
|
|
|
|
///
|
|
|
|
/// - InspectInstruction [default: does nothing]
|
|
|
|
///
|
|
|
|
/// - InspectBasicBlock [default: iterates through the instructions in a
|
|
|
|
/// basic block calling InspectInstruction]
|
|
|
|
///
|
|
|
|
/// - InspectFunction [default: iterates through the basic blocks in a
|
|
|
|
/// function calling InspectBasicBlock]
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
class Instrumenter {
|
|
|
|
public:
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
/// Constructor
|
|
|
|
///
|
|
|
|
/// @param[in] module
|
|
|
|
/// The module being instrumented.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
Instrumenter (llvm::Module &module,
|
|
|
|
DynamicCheckerFunctions &checker_functions) :
|
|
|
|
m_module(module),
|
2010-09-14 05:34:21 +08:00
|
|
|
m_checker_functions(checker_functions),
|
|
|
|
m_i8ptr_ty(NULL)
|
2010-09-02 08:37:32 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-01-26 07:55:37 +08:00
|
|
|
virtual~Instrumenter ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-02 08:37:32 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
/// Inspect a function to find instructions to instrument
|
|
|
|
///
|
|
|
|
/// @param[in] function
|
|
|
|
/// The function to inspect.
|
|
|
|
///
|
|
|
|
/// @return
|
|
|
|
/// True on success; false on error.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
bool Inspect (llvm::Function &function)
|
|
|
|
{
|
|
|
|
return InspectFunction(function);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
/// Instrument all the instructions found by Inspect()
|
|
|
|
///
|
|
|
|
/// @return
|
|
|
|
/// True on success; false on error.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
bool Instrument ()
|
|
|
|
{
|
|
|
|
for (InstIterator ii = m_to_instrument.begin(), last_ii = m_to_instrument.end();
|
|
|
|
ii != last_ii;
|
|
|
|
++ii)
|
|
|
|
{
|
|
|
|
if (!InstrumentInstruction(*ii))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
/// Add instrumentation to a single instruction
|
|
|
|
///
|
|
|
|
/// @param[in] inst
|
|
|
|
/// The instruction to be instrumented.
|
|
|
|
///
|
|
|
|
/// @return
|
|
|
|
/// True on success; false otherwise.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
virtual bool InstrumentInstruction(llvm::Instruction *inst) = 0;
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
/// Register a single instruction to be instrumented
|
|
|
|
///
|
|
|
|
/// @param[in] inst
|
|
|
|
/// The instruction to be instrumented.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void RegisterInstruction(llvm::Instruction &i)
|
|
|
|
{
|
|
|
|
m_to_instrument.push_back(&i);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
/// Determine whether a single instruction is interesting to
|
|
|
|
/// instrument, and, if so, call RegisterInstruction
|
|
|
|
///
|
|
|
|
/// @param[in] i
|
|
|
|
/// The instruction to be inspected.
|
|
|
|
///
|
|
|
|
/// @return
|
|
|
|
/// False if there was an error scanning; true otherwise.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
virtual bool InspectInstruction(llvm::Instruction &i)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
/// Scan a basic block to see if any instructions are interesting
|
|
|
|
///
|
|
|
|
/// @param[in] bb
|
|
|
|
/// The basic block to be inspected.
|
|
|
|
///
|
|
|
|
/// @return
|
|
|
|
/// False if there was an error scanning; true otherwise.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
virtual bool InspectBasicBlock(llvm::BasicBlock &bb)
|
|
|
|
{
|
|
|
|
for (llvm::BasicBlock::iterator ii = bb.begin(), last_ii = bb.end();
|
|
|
|
ii != last_ii;
|
|
|
|
++ii)
|
|
|
|
{
|
|
|
|
if (!InspectInstruction(*ii))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
/// Scan a function to see if any instructions are interesting
|
|
|
|
///
|
|
|
|
/// @param[in] f
|
|
|
|
/// The function to be inspected.
|
|
|
|
///
|
|
|
|
/// @return
|
|
|
|
/// False if there was an error scanning; true otherwise.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
virtual bool InspectFunction(llvm::Function &f)
|
|
|
|
{
|
|
|
|
for (llvm::Function::iterator bbi = f.begin(), last_bbi = f.end();
|
|
|
|
bbi != last_bbi;
|
|
|
|
++bbi)
|
|
|
|
{
|
|
|
|
if (!InspectBasicBlock(*bbi))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-14 05:34:21 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
/// Build a function pointer for a function with signature
|
|
|
|
/// void (*)(uint8_t*) with a given address
|
|
|
|
///
|
|
|
|
/// @param[in] start_address
|
|
|
|
/// The address of the function.
|
|
|
|
///
|
|
|
|
/// @return
|
|
|
|
/// The function pointer, for use in a CallInst.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
llvm::Value *BuildPointerValidatorFunc(lldb::addr_t start_address)
|
|
|
|
{
|
|
|
|
std::vector<const llvm::Type*> params;
|
|
|
|
|
|
|
|
const IntegerType *intptr_ty = llvm::Type::getIntNTy(m_module.getContext(),
|
|
|
|
(m_module.getPointerSize() == llvm::Module::Pointer64) ? 64 : 32);
|
|
|
|
|
2010-11-04 09:51:38 +08:00
|
|
|
params.push_back(GetI8PtrTy());
|
2010-09-14 05:34:21 +08:00
|
|
|
|
|
|
|
FunctionType *fun_ty = FunctionType::get(llvm::Type::getVoidTy(m_module.getContext()), params, true);
|
|
|
|
PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty);
|
|
|
|
Constant *fun_addr_int = ConstantInt::get(intptr_ty, start_address, false);
|
|
|
|
return ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty);
|
|
|
|
}
|
|
|
|
|
2010-11-04 09:51:38 +08:00
|
|
|
const PointerType *GetI8PtrTy()
|
|
|
|
{
|
|
|
|
if (!m_i8ptr_ty)
|
|
|
|
m_i8ptr_ty = llvm::Type::getInt8PtrTy(m_module.getContext());
|
|
|
|
|
|
|
|
return m_i8ptr_ty;
|
|
|
|
}
|
|
|
|
|
2010-09-02 08:37:32 +08:00
|
|
|
typedef std::vector <llvm::Instruction *> InstVector;
|
|
|
|
typedef InstVector::iterator InstIterator;
|
|
|
|
|
|
|
|
InstVector m_to_instrument; ///< List of instructions the inspector found
|
|
|
|
llvm::Module &m_module; ///< The module which is being instrumented
|
|
|
|
DynamicCheckerFunctions &m_checker_functions; ///< The dynamic checker functions for the process
|
2010-11-04 09:51:38 +08:00
|
|
|
private:
|
2010-09-14 05:34:21 +08:00
|
|
|
const PointerType *m_i8ptr_ty;
|
2010-09-02 08:37:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ValidPointerChecker : public Instrumenter
|
|
|
|
{
|
|
|
|
public:
|
2011-01-26 07:55:37 +08:00
|
|
|
ValidPointerChecker (llvm::Module &module,
|
|
|
|
DynamicCheckerFunctions &checker_functions) :
|
2010-09-02 08:37:32 +08:00
|
|
|
Instrumenter(module, checker_functions),
|
|
|
|
m_valid_pointer_check_func(NULL)
|
|
|
|
{
|
|
|
|
}
|
2011-01-26 07:55:37 +08:00
|
|
|
|
|
|
|
virtual ~ValidPointerChecker ()
|
|
|
|
{
|
|
|
|
}
|
2010-09-02 08:37:32 +08:00
|
|
|
private:
|
|
|
|
bool InstrumentInstruction(llvm::Instruction *inst)
|
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
|
2010-09-02 08:37:32 +08:00
|
|
|
|
|
|
|
if(log)
|
|
|
|
log->Printf("Instrumenting load/store instruction: %s\n",
|
|
|
|
PrintValue(inst).c_str());
|
|
|
|
|
|
|
|
if (!m_valid_pointer_check_func)
|
2010-09-14 05:34:21 +08:00
|
|
|
m_valid_pointer_check_func = BuildPointerValidatorFunc(m_checker_functions.m_valid_pointer_check->StartAddress());
|
2010-09-02 08:37:32 +08:00
|
|
|
|
|
|
|
llvm::Value *dereferenced_ptr;
|
|
|
|
|
|
|
|
if (llvm::LoadInst *li = dyn_cast<llvm::LoadInst> (inst))
|
|
|
|
dereferenced_ptr = li->getPointerOperand();
|
|
|
|
else if (llvm::StoreInst *si = dyn_cast<llvm::StoreInst> (inst))
|
|
|
|
dereferenced_ptr = si->getPointerOperand();
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Insert an instruction to cast the loaded value to int8_t*
|
|
|
|
|
|
|
|
BitCastInst *bit_cast = new BitCastInst(dereferenced_ptr,
|
2010-11-04 09:51:38 +08:00
|
|
|
GetI8PtrTy(),
|
2010-09-02 08:37:32 +08:00
|
|
|
"",
|
|
|
|
inst);
|
|
|
|
|
|
|
|
// Insert an instruction to call the helper with the result
|
|
|
|
|
|
|
|
SmallVector <llvm::Value*, 1> args;
|
|
|
|
args.push_back(bit_cast);
|
|
|
|
|
|
|
|
CallInst::Create(m_valid_pointer_check_func,
|
|
|
|
args.begin(),
|
|
|
|
args.end(),
|
|
|
|
"",
|
|
|
|
inst);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InspectInstruction(llvm::Instruction &i)
|
|
|
|
{
|
|
|
|
if (dyn_cast<llvm::LoadInst> (&i) ||
|
|
|
|
dyn_cast<llvm::StoreInst> (&i))
|
|
|
|
RegisterInstruction(i);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *m_valid_pointer_check_func;
|
2010-09-14 05:34:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ObjcObjectChecker : public Instrumenter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ObjcObjectChecker(llvm::Module &module,
|
|
|
|
DynamicCheckerFunctions &checker_functions) :
|
|
|
|
Instrumenter(module, checker_functions),
|
|
|
|
m_objc_object_check_func(NULL)
|
|
|
|
{
|
|
|
|
}
|
2011-01-26 07:55:37 +08:00
|
|
|
|
|
|
|
virtual
|
|
|
|
~ObjcObjectChecker ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-14 05:34:21 +08:00
|
|
|
private:
|
|
|
|
bool InstrumentInstruction(llvm::Instruction *inst)
|
|
|
|
{
|
|
|
|
CallInst *call_inst = dyn_cast<CallInst>(inst);
|
|
|
|
|
|
|
|
if (!call_inst)
|
2010-11-04 09:51:38 +08:00
|
|
|
return false; // call_inst really shouldn't be NULL, because otherwise InspectInstruction wouldn't have registered it
|
2010-09-14 05:34:21 +08:00
|
|
|
|
|
|
|
if (!m_objc_object_check_func)
|
|
|
|
m_objc_object_check_func = BuildPointerValidatorFunc(m_checker_functions.m_objc_object_check->StartAddress());
|
|
|
|
|
|
|
|
llvm::Value *target_object;
|
|
|
|
|
|
|
|
// id objc_msgSend(id theReceiver, SEL theSelector, ...)
|
|
|
|
|
|
|
|
target_object = call_inst->getArgOperand(0);
|
|
|
|
|
|
|
|
// Insert an instruction to cast the receiver id to int8_t*
|
|
|
|
|
|
|
|
BitCastInst *bit_cast = new BitCastInst(target_object,
|
2010-11-04 09:51:38 +08:00
|
|
|
GetI8PtrTy(),
|
2010-09-14 05:34:21 +08:00
|
|
|
"",
|
|
|
|
inst);
|
|
|
|
|
|
|
|
// Insert an instruction to call the helper with the result
|
|
|
|
|
|
|
|
SmallVector <llvm::Value*, 1> args;
|
|
|
|
args.push_back(bit_cast);
|
|
|
|
|
|
|
|
CallInst::Create(m_objc_object_check_func,
|
|
|
|
args.begin(),
|
|
|
|
args.end(),
|
|
|
|
"",
|
|
|
|
inst);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InspectInstruction(llvm::Instruction &i)
|
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
|
2010-09-14 05:34:21 +08:00
|
|
|
|
|
|
|
CallInst *call_inst = dyn_cast<CallInst>(&i);
|
|
|
|
|
|
|
|
if (call_inst)
|
|
|
|
{
|
|
|
|
// This metadata is set by IRForTarget::MaybeHandleCall().
|
|
|
|
|
|
|
|
MDNode *metadata = call_inst->getMetadata("lldb.call.realName");
|
|
|
|
|
|
|
|
if (!metadata)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (metadata->getNumOperands() != 1)
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf("Function call metadata has %d operands for [%p] %s", metadata->getNumOperands(), call_inst, PrintValue(call_inst).c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstantArray *real_name = dyn_cast<ConstantArray>(metadata->getOperand(0));
|
|
|
|
|
|
|
|
if (!real_name)
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf("Function call metadata is not a ConstantArray for [%p] %s", call_inst, PrintValue(call_inst).c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!real_name->isString())
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf("Function call metadata is not a string for [%p] %s", call_inst, PrintValue(call_inst).c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Printf("Found call to %s: %s\n", real_name->getAsString().c_str(), PrintValue(call_inst).c_str());
|
|
|
|
|
|
|
|
if (real_name->getAsString().find("objc_msgSend") != std::string::npos)
|
|
|
|
RegisterInstruction(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *m_objc_object_check_func;
|
2010-09-02 08:37:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
IRDynamicChecks::IRDynamicChecks(DynamicCheckerFunctions &checker_functions,
|
|
|
|
const char *func_name) :
|
2010-09-23 11:01:22 +08:00
|
|
|
ModulePass(ID),
|
2010-09-02 08:37:32 +08:00
|
|
|
m_checker_functions(checker_functions),
|
|
|
|
m_func_name(func_name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-01 08:58:00 +08:00
|
|
|
IRDynamicChecks::~IRDynamicChecks()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IRDynamicChecks::runOnModule(llvm::Module &M)
|
|
|
|
{
|
2010-11-06 09:53:30 +08:00
|
|
|
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
|
2010-09-01 08:58:00 +08:00
|
|
|
|
|
|
|
llvm::Function* function = M.getFunction(StringRef(m_func_name.c_str()));
|
|
|
|
|
|
|
|
if (!function)
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf("Couldn't find %s() in the module", m_func_name.c_str());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-02 08:37:32 +08:00
|
|
|
|
|
|
|
ValidPointerChecker vpc(M, m_checker_functions);
|
2010-09-01 08:58:00 +08:00
|
|
|
|
2010-09-02 08:37:32 +08:00
|
|
|
if (!vpc.Inspect(*function))
|
|
|
|
return false;
|
2010-09-01 08:58:00 +08:00
|
|
|
|
2010-09-02 08:37:32 +08:00
|
|
|
if (!vpc.Instrument())
|
|
|
|
return false;
|
2010-09-01 08:58:00 +08:00
|
|
|
|
2010-09-14 05:34:21 +08:00
|
|
|
ObjcObjectChecker ooc(M, m_checker_functions);
|
|
|
|
|
|
|
|
if (!ooc.Inspect(*function))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!ooc.Instrument())
|
|
|
|
return false;
|
2011-01-22 09:25:40 +08:00
|
|
|
|
|
|
|
if (log && log->GetVerbose())
|
2010-09-09 04:04:08 +08:00
|
|
|
{
|
|
|
|
std::string s;
|
|
|
|
raw_string_ostream oss(s);
|
|
|
|
|
|
|
|
M.print(oss, NULL);
|
|
|
|
|
|
|
|
oss.flush();
|
|
|
|
|
2011-01-22 09:25:40 +08:00
|
|
|
log->Printf ("Module after dynamic checks: \n%s", s.c_str());
|
2010-09-09 04:04:08 +08:00
|
|
|
}
|
|
|
|
|
2010-09-01 08:58:00 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IRDynamicChecks::assignPassManager(PMStack &PMS,
|
|
|
|
PassManagerType T)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PassManagerType
|
|
|
|
IRDynamicChecks::getPotentialPassManagerType() const
|
|
|
|
{
|
|
|
|
return PMT_ModulePassManager;
|
|
|
|
}
|