Debug.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. #if DBG_DUMP
  7. WCHAR* DumpCallStackFull(uint frameCount = -1, bool print = true);
  8. WCHAR* DumpCallStack(uint frameCount = -1);
  9. #endif
  10. #if DBG_DUMP
  11. #define OUTPUT_TRACE_WITH_STACK(Phase, ...) OUTPUT_TRACE_WITH_STACK_COUNT(Phase, /*frameCount*/ 3, __VA_ARGS__)
  12. #define OUTPUT_TRACE_WITH_STACK_COUNT(Phase, frameCount, ...) \
  13. if(Js::Configuration::Global.flags.Verbose) \
  14. { \
  15. Output::TraceWithCallback( Phase, [] () { \
  16. return DumpCallStackFull(frameCount, /*print*/false); \
  17. }, __VA_ARGS__); \
  18. }
  19. #else
  20. #define OUTPUT_TRACE_WITH_STACK(Phase, ...)
  21. #define OUTPUT_TRACE_WITH_STACK_COUNT(Phase, frameCount, ...)
  22. #endif
  23. #if ENABLE_DEBUG_CONFIG_OPTIONS
  24. #define OUTPUT_PRINT(FunctionBody) \
  25. Output::Print(_u("Function %s (#%d.%u, #%u) "), (FunctionBody)->GetDisplayName(), \
  26. (int)(FunctionBody)->GetSourceContextId(), (FunctionBody)->GetLocalFunctionId(), (FunctionBody)->GetFunctionNumber());
  27. #define OUTPUT_TRACE2(Phase, FunctionBody, ...) \
  28. if(Js::Configuration::Global.flags.Trace.IsEnabled((Phase))) \
  29. { \
  30. WCHAR prefixValue[512]; \
  31. swprintf_s(prefixValue, _u("Function %s (#%d.%u, #%u)"), (FunctionBody)->GetDisplayName(), \
  32. (int)(FunctionBody)->GetSourceContextId(), (FunctionBody)->GetLocalFunctionId(), (FunctionBody)->GetFunctionNumber()); \
  33. Output::TraceWithPrefix((Phase), prefixValue, __VA_ARGS__); \
  34. }
  35. #define OUTPUT_TRACE_FUNC(Phase, Func, ...) \
  36. if(PHASE_TRACE((Phase), (Func))) \
  37. { \
  38. WCHAR prefixValue[512]; \
  39. swprintf_s(prefixValue, _u("%s (#%d.%u, #%u)"), (Func)->GetJITFunctionBody()->GetDisplayName(), \
  40. (int)(Func)->GetJITFunctionBody()->GetSourceContextId(), (Func)->GetWorkItem()->GetJITTimeInfo()->GetLocalFunctionId(), (Func)->GetJITFunctionBody()->GetFunctionNumber()); \
  41. Output::TraceWithPrefix((Phase), prefixValue, __VA_ARGS__); \
  42. }
  43. #define OUTPUT_VERBOSE_TRACE2(Phase, FunctionBody, ...) \
  44. if(Js::Configuration::Global.flags.Verbose) \
  45. { \
  46. OUTPUT_TRACE2((Phase), (FunctionBody), __VA_ARGS__); \
  47. }
  48. #define OUTPUT_VERBOSE_TRACE_FUNC(Phase, Func, ...) \
  49. if(Js::Configuration::Global.flags.Verbose) \
  50. { \
  51. OUTPUT_TRACE_FUNC((Phase), (Func), __VA_ARGS__); \
  52. }
  53. #else
  54. #define OUTPUT_PRINT(FunctionBody)
  55. #define OUTPUT_TRACE2(Phase, FunctionBody, ...)
  56. #define OUTPUT_VERBOSE_TRACE2(Phase, FunctionBody, ...)
  57. #define OUTPUT_TRACE_FUNC(Phase, Func, ...)
  58. #define OUTPUT_VERBOSE_TRACE_FUNC(Phase, Func, ...)
  59. #endif