Unable to change the values of $ebp and $eip

Kalpana Ramamurthy kal_pana@hotmail.com
Wed Apr 25 09:39:00 GMT 2007


I have some macros which I want to source within gdb to print the backtrace 
of all the threads I have in my system. So the macro essentially tries to 
switch to each thread and prints its backtrace. This it does by extracting 
the stack pointer which is stored in the thread structure. The back pointer 
and instruction pointer addresses are computed and then the bactrace is 
printed.

The threads are linked by a linked list. Access the address of the next 
thread following the next pointer.

Assuming I am in frame 0 of current thread, the macro does the following :

- Load the core dump file in gdb and then do the following :

- For all threads in the system do this for each thread..

(gdb) set $thr=$thr->next_p
(gdb) set $sp=$thr->obj->registers.stackpointer
(gdb) set $ebp=*(int *)($sp+8)
(gdb) set $ebp= *(int *)($sp + 36)
(gdb) bt

When I start execution of this macro from frame 0 of the first thread, the 
macro executes correctly
and prints the backtrace of all the threads in the system.

Now I exit gdb and restart it again by loading the core file as done above. 
I first switch to another
frame - say frame 3. Then I start execution of the macro. When I do that, I 
am able to extract
the value of $sp correctly. But gdb does not allow me to set $eip and $ebp. 
The macro fails. For every thread in the system, the 1st thread's backtrace 
is printed. Basically I get a same backtrace for every thread in the system. 
When I check $ebp and $eip everytime I extract a new $sp and try to set $ebp 
and $eip, the values set for $ebp and $eip are what it was for the current 
thread (the thread that caused a core).

Why does this happen ? Why am I not able to set/change values of $ebp and 
$eip in the macro after I switch to a non-zero frame (older frame) ? The 
macro works great when I start execution of it from frame 0.

Kalpana
====

_________________________________________________________________
Voice your questions and our experts will answer them 
http://content.msn.co.in/Lifestyle/AskExpert/Default01.htm



More information about the Gdb mailing list