njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 1 | <?xml version="1.0"?> <!-- -*- sgml -*- --> |
| 2 | <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" |
de | 252c614 | 2005-11-27 04:10:00 +0000 | [diff] [blame] | 3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" |
| 4 | [ <!ENTITY % vg-entities SYSTEM "vg-entities.xml"> %vg-entities; ]> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 5 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 6 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 7 | <chapter id="writing-tools" xreflabel="Writing a New Valgrind Tool"> |
| 8 | <title>Writing a New Valgrind Tool</title> |
| 9 | |
| 10 | <sect1 id="writing-tools.intro" xreflabel="Introduction"> |
| 11 | <title>Introduction</title> |
| 12 | |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 13 | So you want to write a Valgrind tool? Here are some instructions that may |
| 14 | help. They were last updated for Valgrind 3.2.2. |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 15 | |
| 16 | <sect2 id="writing-tools.tools" xreflabel="Tools"> |
| 17 | <title>Tools</title> |
| 18 | |
| 19 | <para>The key idea behind Valgrind's architecture is the division |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 20 | between its "core" and "tool plug-ins".</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 21 | |
| 22 | <para>The core provides the common low-level infrastructure to |
tom | a721cec | 2005-11-04 14:11:05 +0000 | [diff] [blame] | 23 | support program instrumentation, including the JIT |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 24 | compiler, low-level memory manager, signal handling and a |
| 25 | scheduler (for pthreads). It also provides certain services that |
| 26 | are useful to some but not all tools, such as support for error |
| 27 | recording and suppression.</para> |
| 28 | |
| 29 | <para>But the core leaves certain operations undefined, which |
| 30 | must be filled by tools. Most notably, tools define how program |
tom | a721cec | 2005-11-04 14:11:05 +0000 | [diff] [blame] | 31 | code should be instrumented. They can also call certain |
| 32 | functions to indicate to the core that they would like to use |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 33 | certain services, or be notified when certain interesting events |
| 34 | occur. But the core takes care of all the hard work.</para> |
| 35 | |
| 36 | </sect2> |
| 37 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 38 | </sect1> |
| 39 | |
| 40 | |
| 41 | |
| 42 | <sect1 id="writing-tools.writingatool" xreflabel="Writing a Tool"> |
| 43 | <title>Writing a Tool</title> |
| 44 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 45 | <sect2 id="writing-tools.howtoolswork" xreflabel="How tools work"> |
| 46 | <title>How tools work</title> |
| 47 | |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 48 | <para>Tool plug-ins must define various functions for instrumenting programs |
| 49 | that are called by Valgrind's core. They are then linked against |
| 50 | Valgrind's core to define a complete Valgrind tool which will be used |
| 51 | when the <option>--tool</option> option is used to select it.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 52 | |
| 53 | </sect2> |
| 54 | |
| 55 | |
| 56 | <sect2 id="writing-tools.gettingcode" xreflabel="Getting the code"> |
| 57 | <title>Getting the code</title> |
| 58 | |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 59 | <para>To write your own tool, you'll need the Valgrind source code. You'll |
| 60 | need a check-out of the Subversion repository for the automake/autoconf |
| 61 | build instructions to work. See the information about how to do check-out |
| 62 | from the repository at <ulink url="&vg-svn-repo;">the Valgrind |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 63 | website</ulink>.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 64 | |
| 65 | </sect2> |
| 66 | |
| 67 | |
| 68 | <sect2 id="writing-tools.gettingstarted" xreflabel="Getting started"> |
| 69 | <title>Getting started</title> |
| 70 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 71 | <para>Valgrind uses GNU <computeroutput>automake</computeroutput> and |
| 72 | <computeroutput>autoconf</computeroutput> for the creation of Makefiles |
| 73 | and configuration. But don't worry, these instructions should be enough |
| 74 | to get you started even if you know nothing about those tools.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 75 | |
| 76 | <para>In what follows, all filenames are relative to Valgrind's |
| 77 | top-level directory <computeroutput>valgrind/</computeroutput>.</para> |
| 78 | |
| 79 | <orderedlist> |
| 80 | <listitem> |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 81 | <para>Choose a name for the tool, and a two-letter abbreviation that can |
| 82 | be used as a short prefix. We'll use |
| 83 | <computeroutput>foobar</computeroutput> and |
| 84 | <computeroutput>fb</computeroutput> as an example.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 85 | </listitem> |
| 86 | |
| 87 | <listitem> |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 88 | <para>Make three new directories <filename>foobar/</filename>, |
| 89 | <filename>foobar/docs/</filename> and |
| 90 | <filename>foobar/tests/</filename>. |
| 91 | </para> |
| 92 | </listitem> |
| 93 | |
| 94 | <listitem> |
| 95 | <para>Create empty files |
| 96 | <filename>foobar/docs/Makefile.am</filename> and |
| 97 | <filename>foobar/tests/Makefile.am</filename>. |
| 98 | </para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 99 | </listitem> |
| 100 | |
| 101 | <listitem> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 102 | <para>Copy <filename>none/Makefile.am</filename> into |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 103 | <filename>foobar/</filename>. Edit it by replacing all |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 104 | occurrences of the string <computeroutput>"none"</computeroutput> with |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 105 | <computeroutput>"foobar"</computeroutput>, and all occurrences of |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 106 | the string <computeroutput>"nl_"</computeroutput> with |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 107 | <computeroutput>"fb_"</computeroutput>.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 108 | </listitem> |
| 109 | |
| 110 | <listitem> |
| 111 | <para>Copy <filename>none/nl_main.c</filename> into |
| 112 | <computeroutput>foobar/</computeroutput>, renaming it as |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 113 | <filename>fb_main.c</filename>. Edit it by changing the |
| 114 | <computeroutput>details</computeroutput> lines in |
| 115 | <function>nl_pre_clo_init()</function> to something appropriate for the |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 116 | tool. These fields are used in the startup message, except for |
| 117 | <computeroutput>bug_reports_to</computeroutput> which is used if a |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 118 | tool assertion fails. Also replace the string |
| 119 | <computeroutput>"nl_"</computeroutput> with |
| 120 | <computeroutput>"fb_"</computeroutput> again.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 121 | </listitem> |
| 122 | |
| 123 | <listitem> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 124 | <para>Edit <filename>Makefile.am</filename>, adding the new directory |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 125 | <filename>foobar</filename> to the |
| 126 | <computeroutput>TOOLS</computeroutput> variable.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 127 | </listitem> |
| 128 | |
| 129 | <listitem> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 130 | <para>Edit <filename>configure.in</filename>, adding |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 131 | <filename>foobar/Makefile</filename>, |
| 132 | <filename>foobar/docs/Makefile</filename> and |
| 133 | <filename>foobar/tests/Makefile</filename> to the |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 134 | <computeroutput>AC_OUTPUT</computeroutput> list.</para> |
| 135 | </listitem> |
| 136 | |
| 137 | <listitem> |
| 138 | <para>Run:</para> |
| 139 | <programlisting><![CDATA[ |
| 140 | autogen.sh |
| 141 | ./configure --prefix=`pwd`/inst |
| 142 | make install]]></programlisting> |
| 143 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 144 | <para>It should automake, configure and compile without errors, |
| 145 | putting copies of the tool in |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 146 | <filename>foobar/</filename> and |
| 147 | <filename>inst/lib/valgrind/</filename>.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 148 | </listitem> |
| 149 | |
| 150 | <listitem> |
| 151 | <para>You can test it with a command like:</para> |
| 152 | <programlisting><![CDATA[ |
| 153 | inst/bin/valgrind --tool=foobar date]]></programlisting> |
| 154 | |
| 155 | <para>(almost any program should work; |
| 156 | <computeroutput>date</computeroutput> is just an example). |
| 157 | The output should be something like this:</para> |
| 158 | <programlisting><![CDATA[ |
| 159 | ==738== foobar-0.0.1, a foobarring tool for x86-linux. |
| 160 | ==738== Copyright (C) 1066AD, and GNU GPL'd, by J. Random Hacker. |
| 161 | ==738== Built with valgrind-1.1.0, a program execution monitor. |
| 162 | ==738== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward. |
| 163 | ==738== Estimated CPU clock rate is 1400 MHz |
| 164 | ==738== For more details, rerun with: -v |
| 165 | ==738== Wed Sep 25 10:31:54 BST 2002 |
| 166 | ==738==]]></programlisting> |
| 167 | |
| 168 | <para>The tool does nothing except run the program |
| 169 | uninstrumented.</para> |
| 170 | </listitem> |
| 171 | |
| 172 | </orderedlist> |
| 173 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 174 | <para>These steps don't have to be followed exactly - you can choose |
| 175 | different names for your source files, and use a different |
| 176 | <option>--prefix</option> for |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 177 | <computeroutput>./configure</computeroutput>.</para> |
| 178 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 179 | <para>Now that we've setup, built and tested the simplest possible tool, |
| 180 | onto the interesting stuff...</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 181 | |
| 182 | </sect2> |
| 183 | |
| 184 | |
| 185 | |
| 186 | <sect2 id="writing-tools.writingcode" xreflabel="Writing the Code"> |
| 187 | <title>Writing the code</title> |
| 188 | |
| 189 | <para>A tool must define at least these four functions:</para> |
| 190 | <programlisting><![CDATA[ |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 191 | pre_clo_init() |
| 192 | post_clo_init() |
| 193 | instrument() |
| 194 | fini()]]></programlisting> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 195 | |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 196 | <para>The names can be different to the above, but these are the usual |
| 197 | names. The first one is registered using the macro |
| 198 | <computeroutput>VG_DETERMINE_INTERFACE_VERSION</computeroutput> (which also |
| 199 | checks that the core/tool interface of the tool matches that of the core). |
| 200 | The last three are registered using the |
sewardj | 7aeb10f | 2006-12-10 02:59:16 +0000 | [diff] [blame^] | 201 | <computeroutput>VG_(basic_tool_funcs)</computeroutput> function.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 202 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 203 | <para>In addition, if a tool wants to use some of the optional services |
| 204 | provided by the core, it may have to define other functions and tell the |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 205 | core about them.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 206 | |
| 207 | </sect2> |
| 208 | |
| 209 | |
| 210 | |
| 211 | <sect2 id="writing-tools.init" xreflabel="Initialisation"> |
| 212 | <title>Initialisation</title> |
| 213 | |
| 214 | <para>Most of the initialisation should be done in |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 215 | <function>pre_clo_init()</function>. Only use |
| 216 | <function>post_clo_init()</function> if a tool provides command line |
| 217 | options and must do some initialisation after option processing takes |
| 218 | place (<computeroutput>"clo"</computeroutput> stands for "command line |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 219 | options").</para> |
| 220 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 221 | <para>First of all, various "details" need to be set for a tool, using |
| 222 | the functions <function>VG_(details_*)()</function>. Some are all |
| 223 | compulsory, some aren't. Some are used when constructing the startup |
| 224 | message, <computeroutput>detail_bug_reports_to</computeroutput> is used |
| 225 | if <computeroutput>VG_(tool_panic)()</computeroutput> is ever called, or |
| 226 | a tool assertion fails. Others have other uses.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 227 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 228 | <para>Second, various "needs" can be set for a tool, using the functions |
| 229 | <function>VG_(needs_*)()</function>. They are mostly booleans, and can |
| 230 | be left untouched (they default to <varname>False</varname>). They |
| 231 | determine whether a tool can do various things such as: record, report |
| 232 | and suppress errors; process command line options; wrap system calls; |
| 233 | record extra information about malloc'd blocks, etc.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 234 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 235 | <para>For example, if a tool wants the core's help in recording and |
| 236 | reporting errors, it must call |
| 237 | <function>VG_(needs_tool_errors)</function> and provide definitions of |
| 238 | eight functions for comparing errors, printing out errors, reading |
| 239 | suppressions from a suppressions file, etc. While writing these |
| 240 | functions requires some work, it's much less than doing error handling |
| 241 | from scratch because the core is doing most of the work. See the |
| 242 | function <function>VG_(needs_tool_errors)</function> in |
| 243 | <filename>include/pub_tool_tooliface.h</filename> for full details of |
| 244 | all the needs.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 245 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 246 | <para>Third, the tool can indicate which events in core it wants to be |
| 247 | notified about, using the functions <function>VG_(track_*)()</function>. |
| 248 | These include things such as blocks of memory being malloc'd, the stack |
| 249 | pointer changing, a mutex being locked, etc. If a tool wants to know |
| 250 | about this, it should provide a pointer to a function, which will be |
| 251 | called when that event happens.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 252 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 253 | <para>For example, if the tool want to be notified when a new block of |
| 254 | memory is malloc'd, it should call |
| 255 | <function>VG_(track_new_mem_heap)()</function> with an appropriate |
| 256 | function pointer, and the assigned function will be called each time |
| 257 | this happens.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 258 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 259 | <para>More information about "details", "needs" and "trackable events" |
| 260 | can be found in |
tom | b931c58 | 2005-11-04 12:17:20 +0000 | [diff] [blame] | 261 | <filename>include/pub_tool_tooliface.h</filename>.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 262 | |
| 263 | </sect2> |
| 264 | |
| 265 | |
| 266 | |
| 267 | <sect2 id="writing-tools.instr" xreflabel="Instrumentation"> |
| 268 | <title>Instrumentation</title> |
| 269 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 270 | <para><function>instrument()</function> is the interesting one. It |
| 271 | allows you to instrument <emphasis>VEX IR</emphasis>, which is |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 272 | Valgrind's RISC-like intermediate language. VEX IR is best described in |
| 273 | the header file <filename>VEX/pub/libvex_ir.h</filename>.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 274 | |
tom | a721cec | 2005-11-04 14:11:05 +0000 | [diff] [blame] | 275 | <para>The easiest way to instrument VEX IR is to insert calls to C |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 276 | functions when interesting things happen. See the tool "Lackey" |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 277 | (<filename>lackey/lk_main.c</filename>) for a simple example of this, or |
| 278 | Cachegrind (<filename>cachegrind/cg_main.c</filename>) for a more |
| 279 | complex example.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 280 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 281 | </sect2> |
| 282 | |
| 283 | |
| 284 | |
| 285 | <sect2 id="writing-tools.fini" xreflabel="Finalisation"> |
| 286 | <title>Finalisation</title> |
| 287 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 288 | <para>This is where you can present the final results, such as a summary |
| 289 | of the information collected. Any log files should be written out at |
| 290 | this point.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 291 | |
| 292 | </sect2> |
| 293 | |
| 294 | |
| 295 | |
| 296 | <sect2 id="writing-tools.otherinfo" xreflabel="Other Important Information"> |
| 297 | <title>Other Important Information</title> |
| 298 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 299 | <para>Please note that the core/tool split infrastructure is quite |
| 300 | complex and not brilliantly documented. Here are some important points, |
| 301 | but there are undoubtedly many others that I should note but haven't |
| 302 | thought of.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 303 | |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 304 | <para>The files <filename>include/pub_tool_*.h</filename> contain all the |
| 305 | types, macros, functions, etc. that a tool should (hopefully) need, and are |
| 306 | the only <filename>.h</filename> files a tool should need to |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 307 | <computeroutput>#include</computeroutput>.</para> |
| 308 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 309 | <para>In particular, you can't use anything from the C library (there |
| 310 | are deep reasons for this, trust us). Valgrind provides an |
| 311 | implementation of a reasonable subset of the C library, details of which |
| 312 | are in <filename>pub_tool_libc*.h</filename>.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 313 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 314 | <para>Similarly, when writing a tool, you shouldn't need to look at any |
| 315 | of the code in Valgrind's core. Although it might be useful sometimes |
| 316 | to help understand something.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 317 | |
tom | df2b4a6 | 2005-11-04 12:27:58 +0000 | [diff] [blame] | 318 | <para>The <filename>pub_tool_*.h</filename> files have a reasonable |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 319 | amount of documentation in it that should hopefully be enough to get |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 320 | you going. |
| 321 | Also, <filename>VEX/pub/libvex_basictypes.h</filename> and |
| 322 | <filename>VEX/pub/libvex_ir.h</filename> have some more details that are |
| 323 | worth reading, particularly about VEX IR. But ultimately, the tools |
| 324 | distributed (Memcheck, Cachegrind, Lackey, etc.) are probably the best |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 325 | documentation of all, for the moment.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 326 | |
tom | a721cec | 2005-11-04 14:11:05 +0000 | [diff] [blame] | 327 | <para>Note that the <computeroutput>VG_</computeroutput> macro is used |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 328 | heavily. This just prepends a longer string in front of names to avoid |
| 329 | potential namespace clashes.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 330 | |
| 331 | </sect2> |
| 332 | |
| 333 | |
| 334 | <sect2 id="writing-tools.advice" xreflabel="Words of Advice"> |
| 335 | <title>Words of Advice</title> |
| 336 | |
| 337 | <para>Writing and debugging tools is not trivial. Here are some |
| 338 | suggestions for solving common problems.</para> |
| 339 | |
| 340 | |
| 341 | <sect3 id="writing-tools.segfaults"> |
| 342 | <title>Segmentation Faults</title> |
| 343 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 344 | <para>If you are getting segmentation faults in C functions used by your |
| 345 | tool, the usual GDB command:</para> |
| 346 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 347 | <screen><![CDATA[ |
| 348 | gdb <prog> core]]></screen> |
| 349 | <para>usually gives the location of the segmentation fault.</para> |
| 350 | |
| 351 | </sect3> |
| 352 | |
| 353 | |
| 354 | <sect3 id="writing-tools.debugfns"> |
| 355 | <title>Debugging C functions</title> |
| 356 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 357 | <para>If you want to debug C functions used by your tool, you can |
tom | 605535f | 2005-11-29 09:59:32 +0000 | [diff] [blame] | 358 | achieve this by following these steps:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 359 | <orderedlist> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 360 | <listitem> |
| 361 | <para>Set <computeroutput>VALGRIND_LAUNCHER</computeroutput> to |
| 362 | <computeroutput><![CDATA[<prefix>/bin/valgrind]]></computeroutput>:</para> |
de | d3c3537 | 2005-11-29 16:06:55 +0000 | [diff] [blame] | 363 | <programlisting> |
| 364 | export VALGRIND_LAUNCHER=/usr/local/bin/valgrind</programlisting> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 365 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 366 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 367 | <listitem> |
| 368 | <para>Then run <computeroutput><![CDATA[ gdb <prefix>/lib/valgrind/<platform>/<tool>:]]></computeroutput></para> |
de | d3c3537 | 2005-11-29 16:06:55 +0000 | [diff] [blame] | 369 | <programlisting> |
| 370 | gdb /usr/local/lib/valgrind/ppc32-linux/lackey</programlisting> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 371 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 372 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 373 | <listitem> |
| 374 | <para>Do <computeroutput>handle SIGSEGV SIGILL nostop |
| 375 | noprint</computeroutput> in GDB to prevent GDB from stopping on a |
| 376 | SIGSEGV or SIGILL:</para> |
de | d3c3537 | 2005-11-29 16:06:55 +0000 | [diff] [blame] | 377 | <programlisting> |
| 378 | (gdb) handle SIGILL SIGSEGV nostop noprint</programlisting> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 379 | </listitem> |
tom | 605535f | 2005-11-29 09:59:32 +0000 | [diff] [blame] | 380 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 381 | <listitem> |
| 382 | <para>Set any breakpoints you want and proceed as normal for GDB:</para> |
de | d3c3537 | 2005-11-29 16:06:55 +0000 | [diff] [blame] | 383 | <programlisting> |
| 384 | (gdb) b vgPlain_do_exec</programlisting> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 385 | <para>The macro VG_(FUNC) is expanded to vgPlain_FUNC, so If you |
| 386 | want to set a breakpoint VG_(do_exec), you could do like this in |
| 387 | GDB.</para> |
| 388 | </listitem> |
tom | 605535f | 2005-11-29 09:59:32 +0000 | [diff] [blame] | 389 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 390 | <listitem> |
| 391 | <para>Run the tool with required options:</para> |
de | d3c3537 | 2005-11-29 16:06:55 +0000 | [diff] [blame] | 392 | <programlisting> |
| 393 | (gdb) run `pwd`</programlisting> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 394 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 395 | |
| 396 | </orderedlist> |
| 397 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 398 | <para>GDB may be able to give you useful information. Note that by |
| 399 | default most of the system is built with |
| 400 | <option>-fomit-frame-pointer</option>, and you'll need to get rid of |
| 401 | this to extract useful tracebacks from GDB.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 402 | |
| 403 | </sect3> |
| 404 | |
| 405 | |
| 406 | <sect3 id="writing-tools.ucode-probs"> |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 407 | <title>IR Instrumentation Problems</title> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 408 | |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 409 | <para>If you are having problems with your VEX IR instrumentation, it's |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 410 | likely that GDB won't be able to help at all. In this case, Valgrind's |
| 411 | <option>--trace-flags</option> option is invaluable for observing the |
| 412 | results of instrumentation.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 413 | |
| 414 | </sect3> |
| 415 | |
| 416 | |
| 417 | <sect3 id="writing-tools.misc"> |
| 418 | <title>Miscellaneous</title> |
| 419 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 420 | <para>If you just want to know whether a program point has been reached, |
| 421 | using the <computeroutput>OINK</computeroutput> macro (in |
| 422 | <filename>include/pub_tool_libcprint.h</filename>) can be easier than |
| 423 | using GDB.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 424 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 425 | <para>The other debugging command line options can be useful too (run |
| 426 | <computeroutput>valgrind --help-debug</computeroutput> for the |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 427 | list).</para> |
| 428 | |
| 429 | </sect3> |
| 430 | |
| 431 | </sect2> |
| 432 | |
| 433 | </sect1> |
| 434 | |
| 435 | |
| 436 | |
| 437 | <sect1 id="writing-tools.advtopics" xreflabel="Advanced Topics"> |
| 438 | <title>Advanced Topics</title> |
| 439 | |
| 440 | <para>Once a tool becomes more complicated, there are some extra |
| 441 | things you may want/need to do.</para> |
| 442 | |
| 443 | <sect2 id="writing-tools.suppressions" xreflabel="Suppressions"> |
| 444 | <title>Suppressions</title> |
| 445 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 446 | <para>If your tool reports errors and you want to suppress some common |
| 447 | ones, you can add suppressions to the suppression files. The relevant |
| 448 | files are <filename>valgrind/*.supp</filename>; the final suppression |
| 449 | file is aggregated from these files by combining the relevant |
| 450 | <filename>.supp</filename> files depending on the versions of linux, X |
| 451 | and glibc on a system.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 452 | |
| 453 | <para>Suppression types have the form |
| 454 | <computeroutput>tool_name:suppression_name</computeroutput>. The |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 455 | <computeroutput>tool_name</computeroutput> here is the name you specify |
| 456 | for the tool during initialisation with |
| 457 | <function>VG_(details_name)()</function>.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 458 | |
| 459 | </sect2> |
| 460 | |
| 461 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 462 | <sect2 id="writing-tools.docs" xreflabel="Documentation"> |
| 463 | <title>Documentation</title> |
| 464 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 465 | <para>As of version 3.0.0, Valgrind documentation has been converted to |
| 466 | XML. Why? See <ulink url="http://www.ucc.ie/xml/">The XML FAQ</ulink>. |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 467 | </para> |
| 468 | |
| 469 | |
| 470 | <sect3 id="writing-tools.xml" xreflabel="The XML Toolchain"> |
| 471 | <title>The XML Toolchain</title> |
| 472 | |
| 473 | <para>If you are feeling conscientious and want to write some |
| 474 | documentation for your tool, please use XML. The Valgrind |
| 475 | Docs use the following toolchain and versions:</para> |
| 476 | |
| 477 | <programlisting> |
| 478 | xmllint: using libxml version 20607 |
| 479 | xsltproc: using libxml 20607, libxslt 10102 and libexslt 802 |
| 480 | pdfxmltex: pdfTeX (Web2C 7.4.5) 3.14159-1.10b |
| 481 | pdftops: version 3.00 |
| 482 | DocBook: version 4.2 |
| 483 | </programlisting> |
| 484 | |
| 485 | <para><command>Latency:</command> you should note that latency is |
| 486 | a big problem: DocBook is constantly being updated, but the tools |
| 487 | tend to lag behind somewhat. It is important that the versions |
| 488 | get on with each other, so if you decide to upgrade something, |
| 489 | then you need to ascertain whether things still work nicely - |
| 490 | this *cannot* be assumed.</para> |
| 491 | |
| 492 | <para><command>Stylesheets:</command> The Valgrind docs use |
| 493 | various custom stylesheet layers, all of which are in |
| 494 | <computeroutput>valgrind/docs/lib/</computeroutput>. You |
| 495 | shouldn't need to modify these in any way.</para> |
| 496 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 497 | <para><command>Catalogs:</command> Catalogs provide a mapping from |
| 498 | generic addresses to specific local directories on a given machine. |
| 499 | Most recent Linux distributions have adopted a common place for storing |
| 500 | catalogs (<filename>/etc/xml/</filename>). Assuming that you have the |
| 501 | various tools listed above installed, you probably won't need to modify |
| 502 | your catalogs. But if you do, then just add another |
| 503 | <computeroutput>group</computeroutput> to this file, reflecting your |
| 504 | local installation.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 505 | |
| 506 | </sect3> |
| 507 | |
| 508 | |
| 509 | <sect3 id="writing-tools.writing" xreflabel="Writing the Documentation"> |
| 510 | <title>Writing the Documentation</title> |
| 511 | |
| 512 | <para>Follow these steps (using <computeroutput>foobar</computeroutput> |
| 513 | as the example tool name again):</para> |
| 514 | |
| 515 | <orderedlist> |
| 516 | |
| 517 | <listitem> |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 518 | <para>The docs go in |
| 519 | <computeroutput>valgrind/foobar/docs/</computeroutput>, which you will |
| 520 | have created when you started writing the tool.</para> |
| 521 | </listitem> |
| 522 | |
| 523 | <listitem> |
| 524 | <para>Write <filename>foobar/docs/Makefile.am</filename>. Use |
| 525 | <filename>memcheck/docs/Makefile.am</filename> as an |
| 526 | example.</para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 527 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 528 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 529 | <listitem> |
| 530 | <para>Copy the XML documentation file for the tool Nulgrind from |
| 531 | <filename>valgrind/none/docs/nl-manual.xml</filename> to |
| 532 | <computeroutput>foobar/docs/</computeroutput>, and rename it to |
| 533 | <filename>foobar/docs/fb-manual.xml</filename>.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 534 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 535 | <para><command>Note</command>: there is a *really stupid* tetex bug |
| 536 | with underscores in filenames, so don't use '_'.</para> |
| 537 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 538 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 539 | <listitem> |
| 540 | <para>Write the documentation. There are some helpful bits and |
| 541 | pieces on using xml markup in |
| 542 | <filename>valgrind/docs/xml/xml_help.txt</filename>.</para> |
| 543 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 544 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 545 | <listitem> |
| 546 | <para>Include it in the User Manual by adding the relevant entry to |
| 547 | <filename>valgrind/docs/xml/manual.xml</filename>. Copy and edit an |
| 548 | existing entry.</para> |
| 549 | </listitem> |
| 550 | |
| 551 | <listitem> |
| 552 | <para>Validate <filename>foobar/docs/fb-manual.xml</filename> using |
| 553 | the following command from within <filename>valgrind/docs/</filename>: |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 554 | </para> |
| 555 | <screen><![CDATA[ |
| 556 | % make valid |
| 557 | ]]></screen> |
| 558 | |
| 559 | <para>You will probably get errors that look like this:</para> |
| 560 | |
| 561 | <screen><![CDATA[ |
| 562 | ./xml/index.xml:5: element chapter: validity error : No declaration for |
| 563 | attribute base of element chapter |
| 564 | ]]></screen> |
| 565 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 566 | <para>Ignore (only) these -- they're not important.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 567 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 568 | <para>Because the xml toolchain is fragile, it is important to ensure |
| 569 | that <filename>fb-manual.xml</filename> won't break the documentation |
| 570 | set build. Note that just because an xml file happily transforms to |
| 571 | html does not necessarily mean the same holds true for pdf/ps.</para> |
| 572 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 573 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 574 | <listitem> |
| 575 | <para>You can (re-)generate the HTML docs while you are writing |
| 576 | <filename>fb-manual.xml</filename> to help you see how it's looking. |
| 577 | The generated files end up in |
| 578 | <filename>valgrind/docs/html/</filename>. Use the following |
| 579 | command, within <filename>valgrind/docs/</filename>:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 580 | <screen><![CDATA[ |
| 581 | % make html-docs |
| 582 | ]]></screen> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 583 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 584 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 585 | <listitem> |
| 586 | <para>When you have finished, also generate pdf and ps output to |
| 587 | check all is well, from within <filename>valgrind/docs/</filename>: |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 588 | </para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 589 | <screen><![CDATA[ |
| 590 | % make print-docs |
| 591 | ]]></screen> |
| 592 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 593 | <para>Check the output <filename>.pdf</filename> and |
| 594 | <filename>.ps</filename> files in |
| 595 | <computeroutput>valgrind/docs/print/</computeroutput>.</para> |
| 596 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 597 | |
| 598 | </orderedlist> |
| 599 | |
| 600 | </sect3> |
| 601 | |
| 602 | </sect2> |
| 603 | |
| 604 | |
| 605 | <sect2 id="writing-tools.regtests" xreflabel="Regression Tests"> |
| 606 | <title>Regression Tests</title> |
| 607 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 608 | <para>Valgrind has some support for regression tests. If you want to |
| 609 | write regression tests for your tool:</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 610 | |
| 611 | <orderedlist> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 612 | <listitem> |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 613 | <para>The tests go in <computeroutput>foobar/tests/</computeroutput>, |
| 614 | which you will have created when you started writing the tool.</para> |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 615 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 616 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 617 | <listitem> |
| 618 | <para>Write <filename>foobar/tests/Makefile.am</filename>. Use |
| 619 | <filename>memcheck/tests/Makefile.am</filename> as an |
| 620 | example.</para> |
| 621 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 622 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 623 | <listitem> |
| 624 | <para>Write the tests, <computeroutput>.vgtest</computeroutput> test |
| 625 | description files, <computeroutput>.stdout.exp</computeroutput> and |
| 626 | <computeroutput>.stderr.exp</computeroutput> expected output files. |
| 627 | (Note that Valgrind's output goes to stderr.) Some details on |
| 628 | writing and running tests are given in the comments at the top of |
| 629 | the testing script |
| 630 | <computeroutput>tests/vg_regtest</computeroutput>.</para> |
| 631 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 632 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 633 | <listitem> |
| 634 | <para>Write a filter for stderr results |
| 635 | <computeroutput>foobar/tests/filter_stderr</computeroutput>. It can |
| 636 | call the existing filters in |
| 637 | <computeroutput>tests/</computeroutput>. See |
| 638 | <computeroutput>memcheck/tests/filter_stderr</computeroutput> for an |
| 639 | example; in particular note the |
| 640 | <computeroutput>$dir</computeroutput> trick that ensures the filter |
| 641 | works correctly from any directory.</para> |
| 642 | </listitem> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 643 | |
| 644 | </orderedlist> |
| 645 | |
| 646 | </sect2> |
| 647 | |
| 648 | |
| 649 | |
| 650 | <sect2 id="writing-tools.profiling" xreflabel="Profiling"> |
| 651 | <title>Profiling</title> |
| 652 | |
njn | bcd75fc | 2005-12-19 22:48:39 +0000 | [diff] [blame] | 653 | <para>To profile a tool, use Cachegrind on it. Read README_DEVELOPERS for |
| 654 | details on running Valgrind under Valgrind.</para> |
njn | 31066fd | 2005-03-26 00:42:02 +0000 | [diff] [blame] | 655 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 656 | </sect2> |
| 657 | |
| 658 | |
| 659 | |
| 660 | <sect2 id="writing-tools.mkhackery" xreflabel="Other Makefile Hackery"> |
| 661 | <title>Other Makefile Hackery</title> |
| 662 | |
| 663 | <para>If you add any directories under |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 664 | <computeroutput>valgrind/foobar/</computeroutput>, you will need to add |
| 665 | an appropriate <filename>Makefile.am</filename> to it, and add a |
| 666 | corresponding entry to the <computeroutput>AC_OUTPUT</computeroutput> |
| 667 | list in <filename>valgrind/configure.in</filename>.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 668 | |
| 669 | <para>If you add any scripts to your tool (see Cachegrind for an |
| 670 | example) you need to add them to the |
| 671 | <computeroutput>bin_SCRIPTS</computeroutput> variable in |
| 672 | <filename>valgrind/foobar/Makefile.am</filename>.</para> |
| 673 | |
| 674 | </sect2> |
| 675 | |
| 676 | |
| 677 | |
| 678 | <sect2 id="writing-tools.ifacever" xreflabel="Core/tool Interface Versions"> |
| 679 | <title>Core/tool Interface Versions</title> |
| 680 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 681 | <para>In order to allow for the core/tool interface to evolve over time, |
| 682 | Valgrind uses a basic interface versioning system. All a tool has to do |
| 683 | is use the |
| 684 | <computeroutput>VG_DETERMINE_INTERFACE_VERSION</computeroutput> macro |
| 685 | exactly once in its code. If not, a link error will occur when the tool |
| 686 | is built.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 687 | |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 688 | <para>The interface version number is changed when binary incompatible |
| 689 | changes are made to the interface. If the core and tool has the same major |
| 690 | version number X they should work together. If X doesn't match, Valgrind |
| 691 | will abort execution with an explanation of the problem.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 692 | |
de | bad57fc | 2005-12-03 22:33:29 +0000 | [diff] [blame] | 693 | <para>This approach was chosen so that if the interface changes in the |
| 694 | future, old tools won't work and the reason will be clearly explained, |
| 695 | instead of possibly crashing mysteriously. We have attempted to |
| 696 | minimise the potential for binary incompatible changes by means such as |
| 697 | minimising the use of naked structs in the interface.</para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 698 | |
| 699 | </sect2> |
| 700 | |
| 701 | </sect1> |
| 702 | |
| 703 | |
| 704 | |
| 705 | <sect1 id="writing-tools.finalwords" xreflabel="Final Words"> |
| 706 | <title>Final Words</title> |
| 707 | |
njn | e5eaf3a | 2006-10-23 21:21:48 +0000 | [diff] [blame] | 708 | <para>The core/tool interface is not fixed. It's pretty stable these days, |
| 709 | but it does change. We deliberately do not provide backward compatibility |
| 710 | with old interfaces, because it is too difficult and too restrictive. |
| 711 | The interface checking should catch any incompatibilities. We view this as |
| 712 | a good thing -- if we had to be backward compatible with earlier versions, |
| 713 | many improvements now in the system could not have been added. |
| 714 | </para> |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 715 | |
njn | 3e986b2 | 2004-11-30 10:43:45 +0000 | [diff] [blame] | 716 | |
| 717 | <para>Happy programming.</para> |
| 718 | |
| 719 | </sect1> |
| 720 | |
| 721 | </chapter> |