Operating System - HP-UX
1752604 Members
4638 Online
108788 Solutions
New Discussion юеВ

Stack Unwinding - Register values

 
SOLVED
Go to solution

Stack Unwinding - Register values

Hi,
I am working on stack unwinding and need to get the values of registers for each frame. When i tried a sample program to get the registers for each frame, i observed that the register values(i am getting 20 GRs) are same for all the frames. Can you please help me to get the Register values for each frame in a stack. PFA my sample program.

Suchitra
10 REPLIES 10

Re: Stack Unwinding - Register values

first of all, not all registers are guaranteed to be preserved across calls. only preserved registers will be restored across contexts. see itanium runtime architecture for more details on these registers. also manpages uc_access(3) and uwx_get_reg(3X) may be useful to you.

secondly, your program is not complicated enough to get these preserved registers value changing. only scratch registers may change.

Re: Stack Unwinding - Register values

Hi,
I saw in the Itanium Architecture document that General registers r4-r7 are preserved registers and tried printing those with
uwx_get_reg(env,UWX_REG_GR(x),┬о) function. I am getting the same values for all the frames for these registers. However when i tried printing 32,33,34,40 i could see some changes in the values. I have attached my code. Also when i used __uc_get_grs() function to get the register values in an array,i am getting all 0 values. I am getting the context as 0 and return value of __uc_get_grs() as 22.
Thanks,
Suchitra

Re: Stack Unwinding - Register values

I am working on stack unwinding and want to print the values of registers for each frames in the stack when any exception happens. Ideally which all register values i need to print ?
Dennis Handly
Acclaimed Contributor

Re: Stack Unwinding - Register values

>I observed that the register values are same for all the frames.

You should not be calling getcontext(2). The proper unwind function is uwx_get_reg(3).

>I am getting the same values for all the frames for these registers.

Because the compiler absolutely doesn't want to use those callee save registers.

>when I used __uc_get_grs() function to get the register values in an array

Again, don't use uc_access(3) with unwind.

>Ideally which all register values I need to print?

What are you going to do with them? It may be better to get a core file and then use a debugger on it.
Otherwise you need to print all of them.

Re: Stack Unwinding - Register values

Hi,
I have tried with unwind libraries and done some changes in the code. Now i am getting a value for the context and getting values for registers(Gr 30 - 50) which are different for each functions. Please let me know whether the approach i have taken is correct or not.
Thanks

Re: Stack Unwinding - Register values

>What are you going to do with them?

i want to print the registers at failure when any exception happens.
Dennis Handly
Acclaimed Contributor

Re: Stack Unwinding - Register values

>I am getting a value for the context and getting values for registers (GR30 - 50) which are different for each functions. Please let me know whether the approach I have taken is correct or not.

You should NOT be using the old unwind lib. Only use the uwx functions.

See attached.
You should also use the CFM register to figure out how many stacked registers there are and not use all 128.

Re: Stack Unwinding - Register values

Hi,
I want to print the values og General registers from 1 to 13 and the following Application registers:

_UNW_AR_RSC, _UNW_AR_BSP, _UNW_AR_BSPSTORE, _UNW_AR_RNAT, _UNW_AR_CCV, _UNW_AR_UNAT, _UNW_AR_FPSR, _UNW_AR_ITC, _UNW_AR_PFS, _UNW_AR_LC, _UNW_AR_EC, and _UNW_AR_LIST_COUNT

When i tried printing the GRs from 1-13 using the function you sent, its throwin g error as Bad uwx status = -9. How can i achieve my goal?

I was using the following code snippet to print the above mentioned values using the unwind libraries.

for(i=1;i<=13;i++) // General Registers 1-13
{
GRegs[j++] = _UNW_getGR(&pCtx->uc,i);
}
j=0;
// Application Registers
ARegs[j++] = _UNW_getAR(&pCtx->uc,_UNW_AR_FPSR);
ARegs[j++] = _UNW_getAR(&pCtx->uc,_UNW_AR_RNAT);
ARegs[j++] = _UNW_getAR(&pCtx->uc,_UNW_AR_UNAT);
ARegs[j++] = _UNW_getAR(&pCtx->uc,_UNW_AR_PFS);
ARegs[j++] = _UNW_getAR(&pCtx->uc,_UNW_AR_BSP);
ARegs[j++] = _UNW_getAR(&pCtx->uc,_UNW_AR_BSPSTORE);
ARegs[j++] = _UNW_getAR(&pCtx->uc,_UNW_AR_RSC);
ARegs[j++] = _UNW_getAR(&pCtx->uc,_UNW_AR_LC);
ARegs[j++] = _UNW_getAR(&pCtx->uc,_UNW_AR_EC);
ARegs[j++] = _UNW_getAR(&pCtx->uc,_UNW_AR_CCV);
ARegs[j++] = _UNW_getAR(&pCtx->uc,_UNW_AR_ITC);

Dennis Handly
Acclaimed Contributor
Solution

Re: Stack Unwinding - Register values

>I want to print the values of General registers from 1 to 13 and the following Application registers:

You can't get all of these, (only r4-r7). You can only do that for the top frame or any with a signal context. And you'll need to use your original getcontext(2) at the top.
In other frames, you can't get the correct values, so don't even try.
And if you do call getcontext(2) this may destroy those registers you want to print.

>it's throwing error as Bad uwx status = -9. How can I achieve my goal?

You got that too. :-)

>I was using the following code snippet to print the above mentioned values using the unwind libraries.

No, you are using the obsolete unwind routines, don't be caught dead using them.