Python_Pin icon indicating copy to clipboard operation
Python_Pin copied to clipboard

use python-pin error

Open ling245100108 opened this issue 9 years ago • 6 comments

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)

ling245100108 avatar May 10 '15 12:05 ling245100108

Please write your full configuration version OS, pintool, c++ and other?

Kosmonit avatar May 10 '15 16:05 Kosmonit

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.

ling245100108 avatar May 10 '15 16:05 ling245100108

What branch did you use? Python_Pin or Python_Pin_Windows?

Kosmonit avatar May 10 '15 17:05 Kosmonit

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.

ancat avatar May 11 '15 03:05 ancat

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 avatar Dec 11 '15 13:12 tosanjay

@tosanjay I agree with you. so we need register a callback in function Instrument().

0xling avatar Dec 22 '15 15:12 0xling