D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3391 - gdb: dynamic arrays and associative arrays are not properly printed
Summary: gdb: dynamic arrays and associative arrays are not properly printed
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks: 4044
  Show dependency treegraph
 
Reported: 2009-10-12 16:08 UTC by Leandro Lucarella
Modified: 2014-04-18 09:12 UTC (History)
1 user (show)

See Also:


Attachments
objdump -W for DMD (8.05 KB, text/plain)
2009-10-17 18:01 UTC, Leandro Lucarella
Details
objdump -W for LDC (9.92 KB, text/plain)
2009-10-17 18:02 UTC, Leandro Lucarella
Details

Note You need to log in before you can comment on or make changes to this issue.
Description Leandro Lucarella 2009-10-12 16:08:36 UTC
DMD 1.049/2.034
---------------

$ cat -n bug.d
     1	version (Tango) alias char[] string;
     2	void main(string[] args)
     3	{
     4		float[2] f;
     5		f[0] = 1.45;
     6		f[1] = 3.45;
     7		int[] i;
     8		i ~= 5;
     9		i ~= 15;
    10		char[string] h;
    11		h["foo"] = 'f';
    12		h["bar"] = 'b';
    13		*(args.ptr + 1_000_000) = "boom";
    14	}
$ dmd -gc bug.d
$ gdb --quiet ./bug
Reading symbols from ./bug...done.
(gdb) run 1 2 3
Starting program: ./bug
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0x08049bd2 in _Dmain (args=578452242739232769) at bug.d:13
13		*(args.ptr + 1_000_000) = "boom";
Current language:  auto
The current source language is "auto; currently d".
(gdb) print i
$1 = 13246370664958394370
(gdb) print f
$2 = {1.45000005, 3.45000005}
(gdb) print h
$3 = (void *) 0xb7d48fe0
(gdb) print args
$4 = 578452242739232769


LDC does a pretty good job with dynamic arrays (including char[] as strings):

Program received signal SIGSEGV, Segmentation fault.
0x08049718 in _Dmain (args=...) at ./bug.d:13
13		*(args.ptr + 1_000_000) = "boom";
(gdb) print i
$1 = {5, 15}
(gdb) print args
$2 = {"./bug", "1", "2", "3"}

Associative arrays seems to be not very well handled by any current compiler...
Comment 1 Leandro Lucarella 2009-10-17 18:00:47 UTC
Maybe this is useful.

For this file:
$ cat -n dbg.d
     1	
     2	void dummy_function()
     3	{
     4		char[][] str_array;
     5		str_array ~= "hello";
     6		str_array ~= "world";
     7		int[2] int_sarray;
     8		int_sarray[0] = 1;
     9		int_sarray[1] = -1;
    10	}
    11	

DMD (svn 1.x branch at r215) generates this:
 <1><6c>: Abbrev Number: 5 (DW_TAG_array_type)
    <6d>   DW_AT_sibling     : <0x7f>
    <71>   DW_AT_type        : <0x65>

While LDC generates:
 <2><86>: Abbrev Number: 3 (DW_TAG_variable)
    <87>   DW_AT_name        : str_array        
    <91>   DW_AT_decl_file   : 1        
    <92>   DW_AT_decl_line   : 4        
    <93>   DW_AT_type        : <0x121>  
    <97>   DW_AT_location    : 2 byte block: 75 70      (DW_OP_breg5: -16)

I will attach the full dump of objdump -W for both DMD and LDC.
Comment 2 Leandro Lucarella 2009-10-17 18:01:47 UTC
Created attachment 478 [details]
objdump -W for DMD
Comment 3 Leandro Lucarella 2009-10-17 18:02:23 UTC
Created attachment 479 [details]
objdump -W for LDC
Comment 4 Leandro Lucarella 2011-12-19 03:53:53 UTC
See https://github.com/D-Programming-Language/dmd/pull/526
Comment 5 Walter Bright 2012-01-18 20:56:59 UTC
Fixed by pull 526.