From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (qmail 13361 invoked from network); 17 Dec 1999 17:50:37 -0000 Received: from mail.redhat.com (199.183.24.239) by lists.redhat.com with SMTP; 17 Dec 1999 17:50:37 -0000 Received: from mailext04.compaq.com (mailext04.compaq.com [207.18.199.42]) by mail.redhat.com (8.8.7/8.8.7) with ESMTP id MAA14826 for ; Fri, 17 Dec 1999 12:50:36 -0500 Received: by mailext04.compaq.com (Postfix, from userid 12345) id AA797104C0F; Fri, 17 Dec 1999 11:50:35 -0600 (CST) Received: from mailint02.im.hou.compaq.com (mailint02.compaq.com [207.18.199.35]) by mailext04.compaq.com (Postfix) with ESMTP id A6822FB101 for ; Fri, 17 Dec 1999 11:50:35 -0600 (CST) Received: by mailint02.im.hou.compaq.com (Postfix, from userid 12345) id 5A0D2BC4D1; Fri, 17 Dec 1999 11:50:28 -0600 (CST) Received: from pdgsrv.mro.dec.com (pdgsrv.mro.dec.com [16.34.112.86]) by mailint02.im.hou.compaq.com (Postfix) with ESMTP id 0D3FAB2A42 for ; Fri, 17 Dec 1999 11:50:28 -0600 (CST) Received: from linux08.mro.dec.com by pdgsrv.mro.dec.com; (8.8.8/1.1.8.2/13Dec96-1209PM) id MAA06775; Fri, 17 Dec 1999 12:50:29 -0500 (EST) Received: from linux08.mro.dec.com (localhost [127.0.0.1]) by linux08.mro.dec.com (8.9.3/8.9.3) with ESMTP id MAA24382 for ; Fri, 17 Dec 1999 12:51:20 -0500 Message-Id: <199912171751.MAA24382@linux08.mro.dec.com> To: axp-list@redhat.com Subject: Re: Retrieving PC from (traversing) the stack on Alpha In-reply-to: Your message of Sun, 19 Dec 1999 09:41:06 -0700. Reply-To: Joseph.Martin@Compaq.com Date: Fri, 17 Dec 1999 12:51:20 -0500 From: "Joseph A. Martin" >Okay, after some research, I think I figured out how to get at the needed >Alpha registers: > >register unsigned long fptr __asm__("$15"); /* get frame pointer? */ >register unsigned long sptr __asm__("$30"); /* get stack pointer? */ If there is a frame pointer, that's how you'd find it. However, there often isn't. It depends on the compiler, and it depends on whether there are references to some outer scope or perhaps arguments passed on the stack. (I may be thinking of SPARC here, so don't take me too seriously about the argument thing.) More often than not there is no frame pointer and integer register 15 is treated as "s6" not "fp". To find the size of the (previous/next higher) stack frame: /* Warning: untested, uncompiled code fragment */ typdef unsigned int instruction; /* * Of course, assembly code writers and compilers I haven't seen may * thwart this heuristic. */ #define is_lda_of_neg_from_30_to_30(X) (((X) & 0xffff8000) == 0x23de8000) /* This one assumes that the low 3 bits of the literal are zero. */ #define is_stack_subq(X) (((X) & 0xffe0ffff) == 0x43c0153e) void stack_crawler(void) { register unsigned long ra __asm__("$26"); register unsigned long sp __asm__("$30"); int frame_size; instruction * instr = (instruction *)ra; /* Look for certain kinds of instructions. */ for(;;) { --instr; if (is_lda_of_neg_from_30_to_30(*instr)) { frame_size = 0x10000 - (*instr & 0xffff); break; } if (is_stack_subq(*instr)) { frame_size = (*instr >> 13) & 0xff; break; } } /* *To tell which regs are stored where, travel forward looking * for STQs onto the stack. */ } \Joe [Joseph.Martin@Compaq.com Joseph A. Martin Compaq Computer Corporation 200 Forest Street MRO1-2/K20 (508) 467-2100 Marlboro, MA 01752 U.S.A. ]