Python_Pin
Python_Pin copied to clipboard
use python-pin error
I try convert the simplest pintools: inscount0.cpp to python. But It has a segment error: C: Tool (or Pin) caused signal 11 at PC 0x7f946f1dd8b9 I don't know what's wrong with me. Here is the python source I write:
import sys, pin
info = file("count.out", "w")
count = 0
def docount(ins_info): global count count = count + 1
def instruction(ins): pin.INS_InsertCall(pin.IPOINT_BEFORE, ins, docount)
def fini(): global count info.writelines(str(count)) info.close()
pin.INS_AddInstrumentFunction(instruction, 0) pin.AddFiniFunction(fini, 0)
Please write your full configuration version OS, pintool, c++ and other?
I use ubuntu 14.04 x86_x64 Linux LING 3.16.0-33-generic #44~14.04.1-Ubuntu SMP Fri Mar 13 10:33:29 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
pin is pin-2.14-71313-gcc.4.4.7-linux
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
And I can run your all examples for example strace.py . I only want to write some python myself.
What branch did you use? Python_Pin or Python_Pin_Windows?
I didn't test this out, but you should be able to increment count
in your instruction
function, without needing to insert a new call at every instruction (since you are instrumenting every instruction anyway). Not exactly a great solution, but it should stop the segfault. I'll have a closer look at some point this week.
I am a new-comer as far as Pintools are concerned, but from what you are suggesting, i guess it may give erroneous results. You are suggesting to increment count in "instrumentation code", which is called only first time when an instruction is about to execute. If the same instruction is executed again, instrumentation routine will not be invoked and you may not increase the count because you have not registered any analysis callback. This is what I understood from the PIN doc. I will be happy to know if I am wrong here.
@tosanjay I agree with you. so we need register a callback in function Instrument().