From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4230 invoked by alias); 10 Feb 2009 14:33:52 -0000 Received: (qmail 4220 invoked by uid 22791); 10 Feb 2009 14:33:51 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from ugmailsc.ugent.be (HELO ugmailsc.ugent.be) (157.193.49.118) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 10 Feb 2009 14:33:44 +0000 Received: from localhost (localhost [127.0.0.1]) by ugmailsc.ugent.be (Postfix) with ESMTP id 73B871CF40C for ; Tue, 10 Feb 2009 15:33:17 +0100 (CET) Received: from ugmailsc.ugent.be ([127.0.0.1]) by localhost (ugmailsc.ugent.be [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eiZIDiCT+-Zu for ; Tue, 10 Feb 2009 15:33:17 +0100 (CET) Received: from cedar.ugent.be (cedar.ugent.be [157.193.49.14]) by ugmailsc.ugent.be (Postfix) with ESMTP id 0F89F1CF3BA for ; Tue, 10 Feb 2009 15:32:08 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEADcekUmdwc4w/2dsb2JhbADTKIQaBg Received: from mail.elis.ugent.be ([157.193.206.48]) by relays9.ugent.be with ESMTP; 10 Feb 2009 15:32:05 +0100 Received: from localhost (localhost [127.0.0.1]) by mail.elis.UGent.be (Postfix) with ESMTP id 840972BAD29; Tue, 10 Feb 2009 15:31:55 +0100 (CET) Received: from bigmac.elis.UGent.be (bigmac.elis.UGent.be [157.193.206.33]) by mail.elis.UGent.be (Postfix) with ESMTP id 760B12BAD1D; Tue, 10 Feb 2009 15:31:55 +0100 (CET) Cc: "'gdb-patches ml'" , "'FPC Core Developer List'" , Message-Id: <85964EC7-B6FF-4869-A5C1-B99D618FF69C@elis.ugent.be> From: Jonas Maebe To: Pierre Muller In-Reply-To: <000001c98b14$a4cb8d60$ee62a820$@u-strasbg.fr> Content-Type: multipart/mixed; boundary=Apple-Mail-32-418561226 Mime-Version: 1.0 (Apple Message framework v930.3) Subject: Re: [Commit] gdb/pascal language 2 or 4 byte char support in strings Date: Tue, 10 Feb 2009 14:33:00 -0000 References: <000001c98b14$a4cb8d60$ee62a820$@u-strasbg.fr> Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-02/txt/msg00220.txt.bz2 --Apple-Mail-32-418561226 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Content-length: 2161 On 10 Feb 2009, at 01:15, Pierre Muller wrote: > I committed the patch below to add > support for fixed width chars > greater than 1 for pascal language. > > This works nicely for Free Pascal, > I couldn't test it for GPC > because I didn't find out if those kind of > char are supported... Hi Pierre, A while ago I wrote a similar patch. I didn't submit it yet because I didn't find time to write explanations why I did everything and on writing test cases for all changes. Anyway, it's in attachment (it's against the p-*.c files before your patch though). Some comments: * pascal-dwarf-char.patch: This one is independent from and complementary to your patch : it properly sets the TYPE_CODE DW_ATE_signed_char/DW_ATE_unsigned_char to TYPE_CODE_CHAR in case of Pascal (rather than only for Ada and Modula-2) * pascalchar.patch: a) I removed all situations in the Pascal string handling where "TYPE_CODE (elttype) == TYPE_CODE_INT" is interpreted as a character. I don't know the original reason for having it there though, but maybe it was because of the lack of a)? At least the stabs debug info of both FPC and GPC results in a char (negative type number -2, as mentioned at http://sourceware.org/gdb/current/onlinedocs/stabs_5.html#SEC35) , which gdb turns into a TYPE_CODE_CHAR. I don't know about GPC and Dwarf, but FPC and Dwarf results in DW_ATE_unsigned_char. The main problem with considering TYPE_CODE_INT as characters is that arrays of bytes (and now presumably also of words and cardinals) are printed as character arrays, which is quite annoying. b) my changes to p-lang.c were basically a copy/paste if all changes in the C version of print_string to support characters of different widths I noticed that I did miss this change you did to p-valprint.c in your patch: - (valaddr + embedded_offset)[temp_len] + extract_unsigned_integer (valaddr + embedded_offset + + temp_len * eltlen, eltlen) The patches are against the gdb archer branch, but applied cleanly against trunk gdb cvs when I tried it last month. Sorry for not informing you earlier about this patch. Jonas --Apple-Mail-32-418561226 Content-Disposition: attachment; filename=pascal-dwarf-char.patch Content-Type: application/octet-stream; x-unix-mode=0666; name="pascal-dwarf-char.patch" Content-Transfer-Encoding: 7bit Content-length: 766 diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 6b226be..295a6d8 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -5177,11 +5177,11 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu) type_flags |= TYPE_FLAG_UNSIGNED; break; case DW_ATE_signed_char: - if (cu->language == language_ada || cu->language == language_m2) + if (cu->language == language_ada || cu->language == language_m2 || cu->language == language_pascal) code = TYPE_CODE_CHAR; break; case DW_ATE_unsigned_char: - if (cu->language == language_ada || cu->language == language_m2) + if (cu->language == language_ada || cu->language == language_m2 || cu->language == language_pascal) code = TYPE_CODE_CHAR; type_flags |= TYPE_FLAG_UNSIGNED; break; --Apple-Mail-32-418561226 Content-Disposition: attachment; filename=pascalchar.patch Content-Type: application/octet-stream; x-unix-mode=0666; name="pascalchar.patch" Content-Transfer-Encoding: 7bit Content-length: 3933 diff --git a/gdb/p-lang.c b/gdb/p-lang.c index 0e0de2e..39f6d1d 100644 --- a/gdb/p-lang.c +++ b/gdb/p-lang.c @@ -218,7 +218,10 @@ pascal_printstr (struct ui_file *stream, const gdb_byte *string, /* If the string was not truncated due to `set print elements', and the last byte of it is a null, we don't print that, in traditional C style. */ - if ((!force_ellipses) && length > 0 && string[length - 1] == '\0') + if (!force_ellipses + && length > 0 + && (extract_unsigned_integer (string + (length - 1) * width, width) + == '\0')) length--; if (length == 0) @@ -234,6 +237,7 @@ pascal_printstr (struct ui_file *stream, const gdb_byte *string, unsigned int rep1; /* Number of repetitions we have detected so far. */ unsigned int reps; + unsigned long current_char; QUIT; @@ -243,9 +247,13 @@ pascal_printstr (struct ui_file *stream, const gdb_byte *string, need_comma = 0; } + current_char = extract_unsigned_integer (string + i * width, width); + rep1 = i + 1; reps = 1; - while (rep1 < length && string[rep1] == string[i]) + while (rep1 < length + && extract_unsigned_integer (string + rep1 * width, width) + == current_char) { ++rep1; ++reps; @@ -262,15 +270,14 @@ pascal_printstr (struct ui_file *stream, const gdb_byte *string, in_quotes = 0; } pascal_printchar (string[i], stream); - fprintf_filtered (stream, " ", reps); + fprintf_filtered (stream, _(" "), reps); i = rep1 - 1; things_printed += options->repeat_count_threshold; need_comma = 1; } else { - int c = string[i]; - if ((!in_quotes) && (PRINT_LITERAL_FORM (c))) + if ((!in_quotes) && (PRINT_LITERAL_FORM (current_char))) { if (options->inspect_it) fputs_filtered ("\\'", stream); @@ -278,7 +285,7 @@ pascal_printstr (struct ui_file *stream, const gdb_byte *string, fputs_filtered ("'", stream); in_quotes = 1; } - pascal_one_char (c, stream, &in_quotes); + pascal_one_char (current_char, stream, &in_quotes); ++things_printed; } } diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c index 9b1b7ff..3e3b688 100644 --- a/gdb/p-valprint.c +++ b/gdb/p-valprint.c @@ -79,10 +79,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, print_spaces_filtered (2 + 2 * recurse, stream); } /* For an array of chars, print with string syntax. */ - if (eltlen == 1 - && ((TYPE_CODE (elttype) == TYPE_CODE_INT) - || ((current_language->la_language == language_pascal) - && (TYPE_CODE (elttype) == TYPE_CODE_CHAR))) + if (TYPE_CODE (elttype) == TYPE_CODE_CHAR && (options->format == 0 || options->format == 's')) { /* If requested, look for the first null char and only print @@ -99,7 +96,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, len = temp_len; } - LA_PRINT_STRING (stream, valaddr + embedded_offset, len, 1, 0, + LA_PRINT_STRING (stream, valaddr + embedded_offset, len, TYPE_LENGTH (elttype), 0, options); i = len; } @@ -165,14 +162,11 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, /* For a pointer to char or unsigned char, also print the string pointed to, unless pointer is null. */ - if (TYPE_LENGTH (elttype) == 1 - && (TYPE_CODE (elttype) == TYPE_CODE_INT - || TYPE_CODE(elttype) == TYPE_CODE_CHAR) + if (TYPE_CODE(elttype) == TYPE_CODE_CHAR && (options->format == 0 || options->format == 's') && addr != 0) { - /* no wide string yet */ - i = val_print_string (addr, -1, 1, stream, options); + i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream, options); } /* also for pointers to pascal strings */ /* Note: this is Free Pascal specific: --Apple-Mail-32-418561226--