0

I am working on Ubuntu 14.04 LTS.

I have an executable file exec compiled from file.c. The file.c makes use of functions from a static library. For example, let's says that fubar() is a function of the static library that is used in file.c. This is something that I have noticed.

  • nm exec | grep fubar gives a certain value.
    (on my system and for my executable, 0808377f)
  • gdb ./exec and then break fubar gives a different value.
    (on my system and for my executable, 0x8083785)

When I do a similar thing for another executable file (exec1 compiled from file1.c, it outputs the same value for both the commands).

Both the commands are supposed to output the same virtual address. Aren't they? I am obviously missing something. Can someone explain what exactly is happening? And what is the difference between both the commands.

progammer
  • 1,951
  • 11
  • 28
  • 50

1 Answers1

2

Barring unusual things like -fPIE, what is going on here is that the gdb command break function actually means "break after the function prologue for function". This way, arguments are set up properly by the time the breakpoint is hit.

If you want to break exactly at the first instruction of a function, use the * syntax, like:

(gdb) break *function

If you do this the addresses will probably match.

Tom Tromey
  • 21,507
  • 2
  • 45
  • 63