Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

__builtin_frame_address()



Is __builtin_frame_address() broken? I have some backtracing code that walks the stack essentially using:

struct Frame
{
    struct Frame *sp;
    long cr;
    void *lr;
};

register void *r1 __asm__("r1");
Frame *frame = (Frame *)r1;

while (frame)
{
    if (frame->lr)
        /* Do something with the return address */
    frame = frame->sp;
}

It seems to me that I could remove the register void *r1 __asm__ ("r1"); and change r1 in the next line to __builtin_frame_address(0); but this doesn't seem to work. The value returned is completely bizarre.

If it makes any difference, I am doing this in c++.

On a slightly related note, the first few values that frame->lr holds are in unrelated functions that are not on the stack at the time. This is new in gcc 4. Prior versions seemed to provide sane addresses. After the first few functions, the stack seems correct.

- Steve

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.