public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* GDB 13.2: breakpoint at wrong line after unrelated change
@ 2024-03-11 18:28 Paul Smith
  2024-03-11 19:14 ` Simon Marchi
  0 siblings, 1 reply; 9+ messages in thread
From: Paul Smith @ 2024-03-11 18:28 UTC (permalink / raw)
  To: gdb

Hi all;

I have an extremely odd error and I'm wondering if it rings any bells
with anyone.  If not I'll embark on an effort of upgrading my tools to
see if it's fixed in newer versions and if not trying to file a bug.

I have a C++ unit test program.  This is GNU/Linux 64bit compiled with
GCC 12.3 and I'm using GDB 13.2 to debug it.  The error happens
regardless of whether I compile with "-ggdb3 -O0" or with "-ggdb3 -O2".
I haven't tried other optimization levels.

In the current behavior, I can set a breakpoint at a function and GDB
will stop at the first line of the function; for example:

  class TestClass : public ... {
    ...
      void breakpointTest(TestData* data)
      {
          printf("obj = %p\n", data);
      }
    ...

If I run:

  (gdb) br TestClass::breakpointTest

  (gdb) run

then GDB will stop at the printf line, and the "data" variable is set
properly:

  Thread 1 "TestClass" hit Breakpoint 1, TestClass::breakpointTest
    (this=0x7ffff2a09a00, data=0x7ffff2aa7000) at TestClass.cpp:100
  100             printf("obj = %p\n", data);


Now if I make a change in my program in a completely different,
irrelevant spot (this change creates a new templated function that uses
Args... and perfect forwarding etc.: it's complex and uses the fmt
library, but it is not being used at all in this function, or even in
this class although it's used in a superclass), then after I do exactly
the same thing above, GDB will stop at the wrong location.  Instead of
stopping at line 100 at the first line of the function it stops
"before" the function is entered and the function arguments are not set
yet (in the example below note the values of "this" and "data" are
wrong).

I have noticed that if I only include the templated function definition
but don't call it, then the problem doesn't happen.  I have to use the
templated function somewhere in the translation unit, but it doesn't
have to be anywhere near the function.

In the failure case if I use "n" to go to the next line, THEN I get to
the first line in the function and everything is set properly.

Example:

  Thread 1 "TestClass" hit Breakpoint 1, TestClass::breakpointTest
    (this=0x0, data=0x21) at TestClass.cpp:98
  98         void breakpointTest(TestData* data)

  (gdb) n
  100             printf("obj = %p\n", txn);

  (gdb) fr
  #0  TestClass::breakpointTest (this=0x7ffff2a09a00, data=0x7ffff2aa7000)
    at TestClass.cpp:100
  100             printf("obj = %p\n", data);


Is anyone aware of any issue in GDB, or GCC, where using templated
functions with perfect forwarding or other complex C++ template
features could cause GDB's understanding of the starting line number of
functions to be miscalculated like this?

Is there a way for me to investigate what information GDB is looking at
to determine where to set breakpoints when given a symbol name like
this?  Is this the same info available via addr2line etc.?

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-03-16 19:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-11 18:28 GDB 13.2: breakpoint at wrong line after unrelated change Paul Smith
2024-03-11 19:14 ` Simon Marchi
2024-03-11 19:38   ` Paul Smith
2024-03-11 19:50     ` Simon Marchi
2024-03-11 20:17       ` Paul Smith
2024-03-15 21:11       ` Paul Smith
2024-03-15 22:19         ` Paul Smith
2024-03-16 16:33           ` Simon Marchi
2024-03-16 19:57             ` Paul Smith

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).