From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14251 invoked by alias); 7 May 2002 00:05:11 -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 14244 invoked from network); 7 May 2002 00:05:10 -0000 Received: from unknown (HELO cygnus.com) (205.180.83.203) by sources.redhat.com with SMTP; 7 May 2002 00:05:10 -0000 Received: from redhat.com (reddwarf.sfbay.redhat.com [172.16.24.50]) by runyon.cygnus.com (8.8.7-cygnus/8.8.7) with ESMTP id RAA26329; Mon, 6 May 2002 17:04:59 -0700 (PDT) Message-ID: <3CD71722.DD3585A4@redhat.com> Date: Mon, 06 May 2002 17:05:00 -0000 From: Michael Snyder Organization: Red Hat, Inc. X-Accept-Language: en MIME-Version: 1.0 To: tromey@redhat.com CC: gdb-patches@sources.redhat.com, green@redhat.com Subject: Re: Patch: printing java `char' values References: <877kmh8a6r.fsf@creche.redhat.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-SW-Source: 2002-05/txt/msg00138.txt.bz2 Hi Tom, For future reference, the convention here is that "Patch" means "I've checked this in, I'm just letting you know". What you want is probably "RFC" (request for comment). Tom Tromey wrote: > > 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. I'm not sure why that's happening, but it tickles my familiar-bone. Has someone else recently posted about something related to this? Maybe Per Bothner? > 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? I agree that this is not the correct fix, but that it does help illustrate the problem. Unfortunately, I don't know who, if anyone, is actively maintaining Java these days. Anthony? > 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')