Is this always the address for the GDB debugging program?

I will limit my questions:

The write address in GDB remains the same for the same program (even after rebooting and after overwriting the source code).

Why is this?

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) β”‚ β”‚0x8048408 <main()+20> mov $0x0,%eax β”‚ β”‚0x804840d <main()+25> leave β”‚ β”‚0x804840e <main()+26> ret 

In addition, the value that we get, 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 tell me? I'm interested in the values ​​before and after each assignment (say c = a + b later), without using breakpoints to jump one line at a time.

Source:

 int main() { int b = 3; int a = 3; return 0; } 

Can someone explain this to me? Thank you (I would also mark this as homework, although this is actually not the case.)

0
source share
2 answers

For example, 0x80483f4 is the starting address.

Probably. If you do not have PIE (position-independent executables), it will remain unchanged (for a single binary file) forever.

 $2 = 0x80483fa <main()+6> (gdb) x $2 0x80483fa <main()+6>: 0x3fc45c7 

This is a binary representation of the instructions in main()+6 . Will not change in one binary.

 (gdb) p 0x3fc45c7 $3 = 66864583 <-- even after reboot. 

This means that 0x3fc45c7 is 66864583 in decimal ...

Note that none of this has anything to do with a or b .

BTW is the best way to get the values ​​of variables "before destination" before printf before destination.

+2
source

Your program is (at least partially) statically linked, and main() almost certain. Rebooting the computer will not change the statically linked part of the executable.

0
source

Source: https://habr.com/ru/post/899019/


All Articles