Pascal Viandier wrote:
I solved this bug (IMHO this is one) by getting the Capacity field too. This field is always initialized for gpc strings - this is an assumption -.
Yes (unless one does strange things), string capacity is initialized automatically. However, there may be a short time before the initialization code is executed (on program start, routine/block entry, or after the internal memory allocation in `New'), but when stepping on the source level, one might not encounter this (but I haven't checked).
Among these strange things one can think of FillChar() if used improperly or Move() (As seen in a recent thread in this mailing list)
Of course. As well as declaring strings in non-imported modules (a somewhat-FAQ), allocating strings with GetMem instead of New, wildly overwriting memory, etc.
the capacity is used to print out the value.
Perhaps it would be better to print something like "uninitialized string", as the value is really invalid?
I was not sure what to do. In fact, my first goal was to stop gdb from crashing each time I was moving the mouse over an uninitialized string variable name or a record containing one in ddd. OTOH, this kind of message could be misleading since it is the only Pascal type that would make it pop and I am not ready to implement this for all types ;-) - if it is feasible at all -.
For some types it's not possible (e.g., default integer types and Char allow all possible values). For some others, it would be possible (e.g., Boolean, most enum types, real (on most FP systems)), but IMHO one can do it one by one type when someone feels like doing it, it's not necessary to do for all types at once.
IMHO, showing the string contents is sufficient to see if the string was initialized since it is full of "random" characters if not.
But there's a difference between a string with invalid length (and possibly capacity), and a string with valid length and random contents.
Frank