From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7589 invoked by alias); 13 Jan 2011 23:18:38 -0000 Received: (qmail 7577 invoked by uid 22791); 13 Jan 2011 23:18:36 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 13 Jan 2011 23:18:32 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 954582BAC4F; Thu, 13 Jan 2011 18:18:30 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Scw6J3YW1KtX; Thu, 13 Jan 2011 18:18:30 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 83BBD2BAC4C; Thu, 13 Jan 2011 18:18:30 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 9CF051459AD; Thu, 13 Jan 2011 18:18:29 -0500 (EST) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Joel Brobecker Subject: [RFA/commit] Fix printing of wide characters (Ada and C) Date: Thu, 13 Jan 2011 23:21:00 -0000 Message-Id: <1294960709-13047-1-git-send-email-brobecker@adacore.com> 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: 2011-01/txt/msg00313.txt.bz2 Wide_Characters and Wide_Wide_Characters are incorrectly printed. Same for the C wchar_t type. Consider for instance: Medium : Wide_Character := Wide_Character'Val(16#dead#); Trying to print the value of this variable yields: (gdb) p medium $1 = 57005 '["ad"]' The integer value is correct (57005 = 0xdead), but the character representation is not, it should be: $1 = 57005 '["dead"]' Same for Wide_Wide_Characters. For the C wchar_t type, we get the same sort of issue, but with the C syntax... wchar_t single = 0xbeef; (gdb) p single $1 = 48879 L'\357' There were two issues: (a) The first issue was in ada-valprint, where we were assuming that character types were 1 byte long; (b) The second problem was in c-valprint, where we were down-casting the integer value of the character to type `unsigned char', causing use to lose all but the lowest byte. gdb/ChangeLog: * ada-valprint. (ada_printchar): Use the correct type length in call to ada_emit_char. * c-valprint.c (c_val_print): Remove cast in call to LA_PRINT_CHAR. Tested on x86_64-linux. Ok to commit? Thanks, -- Joel --- gdb/ada-valprint.c | 2 +- gdb/c-valprint.c | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index 630ceb5..ee37617 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -368,7 +368,7 @@ void ada_printchar (int c, struct type *type, struct ui_file *stream) { fputs_filtered ("'", stream); - ada_emit_char (c, type, stream, '\'', 1); + ada_emit_char (c, type, stream, '\'', TYPE_LENGTH (type)); fputs_filtered ("'", stream); } diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 0c23c7e..c6d3eae 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -536,9 +536,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr, if (c_textual_element_type (unresolved_type, options->format)) { fputs_filtered (" ", stream); - LA_PRINT_CHAR ((unsigned char) unpack_long (type, - valaddr - + embedded_offset), + LA_PRINT_CHAR (unpack_long (type, valaddr + embedded_offset), unresolved_type, stream); } } @@ -561,7 +559,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr, else fprintf_filtered (stream, "%d", (int) val); fputs_filtered (" ", stream); - LA_PRINT_CHAR ((unsigned char) val, unresolved_type, stream); + LA_PRINT_CHAR (val, unresolved_type, stream); } break; -- 1.7.1