libjava/ChangeLog:
[official-gcc.git] / libjava / gnu / gcj / util / natDebug.cc
blobe2631b14a745941031005fce495406a7a6fc95c8
1 // natDebug -- C++ side of Debug
3 /* Copyright (C) 2004 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
11 #include <config.h>
12 #include <stddef.h>
13 #include <gcj/cni.h>
14 #include <gcj/field.h>
15 #include <gcj/javaprims.h>
16 #include <java/lang/reflect/Field.h>
17 #include <java/lang/Class.h>
18 #include <java/lang/Byte.h>
19 #include <java/lang/Short.h>
20 #include <java/lang/Integer.h>
21 #include <java/lang/Long.h>
22 #include <java/lang/Float.h>
23 #include <java/lang/Double.h>
24 #include <java/lang/Boolean.h>
25 #include <java/lang/Character.h>
26 #include <java/lang/IllegalArgumentException.h>
28 #include <gnu/gcj/util/Debug.h>
30 jlong
31 gnu::gcj::util::Debug::getAddr (::java::lang::Object *o)
33 return (jlong)(size_t)o;
36 JArray< ::java::lang::reflect::Field *> *
37 gnu::gcj::util::Debug::getDeclaredFields (::java::lang::Class *c)
39 return c->getDeclaredFields (false);
42 static void *
43 getField (::java::lang::Object *obj,
44 ::java::lang::reflect::Field *field)
46 using namespace java::lang::reflect;
48 jfieldID fld = _Jv_FromReflectedField (field);
49 _Jv_ushort flags = fld->getModifiers();
51 if (flags & Modifier::STATIC)
53 jclass fldClass = field->getDeclaringClass ();
54 JvInitClass(fldClass);
55 return (void*) fld->u.addr;
57 else
59 return (void*) ((char*) obj + fld->getOffset ());
63 ::java::lang::Object *
64 gnu::gcj::util::Debug::getField (::java::lang::Object *o,
65 ::java::lang::reflect::Field *field)
67 void *addr = ::getField (o, field);
69 jclass type = field->getType();
70 if (! type->isPrimitive ())
71 return * (jobject*) addr;
72 if (type == JvPrimClass (double))
73 return new ::java::lang::Double (* (jdouble*) addr);
74 if (type == JvPrimClass (float))
75 return new ::java::lang::Float (* (jfloat*) addr);
76 if (type == JvPrimClass (long))
77 return new ::java::lang::Long (* (jlong*) addr);
78 if (type == JvPrimClass (int))
79 return new ::java::lang::Integer (* (jint*) addr);
80 if (type == JvPrimClass (short))
81 return new ::java::lang::Short (* (jshort*) addr);
82 if (type == JvPrimClass (byte))
83 return new ::java::lang::Byte (* (jbyte*) addr);
84 if (type == JvPrimClass (char))
85 return new ::java::lang::Character (* (jchar*) addr);
86 if (type == JvPrimClass (boolean))
88 _Jv_InitClass (&::java::lang::Boolean::class$);
89 if (* (jboolean*) addr)
90 return ::java::lang::Boolean::TRUE;
91 else
92 return ::java::lang::Boolean::FALSE;
94 throw new ::java::lang::IllegalArgumentException;
97 /* A simple method of printing an object that can be called from a
98 debugger. */
99 extern "C"
100 void
101 _Jv_Debug (void *p)
103 (new ::gnu::gcj::util::Debug ())->write ((jobject)p);
106 extern "C"
107 void
108 _Jv_DeepDebug (void *p, int depth)
110 (new ::gnu::gcj::util::Debug (depth))->write ((jobject)p);
113 extern "C"
114 void
115 _Jv_StaticDeepDebug (void *p, int depth)
117 (new ::gnu::gcj::util::Debug (depth, true))->write ((jobject)p);