-----Message d'origine-----
This problem occurs because gdb uses the value of the 'length' field of the string type schema to print the string contents. If the string is not initialized, this field may contain any value -even negative- so it crashes
gdb.
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)
When printing a string, I compare the value of the actual length and the value of
the
capacity of the string. If the length is either negative or greater than the capacity,
Negative length is, of course, always wrong, even if the capacity is unknown. In fact, you could also check if the capacity is <= 0 (then it's obviously not initialized).
I did not test the value of the capacity field because of the assumption above but this is a good point.
And if you have access to the (memory) size of the string (not sure -- I'm not familiar with gdb internals), you could check against "size - offset (characters)".
This was my first choice but I did not find my way to get the size of the string so I solved this the other way.
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 -. IMHO, showing the string contents is sufficient to see if the string was initialized since it is full of "random" characters if not.
This modification has no impact on other Pascal string types (BP, etc).
I put the patches (4) for gdb 6.4 in attachment.
If someone estimates these patches are interesting enough to transmit them
to
the gdb maintainers, feel free to do so. I am not a member of the gdb
mailing
list and I do not know how to submit patches to them.
Me neither. I suppose Waldek could submit them, but since you're really the author, and the patch may be just a little too long to qualify as trivial under copyright law, you might have to sign a copyright assignment. I hope you won't mind.