Skip to content
Permalink
Browse files
8259350: Add some internal debugging APIs to the debug agent
Reviewed-by: sspitsyn, amenkov
  • Loading branch information
plummercj committed Jan 14, 2021
1 parent a6b2162 commit d18d26e89d8fcbab73e9b866b90b27d0353d0191
Showing 8 changed files with 258 additions and 8 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -1359,3 +1359,90 @@ eventFilterRestricted_deinstall(HandlerNode *node)

return error1 != JVMTI_ERROR_NONE? error1 : error2;
}

/***** debugging *****/

#ifdef DEBUG

void
eventFilter_dumpHandlerFilters(HandlerNode *node)
{
int i;
Filter *filter = FILTERS_ARRAY(node);

for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) {
switch (filter->modifier) {
case JDWP_REQUEST_MODIFIER(ThreadOnly):
tty_message("ThreadOnly: thread(%p)",
filter->u.ThreadOnly.thread);
break;
case JDWP_REQUEST_MODIFIER(ClassOnly): {
char *class_name;
classSignature(filter->u.ClassOnly.clazz, &class_name, NULL);
tty_message("ClassOnly: clazz(%s)",
class_name);
break;
}
case JDWP_REQUEST_MODIFIER(LocationOnly): {
char *method_name;
char *class_name;
methodSignature(filter->u.LocationOnly.method, &method_name, NULL, NULL);
classSignature(filter->u.LocationOnly.clazz, &class_name, NULL);
tty_message("LocationOnly: clazz(%s), method(%s) location(%d)",
class_name,
method_name,
filter->u.LocationOnly.location);
break;
}
case JDWP_REQUEST_MODIFIER(FieldOnly): {
char *class_name;
classSignature(filter->u.FieldOnly.clazz, &class_name, NULL);
tty_message("FieldOnly: clazz(%p), field(%d)",
class_name,
filter->u.FieldOnly.field);
break;
}
case JDWP_REQUEST_MODIFIER(ExceptionOnly):
tty_message("ExceptionOnly: clazz(%p), caught(%d) uncaught(%d)",
filter->u.ExceptionOnly.exception,
filter->u.ExceptionOnly.caught,
filter->u.ExceptionOnly.uncaught);
break;
case JDWP_REQUEST_MODIFIER(InstanceOnly):
tty_message("InstanceOnly: instance(%p)",
filter->u.InstanceOnly.instance);
break;
case JDWP_REQUEST_MODIFIER(Count):
tty_message("Count: count(%d)",
filter->u.Count.count);
break;
case JDWP_REQUEST_MODIFIER(Conditional):
tty_message("Conditional: exprID(%d)",
filter->u.Conditional.exprID);
break;
case JDWP_REQUEST_MODIFIER(ClassMatch):
tty_message("ClassMatch: classPattern(%s)",
filter->u.ClassMatch.classPattern);
break;
case JDWP_REQUEST_MODIFIER(ClassExclude):
tty_message("ClassExclude: classPattern(%s)",
filter->u.ClassExclude.classPattern);
break;
case JDWP_REQUEST_MODIFIER(Step):
tty_message("Step: size(%d) depth(%d) thread(%p)",
filter->u.Step.size,
filter->u.Step.depth,
filter->u.Step.thread);
break;
case JDWP_REQUEST_MODIFIER(SourceNameMatch):
tty_message("SourceNameMatch: sourceNamePattern(%s)",
filter->u.SourceNameOnly.sourceNamePattern);
break;
default:
EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT, "Invalid filter modifier");
return;
}
}
}

#endif /* DEBUG */
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -75,4 +75,10 @@ jvmtiError eventFilter_setSourceNameMatchFilter(HandlerNode *node,
jboolean eventFilter_predictFiltering(HandlerNode *node, jclass clazz, char *classname);
jboolean isBreakpointSet(jclass clazz, jmethodID method, jlocation location);

/***** debugging *****/

#ifdef DEBUG
void eventFilter_dumpHandlerFilters(HandlerNode *node);
#endif

#endif /* _EVENT_FILTER_H */
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -1713,3 +1713,47 @@ eventHandler_installExternal(HandlerNode *node)
standardHandlers_defaultHandler(node->ei),
JNI_TRUE);
}

/***** debugging *****/

#ifdef DEBUG

void
eventHandler_dumpAllHandlers(jboolean dumpPermanent)
{
int ei;
for (ei = EI_min; ei <= EI_max; ++ei) {
eventHandler_dumpHandlers(ei, dumpPermanent);
}
}

void
eventHandler_dumpHandlers(EventIndex ei, jboolean dumpPermanent)
{
HandlerNode *nextNode;
nextNode = getHandlerChain(ei)->first;
if (nextNode != NULL) {
tty_message("\nHandlers for %s(%d)", eventIndex2EventName(ei), ei);
while (nextNode != NULL) {
HandlerNode *node = nextNode;
nextNode = NEXT(node);

if (node->permanent && !dumpPermanent) {
continue; // ignore permanent handlers
}

tty_message("node(%p) handlerID(%d) suspendPolicy(%d) permanent(%d)",
node, node->handlerID, node->suspendPolicy, node->permanent);
eventFilter_dumpHandlerFilters(node);
}
}
}

void
eventHandler_dumpHandler(HandlerNode *node)
{
tty_message("Handler for %s(%d)\n", eventIndex2EventName(node->ei), node->ei);
eventFilter_dumpHandlerFilters(node);
}

#endif /* DEBUG */
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -79,4 +79,12 @@ void eventHandler_unlock(void);

jclass getMethodClass(jvmtiEnv *jvmti_env, jmethodID method);

/***** debugging *****/

#ifdef DEBUG
void eventHandler_dumpAllHandlers(jboolean dumpPermanent);
void eventHandler_dumpHandlers(EventIndex ei, jboolean dumpPermanent);
void eventHandler_dumpHandler(HandlerNode *node);
#endif

#endif /* _EVENTHANDLER_H */
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -140,6 +140,11 @@ typedef struct {

static DeferredEventModeList deferredEventModes;

#ifdef DEBUG
static void dumpThreadList(ThreadList *list);
static void dumpThread(ThreadNode *node);
#endif

static jint
getStackDepth(jthread thread)
{
@@ -2513,3 +2518,40 @@ threadControl_getFrameGeneration(jthread thread)

return frameGeneration;
}

/***** debugging *****/

#ifdef DEBUG

void
threadControl_dumpAllThreads()
{
tty_message("Dumping runningThreads:\n");
dumpThreadList(&runningThreads);
tty_message("Dumping otherThreads:\n");
dumpThreadList(&otherThreads);
}

static void
dumpThreadList(ThreadList *list)
{
ThreadNode *node;
for (node = list->first; node != NULL; node = node->next) {
if (!node->isDebugThread) {
dumpThread(node);
}
}
}

static void
dumpThread(ThreadNode *node) {
tty_message(" Thread: node = %p, jthread = %p", node, node->thread);
#ifdef DEBUG_THREADNAME
tty_message("\tname: %s", node->name);
#endif
// More fields can be printed here when needed. The amount of output is intentionlly
// kept small so it doesn't generate too much output.
tty_message("\tsuspendCount: %d", node->suspendCount);
}

#endif /* DEBUG */
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -75,4 +75,10 @@ void threadControl_saveCLEInfo(JNIEnv *env, jthread thread, EventIndex ei,
jlocation location);
jlong threadControl_getFrameGeneration(jthread thread);

/***** debugging *****/

#ifdef DEBUG
void threadControl_dumpAllThreads();
#endif

#endif
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -1982,6 +1982,60 @@ eventIndex2jvmti(EventIndex i)
return index2jvmti[i-EI_min];
}

#ifdef DEBUG

char*
eventIndex2EventName(EventIndex ei)
{
switch ( ei ) {
case EI_SINGLE_STEP:
return "EI_SINGLE_STEP";
case EI_BREAKPOINT:
return "EI_BREAKPOINT";
case EI_FRAME_POP:
return "EI_FRAME_POP";
case EI_EXCEPTION:
return "EI_EXCEPTION";
case EI_THREAD_START:
return "EI_THREAD_START";
case EI_THREAD_END:
return "EI_THREAD_END";
case EI_CLASS_PREPARE:
return "EI_CLASS_PREPARE";
case EI_GC_FINISH:
return "EI_GC_FINISH";
case EI_CLASS_LOAD:
return "EI_CLASS_LOAD";
case EI_FIELD_ACCESS:
return "EI_FIELD_ACCESS";
case EI_FIELD_MODIFICATION:
return "EI_FIELD_MODIFICATION";
case EI_EXCEPTION_CATCH:
return "EI_EXCEPTION_CATCH";
case EI_METHOD_ENTRY:
return "EI_METHOD_ENTRY";
case EI_METHOD_EXIT:
return "EI_METHOD_EXIT";
case EI_MONITOR_CONTENDED_ENTER:
return "EI_MONITOR_CONTENDED_ENTER";
case EI_MONITOR_CONTENDED_ENTERED:
return "EI_MONITOR_CONTENDED_ENTERED";
case EI_MONITOR_WAIT:
return "EI_MONITOR_WAIT";
case EI_MONITOR_WAITED:
return "EI_MONITOR_WAITED";
case EI_VM_INIT:
return "EI_VM_INIT";
case EI_VM_DEATH:
return "EI_VM_DEATH";
default:
JDI_ASSERT(JNI_FALSE);
return "Bad EI";
}
}

#endif

EventIndex
jdwp2EventIndex(jdwpEvent eventType)
{
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -379,6 +379,9 @@ void *jvmtiAllocate(jint numBytes);
void jvmtiDeallocate(void *buffer);

void eventIndexInit(void);
#ifdef DEBUG
char* eventIndex2EventName(EventIndex ei);
#endif
jdwpEvent eventIndex2jdwp(EventIndex i);
jvmtiEvent eventIndex2jvmti(EventIndex i);
EventIndex jdwp2EventIndex(jdwpEvent eventType);

1 comment on commit d18d26e

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on d18d26e Jan 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.