Example #1
0
static void printRefTables(void) {
    int count;
    int i;
    RefNode *node;

    TTY_MESSAGE(("\nID-based object table:\n"));
    for (count=0, i = 0; i < CR_HASH_SLOT_COUNT; i++) {
        node = objectsByID[i];
        while (node != NULL) {
            TTY_MESSAGE(("%d: slot=%d ref=" PTR_FORMAT " isStrong=%x count=%d refSlot=%d",
                    /*LINTED*/
		    (int)node->seqNum, i, (intptr_t)node->ref, node->isStrong, 
                    node->count, node->refSlot));
            count++;
            node = node->nextByID;
        }
    }
    TTY_MESSAGE(("Total of %d objects", count));

    TTY_MESSAGE(("\nRef-based object table:\n"));
    for (count=0, i = 0; i < CR_HASH_SLOT_COUNT; i++) {
        node = objectsByRef[i];
        while (node != NULL) {
            TTY_MESSAGE((PTR_FORMAT ": slot=%d id=%d isStrong=%x count=%d",
                    /*LINTED*/
                    (intptr_t)node->ref, i, (int)node->seqNum, node->isStrong, 
                    node->count));
            count++;
            node = node->nextByRef;
        }
    }
    TTY_MESSAGE(("Total of %d objects", count));
}
Example #2
0
jdwpError
transport_startTransport(jboolean isServer, char *name, char *address,
                         long timeout)
{
    jvmtiStartFunction func;
    jdwpTransportEnv *trans;
    char threadName[MAXPATHLEN + 100];
    jint err;
    jdwpError serror;

    /*
     * If the transport is already loaded then use it
     * Note: We're assuming here that we don't support multiple
     * transports - when we do then we need to handle the case
     * where the transport library only supports a single environment.
     * That probably means we have a bag a transport environments
     * to correspond to the transports bag.
     */
    if (transport != NULL) {
        trans = transport;
    } else {
        serror = loadTransport(name, &trans);
        if (serror != JDWP_ERROR(NONE)) {
            return serror;
        }
    }

    if (isServer) {

        char *retAddress;
        char *launchCommand;
        TransportInfo *info;
        jvmtiError error;
        int len;
        char* prop_value;

        info = jvmtiAllocate(sizeof(*info));
        if (info == NULL) {
            return JDWP_ERROR(OUT_OF_MEMORY);
        }
        info->name = jvmtiAllocate((int)strlen(name)+1);
        (void)strcpy(info->name, name);
        info->address = NULL;
        info->timeout = timeout;
        if (info->name == NULL) {
            serror = JDWP_ERROR(OUT_OF_MEMORY);
            goto handleError;
        }
        if (address != NULL) {
            info->address = jvmtiAllocate((int)strlen(address)+1);
            (void)strcpy(info->address, address);
            if (info->address == NULL) {
                serror = JDWP_ERROR(OUT_OF_MEMORY);
                goto handleError;
            }
        }

        info->transport = trans;

        err = (*trans)->StartListening(trans, address, &retAddress);
        if (err != JDWPTRANSPORT_ERROR_NONE) {
            printLastError(trans, err);
            serror = JDWP_ERROR(TRANSPORT_INIT);
            goto handleError;
        }

        /*
         * Record listener address in a system property
         */
        len = (int)strlen(name) + (int)strlen(retAddress) + 2; /* ':' and '\0' */
        prop_value = (char*)jvmtiAllocate(len);
        strcpy(prop_value, name);
        strcat(prop_value, ":");
        strcat(prop_value, retAddress);
        setTransportProperty(getEnv(), prop_value);
        jvmtiDeallocate(prop_value);


        (void)strcpy(threadName, "JDWP Transport Listener: ");
        (void)strcat(threadName, name);

        func = &acceptThread;
        error = spawnNewThread(func, (void*)info, threadName);
        if (error != JVMTI_ERROR_NONE) {
            serror = map2jdwpError(error);
            goto handleError;
        }

        launchCommand = debugInit_launchOnInit();
        if (launchCommand != NULL) {
            serror = launch(launchCommand, name, retAddress);
            if (serror != JDWP_ERROR(NONE)) {
                goto handleError;
            }
        } else {
            if ( ! gdata->quiet ) {
                TTY_MESSAGE(("Listening for transport %s at address: %s",
                    name, retAddress));
            }
        }
        return JDWP_ERROR(NONE);

handleError:
        jvmtiDeallocate(info->name);
        jvmtiDeallocate(info->address);
        jvmtiDeallocate(info);
    } else {
        /*
         * Note that we don't attempt to do a launch here. Launching
         * is currently supported only in server mode.
         */

        /*
         * If we're connecting to another process, there shouldn't be
         * any concurrent listens, so its ok if we block here in this
         * thread, waiting for the attach to finish.
         */
         err = (*trans)->Attach(trans, address, timeout, 0);
         if (err != JDWPTRANSPORT_ERROR_NONE) {
             printLastError(trans, err);
             serror = JDWP_ERROR(TRANSPORT_INIT);
             return serror;
         }

         /*
          * Start the transport loop in a separate thread
          */
         (void)strcpy(threadName, "JDWP Transport Listener: ");
         (void)strcat(threadName, name);

         func = &attachThread;
         err = spawnNewThread(func, (void*)trans, threadName);
         serror = map2jdwpError(err);
    }
    return serror;
}
Example #3
0
static void
printUsage(void)
{
    TTY_MESSAGE((
                    "               Java Debugger JDWP Agent Library\n"
                    "               --------------------------------\n"
                    "\n"
                    "  (see http://java.sun.com/products/jpda for more information)\n"
                    "\n"
                    "jdwp usage: java " AGENTLIB "=[help]|[<option>=<value>, ...]\n"
                    "\n"
                    "Option Name and Value            Description                       Default\n"
                    "---------------------            -----------                       -------\n"
                    "suspend=y|n                      wait on startup?                  y\n"
                    "transport=<name>                 transport spec                    none\n"
                    "address=<listen/attach address>  transport spec                    \"\"\n"
                    "server=y|n                       listen for debugger?              n\n"
                    "launch=<command line>            run debugger on event             none\n"
                    "onthrow=<exception name>         debug on throw                    none\n"
                    "onuncaught=y|n                   debug on any uncaught?            n\n"
                    "timeout=<timeout value>          for listen/attach in milliseconds n\n"
                    "mutf8=y|n                        output modified utf-8             n\n"
                    "quiet=y|n                        control over terminal messages    n\n"));

    TTY_MESSAGE((
                    "Obsolete Options\n"
                    "----------------\n"
                    "strict=y|n\n"
                    "stdalloc=y|n\n"
                    "\n"
                    "Examples\n"
                    "--------\n"
                    "  - Using sockets connect to a debugger at a specific address:\n"
                    "    java " AGENTLIB "=transport=dt_socket,address=localhost:8000 ...\n"
                    "  - Using sockets listen for a debugger to attach:\n"
                    "    java " AGENTLIB "=transport=dt_socket,server=y,suspend=y ...\n"
                    "\n"
                    "Notes\n"
                    "-----\n"
                    "  - A timeout value of 0 (the default) is no timeout.\n"
                    "\n"
                    "Warnings\n"
                    "--------\n"
                    "  - The older " XRUN " interface can still be used, but will be removed in\n"
                    "    a future release, for example:\n"
                    "        java " XDEBUG " " XRUN ":[help]|[<option>=<value>, ...]\n"
                ));

#ifdef DEBUG

    TTY_MESSAGE((
                    "\n"
                    "Debugging Options            Description                       Default\n"
                    "-----------------            -----------                       -------\n"
                    "pause=y|n                    pause to debug PID                n\n"
                    "coredump=y|n                 coredump at exit                  n\n"
                    "errorexit=y|n                exit on any error                 n\n"
                    "logfile=filename             name of log file                  none\n"
                    "logflags=flags               log flags (bitmask)               none\n"
                    "                               JVM calls     = 0x001\n"
                    "                               JNI calls     = 0x002\n"
                    "                               JVMTI calls   = 0x004\n"
                    "                               misc events   = 0x008\n"
                    "                               step logs     = 0x010\n"
                    "                               locations     = 0x020\n"
                    "                               callbacks     = 0x040\n"
                    "                               errors        = 0x080\n"
                    "                               everything    = 0xfff"));

    TTY_MESSAGE((
                    "debugflags=flags             debug flags (bitmask)           none\n"
                    "                               USE_ITERATE_THROUGH_HEAP 0x01\n"
                    "\n"
                    "Environment Variables\n"
                    "---------------------\n"
                    "_JAVA_JDWP_OPTIONS\n"
                    "    Options can be added externally via this environment variable.\n"
                    "    Anything contained in it will get a comma prepended to it (if needed),\n"
                    "    then it will be added to the end of the options supplied via the\n"
                    "    " XRUN " or " AGENTLIB " command line option.\n"
                ));

#endif



}