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.

260 lines
6.9 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: gpexts.cxx
  3. *
  4. * This file is for debugging tools and extensions.
  5. *
  6. * Created: 05-14-99
  7. * Author: Adrian Secchia
  8. *
  9. * Copyright (c) 1990 Microsoft Corporation
  10. \**************************************************************************/
  11. #include "precomp.hxx"
  12. extern "C" {
  13. #include <excpt.h>
  14. #include <ntstatus.h>
  15. #include <wdbgexts.h>
  16. };
  17. /***************************************************************************\
  18. * Global variables
  19. \***************************************************************************/
  20. WINDBG_EXTENSION_APIS ExtensionApis;
  21. EXT_API_VERSION ApiVersion = { (GPVER_PRODUCTVERSION_W >> 8), (GPVER_PRODUCTVERSION_W & 0xff), EXT_API_VERSION_NUMBER64, 0 };
  22. USHORT SavedMajorVersion;
  23. USHORT SavedMinorVersion;
  24. DllInit(
  25. HANDLE hModule,
  26. DWORD dwReason,
  27. DWORD dwReserved
  28. )
  29. {
  30. switch (dwReason) {
  31. case DLL_THREAD_ATTACH:
  32. break;
  33. case DLL_THREAD_DETACH:
  34. break;
  35. case DLL_PROCESS_DETACH:
  36. break;
  37. case DLL_PROCESS_ATTACH:
  38. break;
  39. }
  40. return TRUE;
  41. }
  42. VOID
  43. WinDbgExtensionDllInit(
  44. PWINDBG_EXTENSION_APIS64 lpExtensionApis, // 64Bit Change
  45. USHORT MajorVersion,
  46. USHORT MinorVersion
  47. )
  48. {
  49. ExtensionApis = *lpExtensionApis;
  50. SavedMajorVersion = MajorVersion;
  51. SavedMinorVersion = MinorVersion;
  52. return;
  53. }
  54. VOID
  55. CheckVersion(
  56. VOID
  57. )
  58. {
  59. }
  60. LPEXT_API_VERSION
  61. ExtensionApiVersion(
  62. VOID
  63. )
  64. {
  65. return &ApiVersion;
  66. }
  67. char *gaszHelpCli[] = {
  68. "=======================================================================\n"
  69. ,"GPEXTS client debugger extentions:\n"
  70. ,"-----------------------------------------------------------------------\n"
  71. ,"GDI+ UM debugger extensions\n"
  72. ,"dgraphics: dumps a Graphics structure\n"
  73. ,"dgpgraphics: dumps a GpGraphics structure\n"
  74. ,"dmh: dumps gdi+ memory header for memory tracking\n"
  75. ,"=======================================================================\n"
  76. ,NULL
  77. };
  78. DECLARE_API(help)
  79. {
  80. char **ppsz = gaszHelpCli;
  81. while (*ppsz)
  82. dprintf(*ppsz++);
  83. }
  84. char *gaszStatus[] = {
  85. "Ok"
  86. ,"GenericError"
  87. ,"InvalidParameter"
  88. ,"OutOfMemory"
  89. ,"ObjectBusy"
  90. ,"InsufficientBuffer"
  91. ,"NotImplemented"
  92. ,"Win32Error"
  93. ,NULL
  94. };
  95. DECLARE_API(dgraphics)
  96. {
  97. ULONG Size;
  98. using namespace Gdiplus;
  99. GPOBJECT(Gdiplus::Graphics, g);
  100. PARSE_POINTER(dgraphics_help);
  101. ReadMemory(arg, g, sizeof(Gdiplus::Graphics), &Size);
  102. dprintf("Graphics\n");
  103. dprintf("GpGraphics *nativeGraphics %p\n", g->nativeGraphics);
  104. dprintf("Status lastResult %s (%d)\n", gaszStatus[g->lastResult], g->lastResult);
  105. return;
  106. dgraphics_help:
  107. dprintf("Usage: dgraphics [-?] graphics\n");
  108. }
  109. char *gaszGraphicsType[] = {
  110. "GraphicsBitmap"
  111. ,"GraphicsScreen"
  112. ,"GraphicsMetafile"
  113. ,NULL
  114. };
  115. DECLARE_API(dgpgraphics)
  116. {
  117. ULONG Size;
  118. GPOBJECT(GpGraphics, g);
  119. PARSE_POINTER(dgpgraphics_help);
  120. ReadMemory(arg, g, sizeof(GpGraphics), &Size);
  121. dprintf("GpGraphics\n");
  122. dprintf("GpLockable Lockable.LockCount %ld\n", g->Lockable.LockCount);
  123. dprintf("BOOL Valid %s\n", (g->Tag == ObjectTagGraphics)?"True":"False");
  124. dprintf("GpRect SurfaceBounds (%#lx, %#lx, %#lx, %#lx)\n",
  125. g->SurfaceBounds.X,
  126. g->SurfaceBounds.Y,
  127. g->SurfaceBounds.Width,
  128. g->SurfaceBounds.Height);
  129. dprintf("DpBitmap *Surface %p\n", g->Surface);
  130. dprintf("GpMetafile *Metafile %p\n", g->Metafile);
  131. dprintf("GraphicsType Type %s (%d)\n", gaszGraphicsType[g->Type], g->Type);
  132. dprintf("GpDevice *Device %p\n", g->Device);
  133. dprintf("DpDriver *Driver %p\n", g->Driver);
  134. dprintf("DpContext *Context %p\n", g->Context);
  135. dprintf("&DpContext BottomContext %p\n", GPOFFSETOF(g->BottomContext));
  136. dprintf("&DpRegion WindowClip %p\n", GPOFFSETOF(g->WindowClip));
  137. return;
  138. dgpgraphics_help:
  139. dprintf("Usage: dgpgraphics [-?] graphics\n");
  140. return;
  141. }
  142. // copied from Engine\runtime\standalone\mem.cpp
  143. enum AllocTrackHeaderFlags
  144. {
  145. MemoryAllocated = 0x00000001,
  146. MemoryFreed = 0x00000002, // useful in catching double frees
  147. APIAllocation = 0x00000004
  148. };
  149. struct AllocTrackHeader {
  150. struct AllocTrackHeader *flink;
  151. struct AllocTrackHeader *blink;
  152. DWORD size;
  153. DWORD caller_address;
  154. DWORD flags;
  155. #if DBROWN
  156. char *callerFileName;
  157. INT callerLineNumber;
  158. #endif
  159. };
  160. DECLARE_API(dmh)
  161. {
  162. ULONG Size;
  163. BOOL bRecursive = FALSE;
  164. BOOL bFLink = FALSE;
  165. BOOL bBLink = FALSE;
  166. BOOL bCount = FALSE;
  167. BOOL bAPI = FALSE;
  168. int count = 0;
  169. GPOBJECT(AllocTrackHeader, hdr);
  170. PARSE_POINTER(dmh_help);
  171. if(parse_iFindSwitch(tokens, ntok, 'r')!=-1) { bRecursive = TRUE; }
  172. if(parse_iFindSwitch(tokens, ntok, 'f')!=-1) { bFLink = TRUE; }
  173. if(parse_iFindSwitch(tokens, ntok, 'b')!=-1) { bBLink = TRUE; }
  174. if(parse_iFindSwitch(tokens, ntok, 'c')!=-1) { bCount = TRUE; }
  175. if(parse_iFindSwitch(tokens, ntok, 'a')!=-1) { bAPI = TRUE; }
  176. do {
  177. ReadMemory(arg, hdr, sizeof(AllocTrackHeader), &Size);
  178. if( !bAPI || (hdr->flags & APIAllocation) )
  179. {
  180. if(!bCount) {
  181. dprintf("GPMEM Block (%p)\n", arg);
  182. dprintf("FLink 0x%p\n", hdr->flink);
  183. dprintf("BLink 0x%p\n", hdr->blink);
  184. dprintf("size 0x%p\n", hdr->size);
  185. dprintf("Allocation callsite 0x%p\n", hdr->caller_address);
  186. dprintf("Flags 0x%p ", hdr->flags);
  187. if(hdr->flags & APIAllocation) {dprintf("API");}
  188. dprintf("\n");
  189. }
  190. count++;
  191. }
  192. arg = (UINT_PTR)(hdr->flink);
  193. if(bBLink) arg = (UINT_PTR)(hdr->blink);
  194. } while( bRecursive && arg );
  195. if(bRecursive) {
  196. dprintf("Total: %d\n", count);
  197. }
  198. return;
  199. dmh_help:
  200. dprintf("Usage: dmh [-?] [-rfbca] memoryblock\n");
  201. dprintf(" FLink and BLink are forward and backward memory links in the\n"
  202. " double linked list of tracked allocations\n");
  203. dprintf(" Size is the amount of memory in this allocation\n");
  204. dprintf(" Allocation Callsite is the return address of the GpMalloc call that\n"
  205. " allocated this memory block. Unassemble to find the symbol\n");
  206. dprintf(" The tracked memory list head is at gdiplus!gpmemAllocList\n");
  207. dprintf(" -r recursive - default FLink \n");
  208. dprintf(" -f follow FLink (only useful with -r)\n");
  209. dprintf(" -b follow BLink (only useful with -r, will override -f)\n");
  210. dprintf(" -c Suppress output, only display the count. Only useful with -r\n");
  211. dprintf(" -a Only display blocks with the API flag set.\n");
  212. return;
  213. }