Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
4.3 KiB

  1. /***
  2. *tidprint.c - Dislpay thread data
  3. *
  4. * Copyright (c) 1988-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Display the per thread data table.
  8. *
  9. * [NOTE: This module is NOT included in the C runtime libraries but
  10. * is maintained for debugging analysis.]
  11. *
  12. *Revision History:
  13. * 11-17-88 JCR Module created.
  14. * 04-03-89 JCR Added _stackalloc to tid table
  15. * 06-06-89 JCR 386 version
  16. * 06-09-89 JCR 386: Added values to _tiddata struc (for _beginthread)
  17. * 04-09-90 GJF Added #include <cruntime.h>. Made the calling type
  18. * _CALLTYPE1. Also, fixed the copyright.
  19. * 04-10-90 GJF Removed #include <dos.h>.
  20. * 08-16-90 SBM Made _terrno and _tdoserrno int, not unsigned
  21. * 10-08-90 GJF New-style function declarators.
  22. * 10-09-90 GJF Thread ids are of type unsigned long!
  23. * 12-18-90 GJF Use real thread id, not thread id - 1.
  24. * 08-01-91 GJF Adapted for Win32 [_WIN32_].
  25. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  26. * 12-07-93 CFW Rip out Cruiser, add _wasctimebuf.
  27. *
  28. *******************************************************************************/
  29. #include <cruntime.h>
  30. #include <stdio.h>
  31. #include <mtdll.h>
  32. void __cdecl _print_tiddata(unsigned long);
  33. void __cdecl _print_tiddata1(_ptiddata);
  34. /***
  35. *void _print_tiddata(unsigned long) - Display data for a thread
  36. *
  37. *Purpose:
  38. * This routine displays the per thread data for a specific, or all,
  39. * active threads in the _ptd[] table.
  40. *
  41. *Entry:
  42. * unsigned long = <n> = ID of the thread to display
  43. * = -1 = Display thread data for all threads
  44. *
  45. *Exit:
  46. * <void>
  47. *
  48. *Exceptions:
  49. *
  50. *******************************************************************************/
  51. void __cdecl _print_tiddata (
  52. unsigned long tid
  53. )
  54. {
  55. int i; /* loop index */
  56. int threadcnt; /* number of active threads */
  57. /*
  58. * lock the _ptd[] table.
  59. */
  60. _mlock(_THREADDATA_LOCK);
  61. /*
  62. * see if caller want's all threads or just a specific one.
  63. */
  64. if (tid == (unsigned long) -1L) {
  65. /*
  66. * caller want's all threads!
  67. */
  68. for ( i = threadcnt = 0 ; i < 1024 ; i++ )
  69. /*
  70. * print out the fields of *_ptd[i] for each entry
  71. * bound to an active thread (i.e., for each i st
  72. * _ptd[i] non-NULL). also, count up the total number
  73. * of active threads.
  74. */
  75. if ( _ptd[i] != NULL ) {
  76. threadcnt++;
  77. _print_tiddata1(_ptd[i]);
  78. }
  79. printf("\nTHERE ARE %d CURRENTLY ACTIVE THREADS!\n", threadcnt);
  80. }
  81. else {
  82. /*
  83. * caller just interested in a particular thread. search
  84. * the _ptd[] table inline because a call to _getptd[] would
  85. * have unpleasant side effects if tid is not (or no longer)
  86. * valid.
  87. */
  88. for ( i = 0 ; (i < 1024) && ((_ptd[i] == NULL) ||
  89. (_ptd[i] == (_ptiddata)1L) || (_ptd[i]->_tid != tid)) ;
  90. i++ ) ;
  91. if ( i < 1024 )
  92. _print_tiddata1(_ptd[i]);
  93. else
  94. printf("\nTID INVALID OR THREAD HAS TERMINATED!\n");
  95. }
  96. /*
  97. * unlock the _ptd[] table.
  98. */
  99. _munlock(_THREADDATA_LOCK);
  100. }
  101. /***
  102. * void _print_tiddata1(_ptiddata ptd) - print out _tiddata structure
  103. *
  104. *Purpose:
  105. * Given a pointer to a thread data structure, print out its contents
  106. *
  107. *Entry:
  108. * ptd = pointer to thread's data area
  109. *
  110. *Exit:
  111. * <void>
  112. *
  113. *Exceptions:
  114. *
  115. *******************************************************************************/
  116. void __cdecl _print_tiddata1 (
  117. _ptiddata ptd
  118. )
  119. {
  120. printf("\t_tid = %lu\n", ptd->_tid );
  121. printf("\t_thandle = %lu\n", ptd->_thandle );
  122. printf("\t_terrno = %d\n", ptd->_terrno);
  123. printf("\t_tdoserrno = %d\n", ptd->_tdoserrno);
  124. printf("\t_fpds = %#x\n", ptd->_fpds);
  125. printf("\t_holdrand = %u\n", ptd->_holdrand);
  126. printf("\t_token = %p\n", ptd->_token);
  127. printf("\t_errmsg = %p\n", ptd->_errmsg);
  128. printf("\t_namebuf = %p\n", ptd->_namebuf);
  129. printf("\t_asctimebuf = %p\n", ptd->_asctimebuf);
  130. printf("\t_wasctimebuf = %p\n", ptd->_wasctimebuf);
  131. printf("\t_gmtimebuf = %p\n", ptd->_gmtimebuf);
  132. printf("\t_initaddr = %p\n", ptd->_initaddr);
  133. printf("\t_initarg = %p\n", ptd->_initarg);
  134. printf("\t_pxcptacttab = %p\n", ptd->_pxcptacttab);
  135. printf("\t_tpxcptinfoptrs = %p\n", ptd->_tpxcptinfoptrs);
  136. printf("\t_tfpecode = %p\n\n", ptd->_tfpecode);
  137. }