From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29707 invoked by alias); 6 May 2002 17:11:20 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 29694 invoked from network); 6 May 2002 17:11:18 -0000 Received: from unknown (HELO gash2.peakpeak.com) (207.174.178.17) by sources.redhat.com with SMTP; 6 May 2002 17:11:18 -0000 Received: from creche.cygnus.com (ta0201.peakpeak.com [204.144.244.201]) by gash2.peakpeak.com (8.9.3/8.9.3) with ESMTP id LAA01087; Mon, 6 May 2002 11:11:15 -0600 Received: (from tromey@localhost) by creche.cygnus.com (8.9.3/8.9.3) id LAA25513; Mon, 6 May 2002 11:20:44 -0600 To: gdb-patches@sources.redhat.com Subject: Patch: printing java `char' values From: Tom Tromey Reply-To: tromey@redhat.com X-Attribution: Tom X-Zippy: Eisenhower!! Your mimeograph machine upsets my stomach!! Date: Mon, 06 May 2002 10:11:00 -0000 Message-ID: <877kmh8a6r.fsf@creche.redhat.com> X-SW-Source: 2002-05/txt/msg00131.txt.bz2 Compile the appended java program with `gcj -g'. Run gdb on it, and run it with the argument "abc". Put a breakpoint on main and step past the assignment. Then do `p c'. I get: (gdb) p c $1 = 97 This is wrong. Debugging gdb a little, I found that in java_val_print we are seeint a TYPE_CODE_INT and not a TYPE_CODE_CHAR. The appended hack fixes the problem for me. I'm sure there is some better way to handle this, but I don't know what. Why would I end up with a TYPE_CODE_INT here? Tom public class x { public static void main (String[] args) { char c = args[0].charAt(0); System.out.println(c); } } Index: ChangeLog from Tom Tromey * jv-valprint.c (java_val_print): Add special case for Java char. Index: jv-valprint.c =================================================================== RCS file: /cvs/src/src/gdb/jv-valprint.c,v retrieving revision 1.9 diff -u -r1.9 jv-valprint.c --- jv-valprint.c 21 Oct 2001 01:57:42 -0000 1.9 +++ jv-valprint.c 6 May 2002 17:08:19 -0000 @@ -451,9 +452,18 @@ register unsigned int i = 0; /* Number of characters printed */ struct type *target_type; CORE_ADDR addr; + enum type_code code; CHECK_TYPEDEF (type); - switch (TYPE_CODE (type)) + + /* Sometimes a Java `char' shows up as an `int'. So here we make a + special case for that. */ + code = TYPE_CODE (type); + if (code == TYPE_CODE_INT && TYPE_LENGTH (type) == 2 + && ! strcmp (TYPE_NAME (type), "char")) + code = TYPE_CODE_CHAR; + + switch (code) { case TYPE_CODE_PTR: if (format && format != 's')