I will narrow down my questions:
The entry address in GDB stays the same for the same program (even after reboot, and after rewriting the source code).
Why is that?
For example 0x80483f4 is the starting address.
**0x80483f4** <main()> push %ebp │
│0x80483f5 <main()+1> mov %esp,%ebp │
│0x80483f7 <main()+3> sub $0x10,%esp │
│0x80483fa <main()+6> movl $0x3,-0x4(%ebp) │
│0x8048401 <main()+13> movl $0x3,-0x8(%ebp) │
开发者_StackOverflow│0x8048408 <main()+20> mov $0x0,%eax │
│0x804840d <main()+25> leave │
│0x804840e <main()+26> ret
Beside that, the value we get from, let say, 0x80483fa, is always the same.
$2 = 0x80483fa <main()+6>
(gdb) x $2
0x80483fa <main()+6>: 0x3fc45c7
(gdb) p 0x3fc45c7
$3 = 66864583 <-- even after reboot.
What does this suggest me?
I am interested in the values before and after each assignment (say c = a+b later), without using breakpoints to step through one line at a time.The source code:
int main()
{
int b = 3;
int a = 3;
return 0;
}
Can someone please explain this to me? Thanks. (I would also mark this as homework, although it really isn't.)
For example 0x80483f4 is the starting address.
This is likely. Unless you have PIE (position independent executables), it will stay the same (for one binary) forever.
$2 = 0x80483fa <main()+6> (gdb) x $2 0x80483fa <main()+6>: 0x3fc45c7
That is the binary representation of the instructions at main()+6
. Will never change in one binary.
(gdb) p 0x3fc45c7 $3 = 66864583 <-- even after reboot.
That means 0x3fc45c7 is 66864583 in decimal...
Note that none of this has anything to do with a
or b
.
BTW the best way to get values of variables "before assignment" is to printf
them before the assignment.
Your program is (at least partially) statically linked, and main()
almost certainly is. Rebooting your computer isn't going to change that statically linked part of the executable.
精彩评论