Bug 24160 - GDB shows wrong variable value
Summary: GDB shows wrong variable value
Status: UNCONFIRMED
Alias: None
Product: gdb
Classification: Unclassified
Component: d (show other bugs)
Version: 8.2
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-03 18:33 UTC by Victor Porton
Modified: 2019-02-04 16:14 UTC (History)
0 users

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 Victor Porton 2019-02-03 18:33:56 UTC
1. Download a project from https://github.com/vporton/shlex-dlang/tree/aefc515083c09bc4deb4d189d21f027aac0cc42f

2. Compile it with

dub build --config=application --compiler=dmd --build=unittest

using

$ dmd --version
DMD64 D Compiler v2.080.1

$ gdb --version
GNU gdb (Ubuntu 8.2-0ubuntu1) 8.2

Ubuntu Linux 18.10.

Then the following GDB session outputs a wrong value for _isNull (it should be true). Adding a `writeln(result.isNull);` shows the correct value.

$ gdb shlex
...
(gdb) dir source/
Source directories searched: /home/porton/Projects/shlex-dlang/source:$cdir:$cwd
(gdb) break shlex.d:402
Breakpoint 1 at 0x12c373: file source/shlex.d, line 402.
(gdb) run
Starting program: /home/porton/Projects/shlex-dlang/shlex 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, _D5shlex5Shlex10read_tokenMFZS3std8typecons__T8NullableTAyaZQo (this=..., __HID2=0x7fffffffd610) at source/shlex.d:402
402	        if (debug_ > 1) {
(gdb) p result
$1 = {_value = 0x0, _isNull = false}

I submit a long D program source for testing your debugger. For compiler bugs I created minimal sources, is this necessary also for debugger bugs? Or are you OK to deal with the long source I've submitted?
Comment 1 Victor Porton 2019-02-04 16:14:17 UTC
This version of the source shows the bug better: https://github.com/vporton/shlex-dlang/tree/aefc515083c09bc4deb4d189d21f027aac0cc42f

Note that writeln() prints "true" in the following session but `p result` command shows "false". It is surely a GDB (or maybe compiler debug information output?) bug.

dub build --config=application --compiler=dmd --build=unittest

$ gdb
...
(gdb) dir source/
Source directories searched: /home/porton/Projects/shlex-dlang/source:$cdir:$cwd
(gdb) break shlex.d:402
Breakpoint 1 at 0x12c373: file source/shlex.d, line 402.
(gdb) run
Starting program: /home/porton/Projects/shlex-dlang/shlex 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, _D5shlex5Shlex10read_tokenMFZS3std8typecons__T8NullableTAyaZQo (this=..., __HID2=0x7fffffffd620) at source/shlex.d:402
402	            writeln(result.isNull); // FIXME: remove
(gdb) next
true
404	        if (debug_ > 1) {
(gdb) p result
$1 = {_value = 0x0, _isNull = false}