tracing_facility.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>The Tracing Facility</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <link href="theme/style.css" rel="stylesheet" type="text/css">
  7. </head>
  8. <body>
  9. <table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
  10. <tr>
  11. <td width="21"> <h1></h1></td>
  12. <td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">The
  13. Tracing Facility</font></b></font></td>
  14. <td width="96"><a href="http://www.boost.org"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
  15. </tr>
  16. </table>
  17. <br>
  18. <table border="0">
  19. <tr>
  20. <td width="10"></td>
  21. <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
  22. <td width="30"><a href="wave_driver.html"><img src="theme/l_arr.gif" border="0"></a></td>
  23. <td width="30"><a href="acknowledgements.html"><img src="theme/r_arr.gif" border="0"></a></td>
  24. </tr>
  25. </table>
  26. <p>If you ever had the need to debug a macro expansion you had to discover, that
  27. your tools provide only little or no support for this task. For this reason
  28. the <i>Wave</i> library has a tracing facility, which allows to get selectively
  29. some information about the expansion of a certain macro or several macros. </p>
  30. <p>The tracing of macro expansions generates a possibly huge amount of information,
  31. so it is recommended, that you explicitely enable/disable the tracing for the
  32. macro in question only. This may be done with the help of a special, <tt>Wave</tt>
  33. specific #pragma:</p>
  34. <pre><span class="preprocessor"> #pragma</span> wave trace(enable) <span class="comment">// enable the tracing</span>
  35. <span class="comment">// the macro expansions here will be traced</span>
  36. <span class="comment">// ...</span>
  37. <span class="preprocessor"> #pragma</span> wave trace(disable) <span class="comment">// disable the tracing</span></pre>
  38. <p>In C99 mode or when specifying the <tt>--variadics</tt> command line option
  39. you may additionally use the <tt>operator&nbsp;_Pragma()</tt> variant to enable/disable
  40. the tracing output:</p>
  41. <pre><span class="preprocessor"> #define</span> CONCAT(x, y) \
  42. <span class="preprocessor">_Pragma</span>(<span class="string">&quot;wave trace(enable)&quot;</span>) \
  43. x \
  44. <span class="preprocessor">_Pragma</span>(<span class="string">&quot;wave trace(disable)&quot;</span>) \
  45. <span class="keyword">##</span> y</pre>
  46. <p>This way you have the possibility to enable the tracing during the expansion
  47. of a part of a macro only. In the sample shown there is traced the expansion
  48. of the macro argument <tt>'x'</tt> only. Note, that the <tt>operator _Pragma()</tt>
  49. directives expand to nothing inside the macro expansion result.</p>
  50. <p>To see, what the <tt>Wave</tt> driver generates while expanding a simple macro,
  51. let's have a look at the tracing output for the following example:</p>
  52. <pre ><span class="comment"> // test.cpp</span>
  53. <span class="preprocessor"> #define</span> X(x) x<br><span class="preprocessor"> #define</span> Y() 2<br><span class="preprocessor"> #define</span> CONCAT_(x, y) x <span class="keyword">##</span> y
  54. <span class="preprocessor"> #define</span> CONCAT(x, y) CONCAT_(x, y)
  55. <span class="preprocessor"> #pragma</span> wave trace(enable)
  56. <span class="comment"> // this macro expansion is to be traced</span>
  57. CONCAT(X(1), Y()) <span class="comment">// should expand to 12</span>
  58. <span class="preprocessor"> #pragma</span> wave trace(disable)</pre>
  59. <p>When preprocessed with <tt>'wave -t test.trace test.cpp'</tt> the <tt>Wave</tt>
  60. driver generates a file <tt>test.trace</tt>, which contains (without the line
  61. numbers in front of the lines):</p>
  62. <pre> 1: test.cpp:8:1: CONCAT(X(1), Y())
  63. 2: test.cpp:5:9: see macro definition: CONCAT(x, y)
  64. 3: invoked with
  65. 4: [
  66. 5: x = X(1)
  67. 6: y = Y()
  68. 7: ]
  69. 8: [
  70. 9: test.cpp:2:9: see macro definition: X(x)
  71. 10: invoked with
  72. 11: [
  73. 12: x = 1
  74. 13: ]
  75. 14: [
  76. 15: 1
  77. 16: rescanning
  78. 17: [
  79. 18: 1
  80. 19: ]
  81. 20: ]
  82. 21: test.cpp:3:9: see macro definition: Y()
  83. 22: [
  84. 23: 2
  85. 24: rescanning
  86. 25: [
  87. 26: 2
  88. 27: ]
  89. 28: ]
  90. 29: CONCAT_(1, 2)
  91. 30: rescanning
  92. 31: [
  93. 32: test.cpp:4:9: see macro definition: CONCAT_(x, y)
  94. 33: invoked with
  95. 34: [
  96. 35: x = 1
  97. 36: y = 2
  98. 37: ]
  99. 38: [
  100. 39: 12
  101. 40: rescanning
  102. 41: [
  103. 42: 12
  104. 43: ]
  105. 44: ]
  106. 45: 12
  107. 46: ]
  108. 47: ]
  109. </pre>
  110. <p>The generated trace output is very verbose, but allows to follow every step
  111. of the actual macro expansion process. The first line in this tracing example
  112. contains the reference to the position, from where the macro expansion was initiated.
  113. Additionally the following information is contained for every single macro expansion:</p>
  114. <ul>
  115. <li>The reference to the position (line and column numbers), where the macro to expand was defined first
  116. (see lines 2, 9, 21 and 32).</li>
  117. <li>The real parameters supplied for this macro expansion (see lines 3, 10 and
  118. 33), this information is traced inside the <tt>invoked with</tt> block, where
  119. the corresponding formal and actual parameters are listed.</li>
  120. <li>The expansion of the given arguments (if any and if these are defined as
  121. macros). This repeats the full tracing information for the argument macro
  122. expansion, only indended by one level. Note though, that the macro expansion
  123. of the actual arguments is traced, regardless of the fact, whether this argument
  124. is really to be inserted into the replacement list after its expansion
  125. or as it was initially supplied (see C++ Standard [16.3.1.1]: &quot;A parameter
  126. in the replacement list, unless preceded by a <tt>#</tt> or <tt>##</tt> preprocessing
  127. token or followed by a <tt>##</tt> preprocessing token, is replaced by the
  128. corresponding argument after all macros contained therein have been expanded&quot;
  129. <a href="references.html#iso_cpp">[1]</a>). </li>
  130. <li>The result of the argument substitution (see lines 15, 23, 29 and 39), i.e.
  131. the substituted replacement list.</li>
  132. <li>The rescanning process, which again includes the full subsequent macro expansion
  133. process of all found macros (see C++ Standard [16.3.4.1]: &quot;After all
  134. parameters in the replacement list have been substituted, the resulting preprocessing
  135. token sequence is rescanned with all subsequent preprocessing tokens of the
  136. source file for more macro names to replace.&quot; <a href="references.html#iso_cpp">[1]</a>).</li>
  137. <li>The result of the actual macro expansion (this is the last line inside the
  138. corresponding rescanning block - see lines 18, 26, 42 and 45).</li>
  139. </ul>
  140. <p>Every found macro to expand will add an additional indentation level inside
  141. the trace output.</p>
  142. <table border="0">
  143. <tr>
  144. <td width="10"></td>
  145. <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
  146. <td width="30"><a href="wave_driver.html"><img src="theme/l_arr.gif" border="0"></a></td>
  147. <td width="30"><a href="acknowledgements.html"><img src="theme/r_arr.gif" border="0"></a></td>
  148. </tr>
  149. </table>
  150. <hr size="1">
  151. <p class="copyright">Copyright &copy; 2003-2011 Hartmut Kaiser<br>
  152. <br>
  153. <font size="2">Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) </font> </p>
  154. <p class="copyright"><span class="updated">Last updated:
  155. <!-- #BeginDate format:fcAm1m -->Tuesday, March 21, 2006 9:25<!-- #EndDate -->
  156. </span>
  157. </p>
  158. </body>
  159. </html>