From 649ee3fec12dcf7167630ff88087ad116e9eefa6 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Mon, 9 Apr 2012 15:42:15 +0000 Subject: Add -fobjc-trace to emit a call before and after each Objective-C message send for hooking in code flow visualisation applications. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154321 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGObjCGNU.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/CodeGen') diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp index db0bd951c1..6cf370f79e 100644 --- a/lib/CodeGen/CGObjCGNU.cpp +++ b/lib/CodeGen/CGObjCGNU.cpp @@ -322,6 +322,11 @@ private: /// Function used for non-object declared property setters. LazyRuntimeFunction SetStructPropertyFn; + /// Function called before message sends, when tracing + LazyRuntimeFunction TraceEnterFn; + /// Function called after message sends, when tracing + LazyRuntimeFunction TraceExitFn; + /// The version of the runtime that this class targets. Must match the /// version in the runtime. int RuntimeVersion; @@ -768,6 +773,9 @@ CGObjCGNU::CGObjCGNU(CodeGenModule &cgm, unsigned runtimeABIVersion, SetStructPropertyFn.init(&CGM, "objc_setPropertyStruct", VoidTy, PtrTy, PtrTy, PtrDiffTy, BoolTy, BoolTy, NULL); + TraceEnterFn.init(&CGM, "objc_trace_enter", VoidTy, IdTy, SelectorTy, NULL); + TraceExitFn.init(&CGM, "objc_trace_exit", VoidTy, IdTy, SelectorTy, NULL); + // IMP type llvm::Type *IMPArgs[] = { IdTy, SelectorTy }; IMPTy = llvm::PointerType::getUnqual(llvm::FunctionType::get(IdTy, IMPArgs, @@ -1212,12 +1220,19 @@ CGObjCGNU::GenerateMessageSend(CodeGenFunction &CGF, ActualArgs[0] = CallArg(RValue::get(Receiver), ASTIdTy, false); imp = EnforceType(Builder, imp, MSI.MessengerType); + if (CGM.getCodeGenOpts().ObjCTrace) { + Builder.CreateCall2(TraceEnterFn, Receiver, cmd); + } llvm::Instruction *call; RValue msgRet = CGF.EmitCall(MSI.CallInfo, imp, Return, ActualArgs, 0, &call); call->setMetadata(msgSendMDKind, node); + if (CGM.getCodeGenOpts().ObjCTrace) { + Builder.CreateCall2(TraceExitFn, Receiver, cmd); + } + if (!isPointerSizedReturn) { messageBB = CGF.Builder.GetInsertBlock(); -- cgit v1.2.3