From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,682c6a4dc0495d48 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wn11feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada From: anon@anon.org (anon) Subject: Yes it is possible. Re: Stackusage at runtime Reply-To: no to spamers (No@email.given.org) References: X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Tue, 04 Nov 2008 19:41:15 GMT NNTP-Posting-Host: 12.64.240.125 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1225827675 12.64.240.125 (Tue, 04 Nov 2008 19:41:15 GMT) NNTP-Posting-Date: Tue, 04 Nov 2008 19:41:15 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:2571 Date: 2008-11-04T19:41:15+00:00 List-Id: GNAT maintain two internal stacks but both uses the allocated system stacks from the System.Memory package that can be monitored. Will work for all version of GNAT with the understanding that the "Alloc" function may look a little different. To monitor the main (system) stack that GNAT uses, you need to alter the System.Memory package to include some monitoring information like in the following code. Some may not like it but it get the job done. In this version I only show how to monitor allocations, but if you need to monitor Free allocation as well you can either add another variable such as "Free_Stack_Value" and assoc statements or just insert a subtract Alloc_Stack_Value statement in the Free procedure. 1. Create a Tempory dir or use your program dir. This way maintain GNAT system integrity. 2. Copy from your version of GNAT "System.Memory" package aka files s-memory.ad? (need both body amd specs files) to temp dir. 3. Alter the s-memory.adb file by adding the following lines before the Alloc function: -- -- -- -- -- -- -- -- Debuging links -- -- -- -- -- -- -- -- Alloc_Stack_Value : size_t := 0; pragma Export (Ada, Alloc_Stack_Value, "Alloc_Stack_Value"); 4. then insert the following line in the Alloc function: Alloc_Stack_Value := Alloc_Stack_Value + Size; 5. An Example of how the code placement can look using GNAT Ada 3.15p aka a version of GNAT Ada 95. System.Memory package: ... -- removed to save space -- -- -- -- -- -- -- -- Debuging links -- -- -- -- -- -- -- -- Alloc_Stack_Value : size_t := 0; pragma Export (Ada, Alloc_Stack_Value, "Alloc_Stack_Value"); ----------- -- Alloc -- ----------- function Alloc (Size : size_t) return System.Address is Result : System.Address; Actual_Size : size_t := Size; begin if Size = size_t'Last then Raise_Exception (Storage_Error'Identity, "object too large"); end if; -- Change size from zero to non-zero. We still want a proper pointer -- for the zero case because pointers to zero length objects have to -- be distinct, but we can't just go ahead and allocate zero bytes, -- since some malloc's return zero for a zero argument. if Size = 0 then Actual_Size := 1; end if; Abort_Defer.all; Result := c_malloc (Actual_Size); Abort_Undefer.all; if Result = System.Null_Address then Raise_Exception (Storage_Error'Identity, "heap exhausted"); end if; -- -- Insert monitoring code after all error checking is done -- Alloc_Stack_Value := Alloc_Stack_Value + Size; return Result; end Alloc; ... -- removed to save space 6. Compile the new "System.Memory" package: gcc -c -gnatpg s-memory.adb 7. Now a Test program to illustrate usage. Needs to be in the same temporary directory with the newly compiled s-memory package. with Ada.Text_IO ; use Ada.Text_IO ; procedure Test is -- copied from s-memory.ads type size_t is mod 2 ** Standard'Address_Size ; package S_IO is new Ada.Text_IO.Modular_IO ( size_t ) ; Stack_Monitor : size_t ; -- linked to s-memory.adb pragma Import ( Ada, Stack_Monitor, "Alloc_Stack_Value" ) ; type integer_access is access all integer ; type float_access is access all float ; A : Integer_access ; B : float_access ; begin Put ( "Before create Integer := " ) ; S_IO.Put ( Stack_Monitor ) ; A := new Integer ; Put ( " after create operation := " ) ; S_IO.Put ( Stack_Monitor ) ; New_Line ; -- Put ( "Before create Float := " ) ; S_IO.Put ( Stack_Monitor ) ; B := new Float ; Put ( " after create operation := " ) ; S_IO.Put ( Stack_Monitor ) ; New_Line ; end ; 8: Compile test. The compiler will use the newer version of System.Memory package when linking. gnat make test.adb 9. Run Test program. test In , andi.vontobel@gmx.ch writes: >Hi. > >Is it possible to figure out how much of the stack is used at a >specific moment? >-> Ada95 Crosscompiler to PPC >(It is a little bit hard to optimize the stacksize ...) > >Thanks, >Andy