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.

159 lines
3.5 KiB

  1. #include "pch.h"
  2. #if DBG
  3. SOFTPCI_DEBUGLEVEL g_SoftPCIDebugLevel = SoftPciAlways;
  4. WCHAR g_SoftPCIDebugBuffer[SOFTPCI_DEBUG_BUFFER_SIZE];
  5. #define MAX_BUF_SIZE 512
  6. VOID
  7. SoftPCI_DebugPrint(
  8. SOFTPCI_DEBUGLEVEL DebugLevel,
  9. PWCHAR DebugMessage,
  10. ...
  11. )
  12. /*++
  13. Routine Description:
  14. Debug print for SoftPCI UI.
  15. Arguments:
  16. Return Value:
  17. None
  18. --*/
  19. {
  20. va_list ap;
  21. WCHAR debugBuffer[SOFTPCI_DEBUG_BUFFER_SIZE];
  22. va_start(ap, DebugMessage);
  23. if ((DebugLevel == SoftPciAlways) ||
  24. (DebugLevel & g_SoftPCIDebugLevel)) {
  25. _vsnwprintf(debugBuffer, (sizeof(debugBuffer)/sizeof(debugBuffer[0])), DebugMessage, ap);
  26. if (!(DebugLevel & SoftPciNoPrepend)) {
  27. wcscpy(g_SoftPCIDebugBuffer, L"SOFTPCI: ");
  28. wcscat(g_SoftPCIDebugBuffer, debugBuffer);
  29. }else{
  30. wcscpy(g_SoftPCIDebugBuffer, debugBuffer);
  31. }
  32. OutputDebugString(g_SoftPCIDebugBuffer);
  33. }
  34. va_end(ap);
  35. }
  36. VOID
  37. SoftPCI_Assert(
  38. IN CONST CHAR* FailedAssertion,
  39. IN CONST CHAR* FileName,
  40. IN ULONG LineNumber,
  41. IN CONST CHAR* Message OPTIONAL
  42. )
  43. {
  44. INT result;
  45. CHAR buffer[MAX_BUF_SIZE];
  46. PWCHAR wbuffer = NULL, p;
  47. sprintf(buffer,
  48. "%s%s\nSource File: %s, line %ld\n\n",
  49. Message ? Message : "",
  50. Message ? "" : FailedAssertion,
  51. FileName,
  52. LineNumber
  53. );
  54. wbuffer = (PWCHAR) malloc(MAX_BUF_SIZE * sizeof(WCHAR));
  55. if (wbuffer) {
  56. //
  57. // Build a string to output to the debugger window
  58. //
  59. p = wbuffer;
  60. if (Message == NULL) {
  61. wcscpy(wbuffer, L"\nAssertion Failed: ");
  62. p += wcslen(wbuffer);
  63. }
  64. //
  65. // Convert it to unicode so we can debug print it.
  66. //
  67. MultiByteToWideChar(CP_THREAD_ACP,
  68. MB_PRECOMPOSED,
  69. buffer,
  70. -1,
  71. p,
  72. MAX_BUF_SIZE
  73. );
  74. }
  75. strcat(buffer, "OK to debug, CANCEL to ignore\n\n");
  76. result = MessageBoxA(g_SoftPCIMainWnd ? g_SoftPCIMainWnd : NULL,
  77. buffer,
  78. "*** Assertion failed ***",
  79. MB_OKCANCEL);
  80. if (wbuffer) {
  81. SoftPCI_Debug(SoftPciAlways, wbuffer);
  82. free(wbuffer);
  83. }
  84. if (result == IDOK) {
  85. //
  86. // User wants to debug this so init a breakin
  87. //
  88. DebugBreak();
  89. }
  90. }
  91. VOID
  92. SoftPCI_DebugDumpConfig(
  93. IN PPCI_COMMON_CONFIG Config
  94. )
  95. {
  96. PULONG p = (PULONG)&Config;
  97. ULONG i = 0;
  98. //
  99. // Dump the configspace buffer we are going to send in the ioctl
  100. //
  101. SoftPCI_Debug(SoftPciDeviceVerbose, L"CreateDevice - ConfigSpace\n");
  102. for (i=0; i < (sizeof(PCI_COMMON_CONFIG) / sizeof(ULONG)); i++) {
  103. SoftPCI_Debug(SoftPciDeviceVerbose | SoftPciNoPrepend, L"%08x", *p);
  104. if ((((i+1) % 4) == 0) ||
  105. ((i+1) == (sizeof(PCI_COMMON_CONFIG) / sizeof(ULONG)))) {
  106. SoftPCI_Debug(SoftPciDeviceVerbose | SoftPciNoPrepend, L"\n");
  107. }else{
  108. SoftPCI_Debug(SoftPciDeviceVerbose | SoftPciNoPrepend, L",");
  109. }
  110. p++;
  111. }
  112. }
  113. #endif