[aspectc-user] do an aspect for detect line/file of an execution of new operator ??

Heni Dhiab dhiabheni at hotmail.com
Tue Dec 15 03:23:35 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.
 
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);
}
 
When I integrate this sample in an aspect, like this ‘NewDetectionAspectLineFile.ah’ : 
 
 
 #ifndef FIRSTASPECT
#define FIRSTASPECT
 
 
 
 
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#  include <new>
 
 
#  include <string.h>
#  include <new>
 
void* operator new (size_t size, const char* nom_fich, const unsigned long num_ligne)
       throw (std::bad_alloc);
 
 
 
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);
}
#undef new
#define new new (__FILE__, __LINE__)
 
 
//-----------------------------------------------------------------------------
 aspect FirstAspect
{     
      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, 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);
            }
      };
 
 
      advice (execution("% ...::operator new(...)") ) 
            && !within("Pointer") && !within("Pointers"): after () 
      { printf ("executing heap operation \"%s\"\n", JoinPoint::signature ());}
};
#endif //FIRSTASPECT
 
This error is occurred:
 
Error    6          error C2660: 'simple::operator new' : function does not take 1 arguments         
 
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: Keep your friends up to date with what you do online.
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_1:092010
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.aspectc.org/pipermail/aspectc-user/attachments/20091215/34d09abe/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: NewDetectionAspect.ah
Type: application/octet-stream
Size: 2201 bytes
Desc: not available
URL: <http://www.aspectc.org/pipermail/aspectc-user/attachments/20091215/34d09abe/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: NewDetectionAspectLineFile.ah
Type: application/octet-stream
Size: 1504 bytes
Desc: not available
URL: <http://www.aspectc.org/pipermail/aspectc-user/attachments/20091215/34d09abe/attachment-0001.obj>


More information about the aspectc-user mailing list