VirtualBox

Changeset 52457 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 22, 2014 9:05:42 AM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
95670
Message:

IPRT: Tell the windows debugger the name of our threads.

Location:
trunk/src/VBox/Runtime
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/thread.cpp

    r48935 r52457  
    15381538
    15391539#endif /* IPRT_WITH_GENERIC_TLS */
     1540
     1541
     1542#if defined(RT_OS_WINDOWS) && defined(IN_RING3)
     1543
     1544/**
     1545 * Thread enumeration callback for RTThreadNameThreads
     1546 */
     1547static DECLCALLBACK(int) rtThreadNameThreadCallback(PAVLPVNODECORE pNode, void *pvUser)
     1548{
     1549    PRTTHREADINT pThread = (PRTTHREADINT)pNode;
     1550    rtThreadNativeInformDebugger(pThread);
     1551    return 0;
     1552}
     1553
     1554/**
     1555 * A function that can be called from the windows debugger to get the names of
     1556 * all threads when attaching to a process.
     1557 *
     1558 * Usage: .call VBoxRT!RTThreadNameThreads()
     1559 *
     1560 * @returns 0
     1561 * @remarks Do not call from source code as it skips locks.
     1562 */
     1563extern "C" RTDECL(int) RTThreadNameThreads(void);
     1564RTDECL(int) RTThreadNameThreads(void)
     1565{
     1566    return RTAvlPVDoWithAll(&g_ThreadTree, true /* fFromLeft*/, rtThreadNameThreadCallback, NULL);
     1567}
     1568
     1569#endif
  • trunk/src/VBox/Runtime/include/internal/thread.h

    r46593 r52457  
    199199 */
    200200DECLHIDDEN(void) rtThreadNativeDetach(void);
     201
     202/**
     203 * Internal function for informing the debugger about a thread.
     204 * @param   pThread     The thread. May differ from the calling thread.
     205 */
     206DECLHIDDEN(void) rtThreadNativeInformDebugger(PRTTHREADINT pThread);
    201207# endif
    202 #endif /* !IN_RING0 */
     208#endif /* IN_RING3 */
    203209
    204210
  • trunk/src/VBox/Runtime/r3/win/thread-win.cpp

    r48935 r52457  
    5858*******************************************************************************/
    5959static unsigned __stdcall rtThreadNativeMain(void *pvArgs);
     60static void rtThreadWinTellDebuggerThreadName(uint32_t idThread, const char *pszName);
    6061
    6162
     
    107108    if (!TlsSetValue(g_dwSelfTLS, pThread))
    108109        return VERR_FAILED_TO_SET_SELF_TLS;
     110    if (IsDebuggerPresent())
     111        rtThreadWinTellDebuggerThreadName(GetCurrentThreadId(), pThread->szName);
    109112    return VINF_SUCCESS;
     113}
     114
     115
     116DECLHIDDEN(void) rtThreadNativeInformDebugger(PRTTHREADINT pThread)
     117{
     118    rtThreadWinTellDebuggerThreadName((uint32_t)(uintptr_t)pThread->Core.Key, pThread->szName);
     119}
     120
     121
     122/**
     123 * Communicates the thread name to the debugger, if we're begin debugged that
     124 * is.
     125 *
     126 * See http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx for debugger
     127 * interface details.
     128 *
     129 * @param   idThread        The thread ID. UINT32_MAX for current thread.
     130 * @param   pszName         The name.
     131 */
     132static void rtThreadWinTellDebuggerThreadName(uint32_t idThread, const char *pszName)
     133{
     134    struct
     135    {
     136        uint32_t    uType;
     137        const char *pszName;
     138        uint32_t    idThread;
     139        uint32_t    fFlags;
     140    } Pkg = { 0x1000, pszName, idThread, 0 };
     141    __try
     142    {
     143        RaiseException(0x406d1388, 0, sizeof(Pkg)/sizeof(ULONG_PTR), (ULONG_PTR *)&Pkg);
     144    }
     145    __except(EXCEPTION_CONTINUE_EXECUTION)
     146    {
     147
     148    }
    110149}
    111150
     
    208247    if (!TlsSetValue(g_dwSelfTLS, pThread))
    209248        AssertReleaseMsgFailed(("failed to set self TLS. lasterr=%d thread '%s'\n", GetLastError(), pThread->szName));
     249    if (IsDebuggerPresent())
     250        rtThreadWinTellDebuggerThreadName(dwThreadId, &pThread->szName[0]);
    210251
    211252    int rc = rtThreadMain(pThread, dwThreadId, &pThread->szName[0]);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette