[aspectc-user] do an aspect for detect execution of New Operator, and the LINE and FILE where it's executed ??

Heni Dhiab dhiabheni at hotmail.com
Tue Dec 15 05:23:11 CET 2009


I'm developing a debugger for C++ dynamicly memory allocated with aspectC++. So i have to detect each execution of NEW and NEW [] opertors. For this, i did the 'NewDetectionAspect' aspect.
 
#ifndef FIRSTASPECT

#define FIRSTASPECT

#include <stdio.h>

#include <iostream>

#include <string.h>

//securise la gestion de memoire afin de s'assurer qu'aucune autre gestion n'est en place (eviter les conflits) *globalement*

void* operator new (size_t size)

{

printf ("%s \n ligne : %lu - ",__FILE__, __LINE__);

printf("\n changelment de l'opérateur new"); 

return malloc(size); 

}

 

aspect NewDetectionAspect

{ 

void * ptr;

int d;

FILE *F3;



public :

advice classes("%")://securise la gestion de memoire afin de s'assurer qu'aucune autre gestion n'est en place (eviter les conflits)

slice class newdelete

{

public:

 

//Assure que loperateur new n'a pas ete redefinit sinon le garbage collection ne peu fonctionner

void* operator new (size_t size)

{ 

printf ("%s \n ligne : %lu - ",__FILE__, __LINE__);

printf("\n changelment de l'opérateur new");

return malloc(size); 

}

advice execution ("% ...::operator new(...)" ||

"% ...::operator new[](...)") : before () {

printf ("executing heap operation \"%s\"\n", JoinPoint::signature ());

printf (" tjp->that() is %s (should be 0)\n", (tjp->that () ? "not 0" : "0"));

}



};

 

 

The aspect working well, but i want to change the comportment of New operator for return two arguments, the first is the line where New/New [] operator was executed, and the second is the file where it is executed.
 
I did an sample but not with an spectC++ aspect, it is just with a normal C++ class and a header file. it s working well..i can detect each execution line and file of new[]/new operator. The pricipe is like this : 
 
change New operator Prototype  by adding two arguments for line and file in a header file "halloc.h": 
 
 
#  include <string.h>
#    include <new>
 
      void* operator new (size_t size, const char* nom_fich, const unsigned long num_ligne)
       throw (std::bad_alloc);
       #define new new (__FILE__, __LINE__)
  
And develop it in hello.cpp:
 
#include "halloc.h"
#undef new
 
void* operator new (size_t size, const char* nom, const unsigned long ligne)
  throw (std::bad_alloc)
{
  void*ptr= new char;
 
      printf ("%s:%lu - ",nom, ligne);
    return ptr;// MallocSecurise (size, nom, ligne);
}
 
Some one can help me for resolve this problem, and made an aspect/advice/slice for detect the line and the file for a new operator ??
Thank u very much, Heni.
 
  		 	   		  
_________________________________________________________________
Windows Live Hotmail: Your friends can get your Facebook updates, right from Hotmail®.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_4:092009
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.aspectc.org/pipermail/aspectc-user/attachments/20091215/2c0f45af/attachment.html>


More information about the aspectc-user mailing list