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