Bug 92664 - Wrong .debug_line section information when compiling stdin input with -g3
Summary: Wrong .debug_line section information when compiling stdin input with -g3
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 7.2.1
: P3 normal
Target Milestone: 8.4
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-debug
Depends on:
Blocks:
 
Reported: 2019-11-25 16:35 UTC by Robert Dumitru
Modified: 2020-02-14 17:23 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 9.2.0
Last reconfirmed: 2019-11-26 00:00:00


Attachments
gcc10-pr92664.patch (334 bytes, patch)
2019-11-26 11:49 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Dumitru 2019-11-25 16:35:12 UTC
Hello,
 
When compiling simple test programs with -g3 and input from the console (- (stdin)), the .debug_line section is wrong. 

Steps to reproduce this issue: 

1. In your console type:

arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O0 -g3 -c -o test.o -x c -

2. Copy and paste: 

#include <stdio.h>
int main(void)
{
	printf("Hello World\n");
	return 0;
}

3. Ctrl+Z and Return 

4. If you type: arm-none-eabi-readelf --debug-dump=decodedline  test.o
You get the following:

Contents of the .debug_line section:

CU: ./<stdin>:
File name                            Line number    Starting address    View
readelf: Warning: Badly formed extended line op encountered!
readelf: Warning: Badly formed extended line op encountered!
UNKNOWN (116): length 115
<stdin>                                        0                 0xc
<stdin>                                       -1                0x1a
<stdin>                                       -1                0x1e
<stdin>                                        1                0x2a
UNKNOWN (0): length 4
<stdin>                                       -1                0x36
<stdin>                                       -6                0x42
<stdin>                                       -8                0x50
<stdin>                                       -7                0x5c
<stdin>                                       -7                0x60
<stdin>                                       -5                0x6c
UNKNOWN (0): length 2
<stdin>                                        2                0x76
<stdin>                                        2                0x84
<stdin>                                        7                0x92
<stdin>                                        3                0xa0
<stdin>                                        2                0xac
<stdin>                                        1                0xba
<stdin>                                        1                0xbe
<stdin>                                        3                0xca
UNKNOWN (0): length 4
<stdin>                                       -1                0xd8
<stdin>                                       -2                0xe4
<stdin>                                       -3                0xf2
<stdin>                                       -3                0xf6
<stdin>                                       -1               0x102
UNKNOWN (0): length 1
UNKNOWN (115): length 95
<stdin>                                       -2               0x110
<stdin>                                       -6               0x11e
<stdin>                                       -7               0x12a
<stdin>                                      -10               0x136
<stdin>                                      -10               0x13a
<stdin>                                       -8               0x146
UNKNOWN (0): length 1
UNKNOWN (112): length 95

5. Repeating the steps with -g instead of -g3 we get the right .debug_line section:
Contents of the .debug_line section:

CU: ./<stdin>:
File name                            Line number    Starting address    View
<stdin>                                        3                   0
<stdin>                                        4                 0x4
<stdin>                                        5                 0xa
<stdin>                                        6                 0xc
<stdin>                                        6                0x14
Comment 1 Richard Biener 2019-11-26 08:27:18 UTC
[insert "doctor it hurts when I do this ..." here ;)]

Not specific to arm or cross-compiling, confirmed with GCC 9.2 on x86_64.
Comment 2 Jakub Jelinek 2019-11-26 11:49:25 UTC
Created attachment 47359 [details]
gcc10-pr92664.patch

Untested fix.
Comment 3 Jakub Jelinek 2019-11-27 00:24:13 UTC
Author: jakub
Date: Wed Nov 27 00:23:39 2019
New Revision: 278752

URL: https://gcc.gnu.org/viewcvs?rev=278752&root=gcc&view=rev
Log:
	PR debug/92664
	* dwarf2out.c (lookup_filename): Use "<stdin>" instead of "".

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/dwarf2out.c
Comment 4 Jakub Jelinek 2019-12-20 17:24:16 UTC
Author: jakub
Date: Fri Dec 20 17:23:34 2019
New Revision: 279658

URL: https://gcc.gnu.org/viewcvs?rev=279658&root=gcc&view=rev
Log:
	Backported from mainline
	2019-11-27  Jakub Jelinek  <jakub@redhat.com>

	PR debug/92664
	* dwarf2out.c (lookup_filename): Use "<stdin>" instead of "".

Modified:
    branches/gcc-9-branch/gcc/ChangeLog
    branches/gcc-9-branch/gcc/dwarf2out.c
Comment 5 GCC Commits 2020-02-14 16:34:47 UTC
The releases/gcc-8 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:5c265f5f1977f7c935b8b54cfdb23c862f686f20

commit r8-9987-g5c265f5f1977f7c935b8b54cfdb23c862f686f20
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Feb 14 12:49:07 2020 +0100

    backport: re PR debug/92664 (Wrong .debug_line section information when compiling stdin input with -g3)
    
    	Backported from mainline
    	2019-11-27  Jakub Jelinek  <jakub@redhat.com>
    
    	PR debug/92664
    	* dwarf2out.c (lookup_filename): Use "<stdin>" instead of "".
Comment 6 Jakub Jelinek 2020-02-14 17:23:34 UTC
Fixed for 8.4+ and 9.3+.