4
#include <stdio.h>

int main(void){
   int sum = 0;
   sum += 0xabcd;
   printf(“%x”, sum);
   return 0;
}

This is my code and when I use gdb I can find different address when break main / break *main.

When I just type disassemble main it shows like this:

Dump of assembler code for function main:

0x080483c4 <+0>: push %ebp
0x080483c5 <+1>: mov %esp,%ebp
0x080483c7 <+3>: and $0xfffffff0,%esp
0x080483ca <+6>: sub $0x20,%esp
0x080483cd <+9>: movl $0x0,0x1c(%esp)
0x080483d5 <+17>:addl $0xabcd,0x1c(%esp)
0x080483dd <+25>:mov $0x80484c0,%eax
0x080483e2 <+30>:mov 0x1c(%esp),%edx
0x080483e6 <+34>:mov %edx,0x4(%esp)
0x080483ea <+38>:mov %eax,(%esp)
0x080483ed <+41>:call 0x80482f4 <printf@plt>
0x080483f2 <+46>:mov $0x0,%eax
0x080483f7 <+51>:leave
0x080483f8 <+52>:ret

End of assembler dump.

So when I type [break *main] it starts 0x080483c4 but type [break main] it start 0x080483cd

Why is start address is different?

2 Answers 2

5

Why is the address different.

Because break function and break *address are not the same thing(*address specifies the address of the function's first instruction, before the stack frame and arguments have been set up).

In the first case, GDB skips function prolog (setting up the current frame).

Sign up to request clarification or add additional context in comments.

Comments

0

Total guess - and prepared to be totally wrong.

*main if address of the function

Breaking inside main is the first available address to stop inside the function when it is being executed.

Note that 0x080483cd is the first place a debugger can stop as it is modifying a variable (ie assigning zero to sum)

When you are breaking at 0x080483c4 this is before the setup assembler that C knows nothing about

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.