This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hi, I've not a problem with gdb but I'm wondering how unwinding the stack for PA-RISC with HP-UX work (I want to write a backtrace function).It would be great if somebody can give me some advice and hints. The next lines show my function and the problem to go from the stack pointer to the old stack pointer and from the there to the stack pointer before ... ########################################################################### Example programm: #include <stdio.h> #include <iostream.h> void backtrace(); int main() { backtrace(); return 0; } void backtrace() { // At first I fetch the interesting registers ... // I'll write sp for stack pointer and fp for fp register long unsigned *plFp asm("r3"); // fp or old sp register long unsigned *plSp asm("r30"); // sp register long unsigned *r2 asm("r2"); // rp // To get the return pointer rp I could use r2 but I want to // walk from sp because I can't get r2 and rp of the functions that called // backtrace unsigned long *plStack, *saved_rp, *pc; saved_rp = (unsigned long*)((long)(plSp)- 4*5); // or // saved_rp = plSp - 5; // At http://devrsrc1.external.hp.com/STK/partner/rad_11_0_32.pdf // p. 72 I've read that at the position sp - 20 Byte // the saved rp can be fetched. This works. cout << "The adresses: saved_rp = " << saved_rp << ", plSp = " << plSp << endl; pc = (unsigned long*)(*saved_rp + 5); // cout << "r2 = " << r2 << " pc = " << pc << " *saved_rp = " << *saved_rp << endl; // But at the same page can be read that at sp - 4 the previous // sp can be fetched. Sadly that doesn't work ;( // Hmm, rad_11_0_32.pdf is written for HP-UX 11, maybe that's the // problem ? plStack = (unsigned long*)((long)(plSp) - 4); cout << "sp = " << plSp <<" fp = " << plFp << " plStack = " << plStack << endl << "*sp = " << *plSp <<" *fp = " << *plFp << " *plStack = " << *plStack << endl; // also the program shows *plSp != 1 gdb shows 1 here } ########################################################################### Program results: *************** The adresses: saved_rp = 0x7b03a7bc, plSp = 0x7b03a7d0 r2 = 0x6207 pc = 0x61e4 *saved_rp = 25183 sp = 0x7b03a7d0 fp = 0x7b03a750 plStack = 0x7b03a7cc *sp = 2063836880 *fp = 2063836944 *plStack = 0 or run in gdb The adresses: saved_rp = 0x7b03a7f4, plSp = 0x7b03a808 r2 = 0x6207 pc = 0x61e4 *saved_rp = 25183 sp = 0x7b03a808 fp = 0x7b03a788 plStack = 0x7b03a804 *sp = 2063836936 *fp = 2063837000 *plStack = 0 ########################################################################### In gdb: ******* (gdb) f #0 main () at backtrace_hp.cpp:8 8 backtrace() (gdb) i r sp sp 7b03a788 ... (gdb) f #0 backtrace () at backtrace_hp.cpp:25 25 saved_rp = (unsigned long*)((long)(plSp)- 4*5); // or // saved_rp = plSp - 5; (gdb) print plSp $1 = (long unsigned int *) 0x7b03a808 (gdb) print plFp $2 = (long unsigned int *) 0x7b03a788 (gdb) i r fp r3 7b03a788 (gdb) i r sp sp 7b03a808 (gdb) f #0 backtrace () at backtrace_hp.cpp:31 31 pc = (unsigned long*)(*saved_rp + 5); // (gdb) print *saved_rp $4 = 25055 (gdb) i r rp rp 61df => so far everything is ok (gdb) print plSp $2 = (long unsigned int *) 0x7b03a808 (gdb) print *plSp $1 = 1 Here *plSp should be 2063836936 or 0x7B03A708 But my real problem is that I don't find anything near the stackpointer that points to the old stackpointer and make a backtrace possible. ########################################################################## Does anybody now anything about the stack on PA-RISC (HP-UX 10.20) and where I can find information how to unwind the stack there (howto find/calculate the distance from the stack pointer to the frame pointer....?) What's the problem with sp-4 which is in my case != previous sp? My next step will probably be to study the sources of gdb but it would be great if anybody who knows anything about the stack problematic could help me. Thank you for any advice Roland
Attachment:
backtrace_hp.cpp
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |