public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug breakpoints/27179] New: function call with complex switch-case will be skipped by gdb
@ 2021-01-13  5:54 yangyibiao at outlook dot com
  2021-01-13  5:54 ` [Bug breakpoints/27179] " yangyibiao at outlook dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: yangyibiao at outlook dot com @ 2021-01-13  5:54 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 27179
           Summary: function call with complex switch-case will be skipped
                    by gdb
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: breakpoints
          Assignee: unassigned at sourceware dot org
          Reporter: yangyibiao at outlook dot com
                CC: vries at gcc dot gnu.org
  Target Milestone: ---

Consider the following case:
------------------
$ cat small.c
#include <stdio.h>

void foo (int x, int y)
{
  switch (x) {
    case 0: break;
    case 1: break;
    case 2: break;
    case 3:
      for (int z = 0; z < ({ if (y) break; 5; }); z++)
          break;
    case 4: break;
        default: break;
  }
}

int main ()
{
  foo (1, 1);  // L1
  foo (2, 1);  // L2
  printf("hello world!");  // L3
  return 0;
}

--------------------

$ gcc -O0 -g small.c; gdb -q a.out
Reading symbols from a.out...
(gdb) start
Temporary breakpoint 1 at 0x11ac: file small.c, line 19.
Starting program: /home/yibiao/DeVIL/a.out 

Temporary breakpoint 1, main () at small.c:19
19        foo (1, 1);  // L1
(gdb) s
hello world![Inferior 1 (process 87566) exited normally]
(gdb) 


##########################3
L2 and L3 are both executed. However, we can found that L2 is skipped by gdb.
When stepping at instruction level or set breakpoints at L2, L2 will be hit by
gdb.
When examing the line table, L2 is indeed has debug info as follow:

(gdb) maint info line-table
objfile: /home/yibiao/DeVIL/a.out ((struct objfile *) 0x56479b754400)
compunit_symtab: ((struct compunit_symtab *) 0x56479b74bea0)
symtab: /home/yibiao/DeVIL/small.c ((struct symtab *) 0x56479b74bf20)
linetable: ((struct linetable *) 0x56479b795080):
INDEX  LINE   ADDRESS            IS-STMT 
0      4      0x0000555555555149 Y 
1      10     0x0000555555555181 Y 
2      10     0x0000555555555188 Y 
3      10     0x0000555555555189 Y 
4      12     0x0000555555555197 Y 
5      13     0x000055555555519a Y 
6      12     0x000055555555519d Y 
7      10     0x00005555555551a0 Y 
8      15     0x00005555555551a1 Y 
9      18     0x00005555555551a4 Y 
10     19     0x00005555555551ac Y 
11     20     0x00005555555551bb Y 
12     21     0x00005555555551ca Y 
13     22     0x00005555555551db Y 
14     23     0x00005555555551e0 Y 
15     END    0x00005555555551e2 Y 
(gdb) 



$ gcc --version; gdb --version
gcc (Ubuntu 10.2.0-5ubuntu1~20.04) 10.2.0
Copyright (C) 2020 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.

GNU gdb (GDB) 11.0.50.20210113-git
Copyright (C) 2021 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.

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

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

* [Bug breakpoints/27179] function call with complex switch-case will be skipped by gdb
  2021-01-13  5:54 [Bug breakpoints/27179] New: function call with complex switch-case will be skipped by gdb yangyibiao at outlook dot com
@ 2021-01-13  5:54 ` yangyibiao at outlook dot com
  2021-01-13  5:57 ` yangyibiao at outlook dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: yangyibiao at outlook dot com @ 2021-01-13  5:54 UTC (permalink / raw)
  To: gdb-prs

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

Yibiao Yang <yangyibiao at outlook dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yangyibiao at outlook dot com

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

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

* [Bug breakpoints/27179] function call with complex switch-case will be skipped by gdb
  2021-01-13  5:54 [Bug breakpoints/27179] New: function call with complex switch-case will be skipped by gdb yangyibiao at outlook dot com
  2021-01-13  5:54 ` [Bug breakpoints/27179] " yangyibiao at outlook dot com
@ 2021-01-13  5:57 ` yangyibiao at outlook dot com
  2021-01-13 10:30 ` [Bug breakpoints/27179] Handle stepping into function with broken line number info vries at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: yangyibiao at outlook dot com @ 2021-01-13  5:57 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #1 from Yibiao Yang <yangyibiao at outlook dot com> ---
This is produced in Ubuntu 20.04:
$ uname -a
Linux Lab 5.4.0-26-generic #30-Ubuntu SMP Mon Apr 20 16:58:30 UTC 2020 x86_64
x86_64 x86_64 GNU/Linux

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

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

* [Bug breakpoints/27179] Handle stepping into function with broken line number info
  2021-01-13  5:54 [Bug breakpoints/27179] New: function call with complex switch-case will be skipped by gdb yangyibiao at outlook dot com
  2021-01-13  5:54 ` [Bug breakpoints/27179] " yangyibiao at outlook dot com
  2021-01-13  5:57 ` yangyibiao at outlook dot com
@ 2021-01-13 10:30 ` vries at gcc dot gnu.org
  2021-01-17 19:43 ` tromey at sourceware dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2021-01-13 10:30 UTC (permalink / raw)
  To: gdb-prs

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

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|function call with complex  |Handle stepping into
                   |switch-case will be skipped |function with broken line
                   |by gdb                      |number info
           Severity|normal                      |enhancement

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
Reproduced on openSUSE Leap 15.2, using gcc-9, gcc-10, gcc-11.  Works as
expected with gcc-8.

Gdb's behaviour is as follows:
- it steps into foo and arrives at the first insn
- then it sets a breakpoint at the first entry after that in the line table, in
  an attempt to skip the prologue.  Which means a break at line number 10.
- it continues
- the breakpoint never triggers, and the inferior exits

With lldb, we see the same.

Gdb behaves correctly, but the debug info is incorrect.  It breaks the
invariant that the first insn after the prologue has a line number entry. 

Filed gcc PR "switchlower_O0 drops line number of switch" at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98656 .  Regression since gcc-9,
so using gcc-8 or earlier can be a workaround.

Gdb might be able to do better, f.i. by also setting a breakpoint after the
call, to at least not run unbound, but have something like this:
...
Temporary breakpoint 1, main () at small.c:19
19        foo (1, 1);  // L1
(gdb) step
20        foo (2, 1);  // L2
...

Or, analyze the prologue insns and set a breakpoint after, even if there's no
line info entry there, to get something like
...
Temporary breakpoint 1, main () at small.c:19
19        foo (1, 1);  // L1
(gdb) step
0x0000000000400510      4       {
...

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

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

* [Bug breakpoints/27179] Handle stepping into function with broken line number info
  2021-01-13  5:54 [Bug breakpoints/27179] New: function call with complex switch-case will be skipped by gdb yangyibiao at outlook dot com
                   ` (2 preceding siblings ...)
  2021-01-13 10:30 ` [Bug breakpoints/27179] Handle stepping into function with broken line number info vries at gcc dot gnu.org
@ 2021-01-17 19:43 ` tromey at sourceware dot org
  2021-01-18 10:52 ` vries at gcc dot gnu.org
  2021-01-21 12:45 ` [Bug breakpoints/27179] Ensure a step failure degrades to next instead of continue vries at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: tromey at sourceware dot org @ 2021-01-17 19:43 UTC (permalink / raw)
  To: gdb-prs

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

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at sourceware dot org

--- Comment #3 from Tom Tromey <tromey at sourceware dot org> ---
> Gdb behaves correctly, but the debug info is incorrect

FWIW I tend to think this kind of thing should be fixed in the compiler.
Workarounds in gdb tend to outlive their usefulness and inhibit progress.

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

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

* [Bug breakpoints/27179] Handle stepping into function with broken line number info
  2021-01-13  5:54 [Bug breakpoints/27179] New: function call with complex switch-case will be skipped by gdb yangyibiao at outlook dot com
                   ` (3 preceding siblings ...)
  2021-01-17 19:43 ` tromey at sourceware dot org
@ 2021-01-18 10:52 ` vries at gcc dot gnu.org
  2021-01-21 12:45 ` [Bug breakpoints/27179] Ensure a step failure degrades to next instead of continue vries at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2021-01-18 10:52 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom Tromey from comment #3)
> > Gdb behaves correctly, but the debug info is incorrect
> 
> FWIW I tend to think this kind of thing should be fixed in the compiler.
> Workarounds in gdb tend to outlive their usefulness and inhibit progress.

I agree with the general point.

But, a fallback of the kind: we're trying to do a step, and if that fails
somehow let's make sure we get "next" behaviour rather than "continue"
behaviour is also useful if gdb itself makes errors in stepping. See f.i.
PR27151.

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

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

* [Bug breakpoints/27179] Ensure a step failure degrades to next instead of continue
  2021-01-13  5:54 [Bug breakpoints/27179] New: function call with complex switch-case will be skipped by gdb yangyibiao at outlook dot com
                   ` (4 preceding siblings ...)
  2021-01-18 10:52 ` vries at gcc dot gnu.org
@ 2021-01-21 12:45 ` vries at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2021-01-21 12:45 UTC (permalink / raw)
  To: gdb-prs

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

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Handle stepping into        |Ensure a step failure
                   |function with broken line   |degrades to next instead of
                   |number info                 |continue

--- Comment #5 from Tom de Vries <vries at gcc dot gnu.org> ---
So, lets change the title to shift the focus towards robust behaviour rather
than incorrect line info.

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

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

end of thread, other threads:[~2021-01-21 12:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-13  5:54 [Bug breakpoints/27179] New: function call with complex switch-case will be skipped by gdb yangyibiao at outlook dot com
2021-01-13  5:54 ` [Bug breakpoints/27179] " yangyibiao at outlook dot com
2021-01-13  5:57 ` yangyibiao at outlook dot com
2021-01-13 10:30 ` [Bug breakpoints/27179] Handle stepping into function with broken line number info vries at gcc dot gnu.org
2021-01-17 19:43 ` tromey at sourceware dot org
2021-01-18 10:52 ` vries at gcc dot gnu.org
2021-01-21 12:45 ` [Bug breakpoints/27179] Ensure a step failure degrades to next instead of continue vries at gcc dot gnu.org

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