Skip to content

Commit d18d26e

Browse files
committed
8259350: Add some internal debugging APIs to the debug agent
Reviewed-by: sspitsyn, amenkov
1 parent a6b2162 commit d18d26e

File tree

8 files changed

+258
-8
lines changed

8 files changed

+258
-8
lines changed

src/jdk.jdwp.agent/share/native/libjdwp/eventFilter.c

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1359,3 +1359,90 @@ eventFilterRestricted_deinstall(HandlerNode *node)
13591359

13601360
return error1 != JVMTI_ERROR_NONE? error1 : error2;
13611361
}
1362+
1363+
/***** debugging *****/
1364+
1365+
#ifdef DEBUG
1366+
1367+
void
1368+
eventFilter_dumpHandlerFilters(HandlerNode *node)
1369+
{
1370+
int i;
1371+
Filter *filter = FILTERS_ARRAY(node);
1372+
1373+
for (i = 0; i < FILTER_COUNT(node); ++i, ++filter) {
1374+
switch (filter->modifier) {
1375+
case JDWP_REQUEST_MODIFIER(ThreadOnly):
1376+
tty_message("ThreadOnly: thread(%p)",
1377+
filter->u.ThreadOnly.thread);
1378+
break;
1379+
case JDWP_REQUEST_MODIFIER(ClassOnly): {
1380+
char *class_name;
1381+
classSignature(filter->u.ClassOnly.clazz, &class_name, NULL);
1382+
tty_message("ClassOnly: clazz(%s)",
1383+
class_name);
1384+
break;
1385+
}
1386+
case JDWP_REQUEST_MODIFIER(LocationOnly): {
1387+
char *method_name;
1388+
char *class_name;
1389+
methodSignature(filter->u.LocationOnly.method, &method_name, NULL, NULL);
1390+
classSignature(filter->u.LocationOnly.clazz, &class_name, NULL);
1391+
tty_message("LocationOnly: clazz(%s), method(%s) location(%d)",
1392+
class_name,
1393+
method_name,
1394+
filter->u.LocationOnly.location);
1395+
break;
1396+
}
1397+
case JDWP_REQUEST_MODIFIER(FieldOnly): {
1398+
char *class_name;
1399+
classSignature(filter->u.FieldOnly.clazz, &class_name, NULL);
1400+
tty_message("FieldOnly: clazz(%p), field(%d)",
1401+
class_name,
1402+
filter->u.FieldOnly.field);
1403+
break;
1404+
}
1405+
case JDWP_REQUEST_MODIFIER(ExceptionOnly):
1406+
tty_message("ExceptionOnly: clazz(%p), caught(%d) uncaught(%d)",
1407+
filter->u.ExceptionOnly.exception,
1408+
filter->u.ExceptionOnly.caught,
1409+
filter->u.ExceptionOnly.uncaught);
1410+
break;
1411+
case JDWP_REQUEST_MODIFIER(InstanceOnly):
1412+
tty_message("InstanceOnly: instance(%p)",
1413+
filter->u.InstanceOnly.instance);
1414+
break;
1415+
case JDWP_REQUEST_MODIFIER(Count):
1416+
tty_message("Count: count(%d)",
1417+
filter->u.Count.count);
1418+
break;
1419+
case JDWP_REQUEST_MODIFIER(Conditional):
1420+
tty_message("Conditional: exprID(%d)",
1421+
filter->u.Conditional.exprID);
1422+
break;
1423+
case JDWP_REQUEST_MODIFIER(ClassMatch):
1424+
tty_message("ClassMatch: classPattern(%s)",
1425+
filter->u.ClassMatch.classPattern);
1426+
break;
1427+
case JDWP_REQUEST_MODIFIER(ClassExclude):
1428+
tty_message("ClassExclude: classPattern(%s)",
1429+
filter->u.ClassExclude.classPattern);
1430+
break;
1431+
case JDWP_REQUEST_MODIFIER(Step):
1432+
tty_message("Step: size(%d) depth(%d) thread(%p)",
1433+
filter->u.Step.size,
1434+
filter->u.Step.depth,
1435+
filter->u.Step.thread);
1436+
break;
1437+
case JDWP_REQUEST_MODIFIER(SourceNameMatch):
1438+
tty_message("SourceNameMatch: sourceNamePattern(%s)",
1439+
filter->u.SourceNameOnly.sourceNamePattern);
1440+
break;
1441+
default:
1442+
EXIT_ERROR(AGENT_ERROR_ILLEGAL_ARGUMENT, "Invalid filter modifier");
1443+
return;
1444+
}
1445+
}
1446+
}
1447+
1448+
#endif /* DEBUG */

src/jdk.jdwp.agent/share/native/libjdwp/eventFilter.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -75,4 +75,10 @@ jvmtiError eventFilter_setSourceNameMatchFilter(HandlerNode *node,
7575
jboolean eventFilter_predictFiltering(HandlerNode *node, jclass clazz, char *classname);
7676
jboolean isBreakpointSet(jclass clazz, jmethodID method, jlocation location);
7777

78+
/***** debugging *****/
79+
80+
#ifdef DEBUG
81+
void eventFilter_dumpHandlerFilters(HandlerNode *node);
82+
#endif
83+
7884
#endif /* _EVENT_FILTER_H */

src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1713,3 +1713,47 @@ eventHandler_installExternal(HandlerNode *node)
17131713
standardHandlers_defaultHandler(node->ei),
17141714
JNI_TRUE);
17151715
}
1716+
1717+
/***** debugging *****/
1718+
1719+
#ifdef DEBUG
1720+
1721+
void
1722+
eventHandler_dumpAllHandlers(jboolean dumpPermanent)
1723+
{
1724+
int ei;
1725+
for (ei = EI_min; ei <= EI_max; ++ei) {
1726+
eventHandler_dumpHandlers(ei, dumpPermanent);
1727+
}
1728+
}
1729+
1730+
void
1731+
eventHandler_dumpHandlers(EventIndex ei, jboolean dumpPermanent)
1732+
{
1733+
HandlerNode *nextNode;
1734+
nextNode = getHandlerChain(ei)->first;
1735+
if (nextNode != NULL) {
1736+
tty_message("\nHandlers for %s(%d)", eventIndex2EventName(ei), ei);
1737+
while (nextNode != NULL) {
1738+
HandlerNode *node = nextNode;
1739+
nextNode = NEXT(node);
1740+
1741+
if (node->permanent && !dumpPermanent) {
1742+
continue; // ignore permanent handlers
1743+
}
1744+
1745+
tty_message("node(%p) handlerID(%d) suspendPolicy(%d) permanent(%d)",
1746+
node, node->handlerID, node->suspendPolicy, node->permanent);
1747+
eventFilter_dumpHandlerFilters(node);
1748+
}
1749+
}
1750+
}
1751+
1752+
void
1753+
eventHandler_dumpHandler(HandlerNode *node)
1754+
{
1755+
tty_message("Handler for %s(%d)\n", eventIndex2EventName(node->ei), node->ei);
1756+
eventFilter_dumpHandlerFilters(node);
1757+
}
1758+
1759+
#endif /* DEBUG */

src/jdk.jdwp.agent/share/native/libjdwp/eventHandler.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -79,4 +79,12 @@ void eventHandler_unlock(void);
7979

8080
jclass getMethodClass(jvmtiEnv *jvmti_env, jmethodID method);
8181

82+
/***** debugging *****/
83+
84+
#ifdef DEBUG
85+
void eventHandler_dumpAllHandlers(jboolean dumpPermanent);
86+
void eventHandler_dumpHandlers(EventIndex ei, jboolean dumpPermanent);
87+
void eventHandler_dumpHandler(HandlerNode *node);
88+
#endif
89+
8290
#endif /* _EVENTHANDLER_H */

src/jdk.jdwp.agent/share/native/libjdwp/threadControl.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -140,6 +140,11 @@ typedef struct {
140140

141141
static DeferredEventModeList deferredEventModes;
142142

143+
#ifdef DEBUG
144+
static void dumpThreadList(ThreadList *list);
145+
static void dumpThread(ThreadNode *node);
146+
#endif
147+
143148
static jint
144149
getStackDepth(jthread thread)
145150
{
@@ -2513,3 +2518,40 @@ threadControl_getFrameGeneration(jthread thread)
25132518

25142519
return frameGeneration;
25152520
}
2521+
2522+
/***** debugging *****/
2523+
2524+
#ifdef DEBUG
2525+
2526+
void
2527+
threadControl_dumpAllThreads()
2528+
{
2529+
tty_message("Dumping runningThreads:\n");
2530+
dumpThreadList(&runningThreads);
2531+
tty_message("Dumping otherThreads:\n");
2532+
dumpThreadList(&otherThreads);
2533+
}
2534+
2535+
static void
2536+
dumpThreadList(ThreadList *list)
2537+
{
2538+
ThreadNode *node;
2539+
for (node = list->first; node != NULL; node = node->next) {
2540+
if (!node->isDebugThread) {
2541+
dumpThread(node);
2542+
}
2543+
}
2544+
}
2545+
2546+
static void
2547+
dumpThread(ThreadNode *node) {
2548+
tty_message(" Thread: node = %p, jthread = %p", node, node->thread);
2549+
#ifdef DEBUG_THREADNAME
2550+
tty_message("\tname: %s", node->name);
2551+
#endif
2552+
// More fields can be printed here when needed. The amount of output is intentionlly
2553+
// kept small so it doesn't generate too much output.
2554+
tty_message("\tsuspendCount: %d", node->suspendCount);
2555+
}
2556+
2557+
#endif /* DEBUG */

src/jdk.jdwp.agent/share/native/libjdwp/threadControl.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* 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,
7575
jlocation location);
7676
jlong threadControl_getFrameGeneration(jthread thread);
7777

78+
/***** debugging *****/
79+
80+
#ifdef DEBUG
81+
void threadControl_dumpAllThreads();
82+
#endif
83+
7884
#endif

src/jdk.jdwp.agent/share/native/libjdwp/util.c

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1982,6 +1982,60 @@ eventIndex2jvmti(EventIndex i)
19821982
return index2jvmti[i-EI_min];
19831983
}
19841984

1985+
#ifdef DEBUG
1986+
1987+
char*
1988+
eventIndex2EventName(EventIndex ei)
1989+
{
1990+
switch ( ei ) {
1991+
case EI_SINGLE_STEP:
1992+
return "EI_SINGLE_STEP";
1993+
case EI_BREAKPOINT:
1994+
return "EI_BREAKPOINT";
1995+
case EI_FRAME_POP:
1996+
return "EI_FRAME_POP";
1997+
case EI_EXCEPTION:
1998+
return "EI_EXCEPTION";
1999+
case EI_THREAD_START:
2000+
return "EI_THREAD_START";
2001+
case EI_THREAD_END:
2002+
return "EI_THREAD_END";
2003+
case EI_CLASS_PREPARE:
2004+
return "EI_CLASS_PREPARE";
2005+
case EI_GC_FINISH:
2006+
return "EI_GC_FINISH";
2007+
case EI_CLASS_LOAD:
2008+
return "EI_CLASS_LOAD";
2009+
case EI_FIELD_ACCESS:
2010+
return "EI_FIELD_ACCESS";
2011+
case EI_FIELD_MODIFICATION:
2012+
return "EI_FIELD_MODIFICATION";
2013+
case EI_EXCEPTION_CATCH:
2014+
return "EI_EXCEPTION_CATCH";
2015+
case EI_METHOD_ENTRY:
2016+
return "EI_METHOD_ENTRY";
2017+
case EI_METHOD_EXIT:
2018+
return "EI_METHOD_EXIT";
2019+
case EI_MONITOR_CONTENDED_ENTER:
2020+
return "EI_MONITOR_CONTENDED_ENTER";
2021+
case EI_MONITOR_CONTENDED_ENTERED:
2022+
return "EI_MONITOR_CONTENDED_ENTERED";
2023+
case EI_MONITOR_WAIT:
2024+
return "EI_MONITOR_WAIT";
2025+
case EI_MONITOR_WAITED:
2026+
return "EI_MONITOR_WAITED";
2027+
case EI_VM_INIT:
2028+
return "EI_VM_INIT";
2029+
case EI_VM_DEATH:
2030+
return "EI_VM_DEATH";
2031+
default:
2032+
JDI_ASSERT(JNI_FALSE);
2033+
return "Bad EI";
2034+
}
2035+
}
2036+
2037+
#endif
2038+
19852039
EventIndex
19862040
jdwp2EventIndex(jdwpEvent eventType)
19872041
{

src/jdk.jdwp.agent/share/native/libjdwp/util.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -379,6 +379,9 @@ void *jvmtiAllocate(jint numBytes);
379379
void jvmtiDeallocate(void *buffer);
380380

381381
void eventIndexInit(void);
382+
#ifdef DEBUG
383+
char* eventIndex2EventName(EventIndex ei);
384+
#endif
382385
jdwpEvent eventIndex2jdwp(EventIndex i);
383386
jvmtiEvent eventIndex2jvmti(EventIndex i);
384387
EventIndex jdwp2EventIndex(jdwpEvent eventType);

0 commit comments

Comments
 (0)