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.

151 lines
4.7 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. //
  3. // stack backtracing stuff
  4. //
  5. // 22-Nov-1999 sburns (refactored)
  6. namespace Burnslib
  7. {
  8. namespace StackTrace
  9. {
  10. const size_t MODULE_NAME_MAX = 32;
  11. const size_t SYMBOL_NAME_MAX = 256;
  12. // This should be called when stack tracing facilities are no longer
  13. // needed.
  14. void
  15. Cleanup();
  16. // Fill the provided array with a stack backtrace, starting with the
  17. // code address indicated by the context structure supplied.
  18. //
  19. // This version is suited for use in an SEH exception handler to determine
  20. // the call stack at the point at which an exception was raised.
  21. //
  22. // Example:
  23. //
  24. // DWORD64 stackTrace[TRACE_MAX];
  25. // size_t traceMax = TRACE_MAX;
  26. //
  27. // __try
  28. // {
  29. // // call some code that might raise an SEH exception
  30. // }
  31. // __except(
  32. // Burnslib::StackTrace::TraceFilter(
  33. // stackTrace,
  34. // traceMax,
  35. // (GetExceptionInformation())->ContextRecord))
  36. // {
  37. // // for each element in stackTrace, call
  38. // // Burnslib::StackTrace::LookupAddress
  39. // }
  40. //
  41. // Each element is an address that can be used to obtain a corresponding
  42. // module, function name, line number and source file name (or a subset of
  43. // that information, depending on the debugging symbol information
  44. // available), from the LookupAddress function.
  45. // Returns EXCEPTION_EXECUTE_HANDLER
  46. //
  47. // stackTrace - the array to receive the addresses.
  48. //
  49. // traceMax - the maximum number of stack frames to traverse. The
  50. // stackTrace array must be able to hold at least this many elements.
  51. // If the depth of the call stack is less than traceMax, then the
  52. // remaining elements are 0.
  53. DWORD
  54. TraceFilter(
  55. DWORD64 stackTrace[],
  56. size_t traceMax,
  57. CONTEXT* context);
  58. // Fill the provided array with a stack backtrace, starting with the
  59. // invoker of this function.
  60. //
  61. // Each element is an address that can be used to obtain a corresponding
  62. // module, function name, line number and source file name (or a subset of
  63. // that information, depending on the debugging symbol information
  64. // available), from the LookupAddress function.
  65. //
  66. // stackTrace - the array to receive the addresses.
  67. //
  68. // traceMax - the maximum number of stack frames to traverse. The
  69. // stackTrace array must be able to hold at least this many elements.
  70. // If the depth of the call stack is less than traceMax, then the
  71. // remaining elements are 0.
  72. void
  73. Trace(DWORD64 stackTrace[], size_t traceMax);
  74. // Resolves an address obtained by Trace. ::SymSetOptions and
  75. // ::SymInitialize must have been called at some point before this
  76. // function is called.
  77. //
  78. // traceAddress - the address to resolve.
  79. //
  80. // moduleName - address of an array of char to receieve the name of the
  81. // module to which the address originates, or 0. The array must be able
  82. // to hold MODULE_NAME_MAX bytes.
  83. //
  84. // fullImageName - address of an array of char to receive the full path
  85. // name of the binary file from which the module was loaded, or 0. The
  86. // array must be able to hold MAX_PATH bytes.
  87. //
  88. // symbolName - address of an array of char to receive the undecorated
  89. // name of the function corresponding to the address, or 0. The array
  90. // must be able to hold SYMBOL_NAME_MAX bytes.
  91. //
  92. // displacement - address of a DWORD to receive the byte offset from the
  93. // beginning of the function that corresponds to the address, or 0.
  94. //
  95. // line - address of a DWORD to receive the line number in the source of
  96. // the code that corresponds to the instruction at the displacement
  97. // offset of the function, or 0.
  98. //
  99. // fullpath - address of an array of char to receive the full name of
  100. // the source code file that defines the function corresponding to the
  101. // address, or 0. The array must be able to hold MAX_PATH bytes.
  102. void
  103. LookupAddress(
  104. DWORD64 traceAddress,
  105. char moduleName[],
  106. char fullImageName[],
  107. char symbolName[], // must be SYMBOL_NAME_MAX bytes
  108. DWORD64* displacement,
  109. DWORD* line,
  110. char fullpath[]); // must be MAX_PATH bytes
  111. // Calls LookupAddress and fills in the blanks
  112. //
  113. // %1 - module name
  114. // %2 - symbol name
  115. // %3 - source full path
  116. // %4 - line number
  117. String
  118. LookupAddress(
  119. DWORD64 traceAddress,
  120. const wchar_t* format = L"%1%!%2 %3(%4!d!)");
  121. } // namespace StackTrace
  122. } // namespace Burnslib