Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Debugging-the-Analyzer.html 7.2KB

3 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Debugging the Analyzer (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Debugging the Analyzer (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Debugging the Analyzer (GNU Compiler Collection (GCC) Internals)">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Static-Analyzer.html#Static-Analyzer" rel="up" title="Static Analyzer">
  30. <link href="User-Experience-Guidelines.html#User-Experience-Guidelines" rel="next" title="User Experience Guidelines">
  31. <link href="Analyzer-Internals.html#Analyzer-Internals" rel="prev" title="Analyzer Internals">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Debugging-the-Analyzer"></a>
  62. <div class="header">
  63. <p>
  64. Previous: <a href="Analyzer-Internals.html#Analyzer-Internals" accesskey="p" rel="prev">Analyzer Internals</a>, Up: <a href="Static-Analyzer.html#Static-Analyzer" accesskey="u" rel="up">Static Analyzer</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  65. </div>
  66. <hr>
  67. <a name="Debugging-the-Analyzer-1"></a>
  68. <h3 class="section">27.2 Debugging the Analyzer</h3>
  69. <a name="index-analyzer_002c-debugging"></a>
  70. <a name="index-static-analyzer_002c-debugging"></a>
  71. <a name="Special-Functions-for-Debugging-the-Analyzer"></a>
  72. <h4 class="subsection">27.2.1 Special Functions for Debugging the Analyzer</h4>
  73. <p>The analyzer recognizes various special functions by name, for use
  74. in debugging the analyzer. Declarations can be seen in the testsuite
  75. in <samp>analyzer-decls.h</samp>. None of these functions are actually
  76. implemented.
  77. </p>
  78. <p>Add:
  79. </p><div class="smallexample">
  80. <pre class="smallexample"> __analyzer_break ();
  81. </pre></div>
  82. <p>to the source being analyzed to trigger a breakpoint in the analyzer when
  83. that source is reached. By putting a series of these in the source, it&rsquo;s
  84. much easier to effectively step through the program state as it&rsquo;s analyzed.
  85. </p>
  86. <div class="smallexample">
  87. <pre class="smallexample">__analyzer_dump ();
  88. </pre></div>
  89. <p>will dump the copious information about the analyzer&rsquo;s state each time it
  90. reaches the call in its traversal of the source.
  91. </p>
  92. <div class="smallexample">
  93. <pre class="smallexample">__analyzer_dump_path ();
  94. </pre></div>
  95. <p>will emit a placeholder &ldquo;note&rdquo; diagnostic with a path to that call site,
  96. if the analyzer finds a feasible path to it.
  97. </p>
  98. <p>The builtin <code>__analyzer_dump_exploded_nodes</code> will emit a warning
  99. after analysis containing information on all of the exploded nodes at that
  100. program point:
  101. </p>
  102. <div class="smallexample">
  103. <pre class="smallexample"> __analyzer_dump_exploded_nodes (0);
  104. </pre></div>
  105. <p>will output the number of &ldquo;processed&rdquo; nodes, and the IDs of
  106. both &ldquo;processed&rdquo; and &ldquo;merger&rdquo; nodes, such as:
  107. </p>
  108. <div class="smallexample">
  109. <pre class="smallexample">warning: 2 processed enodes: [EN: 56, EN: 58] merger(s): [EN: 54-55, EN: 57, EN: 59]
  110. </pre></div>
  111. <p>With a non-zero argument
  112. </p>
  113. <div class="smallexample">
  114. <pre class="smallexample"> __analyzer_dump_exploded_nodes (1);
  115. </pre></div>
  116. <p>it will also dump all of the states within the &ldquo;processed&rdquo; nodes.
  117. </p>
  118. <div class="smallexample">
  119. <pre class="smallexample"> __analyzer_dump_region_model ();
  120. </pre></div>
  121. <p>will dump the region_model&rsquo;s state to stderr.
  122. </p>
  123. <div class="smallexample">
  124. <pre class="smallexample">__analyzer_eval (expr);
  125. </pre></div>
  126. <p>will emit a warning with text &quot;TRUE&quot;, FALSE&quot; or &quot;UNKNOWN&quot; based on the
  127. truthfulness of the argument. This is useful for writing DejaGnu tests.
  128. </p>
  129. <a name="Other-Debugging-Techniques"></a>
  130. <h4 class="subsection">27.2.2 Other Debugging Techniques</h4>
  131. <p>One approach when tracking down where a particular bogus state is
  132. introduced into the <code>exploded_graph</code> is to add custom code to
  133. <code>region_model::validate</code>.
  134. </p>
  135. <p>For example, this custom code (added to <code>region_model::validate</code>)
  136. breaks with an assertion failure when a variable called <code>ptr</code>
  137. acquires a value that&rsquo;s unknown, using
  138. <code>region_model::get_value_by_name</code> to locate the variable
  139. </p>
  140. <div class="smallexample">
  141. <pre class="smallexample"> /* Find a variable matching &quot;ptr&quot;. */
  142. svalue_id sid = get_value_by_name (&quot;ptr&quot;);
  143. if (!sid.null_p ())
  144. {
  145. svalue *sval = get_svalue (sid);
  146. gcc_assert (sval-&gt;get_kind () != SK_UNKNOWN);
  147. }
  148. </pre></div>
  149. <p>making it easier to investigate further in a debugger when this occurs.
  150. </p>
  151. <hr>
  152. <div class="header">
  153. <p>
  154. Previous: <a href="Analyzer-Internals.html#Analyzer-Internals" accesskey="p" rel="prev">Analyzer Internals</a>, Up: <a href="Static-Analyzer.html#Static-Analyzer" accesskey="u" rel="up">Static Analyzer</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  155. </div>
  156. </body>
  157. </html>