[aspectc-user] RE: aspectc-user Digest, Vol 4, Issue 4

Heni Dhiab dhiabheni at hotmail.com
Tue Dec 22 21:39:18 CET 2009


Hy Olaf, 

 

Thank u for your response ! 

Ok maybe i don't have to change New operator Comportement, but supposed that i need to find a number line and the file name of a method X, how can i do it with Aspect ??

Because i'm developing a memory debugger and i need this kind of informations ..


maybe the problem is a litlle bit dificult, but i find the solution without aspect..we have just to modle it with aspect no ?

 

i want just change a comportement of new/X/Y.. and add him in a new definition tow news arguments (__LINE__//__FILE__)

 

ok i can ask my problem in the ather form:

 

If i want detect the number LINE and name FILE of the method main , how can i do ?

 

thak u for your time, Heni  


 
> Date: Wed, 16 Dec 2009 12:00:04 +0100
> From: aspectc-user-request at aspectc.org
> Subject: aspectc-user Digest, Vol 4, Issue 4
> To: aspectc-user at aspectc.org
> 
> Send aspectc-user mailing list submissions to
> aspectc-user at aspectc.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> http://www.aspectc.org/mailman/listinfo/aspectc-user
> or, via email, send a message with subject or body 'help' to
> aspectc-user-request at aspectc.org
> 
> You can reach the person managing the list at
> aspectc-user-owner at aspectc.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of aspectc-user digest..."
> 
> 
> Today's Topics:
> 
> 1. Re: do an aspect for detect line/file of an execution of new
> operator ?? (Olaf Spinczyk)
> 2. Help about detcting new operator and the line and fle name
> where it is executed ? (Heni Dhiab)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Tue, 15 Dec 2009 15:38:39 +0100
> From: Olaf Spinczyk <os at aspectc.org>
> Subject: Re: [aspectc-user] do an aspect for detect line/file of an
> execution of new operator ??
> To: aspectc-user at aspectc.org
> Message-ID: <4B279F6F.6040905 at aspectc.org>
> Content-Type: text/plain; charset=windows-1256; format=flowed
> 
> Dear Heni,
> 
> redefining the meaning of the token 'new' is rather dangerous. The C 
> prepropressor is very simple and replaces 'new' wherever it appears. 
> Also note that the code, which is transformed by a++, will once again be 
> preprocessed by the C++ compiler.
> 
> The root of the problem ist that call-advice for the new operator is not 
> supported by ac++, yet. If you could use cal- advice, the joinpoint-API 
> would allow you to access the filename and line number easily in your 
> advice code. This would be the best solution.
> 
> If you can't wait until this feature is implemented, I would recommend a 
> workaround like this: Implement a kind of tracing aspect for the 
> execution of all functions. Use a global 'function_name' variable and a 
> global 'new_count' variable. Whenever a function is being executed 
> (before-execution-advice) set the 'function_name' to 
> JoinPoint::signature() and 'new_count' to 0. Additionally, define advice 
> for the execution of the new operator. There you can use the current 
> 'function_name' and 'new_count' as context information. Also increment 
> 'new_count'. If your program is multi-threaded make sure the two globals 
> are allocated in thread-local storage. With this workaround you don't 
> get the file and line, but with the function name and the invocation 
> counter you should normally be able to identify the right new-call.
> 
> So much about my two cents,
> 
> Olaf
> 
> Heni Dhiab wrote:
> >
> > 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> 
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > aspectc-user mailing list
> > aspectc-user at aspectc.org
> > http://www.aspectc.org/mailman/listinfo/aspectc-user
> 
> 
> 
> ------------------------------
> 
> Message: 2
> Date: Tue, 15 Dec 2009 21:55:05 +0100
> From: Heni Dhiab <hdhiab at gmail.com>
> Subject: [aspectc-user] Help about detcting new operator and the line
> and fle name where it is executed ?
> To: aspectc-user at aspectc.org
> Message-ID:
> <f5e1fc4f0912151255y60e0ec00h4106a1102403e7a2 at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> Hello every body ..
> 
> 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 without an aspect, it's just with basic C++ lass and a
> header, some one can help me for integrate this changement in an aspect ??
> 
> 
> 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 longligne)
> 
> 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.
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: http://p15111082.pureserver.info/pipermail/aspectc-user/attachments/20091215/5ab0c44d/attachment-0001.html
> 
> ------------------------------
> 
> _______________________________________________
> aspectc-user mailing list
> aspectc-user at aspectc.org
> http://www.aspectc.org/mailman/listinfo/aspectc-user
> 
> 
> End of aspectc-user Digest, Vol 4, Issue 4
> ******************************************
 		 	   		  
_________________________________________________________________
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/20091222/b716118c/attachment.html>


More information about the aspectc-user mailing list