public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug breakpoints/26096] New: gdb sets breakpoint at cold clone
@ 2020-06-09 10:57 vries at gcc dot gnu.org
  2020-06-09 13:17 ` [Bug breakpoints/26096] " vries at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: vries at gcc dot gnu.org @ 2020-06-09 10:57 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26096

            Bug ID: 26096
           Summary: gdb sets breakpoint at cold clone
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: breakpoints
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Consider test-case test.c:
...
$ cat test.c
#include <stdlib.h>

int a;
int b;
int c;

static int __attribute__((used, noinline, noclone))
foo (void)
{
  a = 2;
  if (b)
    abort ();

  return c;
}

static int __attribute__((used, noinline, noclone))
bar (void)
{
  a = 1;
  if (c)
    abort ();
  return b;
}

int
main (int argc, char **)
{
  b = argc * 2;
  c = argc / 2;

  if (b + c == 5)
    abort ();

  return foo () + bar ();
}
...

Compiled with gcc-10:
...
$ g++-10 test.c -O2 -g  -Wall -Wextra
...

The functions foo and bar get split into a hot and cold part by gcc's
freorder-blocks-and-partition:
...
$ nm a.out | c++filt | egrep "foo|bar"
00000000004005b0 t bar()
0000000000400455 t bar() [clone .cold]
0000000000400580 t foo()
0000000000400450 t foo() [clone .cold]
...

When we set breakpoints on foo and bar however, we get two breakpoint locations
per function:
...
$ gdb -batch a.out -ex "b foo" -ex "b bar" -ex "info break"
Breakpoint 1 at 0x400450: foo. (2 locations)
Breakpoint 2 at 0x400455: bar. (2 locations)
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   <MULTIPLE>         
1.1                         y   0x0000000000400450 in foo() at test.c:12
1.2                         y   0x0000000000400580 in foo() at test.c:10
2       breakpoint     keep y   <MULTIPLE>         
2.1                         y   0x0000000000400455 in bar() at test.c:22
2.2                         y   0x00000000004005b0 in bar() at test.c:20
...

So, the cold part of the function gets its own breakpoint.

In other words, we have:
...
$ gdb -q a.out
Reading symbols from a.out...
(gdb) b foo
Breakpoint 1 at 0x400450: foo. (2 locations)
(gdb) r
Starting program: /home/vries/a.out 

Breakpoint 1, foo () at test.c:10
10        a = 2;
(gdb) c
Continuing.

Breakpoint 1, foo () at test.c:12
12          abort ();
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2021-06-01 14:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-09 10:57 [Bug breakpoints/26096] New: gdb sets breakpoint at cold clone vries at gcc dot gnu.org
2020-06-09 13:17 ` [Bug breakpoints/26096] " vries at gcc dot gnu.org
2020-06-09 14:23 ` vries at gcc dot gnu.org
2021-05-29 10:38 ` vries at gcc dot gnu.org
2021-05-31 14:16 ` vries at gcc dot gnu.org
2021-05-31 14:35 ` vries at gcc dot gnu.org
2021-05-31 17:06 ` bernd.edlinger at hotmail dot de
2021-06-01 13:25 ` cvs-commit at gcc dot gnu.org
2021-06-01 13:33 ` vries at gcc dot gnu.org
2021-06-01 13:33 ` vries at gcc dot gnu.org
2021-06-01 14:14 ` bernd.edlinger at hotmail dot de

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