[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libunwind] Some basic questions about libunwind

From: Archie Cobbs
Subject: Re: [libunwind] Some basic questions about libunwind
Date: Mon, 06 Dec 2004 16:37:47 -0600
User-agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.3) Gecko/20041129

David Mosberger wrote:
> Close, but no cigar: libunwind will restore the preserved registers,
> but in general they won't have the same contents as of at the time of
> the call to setjmp().  Consider something along the lines of:
> bar() {
>   longjmp(&jbuf);
> }
> foo() {
>   if (setjmp(&jbuf))
>     ...;
>   do some other stuff...;
>   bar();
> }
> With the libunwind-based longjmp(), the preserved registers will be
> restored as of the point at which bar() was called.  Fortunately, the
> C standard allows for this.  Unfortunately, it still means that
> variables allocated in registers will get clobbered by the longjmp(),
> though the clobbering is somewhat controlled.

Do I have something backwards then? My longjmp(3) man page says:

   All accessible objects have values as of the time longjmp() routine was
   called, except that the values of objects of automatic storage invocation
   duration that do not have the volatile type and have been changed between
   the setjmp() invocation and longjmp() call are indeterminate.

Thus "clobbering" happens when a variable is stored in a register, that
register is saved by setjmp(), then the register is changed, then longjmp()
restores the register back to its old value, where old = when setjmp() was

It seems like with libunwind's longjmp(), variables in registers would
always be restored to the values they had when longjmp() is called,
because you can never pluck an "old" value off the stack (i.e., the
register values are never stored in more than one place).



      int x = 1;
      x = 2;
      printf("%d\n", x);

With normal setjmp(), the standard allows anything to be printed
(but probably "1" will be printed). With libunwind, it seems that
"2" would always be printed -- i.e., the variable is never "clobbered".


Archie Cobbs      *        CTO, Awarix        *

Confidentiality Notice: This e-mail message, including any attachments, is for 
the sole use of the intended recipient(s) and may contain confidential and 
privileged information. Any unauthorized review, use, disclosure or 
distribution is prohibited. If you are not the intended
recipient, please contact the sender by reply e-mail and destroy all copies of 
the original message.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]