This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch: printing java `char' values


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  <tromey@redhat.com>
> 
>         * 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')


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]