Function supposedly in multiple locations

Ian Lance Taylor iant@google.com
Tue Apr 3 05:29:00 GMT 2012


Amittai Aviram <amittai.aviram.0@gmail.com> writes:

> I am using GDB to debug a C program I compiled with GCC 4.6.2.  My program has a function called "foo."  When I insert a breakpoint at foo, GDB reports "2 locations."  On "info break," GDB shows that the two locations are two instruction lines but the same source code line.  When I look at the objdump disassembly of my program, I see that the first of the two locations is the first instruction in foo, while the second instruction is simply another instruction further down in foo.  Why am I seeing this?  I'm presuming that GCC with the -g flag must have inserted two entries for foo, one at its beginning and one at its 23rd instruction 80 bytes later.  If that is correct, why would GDB do this?  Thanks!

This is normal behaviour when optimizing.  Statements are often
implemented by non-adjacent instructions.  It's rarely clear what the
best debugging behaviour is in such a case.  GCC normally will annotate
each instruction with the source line that it corresponds to.  I guess
your version of GDB will set breakpoints on each instruction annotated
that way.

Ian



More information about the Gcc-help mailing list