Bug 24602 - [gdb] gdb wrongly stopped at a breakpoint in an unexecuted line of code
Summary: [gdb] gdb wrongly stopped at a breakpoint in an unexecuted line of code
Status: RESOLVED NOTABUG
Alias: None
Product: gdb
Classification: Unclassified
Component: symtab (show other bugs)
Version: HEAD
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-22 14:53 UTC by Anonymous
Modified: 2022-05-29 09:09 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anonymous 2019-05-22 14:53:04 UTC
$ gcc --version
gcc (GCC) 10.0.0 20190517 (experimental)
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gdb --version
GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 

$ cat small.c
#include <stdio.h>

int main(int argc, char **argv)
{
  if (argc == 0)
  {
    int *ptr;
    label:
      {
      }
  }
  if (argc == 1)
  {
     printf("hello\n");
  }
  return 0;
}

$ gcc -g small.c; ./a.out
hello

$ gdb -batch -x cmds a.out
Breakpoint 1 at 0x400501: file small.c, line 8.

Breakpoint 1, main (argc=1, argv=0x7fffffffde58) at small.c:8
8	    label:
ptr = <optimized out>
Kill the program being debugged? (y or n) [answered Y; input not from terminal]


$ cat cmds
b 8
r
info locals
kill
q


Line 8 in the body of the "if (argc==0)" is not executed according to the program output. 

Thus, when we set breakpoint in Line #8, gdb should not stop. However, in this case, it stopped and print something. Thus, I was wondering this should be a bug in gdb.
Comment 1 Anonymous 2020-01-17 01:48:21 UTC
This problem is still exist in latest development version of gdb

$ gdb -v
GNU gdb (GDB) 9.0.50.20191210-git
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ gdb ./a.out -q
Reading symbols from ./a.out...
(gdb) break 8
Breakpoint 1 at 0x1148: file small.c, line 8.
(gdb) run
Starting program: /home/yibiao/tgdb/a.out 

Breakpoint 1, main (argc=1, argv=0x7fffffffe008) at small.c:8
8	    label:
(gdb)
Comment 2 Anonymous 2020-12-27 01:30:08 UTC
This problem is no longer exist in latest development version of gdb

$ gdb --version
GNU gdb (GDB) 11.0.50.20201224-git
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Comment 3 Anonymous 2022-05-29 02:23:34 UTC
Not sure whether this one is fixed in the latest version.
Comment 4 Tom de Vries 2022-05-29 09:09:28 UTC
You're probably looking at a bug in debug info generation.

I can reproduce this with gcc 9.3.1, and not anymore with gcc 10.3.0.

GDB just reads the line info as generated by the compiler and uses it, I don't see anything wrong with what GDB does.