gcc - Run Time Memory Capture

kodandaraman govindan raman.govindan@wipro.com
Mon Apr 23 05:55:00 GMT 2001


Hi,

  I have an idea regarding enhancing gcc to capture Run Time Stack
Size. Find enclosed a paper on the same.

  I am not sure if this feature is already implemented in gcc. If so
please let me know and forgive my ignorance.

Thanks & Regards
-raman

PS: I had posted this mail to gnu@gnu.org and I got response to
contact you. In addition, I was suggested to write this up as a
technical report for 
http://www.gnu.org/mailman/listinfo/info-tech-reports/ .

 I was not able to access the above mentioned site.

-------------------------------------------------------------------------

 	
                         Runtime Stack Size

 1. Abstract
    --------

    To sell a product, footprint plays an important rule, especially if
 the product is to embedded into a device. This paper describes about
 how to capture Runtime stack size on a intel platform.

 2. Concept
    -------

   The GNU compiler, gcc with -mstats options gives the stack
 statistics on MIPS processor only. This paper describes how to modify
 the gcc to obtain stack statistics on intel platform. The same idea
 can be extended to other platforms as well.


                                 STACK

 					       -----------------
 baseStackPosition --->   |                 |
 				          |                 |
 				     	   -----------------
  				          |                 |
 				          |                 |
 					       -----------------
 				          |                 |
 				          |                 |
 					       -----------------
 currentStackPosition --> |                 |
         			      |                 |
 					       -----------------
 				          |                 |
 				          |      .          |
 					      |      .          |
 				          |      .          |
 				          |                 |
 					       -----------------
  				          |                 |
 				          |                 |
 					       -----------------



    PIECE OF CODE TO KEEP TRACK OF MAXIMUM STACK SIZE
    -------------------------------------------------

        maximumStackSize = 0;
        baseStackPosition is the initial Stack Position
        currentStackPosition is the current Stack Position

        Whenever a function is called, the stack grows and the
        currentStackPosition (%esp) changes.

        if ( (%esp - baseStackPosition) greater than maximumStackSize )
        then
            maximumStackSize = %esp - baseStackPosition
            output the stderr the value of maximumStackSize
        endif



 gcc can be modified in the code generation phase, so that every time a
 "push" instruction is emitted, "PIECE OF CODE TO KEEP TRACK OF MAXIMUM
 STACK SIZE" described above is also emitted.

 3.  Practical Significance
     ----------------------

 This can be used to capture RunTime Stack Size of a product.



-- 
_______________________________________________________________
Raman Govindan, Software Specialist,
Global R&D Division, Wipro Technologies.

Visit http://netphone.wipro.com (For now Only Wipro Employees)
Email: raman.govindan@wipro.com
Tel: +91-(80)-5364801/07, Ext: 160 (Office)
_______________________________________________________________



More information about the Gcc-bugs mailing list