0N/A/*
2362N/A * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#ifndef JDWP_UTIL_H
0N/A#define JDWP_UTIL_H
0N/A
0N/A#include <stddef.h>
0N/A#include <stdio.h>
0N/A#include <string.h>
0N/A#include <stdlib.h>
0N/A#include <stdarg.h>
0N/A
0N/A#ifdef DEBUG
0N/A /* Just to make sure these interfaces are not used here. */
0N/A #undef free
0N/A #define free(p) Do not use this interface.
0N/A #undef malloc
0N/A #define malloc(p) Do not use this interface.
0N/A #undef calloc
0N/A #define calloc(p) Do not use this interface.
0N/A #undef realloc
0N/A #define realloc(p) Do not use this interface.
0N/A #undef strdup
0N/A #define strdup(p) Do not use this interface.
0N/A#endif
0N/A
0N/A#include "log_messages.h"
0N/A#include "vm_interface.h"
0N/A#include "JDWP.h"
0N/A#include "util_md.h"
0N/A#include "error_messages.h"
0N/A#include "debugInit.h"
0N/A
0N/A/* Get access to Native Platform Toolkit functions */
0N/A#include "npt.h"
0N/A
0N/A/* Definition of a CommonRef tracked by the backend for the frontend */
0N/Atypedef struct RefNode {
0N/A jlong seqNum; /* ID of reference, also key for hash table */
0N/A jobject ref; /* could be strong or weak */
0N/A struct RefNode *next; /* next RefNode* in bucket chain */
0N/A jint count; /* count of references */
0N/A unsigned isStrong : 1; /* 1 means this is a string reference */
0N/A} RefNode;
0N/A
0N/A/* Value of a NULL ID */
0N/A#define NULL_OBJECT_ID ((jlong)0)
0N/A
0N/A/*
0N/A * Globals used throughout the back end
0N/A */
0N/A
0N/Atypedef jint FrameNumber;
0N/A
0N/Atypedef struct {
0N/A jvmtiEnv *jvmti;
0N/A JavaVM *jvm;
0N/A volatile jboolean vmDead; /* Once VM is dead it stays that way - don't put in init */
0N/A jboolean assertOn;
0N/A jboolean assertFatal;
0N/A jboolean doerrorexit;
0N/A jboolean modifiedUtf8;
0N/A jboolean quiet;
0N/A
0N/A /* Debug flags (bit mask) */
0N/A int debugflags;
0N/A
0N/A /* Possible debug flags */
0N/A #define USE_ITERATE_THROUGH_HEAP 0X001
0N/A
0N/A char * options;
0N/A
0N/A jclass classClass;
0N/A jclass threadClass;
0N/A jclass threadGroupClass;
0N/A jclass classLoaderClass;
0N/A jclass stringClass;
0N/A jclass systemClass;
0N/A jmethodID threadConstructor;
0N/A jmethodID threadSetDaemon;
0N/A jmethodID threadResume;
0N/A jmethodID systemGetProperty;
0N/A jmethodID setProperty;
0N/A jthreadGroup systemThreadGroup;
0N/A jobject agent_properties;
0N/A
0N/A jint cachedJvmtiVersion;
0N/A jvmtiCapabilities cachedJvmtiCapabilities;
0N/A jboolean haveCachedJvmtiCapabilities;
0N/A jvmtiEventCallbacks callbacks;
0N/A
0N/A /* Various property values we should grab on initialization */
0N/A char* property_java_version; /* UTF8 java.version */
0N/A char* property_java_vm_name; /* UTF8 java.vm.name */
0N/A char* property_java_vm_info; /* UTF8 java.vm.info */
0N/A char* property_java_class_path; /* UTF8 java.class.path */
0N/A char* property_sun_boot_class_path; /* UTF8 sun.boot.class.path */
0N/A char* property_sun_boot_library_path; /* UTF8 sun.boot.library.path */
0N/A char* property_path_separator; /* UTF8 path.separator */
0N/A char* property_user_dir; /* UTF8 user.dir */
0N/A
0N/A unsigned log_flags;
0N/A
0N/A /* The Native Platform Toolkit access */
0N/A NptEnv *npt;
0N/A
0N/A /* Common References static data */
0N/A jrawMonitorID refLock;
0N/A jlong nextSeqNum;
0N/A RefNode **objectsByID;
0N/A int objectsByIDsize;
0N/A int objectsByIDcount;
0N/A
0N/A /* Indication that the agent has been loaded */
0N/A jboolean isLoaded;
0N/A
0N/A} BackendGlobalData;
0N/A
0N/Aextern BackendGlobalData * gdata;
0N/A
0N/A/*
0N/A * Event Index for handlers
0N/A */
0N/A
0N/Atypedef enum {
0N/A EI_min = 1,
0N/A
0N/A EI_SINGLE_STEP = 1,
0N/A EI_BREAKPOINT = 2,
0N/A EI_FRAME_POP = 3,
0N/A EI_EXCEPTION = 4,
0N/A EI_THREAD_START = 5,
0N/A EI_THREAD_END = 6,
0N/A EI_CLASS_PREPARE = 7,
0N/A EI_GC_FINISH = 8,
0N/A EI_CLASS_LOAD = 9,
0N/A EI_FIELD_ACCESS = 10,
0N/A EI_FIELD_MODIFICATION = 11,
0N/A EI_EXCEPTION_CATCH = 12,
0N/A EI_METHOD_ENTRY = 13,
0N/A EI_METHOD_EXIT = 14,
0N/A EI_MONITOR_CONTENDED_ENTER = 15,
0N/A EI_MONITOR_CONTENDED_ENTERED = 16,
0N/A EI_MONITOR_WAIT = 17,
0N/A EI_MONITOR_WAITED = 18,
0N/A EI_VM_INIT = 19,
0N/A EI_VM_DEATH = 20,
0N/A EI_max = 20
0N/A} EventIndex;
0N/A
0N/A/* Agent errors that might be in a jvmtiError for JDWP or internal.
0N/A * (Done this way so that compiler allows it's use as a jvmtiError)
0N/A */
0N/A#define _AGENT_ERROR(x) ((jvmtiError)(JVMTI_ERROR_MAX+64+x))
0N/A#define AGENT_ERROR_INTERNAL _AGENT_ERROR(1)
0N/A#define AGENT_ERROR_VM_DEAD _AGENT_ERROR(2)
0N/A#define AGENT_ERROR_NO_JNI_ENV _AGENT_ERROR(3)
0N/A#define AGENT_ERROR_JNI_EXCEPTION _AGENT_ERROR(4)
0N/A#define AGENT_ERROR_JVMTI_INTERNAL _AGENT_ERROR(5)
0N/A#define AGENT_ERROR_JDWP_INTERNAL _AGENT_ERROR(6)
0N/A#define AGENT_ERROR_NOT_CURRENT_FRAME _AGENT_ERROR(7)
0N/A#define AGENT_ERROR_OUT_OF_MEMORY _AGENT_ERROR(8)
0N/A#define AGENT_ERROR_INVALID_TAG _AGENT_ERROR(9)
0N/A#define AGENT_ERROR_ALREADY_INVOKING _AGENT_ERROR(10)
0N/A#define AGENT_ERROR_INVALID_INDEX _AGENT_ERROR(11)
0N/A#define AGENT_ERROR_INVALID_LENGTH _AGENT_ERROR(12)
0N/A#define AGENT_ERROR_INVALID_STRING _AGENT_ERROR(13)
0N/A#define AGENT_ERROR_INVALID_CLASS_LOADER _AGENT_ERROR(14)
0N/A#define AGENT_ERROR_INVALID_ARRAY _AGENT_ERROR(15)
0N/A#define AGENT_ERROR_TRANSPORT_LOAD _AGENT_ERROR(16)
0N/A#define AGENT_ERROR_TRANSPORT_INIT _AGENT_ERROR(17)
0N/A#define AGENT_ERROR_NATIVE_METHOD _AGENT_ERROR(18)
0N/A#define AGENT_ERROR_INVALID_COUNT _AGENT_ERROR(19)
0N/A#define AGENT_ERROR_INVALID_FRAMEID _AGENT_ERROR(20)
0N/A#define AGENT_ERROR_NULL_POINTER _AGENT_ERROR(21)
0N/A#define AGENT_ERROR_ILLEGAL_ARGUMENT _AGENT_ERROR(22)
0N/A#define AGENT_ERROR_INVALID_THREAD _AGENT_ERROR(23)
0N/A#define AGENT_ERROR_INVALID_EVENT_TYPE _AGENT_ERROR(24)
0N/A#define AGENT_ERROR_INVALID_OBJECT _AGENT_ERROR(25)
0N/A#define AGENT_ERROR_NO_MORE_FRAMES _AGENT_ERROR(26)
0N/A
0N/A/* Combined event information */
0N/A
0N/Atypedef struct {
0N/A
0N/A EventIndex ei;
0N/A jthread thread;
0N/A jclass clazz;
0N/A jmethodID method;
0N/A jlocation location;
0N/A jobject object; /* possibly an exception or user object */
0N/A
0N/A union {
0N/A
0N/A /* ei = EI_FIELD_ACCESS */
0N/A struct {
0N/A jclass field_clazz;
0N/A jfieldID field;
0N/A } field_access;
0N/A
0N/A /* ei = EI_FIELD_MODIFICATION */
0N/A struct {
0N/A jclass field_clazz;
0N/A jfieldID field;
0N/A char signature_type;
0N/A jvalue new_value;
0N/A } field_modification;
0N/A
0N/A /* ei = EI_EXCEPTION */
0N/A struct {
0N/A jclass catch_clazz;
0N/A jmethodID catch_method;
0N/A jlocation catch_location;
0N/A } exception;
0N/A
0N/A /* ei = EI_METHOD_EXIT */
0N/A struct {
0N/A jvalue return_value;
0N/A } method_exit;
0N/A
0N/A /* For monitor wait events */
0N/A union {
0N/A /* ei = EI_MONITOR_WAIT */
0N/A jlong timeout;
0N/A /* ei = EI_MONITOR_WAITED */
0N/A jboolean timed_out;
0N/A } monitor;
0N/A } u;
0N/A
0N/A} EventInfo;
0N/A
0N/A/* Structure to hold dynamic array of objects */
0N/Atypedef struct ObjectBatch {
0N/A jobject *objects;
0N/A jint count;
0N/A} ObjectBatch;
0N/A
0N/A/*
0N/A * JNI signature constants, beyond those defined in JDWP_TAG(*)
0N/A */
0N/A#define SIGNATURE_BEGIN_ARGS '('
0N/A#define SIGNATURE_END_ARGS ')'
0N/A#define SIGNATURE_END_CLASS ';'
0N/A
0N/A/*
0N/A * Modifier flags for classes, fields, methods
0N/A */
0N/A#define MOD_PUBLIC 0x0001 /* visible to everyone */
0N/A#define MOD_PRIVATE 0x0002 /* visible only to the defining class */
0N/A#define MOD_PROTECTED 0x0004 /* visible to subclasses */
0N/A#define MOD_STATIC 0x0008 /* instance variable is static */
0N/A#define MOD_FINAL 0x0010 /* no further subclassing, overriding */
0N/A#define MOD_SYNCHRONIZED 0x0020 /* wrap method call in monitor lock */
0N/A#define MOD_VOLATILE 0x0040 /* can cache in registers */
0N/A#define MOD_TRANSIENT 0x0080 /* not persistant */
0N/A#define MOD_NATIVE 0x0100 /* implemented in C */
0N/A#define MOD_INTERFACE 0x0200 /* class is an interface */
0N/A#define MOD_ABSTRACT 0x0400 /* no definition provided */
0N/A/*
0N/A * Additional modifiers not defined as such in the JVM spec
0N/A */
0N/A#define MOD_SYNTHETIC 0xf0000000 /* not in source code */
0N/A
0N/A/*
0N/A * jlong conversion macros
0N/A */
0N/A#define jlong_zero ((jlong) 0)
0N/A#define jlong_one ((jlong) 1)
0N/A
0N/A#define jlong_to_ptr(a) ((void*)(intptr_t)(a))
0N/A#define ptr_to_jlong(a) ((jlong)(intptr_t)(a))
0N/A#define jint_to_jlong(a) ((jlong)(a))
0N/A#define jlong_to_jint(a) ((jint)(a))
0N/A
0N/A
0N/A/*
0N/A * util funcs
0N/A */
0N/Avoid util_initialize(JNIEnv *env);
0N/Avoid util_reset(void);
0N/A
0N/Astruct PacketInputStream;
0N/Astruct PacketOutputStream;
0N/A
0N/Ajint uniqueID(void);
0N/Ajbyte referenceTypeTag(jclass clazz);
0N/Ajbyte specificTypeKey(JNIEnv *env, jobject object);
0N/Ajboolean isObjectTag(jbyte tag);
0N/AjvmtiError spawnNewThread(jvmtiStartFunction func, void *arg, char *name);
0N/Avoid convertSignatureToClassname(char *convert);
0N/Avoid writeCodeLocation(struct PacketOutputStream *out, jclass clazz,
0N/A jmethodID method, jlocation location);
0N/A
0N/AjvmtiError classInstances(jclass klass, ObjectBatch *instances, int maxInstances);
0N/AjvmtiError classInstanceCounts(jint classCount, jclass *classes, jlong *counts);
0N/AjvmtiError objectReferrers(jobject obj, ObjectBatch *referrers, int maxObjects);
0N/A
0N/A/*
0N/A * Command handling helpers shared among multiple command sets
0N/A */
0N/Aint filterDebugThreads(jthread *threads, int count);
0N/A
0N/A
0N/Avoid sharedGetFieldValues(struct PacketInputStream *in,
0N/A struct PacketOutputStream *out,
0N/A jboolean isStatic);
0N/Ajboolean sharedInvoke(struct PacketInputStream *in,
0N/A struct PacketOutputStream *out);
0N/A
0N/AjvmtiError fieldSignature(jclass, jfieldID, char **, char **, char **);
0N/AjvmtiError fieldModifiers(jclass, jfieldID, jint *);
0N/AjvmtiError methodSignature(jmethodID, char **, char **, char **);
0N/AjvmtiError methodReturnType(jmethodID, char *);
0N/AjvmtiError methodModifiers(jmethodID, jint *);
0N/AjvmtiError methodClass(jmethodID, jclass *);
0N/AjvmtiError methodLocation(jmethodID, jlocation*, jlocation*);
0N/AjvmtiError classLoader(jclass, jobject *);
0N/A
0N/A/*
0N/A * Thin wrappers on top of JNI
0N/A */
0N/AJNIEnv *getEnv(void);
0N/Ajboolean isClass(jobject object);
0N/Ajboolean isThread(jobject object);
0N/Ajboolean isThreadGroup(jobject object);
0N/Ajboolean isString(jobject object);
0N/Ajboolean isClassLoader(jobject object);
0N/Ajboolean isArray(jobject object);
0N/A
0N/A/*
0N/A * Thin wrappers on top of JVMTI
0N/A */
0N/AjvmtiError jvmtiGetCapabilities(jvmtiCapabilities *caps);
0N/Ajint jvmtiMajorVersion(void);
0N/Ajint jvmtiMinorVersion(void);
0N/Ajint jvmtiMicroVersion(void);
0N/AjvmtiError getSourceDebugExtension(jclass clazz, char **extensionPtr);
0N/Ajboolean canSuspendResumeThreadLists(void);
0N/A
0N/AjrawMonitorID debugMonitorCreate(char *name);
0N/Avoid debugMonitorEnter(jrawMonitorID theLock);
0N/Avoid debugMonitorExit(jrawMonitorID theLock);
0N/Avoid debugMonitorWait(jrawMonitorID theLock);
0N/Avoid debugMonitorTimedWait(jrawMonitorID theLock, jlong millis);
0N/Avoid debugMonitorNotify(jrawMonitorID theLock);
0N/Avoid debugMonitorNotifyAll(jrawMonitorID theLock);
0N/Avoid debugMonitorDestroy(jrawMonitorID theLock);
0N/A
0N/Ajthread *allThreads(jint *count);
0N/A
0N/Avoid threadGroupInfo(jthreadGroup, jvmtiThreadGroupInfo *info);
0N/A
0N/Achar *getClassname(jclass);
0N/AjvmtiError classSignature(jclass, char**, char**);
0N/Ajint classStatus(jclass);
0N/Avoid writeGenericSignature(struct PacketOutputStream *, char *);
0N/Ajboolean isMethodNative(jmethodID);
0N/Ajboolean isMethodObsolete(jmethodID);
0N/AjvmtiError isMethodSynthetic(jmethodID, jboolean*);
0N/AjvmtiError isFieldSynthetic(jclass, jfieldID, jboolean*);
0N/A
0N/Ajboolean isSameObject(JNIEnv *env, jobject o1, jobject o2);
0N/A
0N/Ajint objectHashCode(jobject);
0N/A
0N/AjvmtiError allInterfaces(jclass clazz, jclass **ppinterfaces, jint *count);
0N/AjvmtiError allLoadedClasses(jclass **ppclasses, jint *count);
0N/AjvmtiError allClassLoaderClasses(jobject loader, jclass **ppclasses, jint *count);
0N/AjvmtiError allNestedClasses(jclass clazz, jclass **ppnested, jint *pcount);
0N/A
0N/Avoid setAgentPropertyValue(JNIEnv *env, char *propertyName, char* propertyValue);
0N/A
0N/Avoid *jvmtiAllocate(jint numBytes);
0N/Avoid jvmtiDeallocate(void *buffer);
0N/A
0N/Avoid eventIndexInit(void);
0N/AjdwpEvent eventIndex2jdwp(EventIndex i);
0N/AjvmtiEvent eventIndex2jvmti(EventIndex i);
0N/AEventIndex jdwp2EventIndex(jdwpEvent eventType);
0N/AEventIndex jvmti2EventIndex(jvmtiEvent kind);
0N/A
0N/AjvmtiError map2jvmtiError(jdwpError);
0N/AjdwpError map2jdwpError(jvmtiError);
0N/AjdwpThreadStatus map2jdwpThreadStatus(jint state);
0N/Ajint map2jdwpSuspendStatus(jint state);
0N/Ajint map2jdwpClassStatus(jint);
0N/A
0N/Avoid log_debugee_location(const char *func,
0N/A jthread thread, jmethodID method, jlocation location);
0N/A
0N/A/*
0N/A * Local Reference management. The two macros below are used
0N/A * throughout the back end whenever space for JNI local references
0N/A * is needed in the current frame.
0N/A */
0N/A
0N/Avoid createLocalRefSpace(JNIEnv *env, jint capacity);
0N/A
0N/A#define WITH_LOCAL_REFS(env, number) \
0N/A createLocalRefSpace(env, number); \
0N/A { /* BEGINNING OF WITH SCOPE */
0N/A
0N/A#define END_WITH_LOCAL_REFS(env) \
0N/A JNI_FUNC_PTR(env,PopLocalFrame)(env, NULL); \
0N/A } /* END OF WITH SCOPE */
0N/A
0N/Avoid saveGlobalRef(JNIEnv *env, jobject obj, jobject *pobj);
0N/Avoid tossGlobalRef(JNIEnv *env, jobject *pobj);
0N/A
0N/A#endif