Skip to content

Commit

Permalink
8322980: Debug agent's dumpThread() API should update thread's name b…
Browse files Browse the repository at this point in the history
…efore printing it

Reviewed-by: kevinw, sspitsyn
  • Loading branch information
plummercj committed Jan 8, 2024
1 parent c4a83bd commit 387828a
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions src/jdk.jdwp.agent/share/native/libjdwp/threadControl.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024, 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
Expand Down Expand Up @@ -2623,15 +2623,58 @@ dumpThreadList(ThreadList *list)
}
}

#ifdef DEBUG_THREADNAME
static void
setThreadName(ThreadNode *node)
{
/*
* Sometimes the debuggee changes the thread name, so we need to fetch
* and set it again.
*/
jvmtiThreadInfo info;
jvmtiError error;

memset(&info, 0, sizeof(info));
error = JVMTI_FUNC_PTR(gdata->jvmti,GetThreadInfo)
(gdata->jvmti, node->thread, &info);
if (info.name != NULL) {
strncpy(node->name, info.name, sizeof(node->name) - 1);
jvmtiDeallocate(info.name);
}
}
#endif

#if 0
static jint
getThreadState(ThreadNode *node)
{
jint state = 0;
jvmtiError error = FUNC_PTR(gdata->jvmti,GetThreadState)
(gdata->jvmti, node->thread, &state);
return state;
}
#endif

static void
dumpThread(ThreadNode *node) {
tty_message(" Thread: node = %p, jthread = %p", node, node->thread);
tty_message("Thread: node = %p, jthread = %p", node, node->thread);
#ifdef DEBUG_THREADNAME
setThreadName(node);
tty_message("\tname: %s", node->name);
#endif
// More fields can be printed here when needed. The amount of output is intentionally
// kept small so it doesn't generate too much output.
tty_message("\tsuspendCount: %d", node->suspendCount);
#if 0
tty_message("\tsuspendAllCount: %d", suspendAllCount);
tty_message("\tthreadState: 0x%x", getThreadState(node));
tty_message("\ttoBeResumed: %d", node->toBeResumed);
tty_message("\tis_vthread: %d", node->is_vthread);
tty_message("\tcurrentInvoke.pending: %d", node->currentInvoke.pending);
tty_message("\tcurrentInvoke.started: %d", node->currentInvoke.started);
tty_message("\tcurrentInvoke.available: %d", node->currentInvoke.available);
tty_message("\tobjID: %d", commonRef_refToID(getEnv(), node->thread));
#endif
}

#endif /* DEBUG */

1 comment on commit 387828a

@openjdk-notifier
Copy link

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.