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.

107 lines
1.4 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. debug.c
  5. Abstract:
  6. Log messages
  7. Author:
  8. Ahmed Mohamed (ahmedm) 12, 01, 2000
  9. Revision History:
  10. --*/
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <stdarg.h>
  14. #include "type.h"
  15. gs_lock_t prlock;
  16. ULONG debugLevel = 0xff;
  17. FILE *debugfp = NULL;
  18. void
  19. halt(int status)
  20. {
  21. char *p = NULL;
  22. *p = 1;
  23. }
  24. void
  25. WINAPI
  26. debug_log_file(char *logfile)
  27. {
  28. FILE *fp;
  29. if (logfile != NULL) {
  30. fp = fopen(logfile, "w");
  31. if (fp == NULL) {
  32. printf("Unable to open log file %s\n", logfile);
  33. } else {
  34. debugfp = fp;
  35. }
  36. }
  37. }
  38. void
  39. WINAPI
  40. debug_level(ULONG level)
  41. {
  42. debugLevel = level;
  43. }
  44. void
  45. WINAPI
  46. debug_log(char *format, ...)
  47. {
  48. static int cnt = 0;
  49. va_list marker;
  50. va_start(marker, format);
  51. GsLockEnter(prlock);
  52. if (debugfp != NULL) {
  53. fprintf(debugfp, "%d:%x:",GetTickCount(), GetCurrentThreadId());
  54. vfprintf(debugfp, format, marker);
  55. fflush(debugfp);
  56. } else {
  57. fprintf(stderr, "%d:%x:",GetTickCount(), GetCurrentThreadId());
  58. vfprintf(stderr, format, marker);
  59. fflush(stderr);
  60. }
  61. #if 0
  62. cnt++;
  63. if (cnt > 100000) {
  64. cnt = 0;
  65. fseek(debugfp, 0, SEEK_SET);
  66. }
  67. #endif
  68. GsLockExit(prlock);
  69. va_end(marker);
  70. }
  71. void
  72. WINAPI
  73. debug_init()
  74. {
  75. char *s = getenv("GsDebugLevel");
  76. debugfp = stdout;
  77. GsLockInit(prlock);
  78. if (s != NULL) {
  79. debugLevel = atoi(s);
  80. }
  81. }