Pascal Viandier wrote:
When debugging gpc programs, I often get a gdb coredump when printing the value of string which is not -yet- initialized. This happens even more often when using ddd on top of gdb since the value is displayed as soon as you move the mouse pointer over the variable name.
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).
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). 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)".
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?
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.
Frank