I am experimenting with intel-pin tool. I have a simple Hello-world.c
(It prints nothing but "Hello world") program (say a.out
). If I want to generate assembly from the binary, I would do objdump -D a.out
.
I want to instrument some instructions in that.
Is it possible to get objdump using pin tool, before (This can be easily done by objdump) and after instrumentation?
I have created a tool which prints all the instructions.
#include <stdio.h>
#include "pin.H"
#include <cstdint>
FILE * trace;
KNOB<string> KnobOutputFile(KNOB_MODE_WRITEONCE, "pintool", "o", "pinatrace.out","A pin tool");
VOID Count(INS ins, void *v) {
fprintf(trace,"\n%s",(INS_Disassemble(ins)).c_str());
}
VOID Fini(INT32 code, VOID *v)
{
printf("count = %ld\n",(long)icount);
fprintf(trace, "#eof\n");
fclose(trace);
}
/* ===================================================================== */
/* Print Help Message */
/* ===================================================================== */
INT32 Usage()
{
PIN_ERROR( "This Pintool prints a trace of memory addresses\n"
+ KNOB_BASE::StringKnobSummary() + "\n");
return -1;
}
/* ===================================================================== */
/* Main */
/* ===================================================================== */
int main(int argc, char *argv[])
{
if (PIN_Init(argc, argv)) return Usage();
trace = fopen("pinatrace.out", "w");
INS_AddInstrumentFunction(Count, 0);
PIN_AddFiniFunction(Fini, 0);
// Never returns
PIN_StartProgram();
return 0;
}
It prints the assembly instructions, but I am not sure if it includes the instrumented instructions.
Is this the proper way to do this? Could you please help me?