D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14225 - [REG2.067a] GDB: error reading variable (string + dup)
Summary: [REG2.067a] GDB: error reading variable (string + dup)
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: x86 Linux
: P1 regression
Assignee: No Owner
URL:
Keywords: DebugInfo, pull
Depends on:
Blocks:
 
Reported: 2015-02-25 15:40 UTC by Martin Krejcirik
Modified: 2015-06-17 21:02 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Krejcirik 2015-02-25 15:40:51 UTC
char[] chars;

void main()
{
        string lok = "Something";
        chars = "Anything".dup;
}

compiled dmd -g

mk@bid:~/work/pokus/debug$ gdb ./locals
GNU gdb (GDB) 7.8.50.20141030-cvs
(gdb) b 6
Breakpoint 1 at 0x8064e88: file locals.d, line 6.
(gdb) r
Starting program: /home/mk/work/pokus/debug/locals

Breakpoint 1, D main () at locals.d:6
6               chars = "Anything".dup;
(gdb) info locals
lok = <error reading variable>

This is with Ian's patched gdb on linux x86

dmd 2.066 works and 2.067a -gc works too.
Debug info (2.066 vs 2.067a) looks the same.

I haven't tested patched gdb + x86_64

I suspect this may be a gdb problem or something botched up on my side, but I don't have time for more testing now.
Comment 2 Martin Krejcirik 2015-02-27 20:12:50 UTC
Small correction: -gc doesn't make it work.
Also the problem is not limited to recent gdb version, 7.4.1-debian is affected too for example.
Comment 3 Vladimir Panteleev 2015-03-04 04:16:25 UTC
Pull request in question:
https://github.com/D-Programming-Language/druntime/pull/1031
Comment 4 Martin Nowak 2015-03-04 04:33:40 UTC
Confirmed, doesn't depend on ld.bfd vs. ld.gold.
Neither dwarfdump nor readelf --debug-dump report any error.
Comment 5 Martin Nowak 2015-03-04 04:38:59 UTC
.debug_frame and .debug_ranges changed and look indeed weird.
There is an overlapping PC range.

000000c0 0000000000000024 00000000 FDE cie=00000000 pc=0000000000000000..0000000000000084
  DW_CFA_advance_loc: 1 to 0000000000000001
  DW_CFA_def_cfa_offset: 16
  DW_CFA_offset: r6 (rbp) at cfa-16
  DW_CFA_advance_loc: 2 to 0000000000000003
  DW_CFA_def_cfa_register: r6 (rbp)
  DW_CFA_advance_loc: 6 to 0000000000000009
  DW_CFA_offset: r1 (rdx) at cfa-80
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop

000000e8 0000000000000024 00000000 FDE cie=00000000 pc=0000000000000000..0000000000000053
  DW_CFA_advance_loc: 1 to 0000000000000001
  DW_CFA_def_cfa_offset: 16
  DW_CFA_offset: r6 (rbp) at cfa-16
  DW_CFA_advance_loc: 2 to 0000000000000003
  DW_CFA_def_cfa_register: r6 (rbp)
  DW_CFA_advance_loc: 6 to 0000000000000009
  DW_CFA_offset: r1 (rdx) at cfa-24
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop


    00000000 0000000000000000 0000000000000084 
    00000000 0000000000000000 0000000000000053 

Further investigation tomorrow ;).
Comment 6 Walter Bright 2015-03-09 09:46:11 UTC
Any news?
Comment 7 Martin Nowak 2015-03-09 22:28:12 UTC
For yet unknown reason gdb reads an incorrect sizeof for the .length variable of the string. This only applies to the arrays in main not the ones passed to the dup functions.
It also works in lldb.

It would be more optimal if dmd cached and emitted only a single instance per array type. Will try to implement that and see if it helps before spending more hours debugging gdb.
Comment 8 Martin Nowak 2015-03-09 23:49:48 UTC
(In reply to Martin Nowak from comment #7)
> It would be more optimal if dmd cached and emitted only a single instance
> per array type. Will try to implement that and see if it helps before
> spending more hours debugging gdb.

Indeed, fixing the type repetition of debug infos for arrays fixes the issue.
The code is pretty ugly and needs some refactoring before fixing the incorrect hashing, but that'd be my preferred fix as it get's rid of a lot of unnecessary debug info.
Comment 9 Walter Bright 2015-03-11 23:01:56 UTC
(In reply to Martin Nowak from comment #8)
> Indeed, fixing the type repetition of debug infos for arrays fixes the issue.
> The code is pretty ugly and needs some refactoring before fixing the
> incorrect hashing, but that'd be my preferred fix as it get's rid of a lot
> of unnecessary debug info.

What is the prospect of this being done in time for 2.067?
Comment 10 Martin Nowak 2015-03-13 17:42:39 UTC
(In reply to Walter Bright from comment #9)
> What is the prospect of this being done in time for 2.067?

I'm working on that, but dwarf.c is a mess. So far everything I tried had to touch too much code, likely resulting in a regression.
I think the simplest solution is to throw out DW_AT_siblings, it's not that useful anyhow.
Comment 11 Martin Nowak 2015-03-13 22:12:11 UTC
OK, found it. For TYref we set the pointer byte_size to -1.
Wondering why we're emitting TYref for arrays though.
Comment 13 github-bugzilla 2015-03-14 05:16:31 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/c89d666984b74bcd6d50afbdf2d478370f3c52a9
fix Issue 14225 - GDB: error reading variable (string + dup)

- tysize(t->Tty) for TYref was -1
- fixed by omitting the explicit byte_size for pointers
- the debugger will use the address_size for the compilation
  unit instead

https://github.com/D-Programming-Language/dmd/commit/7cb0b4fe2a56d187b4ef8c6416446dc15e1218cf
Merge pull request #4494 from MartinNowak/fix14225

fix Issue 14225 - GDB: error reading variable (string + dup)
Comment 14 github-bugzilla 2015-03-14 12:15:37 UTC
Commit pushed to 2.067 at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/c4a2d7c74897c0114e1c4c1896620abec65c91a0
Merge pull request #4494 from MartinNowak/fix14225

fix Issue 14225 - GDB: error reading variable (string + dup)
Comment 15 github-bugzilla 2015-04-11 12:25:01 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/c4a2d7c74897c0114e1c4c1896620abec65c91a0
Merge pull request #4494 from MartinNowak/fix14225
Comment 16 github-bugzilla 2015-06-17 21:02:07 UTC
Commits pushed to stable at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/c89d666984b74bcd6d50afbdf2d478370f3c52a9
fix Issue 14225 - GDB: error reading variable (string + dup)

https://github.com/D-Programming-Language/dmd/commit/7cb0b4fe2a56d187b4ef8c6416446dc15e1218cf
Merge pull request #4494 from MartinNowak/fix14225