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.

165 lines
3.2 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1992 - 1999
  3. Module Name:
  4. util.c
  5. Abstract:
  6. Utility library used for the various debugger extensions in this library.
  7. Author:
  8. Peter Wieland (peterwie) 16-Oct-1995
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "pch.h"
  14. PUCHAR devicePowerStateNames[] = {
  15. "PowerDeviceUnspecified",
  16. "PowerDeviceD0",
  17. "PowerDeviceD1",
  18. "PowerDeviceD2",
  19. "PowerDeviceD3",
  20. "PowerDeviceMaximum",
  21. "Invalid"
  22. };
  23. FLAG_NAME SrbFlagsMap[] = {
  24. FLAG_NAME(SRB_FLAGS_QUEUE_ACTION_ENABLE),
  25. FLAG_NAME(SRB_FLAGS_DISABLE_DISCONNECT),
  26. FLAG_NAME(SRB_FLAGS_DISABLE_SYNCH_TRANSFER),
  27. FLAG_NAME(SRB_FLAGS_BYPASS_FROZEN_QUEUE),
  28. FLAG_NAME(SRB_FLAGS_DISABLE_AUTOSENSE),
  29. FLAG_NAME(SRB_FLAGS_DATA_IN),
  30. FLAG_NAME(SRB_FLAGS_DATA_OUT),
  31. FLAG_NAME(SRB_FLAGS_NO_QUEUE_FREEZE),
  32. FLAG_NAME(SRB_FLAGS_ADAPTER_CACHE_ENABLE),
  33. FLAG_NAME(SRB_FLAGS_IS_ACTIVE),
  34. FLAG_NAME(SRB_FLAGS_ALLOCATED_FROM_ZONE),
  35. FLAG_NAME(SRB_FLAGS_SGLIST_FROM_POOL),
  36. FLAG_NAME(SRB_FLAGS_BYPASS_LOCKED_QUEUE),
  37. FLAG_NAME(SRB_FLAGS_NO_KEEP_AWAKE),
  38. FLAG_NAME(SRB_FLAGS_PORT_DRIVER_ALLOCSENSE),
  39. FLAG_NAME(SRB_FLAGS_PORT_DRIVER_SENSEHASPORT),
  40. FLAG_NAME(SRB_FLAGS_DONT_START_NEXT_PACKET),
  41. FLAG_NAME(SRB_FLAGS_PORT_DRIVER_RESERVED),
  42. FLAG_NAME(SRB_FLAGS_CLASS_DRIVER_RESERVED),
  43. {0,0}
  44. };
  45. PUCHAR
  46. DevicePowerStateToString(
  47. IN DEVICE_POWER_STATE State
  48. )
  49. {
  50. if(State > PowerDeviceMaximum) {
  51. return "Invalid";
  52. } else {
  53. return devicePowerStateNames[(UCHAR) State];
  54. }
  55. }
  56. VOID
  57. xdprintf(
  58. ULONG Depth,
  59. PCCHAR S,
  60. ...
  61. )
  62. {
  63. va_list ap;
  64. ULONG i;
  65. CCHAR DebugBuffer[256] = {0};
  66. for (i=0; i<Depth; i++) {
  67. dprintf (" ");
  68. }
  69. va_start(ap, S);
  70. _vsnprintf(DebugBuffer, sizeof(DebugBuffer)-1, S, ap);
  71. dprintf (DebugBuffer);
  72. va_end(ap);
  73. }
  74. VOID
  75. DumpFlags(
  76. ULONG Depth,
  77. PUCHAR Name,
  78. ULONG Flags,
  79. PFLAG_NAME FlagTable
  80. )
  81. {
  82. ULONG i;
  83. ULONG mask = 0;
  84. ULONG count = 0;
  85. UCHAR prolog[64] = {0};
  86. _snprintf(prolog, sizeof(prolog)-1, "%s (0x%08x): ", Name, Flags);
  87. xdprintfEx(Depth, ("%s", prolog));
  88. if(Flags == 0) {
  89. dprintf("\n");
  90. return;
  91. }
  92. memset(prolog, ' ', strlen(prolog));
  93. for(i = 0; FlagTable[i].Name != 0; i++) {
  94. PFLAG_NAME flag = &(FlagTable[i]);
  95. mask |= flag->Flag;
  96. if((Flags & flag->Flag) == flag->Flag) {
  97. //
  98. // print trailing comma
  99. //
  100. if(count != 0) {
  101. dprintf(", ");
  102. //
  103. // Only print two flags per line.
  104. //
  105. if((count % 2) == 0) {
  106. dprintf("\n");
  107. xdprintfEx(Depth, ("%s", prolog));
  108. }
  109. }
  110. dprintf("%s", flag->Name);
  111. count++;
  112. }
  113. }
  114. dprintf("\n");
  115. if((Flags & (~mask)) != 0) {
  116. xdprintfEx(Depth, ("%sUnknown flags %#010lx\n", prolog, (Flags & (~mask))));
  117. }
  118. return;
  119. }