Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Patch: printing java `char' values
@ 2002-05-06 10:11 Tom Tromey
  2002-05-06 17:05 ` Michael Snyder
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Tom Tromey @ 2002-05-06 10:11 UTC (permalink / raw)
  To: gdb-patches

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  <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')


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2002-05-09 18:09 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-06 10:11 Patch: printing java `char' values Tom Tromey
2002-05-06 17:05 ` Michael Snyder
2002-05-07 13:29   ` Tom Tromey
2002-05-07 15:45     ` Andrew Cagney
2002-05-07 13:43 ` Daniel Jacobowitz
2002-05-07 14:22 ` Michael Snyder
2002-05-07 14:35   ` Tom Tromey
2002-05-08 12:12     ` Michael Snyder
2002-05-08 12:47       ` Daniel Jacobowitz
2002-05-08 13:32         ` Tom Tromey
2002-05-08 13:46           ` Daniel Jacobowitz
2002-05-08 14:10             ` Michael Snyder
2002-05-08 14:20               ` Daniel Jacobowitz
2002-05-08 15:39                 ` Michael Snyder
2002-05-08 15:42       ` Tom Tromey
2002-05-08 16:52         ` Michael Snyder
2002-05-08 21:09           ` Tom Tromey
2002-05-09 11:09             ` Michael Snyder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox