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.

139 lines
4.4 KiB

  1. The Debugger library works as follows:
  2. User View:
  3. For the example, your component is Comp.
  4. In your component's header file, put lines such as:
  5. #include <dsysdbg.h>
  6. DECLARE_DEBUG2(Comp);
  7. #if DBG
  8. #define DebugLog(x) CompDebugPrint x
  9. #else
  10. #define DebugLog(x)
  11. #endif
  12. #define TRACE_STUFF 0x00000008
  13. The DECLARE macro sets up a prototype for a function called CompDebugOut.
  14. This function is a wrapper to a function in the library, called _DebugOut.
  15. It also declares a variable called CompInfoLevel, which is treated as a
  16. bitmask for different things to report on. Finally, it declares a
  17. pointer that is used by the debug library called CompControlBlock.
  18. In *one* file in your component, put in something like this:
  19. DEFINE_DEBUG2(Comp);
  20. DEBUG_KEY MyDebugKeys[] = { {DEB_ERROR, "Error"},
  21. {DEB_WARN, "Warning"},
  22. {DEB_TRACE, "Trace"},
  23. {TRACE_STUFF, "Stuff"},
  24. {0, NULL }
  25. };
  26. The keys here are pairs of (bitmask, text), and are used when determining
  27. what flags are set, and what to display on a debug output. This also defines
  28. the CompDebugOut function, and the CompInfoLevel variable. Then, when you
  29. are initializing, do this:
  30. main/DllMain:
  31. #if DBG
  32. CompInitDebug( MyDebugKeys );
  33. #endif
  34. This will determine which flags have been set in the win.ini file, and
  35. update the info level mask accordingly. It will also link up with the other
  36. dsysdbg components in the process so that they share certain global flags.
  37. Now, whenever you are in the middle of something interesting, you can make this
  38. call:
  39. DebugLog((TRACE_STUFF, "Wow, I got this status back! %x\n", Status));
  40. This will only be present on debug builds, and is filtered by the common code
  41. in the dsysdbg library.
  42. Common Flags:
  43. These flags are specified on the DsysDebug section (see below).
  44. NoDebugger No Debug I/O, unless we are running in ntsd. Thus, no output
  45. is sent to the kernel debugger, unless you have started NTSD
  46. on the process.
  47. TimeStamp Add a time/date stamp to every message.
  48. DebuggerOk [Used internally] Means a debugger has been started on this
  49. process.
  50. Logfile[:path] Echo all output to a log file. A log file is created either
  51. as the specified path, or as executable_name.LOG.
  52. AutoDebug Automatically start up in the debugger. Not supported yet.
  53. UseKD Use the kernel debugger (-d option) when starting the debugger
  54. for AutoDebug or Asserts.
  55. HeapCheck Does HeapValidate() on every call to _DebugOut.
  56. MultiThread Enabled synchronization around the debug header. Not used
  57. by default.
  58. DisableAssert Disables all dsys asserts
  59. NoPrompts Automatically start the debugger on assert, as opposed to
  60. prompting on the kernel debugger.
  61. Details View:
  62. A shared memory segment is created, and is accessed through the DbgpHeader
  63. variable in the library. This segment has a header, and one or more debug
  64. modules, arranged in a chain. Each module has two parts, a bunch of fields,
  65. and a string table. The string table is each flag description, and the fields
  66. are all described in debugp.h
  67. As each module that has separate debugging initializes, a debug module is
  68. allocated from the shared memory. The strings are loaded into the string
  69. table, and the flags are calculated as follows (for app SAMPLE.EXE, with
  70. modules DSYS and Sec):
  71. First, during shared memory init, we look in win.ini for a section
  72. [DsysDebug]
  73. SAMPLE=Flag1,Flag2,Flag3
  74. DebugFlags=Flag1,Flag2, Flag3
  75. If they exist, they are or'd together. These are the DSYS Debug Flags, which
  76. control output (to a logfile, for example), or heap checking or whatever.
  77. Then, as Sec and DSYS are initialized, they look in win.ini for a section
  78. like:
  79. [Sec]
  80. DebugFlags=ModFlag1, ModFlag2
  81. SAMPLE=ModFlag1, ModFlag2
  82. then
  83. [DsysDebug]
  84. Sec=ModFlag1, ModFlag2
  85. and
  86. [DSYS]
  87. DebugFlags=ModFlagX, ModFlagY
  88. SAMPLE=ModFlagX, ModFlagY
  89. then
  90. [DsysDebug]
  91. Dsys=ModFlagX, ModFlagY
  92. This gives several orders of granularity, allowing you to specify flags for
  93. whenever your module is loaded, or only for a specific executable.