I am writing an LLVM pass that should receive the values passed to the declared function and say print them. Note that the declared function is called in the LLVM IR.
I wrote a module pass to repeat all the instructions in the program. The fragment for receiving the arguments of the called function in the instruction is as follows:
for (auto &B: F){
for (auto &I: B){
if (auto *InvokeI = dyn_cast <InvokeInst>(&I)) {
if (InvokeI->getCalledFunction()->getName().str() == "function_name") {
errs() << "===\n";
errs() << *(InvokeI->getOperand(0)) <<"\n";
errs() << *(InvokeI->getOperand(1)) <<"\n";
errs() << *(InvokeI->getOperand(2)) <<"\n";
}
}
}
}
However, if the LLVM IR for the called function looks something like this:
invoke void @function_name(i8* %4, i8* bitcast (i8** @_ZTIi to i8*), i8* null)
to label %36 unwind label %6
then my code snippets above are output:
%4 = call i8* @__cxa_allocate_exception(i64 4)
i8* bitcast (i8** @_ZTIi to i8*)
i8* null
Instead of displaying the actual value that is passed during the function call.
My question is: how do we get the values that are passed at runtime. Is there a way to add a function body to declared functions that return nothing?
Any help on this is appreciated, thanks