Operating System - HP-UX
1832106 Members
3138 Online
110038 Solutions
New Discussion

Re: Frame size calculation

 
SOLVED
Go to solution

Freame size calculation

Hi,
I am working on Stack unwinding on HP Itanium and wrt a recent thread on calculating the Frame size(http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1410703) i was trying to calculate the frame size with Stack pointer and Prev Stack pointer, and with BSP and Prev BSP values. PFA my sample code. When i print the values for Frame size with Memory stack, and when i debug(using wdb) the values showed for Size of Frame in 'frame info' command looks different. Why is this so. For eg : For frame 2 i am getting the frame size as 20 from the gdb and in my program i get as 64.
Thanks
6 REPLIES 6
Dennis Handly
Acclaimed Contributor

Re: Frame size calculation

>values showed for Size of Frame in 'frame info' command looks different. For frame 2, I am getting the frame size as 20 from the gdb and in my program I get as 64.

The values from "info frame" are register frame, in registers. The values for memory frame are always a multiple of 16 bytes.

Re: Freame size calculation

Hi,
The value shown in Info frame and the frame size calculated by getting the difference of BSP for current frame and previous frame also lpoks differnt. For eg: For frame 4 the value shown in wdb Info frame is 5 and that using the program i sent is 24.

And what exactly is the frame size. I get different values in Wdb, the calulation of frame size using SP and PSP and the calculation using BSP and previous BSP. Which among this is the actual one ?

Dennis Handly
Acclaimed Contributor

Re: Frame size calculation

>The value shown in info frame and the frame size calculated by getting the difference of BSP for current frame and previous frame also looks different.

Several reasons. The value gdb uses is based on the CFM register and is the number of registers.
The value you compute is the size of the previous register frame. And every 63 registers, contains a NaT register.

>And what exactly is the frame size?

There are two frames. To keep it simple, you should only print out the memory frame size. If you want to print out the number of registers in the register frame, you can do that too but they are separate.

You have several coding style problems with your source.
You are going off the right by indentation. Instead you should use gotos, return or break to limit the indent.

You are using evil prespacing, Fortran carriage control or COBOL AFTER ADVANCING. This doesn't belong with C.
I.e. Don't use "\n" at the start of your formats, only if you don't know what has been output before.

Attached is where I have rewritten everything to use CFM register.

Ret add is 60000000c00269f0
IP is 40032c0 Current function name is: main
Sp = 200000007fffed70 PSp = 200000007fffed70
Memory Frame size = 0
BSP = 200000007fffed70 CFM = c000000000000103
Reg Frame size = 24

Re: Freame size calculation

Thanks Dennis.
Now also when i run and check the frame size in gdb and the one you calculated using CFM, they are different.

For a frame where memory stack frame size is 0, can we take register frame size as the frame size ? (BSP-prev BSP or the one calculated using CFM) ?
Dennis Handly
Acclaimed Contributor
Solution

Re: Frame size calculation

>when I run and check the frame size in gdb and the one you calculated using CFM, they are different.

Well, 8 times bigger since I converted it to bytes.

>For a frame where memory stack frame size is 0, can we take register frame size as the frame size?

The memory frame size is the memory frame size. Zero is a valid value, don't be scared. :-)

Dennis Handly
Acclaimed Contributor

Re: Frame size calculation

FYI, a colleague noticed you have a bounds error in foo3, your buf isn't large enough for the strcpy.
Compiling with +wlint shows the error right away:
procedure foo3: warning #20206-D: Possible out of bound access (In expression "strcpy((char*)buf, (const char*))", variable "buf" (type: char [32]) has byte range [0 .. 31], writing byte range [0 .. 33].)