Source code of Windows XP (NT5)
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.

204 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. atom.c
  5. Abstract:
  6. WinDbg Extension Api
  7. Author:
  8. Ramon J San Andres (ramonsa) 5-Nov-1993
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. #define MAXINTATOM 0xC000
  16. VOID
  17. AtomExtension(
  18. PCSTR lpArgumentString
  19. );
  20. VOID DumpAtomTable(
  21. ULONG64 ppat,
  22. ULONG a
  23. );
  24. DECLARE_API( atom )
  25. /*++
  26. Routine Description:
  27. This function is called as an NTSD extension to dump a user mode atom table
  28. Called as:
  29. !atom [address]
  30. If an address if not given or an address of 0 is given, then the
  31. process atom table is dumped.
  32. Arguments:
  33. args - [address [detail]]
  34. Return Value:
  35. None
  36. --*/
  37. {
  38. // AtomExtension( args );
  39. // Copied its code here :-
  40. ULONG64 ppat, pat;
  41. ULONG a;
  42. INIT_API();
  43. try {
  44. while (*args == ' ') {
  45. args++;
  46. }
  47. if (*args && *args != 0xa) {
  48. a = (ULONG) GetExpression((LPSTR)args);
  49. } else {
  50. a = 0;
  51. }
  52. ppat = GetExpression("kernel32!BaseLocalAtomTable");
  53. if ((ppat != 0) &&
  54. ReadPointer(ppat, &pat)) {
  55. dprintf("\nLocal atom table ");
  56. DumpAtomTable(ppat, a);
  57. dprintf("Use 'dt _RTL_ATOM_TABLE %p'.\n", ppat);
  58. }
  59. } except (EXCEPTION_EXECUTE_HANDLER) {
  60. ;
  61. }
  62. EXIT_API();
  63. return S_OK;
  64. }
  65. CHAR szBaseLocalAtomTable[] = "kernel32!BaseLocalAtomTable";
  66. VOID DumpAtomTable(
  67. ULONG64 ppat,
  68. ULONG a
  69. )
  70. {
  71. ULONG64 pat;
  72. ULONG64 pate;
  73. ULONG iBucket, NumberOfBuckets, PtrSize, Off, NameOff;
  74. LPWSTR pwsz;
  75. BOOL fFirst;
  76. ReadPointer(ppat, &pat);
  77. if (pat == 0) {
  78. dprintf("is not initialized.\n");
  79. return;
  80. }
  81. if (InitTypeRead(pat, _RTL_ATOM_TABLE)) {
  82. return;
  83. }
  84. if (a) {
  85. dprintf("\n");
  86. } else {
  87. dprintf("at %x\n", pat);
  88. }
  89. NumberOfBuckets = (ULONG) ReadField(NumberOfBuckets);
  90. GetFieldOffset("_RTL_ATOM_TABLE", "Buckets", &Off);
  91. GetFieldOffset("_RTL_ATOM_TABLE", "Name", &NameOff);
  92. PtrSize = IsPtr64() ? 8 : 4;
  93. for (iBucket = 0; iBucket < NumberOfBuckets; iBucket++) {
  94. ReadPointer(pat + iBucket * PtrSize + Off, &pate);
  95. if (pate != 0 && !a) {
  96. dprintf("Bucket %2d:", iBucket);
  97. }
  98. fFirst = TRUE;
  99. while (pate != 0) {
  100. ULONG NameLength;
  101. if (!fFirst && !a) {
  102. dprintf(" ");
  103. }
  104. fFirst = FALSE;
  105. if (InitTypeRead(pate, _RTL_ATOM_TABLE_ENTRY)) {
  106. return;
  107. }
  108. NameLength = (ULONG) ReadField(NameLength);
  109. pwsz = (LPWSTR)LocalAlloc(LPTR, ((NameLength) + 1) * sizeof(WCHAR));
  110. ReadMemory(pate + NameOff, pwsz, NameLength * sizeof(WCHAR), NULL);
  111. pwsz[NameLength ] = L'\0';
  112. if (a == 0 || a == ((ULONG)ReadField(HandleIndex) | MAXINTATOM)) {
  113. dprintf("%hx(%2d) = %ls (%d)%s\n",
  114. (ATOM)((ULONG)ReadField(HandleIndex) | MAXINTATOM),
  115. (ULONG)ReadField(ReferenceCount),
  116. pwsz, (NameLength),
  117. (ULONG)ReadField(Flags) & RTL_ATOM_PINNED ? " pinned" : "");
  118. if (a) {
  119. LocalFree(pwsz);
  120. return;
  121. }
  122. }
  123. LocalFree(pwsz);
  124. if (pate == ReadField(HashLink)) {
  125. dprintf("Bogus hash link at %p\n", pate);
  126. break;
  127. }
  128. pate = ReadField(HashLink);
  129. }
  130. }
  131. if (a)
  132. dprintf("\n");
  133. }
  134. VOID
  135. AtomExtension(
  136. PCSTR lpArgumentString
  137. )
  138. {
  139. ULONG64 ppat;
  140. ULONG a;
  141. try {
  142. while (*lpArgumentString == ' ') {
  143. lpArgumentString++;
  144. }
  145. if (*lpArgumentString && *lpArgumentString != 0xa) {
  146. a = (ATOM)GetExpression((LPSTR)lpArgumentString);
  147. } else {
  148. a = 0;
  149. }
  150. ppat = GetExpression(szBaseLocalAtomTable);
  151. if (ppat != 0) {
  152. dprintf("\nLocal atom table ");
  153. DumpAtomTable(ppat, a);
  154. }
  155. } except (EXCEPTION_EXECUTE_HANDLER) {
  156. ;
  157. }
  158. }