Follow-up
Hmmm I am not sure if I am doing the right thing. Thanks for all the helps thus far.
My previous thread: Is this really the address
I am making new thread because this is really a separate problem, and the core problem.
Please bear with me, thank you.
Let me restate my goal:
I want to be able to look into the memory address of each variable (we know the entry address of the program, and we know how many bytes are set aside from reading the assembly code). Suppose we are given the following source code:
Source Code
int main()
{
int a = 15;
int b;
int c;
b = c;
c = c+1;
return 0;
}
We should be able to find out the address of variable a and c, and the values in these memory addresses.
Using gdb layout asm I get this
│0x80483f4 <main()> push %ebp │
│0x80483f5 <main()+1> mov %esp,%ebp │
│0x80483f7 <main()+3> sub $0x10,%esp │
│0x80483fa <main()+6> movl $0xf,-0x4(%ebp) │
│0x8048401 <main()+13> mov -0x8(%ebp),%eax │
│0x8048404 <main()+16> mov %eax,-0xc(%ebp) │
│0x8048407 <main()+19> addl $0x1,-0x8(%ebp) │
│0x804840b <main()+23> mov $0x0,%eax │
│0x8048410 <main()+28> leave │
│0x8048411 <main()+29> ret │
│0x8048412 nop
// the statement int a = 15 is in the address 0x80483fa
// I want to get the value 15
x/w 0x80483fd <== this will print 15
But it doesn't make sense to me because from what I recalled, the variables are supposed to be in ebp - 0x10 right?
// the starting address of the program is 0x80483f4
// minus 0x10 we get 0x80483E4
x/w 0x80483E4 <== will print a big number
// Since b = c, I should be able to get that as I decrement, but no luck
I don't think I know what I am doing...? On one hand, the automatic variables are destroyed as soon as the program terminates...
PS: I really can't use cout, or printf, or setting breakpoints or watcher while debugging.
So doing print $ebp will not work because there is no active register (remember the program terminates - no breakpoint!). So commands like info locals, info registers aren't available.
I have been spending the whole day trying to figure out what is going on. I really appreciate all the helps and I am looking forward to getting more. Thanks.
What should I do?? I need to look at the value of variable a, b, c. How can this be done?
Thank you very much.
Not really a homework, but a class discussion.