Newbie GDC issues
Iain Buclaw
ibuclaw at ubuntu.com
Fri Sep 6 00:02:43 PDT 2013
On 6 September 2013 01:59, Ramon <spam at thanks.no> wrote:
> On Thursday, 5 September 2013 at 23:58:06 UTC, H. S. Teoh wrote:
>
> Thanks and
>
>
>> @Iain: on that note, it looks like gdb thinks it's debugging C++, but D
>> doesn't have anything called 'operator[]'. It would be Really Nice if we
>> could somehow coax gdb to use opIndex instead (though it doesn't really
>> help in the case of dyn arrays 'cos they are built-in, and don't
>> actually have any opIndex to speak of).
>
>
> I'm not so sure.
>
> Observation:
>
>> print someDynArray.length
>
> 10 // works
>
> char[5] cArray = "Hello"; // Let's try C like fixed length array
>
>> print cArray[3]
>
> 'l' // works
>
> I'm not that sure dyn arrays have no [] (or index or whatever it's called)
> operator. In the end they are just arrays with smart housekeeping behind the
> curtains and some methods (like "length").
>
> I'm looking forward to hear and learn from Iain.
>
Dynamic arrays are just structs with a length and ptr field. So when
you invoke '.length' in the debugger you aren't calling a method, you
are just retrieving the type's field value.
Currently, the only fancy thing the gdb does with D arrays is that it
pretty prints them. So take for example you have:
{ .length = 5, .ptr = "Hello" };
Rather than printing the dynamic array like the above, it does a
printf("%*.s") style operation to print the contents of .ptr, but only
as far as .length. This is important because dynamic arrays are not
expected to be '0' terminated, and you can slice a dynamic array into
smaller arrays without copying data.
Having the ability to slice D arrays using [] in gdb is something on
my todo list when I get round to improving gdb for D.
--
Iain Buclaw
*(p < e ? p++ : p) = (c & 0x0f) + '0';
More information about the D.gnu
mailing list