Operating System - HP-UX
1755916 Members
3502 Online
108839 Solutions
New Discussion юеВ

Re: stack pointer values using uxw - show strange behaviour

 
SOLVED
Go to solution
Dennis Handly
Acclaimed Contributor
Solution

Re: stack pointer values using uxw - show strange behaviour

>Is there direct way to know if the frame resides on the register stack or memory stack?

You are asking the wrong question.
Every function (context) has both a memory stack and a register stack. With the memory stack possibly being of size 0.
Adarsh Thampan
Advisor

Re: stack pointer values using uxw - show strange behaviour

So how am I going to find my framesize and SP value for each frame in the stack for HP itanium.

In Linux and Solaris I just had a memory stack to worry about and I could just has to use the SP and framesize value.

I am sure there is a way since the gdb on Itanoium does display the backtrace , along with the stackpointer values for each frame in the stack . I just need to do the same.

Re: stack pointer values using uxw - show strange behaviour

as dennis suggested above, the test case you have, cannot show the difference in stack pointer. even gdb does not show that. what gdb shows in 'bt' command is the IP. if you want to see the difference in SP, add alloca(3C) to each of your calls or have more than 8 parameters being passed to the function calls, etc. you can see the difference.

difference in stack pointer is seen when the memory stack size is non zero. or else you can see only BSP changing.

looks like gdb uses other mechanisms to get the frame size. it is not a simple arithmetic based on register values between contexts.
Dennis Handly
Acclaimed Contributor

Re: stack pointer values using uxw - show strange behaviour

>how am I going to find my framesize and SP value for each frame?

Your program already knows how to find the SP value. In your other thread I told you how to compute the framesize:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1407123

>along with the SP values for each frame in the stack.

Yes, "info frame" will do that for the current frame.

>Suprateeka: cannot show the difference in stack pointer.

Sure you can. The difference is 0.

>add alloca(3C) to each of your calls or have more than 8 parameters being passed to the function calls, etc.

Why work that hard? If you want a non-zero sized frame, have some local variables, that you use:
char buf[1024 * 1024];

>looks like gdb uses other mechanisms to get the frame size. it is not a simple arithmetic based on register values between contexts.

Sure it is that simple. The "other" method is only needed if you want to distinguish between the fixed size frame and an any alloca(3) parts.
Adarsh Thampan
Advisor

Re: stack pointer values using uxw - show strange behaviour

Hi ,

I have attached teh sample program that prints out framesize usng both SP and BSP for memory stack and register stack coresspondingly.

I have observed the following:-

1> Using SP the framesize is mostly 0, even if I use some local variables.

2> Using BSP I seem to get some correct values of framesize.


Can I always use BSP to get the framesize for any function in my code. In case not , please explain why ?


I am unclear about the fact that under what circumstances does a function use

1. only register stack
2. only memory stack ( I am not sure whether this is possible in Itanium).
3. Both register and memory stack.


P.S - My program need is to use 32 bit binaries only.

Re: stack pointer values using uxw - show strange behaviour

> 1> Using SP the framesize is mostly 0, even if I use some local variables.

you are just declaring the buffers. you have to use it in your code or the compiler may optimize it away.

> I am unclear about the fact that under what circumstances does a function use
1. only register stack
2. only memory stack ( I am not sure whether this is possible in Itanium).
3. Both register and memory stack.

as far as i know, its always both register and memory stack. and for trivial functions, the memory stack is of zero size.

Re: stack pointer values using uxw - show strange behaviour

> Can I always use BSP to get the framesize for any function in my code. In case not , please explain why ?

no. it is because a function may also have memory stack size which is not reflected by bsp values. you have to consider both sp and bsp.
Dennis Handly
Acclaimed Contributor

Re: stack pointer values using uxw - show strange behaviour

>that prints out framesize usng both SP and BSP
>framesize=psp-sp;

This should be reversed.

>%d for function %s \n",

You should not print a space before the newline.

>if I use some local variables.

As I cautioned you, you have to really use them, not just define them.

>2> Using BSP I seem to get some correct values of framesize.

You wouldn't know if this was correct until you looked at the machine code.

>Can I always use BSP to get the framesize for any function in my code.

Of course not. There are two stack "frames" and you must have two sizes.

>I am unclear about the fact that under what circumstances does a function use
>1. only register stack
>2. only memory stack
>3. Both register and memory stack.

You should assume it always uses both. As I said, they can have zero size.

>Suprateeka: you have to consider both sp and bsp.

Right. There is no need to special case a zero size. Zero is a valid size.
Dennis Handly
Acclaimed Contributor

Re: stack pointer values using uxw - show strange behaviour

Attached is your original test case modified to print framesize and other variables on the same line.