Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Paul Smith via Gdb <gdb@sourceware.org>
To: gdb@sourceware.org
Subject: GDB 13.2: breakpoint at wrong line after unrelated change
Date: Mon, 11 Mar 2024 14:28:43 -0400	[thread overview]
Message-ID: <7c064cc544bfe453a250ca58b4d5ebd97919178d.camel@gnu.org> (raw)

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.?

             reply	other threads:[~2024-03-11 18:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-11 18:28 Paul Smith via Gdb [this message]
2024-03-11 19:14 ` Simon Marchi via Gdb
2024-03-11 19:38   ` Paul Smith via Gdb
2024-03-11 19:50     ` Simon Marchi via Gdb
2024-03-11 20:17       ` Paul Smith via Gdb
2024-03-15 21:11       ` Paul Smith via Gdb
2024-03-15 22:19         ` Paul Smith via Gdb
2024-03-16 16:33           ` Simon Marchi via Gdb
2024-03-16 19:57             ` Paul Smith via Gdb

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7c064cc544bfe453a250ca58b4d5ebd97919178d.camel@gnu.org \
    --to=gdb@sourceware.org \
    --cc=psmith@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox