[DynInst_API:] Fw: Not able to get my sample program working


Date: Thu, 28 Feb 2008 11:43:03 +0530 (IST)
From: alok singh <alok_shishir@xxxxxxxxxxx>
Subject: [DynInst_API:] Fw: Not able to get my sample program working


Hi,

I am new to Dyninst and using its API. So, I first tried to get a simple program working to get a bit of confidence to move ahead. The program simply counts the number of times it encounters a functions f() by incrementing a counter intCounter. I have attached the simple program for your reference.
I installed the libdyninst and libdyninst-dev (v5.1) packages using the deb installers. By the way, I am using Ubuntu 7.10 on an IBM T43 with 512 MB RAM and 1.86 GHz processor. I compile my program like this:


 g++-4.2 -Wno-deprecated -L/usr/lib -l dyninstAPI /home/alok/Documents/Packages/dwarf-20071209/libdwarf/libdwarf.a -o count1 count1.cpp

The reason for manually specifying the dwarf library is that the dwarf library present in system is old and and is missing new files, particularly frame2.c (and if i try to compile using that, I get an error message in that regard).
But after compiling, when I try to run the program ./count1, I get the following error message:

Warning: failed pre-exec notification setup
I am a function
I am a function
I am a function
process.C[3739][UI]:  readDataSpace() failing, not attached
The value of intCounter is -1075602072

I have included the program and its binary to whom I am trying to patch. Please ignore the commented out lines. Can you please go through the errors, my programs and the steps I am following and guide me as to how to get it working?

Thanks,
Alok



-----Inline Attachment Follows-----

#include <iostream.h>
#include "/usr/include/dyninst/BPatch.h"
#include "/usr/include/dyninst/BPatch_image.h"
#include "/usr/include/dyninst/BPatch_thread.h"
#include "/usr/include/dyninst/BPatch_Vector.h"
#include "/usr/include/dyninst/BPatch_point.h"

using namespace std;

int main()
{

    BPatch bpatch;

    BPatch_thread *appThread->bpatch.createProcess("/home/alok/Documents/Dyninst/inline", "");
    BPatch_image *appImage = appThread->getImage();

    BPatch_Vector<BPatch_point*> *points = appImage->findFunctionByAddr("f");

    BPatch_variableExpr *intCounter =  appThread->malloc(*appImage->findType("int"));

    /*int zero = 0;
    intCounter.writeValue(&zero);*/

    BPatch_arithExpr addOne(BPatch_assign, *intCounter, BPatch_arithExpr(BPatch_plus, *intCounter, BPatch_constExpr(1)));

    appThread->insertSnippet(addOne, *points);

}


-----Inline Attachment Follows-----

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 1
//#define INCOMING_FRAME_SP_OFFSET
//void TARGET_ASM_FUNCTION_PROLOGUE (FILE *file, HOST_WIDE_INT size);

/*void __cyg_profile_func_enter( void *func_address, void *call_site )
                                __attribute__ ((no_instrument_function));

void __cyg_profile_func_enter( void *func_address, void *call_site )
{
  printf("haha\n");
}

void __cyg_profile_func_exit ( void *func_address, void *call_site )
                                __attribute__ ((no_instrument_function));

void __cyg_profile_func_exit ( void *func_address, void *call_site )
{
    printf("hehe\n");
}*/

void f()
{
    printf("I am a function\n");
}


int main(int argc, char ** argv)
{
   
    f();       
//    TARGET_ASM_FUNCTION_EPILOGUE(stdout, 1000);
//    printf("INCOMING_FRAME_SP_OFFSET:%d\n", INCOMING_FRAME_SP_OFFSET);
    f();       
    f();       
    return 0;
}





Get the freedom to save as many mails as you wish. Click here to know how.
#include <iostream.h>
#include "/usr/include/dyninst/BPatch.h"
#include "/usr/include/dyninst/BPatch_image.h"
#include "/usr/include/dyninst/BPatch_thread.h"
#include "/usr/include/dyninst/BPatch_Vector.h"
#include "/usr/include/dyninst/BPatch_point.h"

using namespace std;

int main()
{

	BPatch bpatch;

	BPatch_thread *appThread->bpatch.createProcess("/home/alok/Documents/Dyninst/inline", "");
	BPatch_image *appImage = appThread->getImage();

	BPatch_Vector<BPatch_point*> *points = appImage->findFunctionByAddr("f");

	BPatch_variableExpr *intCounter =  appThread->malloc(*appImage->findType("int"));

	/*int zero = 0;
	intCounter.writeValue(&zero);*/

	BPatch_arithExpr addOne(BPatch_assign, *intCounter, BPatch_arithExpr(BPatch_plus, *intCounter, BPatch_constExpr(1)));

	appThread->insertSnippet(addOne, *points);

}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 1
//#define INCOMING_FRAME_SP_OFFSET
//void TARGET_ASM_FUNCTION_PROLOGUE (FILE *file, HOST_WIDE_INT size);

/*void __cyg_profile_func_enter( void *func_address, void *call_site )
                                __attribute__ ((no_instrument_function));

void __cyg_profile_func_enter( void *func_address, void *call_site )
{
  printf("haha\n");
}

void __cyg_profile_func_exit ( void *func_address, void *call_site )
                                __attribute__ ((no_instrument_function));

void __cyg_profile_func_exit ( void *func_address, void *call_site )
{
	printf("hehe\n");
}*/

void f()
{
 	 printf("I am a function\n");
}


int main(int argc, char ** argv)
{
	
	f();		
//	TARGET_ASM_FUNCTION_EPILOGUE(stdout, 1000);
//	printf("INCOMING_FRAME_SP_OFFSET:%d\n", INCOMING_FRAME_SP_OFFSET);
	f();		
	f();		
	return 0;
}


Attachment: inline
Description: inline

[← Prev in Thread] Current Thread [Next in Thread→]
  • [DynInst_API:] Fw: Not able to get my sample program working, alok singh <=