1 <?xml version="1.0"?> <!-- -*- sgml -*- --> 2 <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" 3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" 4 [ <!ENTITY % vg-entities SYSTEM "vg-entities.xml"> %vg-entities; ]> 5 6 7 <chapter id="manual-core" xreflabel="Valgrind's core"> 8 <title>Using and understanding the Valgrind core</title> 9 10 <para>This chapter describes the Valgrind core services, command-line 11 options and behaviours. That means it is relevant regardless of what 12 particular tool you are using. The information should be sufficient for you 13 to make effective day-to-day use of Valgrind. Advanced topics related to 14 the Valgrind core are described in <xref linkend="manual-core-adv"/>. 15 </para> 16 17 <para> 18 A point of terminology: most references to "Valgrind" in this chapter 19 refer to the Valgrind core services. </para> 20 21 22 23 <sect1 id="manual-core.whatdoes" 24 xreflabel="What Valgrind does with your program"> 25 <title>What Valgrind does with your program</title> 26 27 <para>Valgrind is designed to be as non-intrusive as possible. It works 28 directly with existing executables. You don't need to recompile, relink, 29 or otherwise modify the program to be checked.</para> 30 31 <para>You invoke Valgrind like this:</para> 32 <programlisting><![CDATA[ 33 valgrind [valgrind-options] your-prog [your-prog-options]]]></programlisting> 34 35 <para>The most important option is <option>--tool</option> which dictates 36 which Valgrind tool to run. For example, if want to run the command 37 <computeroutput>ls -l</computeroutput> using the memory-checking tool 38 Memcheck, issue this command:</para> 39 40 <programlisting><![CDATA[ 41 valgrind --tool=memcheck ls -l]]></programlisting> 42 43 <para>However, Memcheck is the default, so if you want to use it you can 44 omit the <option>--tool</option> option.</para> 45 46 <para>Regardless of which tool is in use, Valgrind takes control of your 47 program before it starts. Debugging information is read from the 48 executable and associated libraries, so that error messages and other 49 outputs can be phrased in terms of source code locations, when 50 appropriate.</para> 51 52 <para>Your program is then run on a synthetic CPU provided by the 53 Valgrind core. As new code is executed for the first time, the core 54 hands the code to the selected tool. The tool adds its own 55 instrumentation code to this and hands the result back to the core, 56 which coordinates the continued execution of this instrumented 57 code.</para> 58 59 <para>The amount of instrumentation code added varies widely between 60 tools. At one end of the scale, Memcheck adds code to check every 61 memory access and every value computed, 62 making it run 10-50 times slower than natively. 63 At the other end of the spectrum, the minimal tool, called Nulgrind, 64 adds no instrumentation at all and causes in total "only" about a 4 times 65 slowdown.</para> 66 67 <para>Valgrind simulates every single instruction your program executes. 68 Because of this, the active tool checks, or profiles, not only the code 69 in your application but also in all supporting dynamically-linked libraries, 70 including the C library, graphical libraries, and so on.</para> 71 72 <para>If you're using an error-detection tool, Valgrind may 73 detect errors in system libraries, for example the GNU C or X11 74 libraries, which you have to use. You might not be interested in these 75 errors, since you probably have no control over that code. Therefore, 76 Valgrind allows you to selectively suppress errors, by recording them in 77 a suppressions file which is read when Valgrind starts up. The build 78 mechanism selects default suppressions which give reasonable 79 behaviour for the OS and libraries detected on your machine. 80 To make it easier to write suppressions, you can use the 81 <option>--gen-suppressions=yes</option> option. This tells Valgrind to 82 print out a suppression for each reported error, which you can then 83 copy into a suppressions file.</para> 84 85 <para>Different error-checking tools report different kinds of errors. 86 The suppression mechanism therefore allows you to say which tool or 87 tool(s) each suppression applies to.</para> 88 89 </sect1> 90 91 92 <sect1 id="manual-core.started" xreflabel="Getting started"> 93 <title>Getting started</title> 94 95 <para>First off, consider whether it might be beneficial to recompile 96 your application and supporting libraries with debugging info enabled 97 (the <option>-g</option> option). Without debugging info, the best 98 Valgrind tools will be able to do is guess which function a particular 99 piece of code belongs to, which makes both error messages and profiling 100 output nearly useless. With <option>-g</option>, you'll get 101 messages which point directly to the relevant source code lines.</para> 102 103 <para>Another option you might like to consider, if you are working with 104 C++, is <option>-fno-inline</option>. That makes it easier to see the 105 function-call chain, which can help reduce confusion when navigating 106 around large C++ apps. For example, debugging 107 OpenOffice.org with Memcheck is a bit easier when using this option. You 108 don't have to do this, but doing so helps Valgrind produce more accurate 109 and less confusing error reports. Chances are you're set up like this 110 already, if you intended to debug your program with GNU GDB, or some 111 other debugger.</para> 112 113 <para>If you are planning to use Memcheck: On rare 114 occasions, compiler optimisations (at <option>-O2</option> 115 and above, and sometimes <option>-O1</option>) have been 116 observed to generate code which fools Memcheck into wrongly reporting 117 uninitialised value errors, or missing uninitialised value errors. We have 118 looked in detail into fixing this, and unfortunately the result is that 119 doing so would give a further significant slowdown in what is already a slow 120 tool. So the best solution is to turn off optimisation altogether. Since 121 this often makes things unmanageably slow, a reasonable compromise is to use 122 <option>-O</option>. This gets you the majority of the 123 benefits of higher optimisation levels whilst keeping relatively small the 124 chances of false positives or false negatives from Memcheck. Also, you 125 should compile your code with <option>-Wall</option> because 126 it can identify some or all of the problems that Valgrind can miss at the 127 higher optimisation levels. (Using <option>-Wall</option> 128 is also a good idea in general.) All other tools (as far as we know) are 129 unaffected by optimisation level, and for profiling tools like Cachegrind it 130 is better to compile your program at its normal optimisation level.</para> 131 132 <para>Valgrind understands both the older "stabs" debugging format, used 133 by GCC versions prior to 3.1, and the newer DWARF2/3/4 formats 134 used by GCC 135 3.1 and later. We continue to develop our debug-info readers, 136 although the majority of effort will naturally enough go into the newer 137 DWARF readers.</para> 138 139 <para>When you're ready to roll, run Valgrind as described above. 140 Note that you should run the real 141 (machine-code) executable here. If your application is started by, for 142 example, a shell or Perl script, you'll need to modify it to invoke 143 Valgrind on the real executables. Running such scripts directly under 144 Valgrind will result in you getting error reports pertaining to 145 <filename>/bin/sh</filename>, 146 <filename>/usr/bin/perl</filename>, or whatever interpreter 147 you're using. This may not be what you want and can be confusing. You 148 can force the issue by giving the option 149 <option>--trace-children=yes</option>, but confusion is still 150 likely.</para> 151 152 </sect1> 153 154 155 <sect1 id="manual-core.comment" xreflabel="The Commentary"> 156 <title>The Commentary</title> 157 158 <para>Valgrind tools write a commentary, a stream of text, detailing 159 error reports and other significant events. All lines in the commentary 160 have following form: 161 162 <programlisting><![CDATA[ 163 ==12345== some-message-from-Valgrind]]></programlisting> 164 </para> 165 166 <para>The <computeroutput>12345</computeroutput> is the process ID. 167 This scheme makes it easy to distinguish program output from Valgrind 168 commentary, and also easy to differentiate commentaries from different 169 processes which have become merged together, for whatever reason.</para> 170 171 <para>By default, Valgrind tools write only essential messages to the 172 commentary, so as to avoid flooding you with information of secondary 173 importance. If you want more information about what is happening, 174 re-run, passing the <option>-v</option> option to Valgrind. A second 175 <option>-v</option> gives yet more detail. 176 </para> 177 178 <para>You can direct the commentary to three different places:</para> 179 180 <orderedlist> 181 182 <listitem id="manual-core.out2fd" xreflabel="Directing output to fd"> 183 <para>The default: send it to a file descriptor, which is by default 184 2 (stderr). So, if you give the core no options, it will write 185 commentary to the standard error stream. If you want to send it to 186 some other file descriptor, for example number 9, you can specify 187 <option>--log-fd=9</option>.</para> 188 189 <para>This is the simplest and most common arrangement, but can 190 cause problems when Valgrinding entire trees of processes which 191 expect specific file descriptors, particularly stdin/stdout/stderr, 192 to be available for their own use.</para> 193 </listitem> 194 195 <listitem id="manual-core.out2file" 196 xreflabel="Directing output to file"> <para>A less intrusive 197 option is to write the commentary to a file, which you specify by 198 <option>--log-file=filename</option>. There are special format 199 specifiers that can be used to use a process ID or an environment 200 variable name in the log file name. These are useful/necessary if your 201 program invokes multiple processes (especially for MPI programs). 202 See the <link linkend="manual-core.basicopts">basic options section</link> 203 for more details.</para> 204 </listitem> 205 206 <listitem id="manual-core.out2socket" 207 xreflabel="Directing output to network socket"> <para>The 208 least intrusive option is to send the commentary to a network 209 socket. The socket is specified as an IP address and port number 210 pair, like this: <option>--log-socket=192.168.0.1:12345</option> if 211 you want to send the output to host IP 192.168.0.1 port 12345 212 (note: we 213 have no idea if 12345 is a port of pre-existing significance). You 214 can also omit the port number: 215 <option>--log-socket=192.168.0.1</option>, in which case a default 216 port of 1500 is used. This default is defined by the constant 217 <computeroutput>VG_CLO_DEFAULT_LOGPORT</computeroutput> in the 218 sources.</para> 219 220 <para>Note, unfortunately, that you have to use an IP address here, 221 rather than a hostname.</para> 222 223 <para>Writing to a network socket is pointless if you don't 224 have something listening at the other end. We provide a simple 225 listener program, 226 <computeroutput>valgrind-listener</computeroutput>, which accepts 227 connections on the specified port and copies whatever it is sent to 228 stdout. Probably someone will tell us this is a horrible security 229 risk. It seems likely that people will write more sophisticated 230 listeners in the fullness of time.</para> 231 232 <para><computeroutput>valgrind-listener</computeroutput> can accept 233 simultaneous connections from up to 50 Valgrinded processes. In front 234 of each line of output it prints the current number of active 235 connections in round brackets.</para> 236 237 <para><computeroutput>valgrind-listener</computeroutput> accepts two 238 command-line options:</para> 239 <itemizedlist> 240 <listitem> 241 <para><option>-e</option> or <option>--exit-at-zero</option>: 242 when the number of connected processes falls back to zero, 243 exit. Without this, it will run forever, that is, until you 244 send it Control-C.</para> 245 </listitem> 246 <listitem> 247 <para><option>portnumber</option>: changes the port it listens 248 on from the default (1500). The specified port must be in the 249 range 1024 to 65535. The same restriction applies to port 250 numbers specified by a <option>--log-socket</option> to 251 Valgrind itself.</para> 252 </listitem> 253 </itemizedlist> 254 255 <para>If a Valgrinded process fails to connect to a listener, for 256 whatever reason (the listener isn't running, invalid or unreachable 257 host or port, etc), Valgrind switches back to writing the commentary 258 to stderr. The same goes for any process which loses an established 259 connection to a listener. In other words, killing the listener 260 doesn't kill the processes sending data to it.</para> 261 </listitem> 262 263 </orderedlist> 264 265 <para>Here is an important point about the relationship between the 266 commentary and profiling output from tools. The commentary contains a 267 mix of messages from the Valgrind core and the selected tool. If the 268 tool reports errors, it will report them to the commentary. However, if 269 the tool does profiling, the profile data will be written to a file of 270 some kind, depending on the tool, and independent of what 271 <option>--log-*</option> options are in force. The commentary is 272 intended to be a low-bandwidth, human-readable channel. Profiling data, 273 on the other hand, is usually voluminous and not meaningful without 274 further processing, which is why we have chosen this arrangement.</para> 275 276 </sect1> 277 278 279 <sect1 id="manual-core.report" xreflabel="Reporting of errors"> 280 <title>Reporting of errors</title> 281 282 <para>When an error-checking tool 283 detects something bad happening in the program, an error 284 message is written to the commentary. Here's an example from Memcheck:</para> 285 286 <programlisting><![CDATA[ 287 ==25832== Invalid read of size 4 288 ==25832== at 0x8048724: BandMatrix::ReSize(int, int, int) (bogon.cpp:45) 289 ==25832== by 0x80487AF: main (bogon.cpp:66) 290 ==25832== Address 0xBFFFF74C is not stack'd, malloc'd or free'd]]></programlisting> 291 292 <para>This message says that the program did an illegal 4-byte read of 293 address 0xBFFFF74C, which, as far as Memcheck can tell, is not a valid 294 stack address, nor corresponds to any current heap blocks or recently freed 295 heap blocks. The read is happening at line 45 of 296 <filename>bogon.cpp</filename>, called from line 66 of the same file, 297 etc. For errors associated with an identified (current or freed) heap block, 298 for example reading freed memory, Valgrind reports not only the 299 location where the error happened, but also where the associated heap block 300 was allocated/freed.</para> 301 302 <para>Valgrind remembers all error reports. When an error is detected, 303 it is compared against old reports, to see if it is a duplicate. If so, 304 the error is noted, but no further commentary is emitted. This avoids 305 you being swamped with bazillions of duplicate error reports.</para> 306 307 <para>If you want to know how many times each error occurred, run with 308 the <option>-v</option> option. When execution finishes, all the 309 reports are printed out, along with, and sorted by, their occurrence 310 counts. This makes it easy to see which errors have occurred most 311 frequently.</para> 312 313 <para>Errors are reported before the associated operation actually 314 happens. For example, if you're using Memcheck and your program attempts to 315 read from address zero, Memcheck will emit a message to this effect, and 316 your program will then likely die with a segmentation fault.</para> 317 318 <para>In general, you should try and fix errors in the order that they 319 are reported. Not doing so can be confusing. For example, a program 320 which copies uninitialised values to several memory locations, and later 321 uses them, will generate several error messages, when run on Memcheck. 322 The first such error message may well give the most direct clue to the 323 root cause of the problem.</para> 324 325 <para>The process of detecting duplicate errors is quite an 326 expensive one and can become a significant performance overhead 327 if your program generates huge quantities of errors. To avoid 328 serious problems, Valgrind will simply stop collecting 329 errors after 1,000 different errors have been seen, or 10,000,000 errors 330 in total have been seen. In this situation you might as well 331 stop your program and fix it, because Valgrind won't tell you 332 anything else useful after this. Note that the 1,000/10,000,000 limits 333 apply after suppressed errors are removed. These limits are 334 defined in <filename>m_errormgr.c</filename> and can be increased 335 if necessary.</para> 336 337 <para>To avoid this cutoff you can use the 338 <option>--error-limit=no</option> option. Then Valgrind will always show 339 errors, regardless of how many there are. Use this option carefully, 340 since it may have a bad effect on performance.</para> 341 342 </sect1> 343 344 345 <sect1 id="manual-core.suppress" xreflabel="Suppressing errors"> 346 <title>Suppressing errors</title> 347 348 <para>The error-checking tools detect numerous problems in the system 349 libraries, such as the C library, 350 which come pre-installed with your OS. You can't easily fix 351 these, but you don't want to see these errors (and yes, there are many!) 352 So Valgrind reads a list of errors to suppress at startup. A default 353 suppression file is created by the 354 <computeroutput>./configure</computeroutput> script when the system is 355 built.</para> 356 357 <para>You can modify and add to the suppressions file at your leisure, 358 or, better, write your own. Multiple suppression files are allowed. 359 This is useful if part of your project contains errors you can't or 360 don't want to fix, yet you don't want to continuously be reminded of 361 them.</para> 362 363 <formalpara><title>Note:</title> <para>By far the easiest way to add 364 suppressions is to use the <option>--gen-suppressions=yes</option> option 365 described in <xref linkend="manual-core.options"/>. This generates 366 suppressions automatically. For best results, 367 though, you may want to edit the output 368 of <option>--gen-suppressions=yes</option> by hand, in which 369 case it would be advisable to read through this section. 370 </para> 371 </formalpara> 372 373 <para>Each error to be suppressed is described very specifically, to 374 minimise the possibility that a suppression-directive inadvertently 375 suppresses a bunch of similar errors which you did want to see. The 376 suppression mechanism is designed to allow precise yet flexible 377 specification of errors to suppress.</para> 378 379 <para>If you use the <option>-v</option> option, at the end of execution, 380 Valgrind prints out one line for each used suppression, giving its name 381 and the number of times it got used. Here's the suppressions used by a 382 run of <computeroutput>valgrind --tool=memcheck ls -l</computeroutput>:</para> 383 384 <programlisting><![CDATA[ 385 --27579-- supp: 1 socketcall.connect(serv_addr)/__libc_connect/__nscd_getgrgid_r 386 --27579-- supp: 1 socketcall.connect(serv_addr)/__libc_connect/__nscd_getpwuid_r 387 --27579-- supp: 6 strrchr/_dl_map_object_from_fd/_dl_map_object]]></programlisting> 388 389 <para>Multiple suppressions files are allowed. By default, Valgrind 390 uses <filename>$PREFIX/lib/valgrind/default.supp</filename>. You can 391 ask to add suppressions from another file, by specifying 392 <option>--suppressions=/path/to/file.supp</option>. 393 </para> 394 395 <para>If you want to understand more about suppressions, look at an 396 existing suppressions file whilst reading the following documentation. 397 The file <filename>glibc-2.3.supp</filename>, in the source 398 distribution, provides some good examples.</para> 399 400 <para>Each suppression has the following components:</para> 401 402 <itemizedlist> 403 404 <listitem> 405 <para>First line: its name. This merely gives a handy name to the 406 suppression, by which it is referred to in the summary of used 407 suppressions printed out when a program finishes. It's not 408 important what the name is; any identifying string will do.</para> 409 </listitem> 410 411 <listitem> 412 <para>Second line: name of the tool(s) that the suppression is for 413 (if more than one, comma-separated), and the name of the suppression 414 itself, separated by a colon (n.b.: no spaces are allowed), eg:</para> 415 <programlisting><![CDATA[ 416 tool_name1,tool_name2:suppression_name]]></programlisting> 417 418 <para>Recall that Valgrind is a modular system, in which 419 different instrumentation tools can observe your program whilst it 420 is running. Since different tools detect different kinds of errors, 421 it is necessary to say which tool(s) the suppression is meaningful 422 to.</para> 423 424 <para>Tools will complain, at startup, if a tool does not understand 425 any suppression directed to it. Tools ignore suppressions which are 426 not directed to them. As a result, it is quite practical to put 427 suppressions for all tools into the same suppression file.</para> 428 </listitem> 429 430 <listitem> 431 <para>Next line: a small number of suppression types have extra 432 information after the second line (eg. the <varname>Param</varname> 433 suppression for Memcheck)</para> 434 </listitem> 435 436 <listitem> 437 <para>Remaining lines: This is the calling context for the error -- 438 the chain of function calls that led to it. There can be up to 24 439 of these lines.</para> 440 441 <para>Locations may be names of either shared objects or 442 functions. They begin 443 <computeroutput>obj:</computeroutput> and 444 <computeroutput>fun:</computeroutput> respectively. Function and 445 object names to match against may use the wildcard characters 446 <computeroutput>*</computeroutput> and 447 <computeroutput>?</computeroutput>.</para> 448 449 <para><command>Important note: </command> C++ function names must be 450 <command>mangled</command>. If you are writing suppressions by 451 hand, use the <option>--demangle=no</option> option to get the 452 mangled names in your error messages. An example of a mangled 453 C++ name is <computeroutput>_ZN9QListView4showEv</computeroutput>. 454 This is the form that the GNU C++ compiler uses internally, and 455 the form that must be used in suppression files. The equivalent 456 demangled name, <computeroutput>QListView::show()</computeroutput>, 457 is what you see at the C++ source code level. 458 </para> 459 460 <para>A location line may also be 461 simply "<computeroutput>...</computeroutput>" (three dots). This is 462 a frame-level wildcard, which matches zero or more frames. Frame 463 level wildcards are useful because they make it easy to ignore 464 varying numbers of uninteresting frames in between frames of 465 interest. That is often important when writing suppressions which 466 are intended to be robust against variations in the amount of 467 function inlining done by compilers.</para> 468 </listitem> 469 470 <listitem> 471 <para>Finally, the entire suppression must be between curly 472 braces. Each brace must be the first character on its own 473 line.</para> 474 </listitem> 475 476 </itemizedlist> 477 478 <para>A suppression only suppresses an error when the error matches all 479 the details in the suppression. Here's an example:</para> 480 481 <programlisting><![CDATA[ 482 { 483 __gconv_transform_ascii_internal/__mbrtowc/mbtowc 484 Memcheck:Value4 485 fun:__gconv_transform_ascii_internal 486 fun:__mbr*toc 487 fun:mbtowc 488 }]]></programlisting> 489 490 491 <para>What it means is: for Memcheck only, suppress a 492 use-of-uninitialised-value error, when the data size is 4, when it 493 occurs in the function 494 <computeroutput>__gconv_transform_ascii_internal</computeroutput>, when 495 that is called from any function of name matching 496 <computeroutput>__mbr*toc</computeroutput>, when that is called from 497 <computeroutput>mbtowc</computeroutput>. It doesn't apply under any 498 other circumstances. The string by which this suppression is identified 499 to the user is 500 <computeroutput>__gconv_transform_ascii_internal/__mbrtowc/mbtowc</computeroutput>.</para> 501 502 <para>(See <xref linkend="mc-manual.suppfiles"/> for more details 503 on the specifics of Memcheck's suppression kinds.)</para> 504 505 <para>Another example, again for the Memcheck tool:</para> 506 507 <programlisting><![CDATA[ 508 { 509 libX11.so.6.2/libX11.so.6.2/libXaw.so.7.0 510 Memcheck:Value4 511 obj:/usr/X11R6/lib/libX11.so.6.2 512 obj:/usr/X11R6/lib/libX11.so.6.2 513 obj:/usr/X11R6/lib/libXaw.so.7.0 514 }]]></programlisting> 515 516 <para>This suppresses any size 4 uninitialised-value error which occurs 517 anywhere in <filename>libX11.so.6.2</filename>, when called from 518 anywhere in the same library, when called from anywhere in 519 <filename>libXaw.so.7.0</filename>. The inexact specification of 520 locations is regrettable, but is about all you can hope for, given that 521 the X11 libraries shipped on the Linux distro on which this example 522 was made have had their symbol tables removed.</para> 523 524 <para>Although the above two examples do not make this clear, you can 525 freely mix <computeroutput>obj:</computeroutput> and 526 <computeroutput>fun:</computeroutput> lines in a suppression.</para> 527 528 <para>Finally, here's an example using three frame-level wildcards:</para> 529 530 <programlisting><![CDATA[ 531 { 532 a-contrived-example 533 Memcheck:Leak 534 fun:malloc 535 ... 536 fun:ddd 537 ... 538 fun:ccc 539 ... 540 fun:main 541 } 542 ]]></programlisting> 543 This suppresses Memcheck memory-leak errors, in the case where 544 the allocation was done by <computeroutput>main</computeroutput> 545 calling (though any number of intermediaries, including zero) 546 <computeroutput>ccc</computeroutput>, 547 calling onwards via 548 <computeroutput>ddd</computeroutput> and eventually 549 to <computeroutput>malloc.</computeroutput>. 550 </sect1> 551 552 553 <sect1 id="manual-core.options" 554 xreflabel="Core Command-line Options"> 555 <title>Core Command-line Options</title> 556 557 <para>As mentioned above, Valgrind's core accepts a common set of options. 558 The tools also accept tool-specific options, which are documented 559 separately for each tool.</para> 560 561 <para>Valgrind's default settings succeed in giving reasonable behaviour 562 in most cases. We group the available options by rough categories.</para> 563 564 <sect2 id="manual-core.toolopts" xreflabel="Tool-selection Option"> 565 <title>Tool-selection Option</title> 566 567 <para>The single most important option.</para> 568 569 <variablelist> 570 571 <varlistentry id="tool_name" xreflabel="--tool"> 572 <term> 573 <option><![CDATA[--tool=<toolname> [default: memcheck] ]]></option> 574 </term> 575 <listitem> 576 <para>Run the Valgrind tool called <varname>toolname</varname>, 577 e.g. Memcheck, Cachegrind, etc.</para> 578 </listitem> 579 </varlistentry> 580 581 </variablelist> 582 583 </sect2> 584 585 586 587 <sect2 id="manual-core.basicopts" xreflabel="Basic Options"> 588 <title>Basic Options</title> 589 590 <!-- start of xi:include in the manpage --> 591 <para id="basic.opts.para">These options work with all tools.</para> 592 593 <variablelist id="basic.opts.list"> 594 595 <varlistentry id="opt.help" xreflabel="--help"> 596 <term><option>-h --help</option></term> 597 <listitem> 598 <para>Show help for all options, both for the core and for the 599 selected tool. If the option is repeated it is equivalent to giving 600 <option>--help-debug</option>.</para> 601 </listitem> 602 </varlistentry> 603 604 <varlistentry id="opt.help-debug" xreflabel="--help-debug"> 605 <term><option>--help-debug</option></term> 606 <listitem> 607 <para>Same as <option>--help</option>, but also lists debugging 608 options which usually are only of use to Valgrind's 609 developers.</para> 610 </listitem> 611 </varlistentry> 612 613 <varlistentry id="opt.version" xreflabel="--version"> 614 <term><option>--version</option></term> 615 <listitem> 616 <para>Show the version number of the Valgrind core. Tools can have 617 their own version numbers. There is a scheme in place to ensure 618 that tools only execute when the core version is one they are 619 known to work with. This was done to minimise the chances of 620 strange problems arising from tool-vs-core version 621 incompatibilities.</para> 622 </listitem> 623 </varlistentry> 624 625 <varlistentry id="opt.quiet" xreflabel="--quiet"> 626 <term><option>-q</option>, <option>--quiet</option></term> 627 <listitem> 628 <para>Run silently, and only print error messages. Useful if you 629 are running regression tests or have some other automated test 630 machinery.</para> 631 </listitem> 632 </varlistentry> 633 634 <varlistentry id="opt.verbose" xreflabel="--verbose"> 635 <term><option>-v</option>, <option>--verbose</option></term> 636 <listitem> 637 <para>Be more verbose. Gives extra information on various aspects 638 of your program, such as: the shared objects loaded, the 639 suppressions used, the progress of the instrumentation and 640 execution engines, and warnings about unusual behaviour. Repeating 641 the option increases the verbosity level.</para> 642 </listitem> 643 </varlistentry> 644 645 <varlistentry id="opt.trace-children" xreflabel="--trace-children"> 646 <term> 647 <option><![CDATA[--trace-children=<yes|no> [default: no] ]]></option> 648 </term> 649 <listitem> 650 <para>When enabled, Valgrind will trace into sub-processes 651 initiated via the <varname>exec</varname> system call. This is 652 necessary for multi-process programs. 653 </para> 654 <para>Note that Valgrind does trace into the child of a 655 <varname>fork</varname> (it would be difficult not to, since 656 <varname>fork</varname> makes an identical copy of a process), so this 657 option is arguably badly named. However, most children of 658 <varname>fork</varname> calls immediately call <varname>exec</varname> 659 anyway. 660 </para> 661 </listitem> 662 </varlistentry> 663 664 <varlistentry id="opt.trace-children-skip" xreflabel="--trace-children-skip"> 665 <term> 666 <option><![CDATA[--trace-children-skip=patt1,patt2 ]]></option> 667 </term> 668 <listitem> 669 <para>This option only has an effect when 670 <option>--trace-children=yes</option> is specified. It allows 671 for some children to be skipped. The option takes a comma 672 separated list of patterns for the names of child executables 673 that Valgrind should not trace into. Patterns may include the 674 metacharacters <computeroutput>?</computeroutput> 675 and <computeroutput>*</computeroutput>, which have the usual 676 meaning.</para> 677 <para> 678 This can be useful for pruning uninteresting branches from a 679 tree of processes being run on Valgrind. But you should be 680 careful when using it. When Valgrind skips tracing into an 681 executable, it doesn't just skip tracing that executable, it 682 also skips tracing any of that executable's child processes. 683 In other words, the flag doesn't merely cause tracing to stop 684 at the specified executables -- it skips tracing of entire 685 process subtrees rooted at any of the specified 686 executables.</para> 687 </listitem> 688 </varlistentry> 689 690 <varlistentry id="opt.child-silent-after-fork" 691 xreflabel="--child-silent-after-fork"> 692 <term> 693 <option><![CDATA[--child-silent-after-fork=<yes|no> [default: no] ]]></option> 694 </term> 695 <listitem> 696 <para>When enabled, Valgrind will not show any debugging or 697 logging output for the child process resulting from 698 a <varname>fork</varname> call. This can make the output less 699 confusing (although more misleading) when dealing with processes 700 that create children. It is particularly useful in conjunction 701 with <varname>--trace-children=</varname>. Use of this option is also 702 strongly recommended if you are requesting XML output 703 (<varname>--xml=yes</varname>), since otherwise the XML from child and 704 parent may become mixed up, which usually makes it useless. 705 </para> 706 </listitem> 707 </varlistentry> 708 709 <varlistentry id="opt.track-fds" xreflabel="--track-fds"> 710 <term> 711 <option><![CDATA[--track-fds=<yes|no> [default: no] ]]></option> 712 </term> 713 <listitem> 714 <para>When enabled, Valgrind will print out a list of open file 715 descriptors on exit. Along with each file descriptor is printed a 716 stack backtrace of where the file was opened and any details 717 relating to the file descriptor such as the file name or socket 718 details.</para> 719 </listitem> 720 </varlistentry> 721 722 <varlistentry id="opt.time-stamp" xreflabel="--time-stamp"> 723 <term> 724 <option><![CDATA[--time-stamp=<yes|no> [default: no] ]]></option> 725 </term> 726 <listitem> 727 <para>When enabled, each message is preceded with an indication of 728 the elapsed wallclock time since startup, expressed as days, 729 hours, minutes, seconds and milliseconds.</para> 730 </listitem> 731 </varlistentry> 732 733 <varlistentry id="opt.log-fd" xreflabel="--log-fd"> 734 <term> 735 <option><![CDATA[--log-fd=<number> [default: 2, stderr] ]]></option> 736 </term> 737 <listitem> 738 <para>Specifies that Valgrind should send all of its messages to 739 the specified file descriptor. The default, 2, is the standard 740 error channel (stderr). Note that this may interfere with the 741 client's own use of stderr, as Valgrind's output will be 742 interleaved with any output that the client sends to 743 stderr.</para> 744 </listitem> 745 </varlistentry> 746 747 <varlistentry id="opt.log-file" xreflabel="--log-file"> 748 <term> 749 <option><![CDATA[--log-file=<filename> ]]></option> 750 </term> 751 <listitem> 752 <para>Specifies that Valgrind should send all of its messages to 753 the specified file. If the file name is empty, it causes an abort. 754 There are three special format specifiers that can be used in the file 755 name.</para> 756 757 <para><option>%p</option> is replaced with the current process ID. 758 This is very useful for program that invoke multiple processes. 759 WARNING: If you use <option>--trace-children=yes</option> and your 760 program invokes multiple processes OR your program forks without 761 calling exec afterwards, and you don't use this specifier 762 (or the <option>%q</option> specifier below), the Valgrind output from 763 all those processes will go into one file, possibly jumbled up, and 764 possibly incomplete.</para> 765 766 <para><option>%q{FOO}</option> is replaced with the contents of the 767 environment variable <varname>FOO</varname>. If the 768 <option>{FOO}</option> part is malformed, it causes an abort. This 769 specifier is rarely needed, but very useful in certain circumstances 770 (eg. when running MPI programs). The idea is that you specify a 771 variable which will be set differently for each process in the job, 772 for example <computeroutput>BPROC_RANK</computeroutput> or whatever is 773 applicable in your MPI setup. If the named environment variable is not 774 set, it causes an abort. Note that in some shells, the 775 <option>{</option> and <option>}</option> characters may need to be 776 escaped with a backslash.</para> 777 778 <para><option>%%</option> is replaced with <option>%</option>.</para> 779 780 <para>If an <option>%</option> is followed by any other character, it 781 causes an abort.</para> 782 </listitem> 783 </varlistentry> 784 785 <varlistentry id="opt.log-socket" xreflabel="--log-socket"> 786 <term> 787 <option><![CDATA[--log-socket=<ip-address:port-number> ]]></option> 788 </term> 789 <listitem> 790 <para>Specifies that Valgrind should send all of its messages to 791 the specified port at the specified IP address. The port may be 792 omitted, in which case port 1500 is used. If a connection cannot 793 be made to the specified socket, Valgrind falls back to writing 794 output to the standard error (stderr). This option is intended to 795 be used in conjunction with the 796 <computeroutput>valgrind-listener</computeroutput> program. For 797 further details, see 798 <link linkend="manual-core.comment">the commentary</link> 799 in the manual.</para> 800 </listitem> 801 </varlistentry> 802 803 </variablelist> 804 <!-- end of xi:include in the manpage --> 805 806 </sect2> 807 808 809 <sect2 id="manual-core.erropts" xreflabel="Error-related Options"> 810 <title>Error-related Options</title> 811 812 <!-- start of xi:include in the manpage --> 813 <para id="error-related.opts.para">These options are used by all tools 814 that can report errors, e.g. Memcheck, but not Cachegrind.</para> 815 816 <variablelist id="error-related.opts.list"> 817 818 <varlistentry id="opt.xml" xreflabel="--xml"> 819 <term> 820 <option><![CDATA[--xml=<yes|no> [default: no] ]]></option> 821 </term> 822 <listitem> 823 <para>When enabled, the important parts of the output (e.g. tool error 824 messages) will be in XML format rather than plain text. Furthermore, 825 the XML output will be sent to a different output channel than the 826 plain text output. Therefore, you also must use one of 827 <option>--xml-fd</option>, <option>--xml-file</option> or 828 <option>--xml-socket</option> to specify where the XML is to be sent. 829 </para> 830 831 <para>Less important messages will still be printed in plain text, but 832 because the XML output and plain text output are sent to different 833 output channels (the destination of the plain text output is still 834 controlled by <option>--log-fd</option>, <option>--log-file</option> 835 and <option>--log-socket</option>) this should not cause problems. 836 </para> 837 838 <para>This option is aimed at making life easier for tools that consume 839 Valgrind's output as input, such as GUI front ends. Currently this 840 option works with Memcheck, Helgrind and Ptrcheck. The output format 841 is specified in the file 842 <computeroutput>docs/internals/xml-output-protocol4.txt</computeroutput> 843 in the source tree for Valgrind 3.5.0 or later.</para> 844 845 <para>The recommended options for a GUI to pass, when requesting 846 XML output, are: <option>--xml=yes</option> to enable XML output, 847 <option>--xml-file</option> to send the XML output to a (presumably 848 GUI-selected) file, <option>--log-file</option> to send the plain 849 text output to a second GUI-selected file, 850 <option>--child-silent-after-fork=yes</option>, and 851 <option>-q</option> to restrict the plain text output to critical 852 error messages created by Valgrind itself. For example, failure to 853 read a specified suppressions file counts as a critical error message. 854 In this way, for a successful run the text output file will be empty. 855 But if it isn't empty, then it will contain important information 856 which the GUI user should be made aware 857 of.</para> 858 </listitem> 859 </varlistentry> 860 861 <varlistentry id="opt.xml-fd" xreflabel="--xml-fd"> 862 <term> 863 <option><![CDATA[--xml-fd=<number> [default: -1, disabled] ]]></option> 864 </term> 865 <listitem> 866 <para>Specifies that Valgrind should send its XML output to the 867 specified file descriptor. It must be used in conjunction with 868 <option>--xml=yes</option>.</para> 869 </listitem> 870 </varlistentry> 871 872 <varlistentry id="opt.xml-file" xreflabel="--xml-file"> 873 <term> 874 <option><![CDATA[--xml-file=<filename> ]]></option> 875 </term> 876 <listitem> 877 <para>Specifies that Valgrind should send its XML output 878 to the specified file. It must be used in conjunction with 879 <option>--xml=yes</option>. Any <option>%p</option> or 880 <option>%q</option> sequences appearing in the filename are expanded 881 in exactly the same way as they are for <option>--log-file</option>. 882 See the description of <option>--log-file</option> for details. 883 </para> 884 </listitem> 885 </varlistentry> 886 887 <varlistentry id="opt.xml-socket" xreflabel="--xml-socket"> 888 <term> 889 <option><![CDATA[--xml-socket=<ip-address:port-number> ]]></option> 890 </term> 891 <listitem> 892 <para>Specifies that Valgrind should send its XML output the 893 specified port at the specified IP address. It must be used in 894 conjunction with <option>--xml=yes</option>. The form of the argument 895 is the same as that used by <option>--log-socket</option>. 896 See the description of <option>--log-socket</option> 897 for further details.</para> 898 </listitem> 899 </varlistentry> 900 901 <varlistentry id="opt.xml-user-comment" xreflabel="--xml-user-comment"> 902 <term> 903 <option><![CDATA[--xml-user-comment=<string> ]]></option> 904 </term> 905 <listitem> 906 <para>Embeds an extra user comment string at the start of the XML 907 output. Only works when <option>--xml=yes</option> is specified; 908 ignored otherwise.</para> 909 </listitem> 910 </varlistentry> 911 912 <varlistentry id="opt.demangle" xreflabel="--demangle"> 913 <term> 914 <option><![CDATA[--demangle=<yes|no> [default: yes] ]]></option> 915 </term> 916 <listitem> 917 <para>Enable/disable automatic demangling (decoding) of C++ names. 918 Enabled by default. When enabled, Valgrind will attempt to 919 translate encoded C++ names back to something approaching the 920 original. The demangler handles symbols mangled by g++ versions 921 2.X, 3.X and 4.X.</para> 922 923 <para>An important fact about demangling is that function names 924 mentioned in suppressions files should be in their mangled form. 925 Valgrind does not demangle function names when searching for 926 applicable suppressions, because to do otherwise would make 927 suppression file contents dependent on the state of Valgrind's 928 demangling machinery, and also slow down suppression matching.</para> 929 </listitem> 930 </varlistentry> 931 932 <varlistentry id="opt.num-callers" xreflabel="--num-callers"> 933 <term> 934 <option><![CDATA[--num-callers=<number> [default: 12] ]]></option> 935 </term> 936 <listitem> 937 <para>Specifies the maximum number of entries shown in stack traces 938 that identify program locations. Note that errors are commoned up 939 using only the top four function locations (the place in the current 940 function, and that of its three immediate callers). So this doesn't 941 affect the total number of errors reported.</para> 942 943 <para>The maximum value for this is 50. Note that higher settings 944 will make Valgrind run a bit more slowly and take a bit more 945 memory, but can be useful when working with programs with 946 deeply-nested call chains.</para> 947 </listitem> 948 </varlistentry> 949 950 <varlistentry id="opt.error-limit" xreflabel="--error-limit"> 951 <term> 952 <option><![CDATA[--error-limit=<yes|no> [default: yes] ]]></option> 953 </term> 954 <listitem> 955 <para>When enabled, Valgrind stops reporting errors after 10,000,000 956 in total, or 1,000 different ones, have been seen. This is to 957 stop the error tracking machinery from becoming a huge performance 958 overhead in programs with many errors.</para> 959 </listitem> 960 </varlistentry> 961 962 <varlistentry id="opt.error-exitcode" xreflabel="--error-exitcode"> 963 <term> 964 <option><![CDATA[--error-exitcode=<number> [default: 0] ]]></option> 965 </term> 966 <listitem> 967 <para>Specifies an alternative exit code to return if Valgrind 968 reported any errors in the run. When set to the default value 969 (zero), the return value from Valgrind will always be the return 970 value of the process being simulated. When set to a nonzero value, 971 that value is returned instead, if Valgrind detects any errors. 972 This is useful for using Valgrind as part of an automated test 973 suite, since it makes it easy to detect test cases for which 974 Valgrind has reported errors, just by inspecting return codes.</para> 975 </listitem> 976 </varlistentry> 977 978 <varlistentry id="opt.stack-traces" xreflabel="--show-below-main"> 979 <term> 980 <option><![CDATA[--show-below-main=<yes|no> [default: no] ]]></option> 981 </term> 982 <listitem> 983 <para>By default, stack traces for errors do not show any 984 functions that appear beneath <function>main</function> because 985 most of the time it's uninteresting C library stuff and/or 986 gobbledygook. Alternatively, if <function>main</function> is not 987 present in the stack trace, stack traces will not show any functions 988 below <function>main</function>-like functions such as glibc's 989 <function>__libc_start_main</function>. Furthermore, if 990 <function>main</function>-like functions are present in the trace, 991 they are normalised as <function>(below main)</function>, in order to 992 make the output more deterministic.</para> 993 994 <para>If this option is enabled, all stack trace entries will be 995 shown and <function>main</function>-like functions will not be 996 normalised.</para> 997 </listitem> 998 </varlistentry> 999 1000 <varlistentry id="opt.fullpath-after" xreflabel="--fullpath-after"> 1001 <term> 1002 <option><![CDATA[--fullpath-after=<string> 1003 [default: don't show source paths] ]]></option> 1004 </term> 1005 <listitem> 1006 <para>By default Valgrind only shows the filenames in stack 1007 traces, but not full paths to source files. When using Valgrind 1008 in large projects where the sources reside in multiple different 1009 directories, this can be inconvenient. 1010 <option>--fullpath-after</option> provides a flexible solution 1011 to this problem. When this option is present, the path to each 1012 source file is shown, with the following all-important caveat: 1013 if <option>string</option> is found in the path, then the path 1014 up to and including <option>string</option> is omitted, else the 1015 path is shown unmodified. Note that <option>string</option> is 1016 not required to be a prefix of the path.</para> 1017 1018 <para>For example, consider a file named 1019 <computeroutput>/home/janedoe/blah/src/foo/bar/xyzzy.c</computeroutput>. 1020 Specifying <option>--fullpath-after=/home/janedoe/blah/src/</option> 1021 will cause Valgrind to show the name 1022 as <computeroutput>foo/bar/xyzzy.c</computeroutput>.</para> 1023 1024 <para>Because the string is not required to be a prefix, 1025 <option>--fullpath-after=src/</option> will produce the same 1026 output. This is useful when the path contains arbitrary 1027 machine-generated characters. For example, the 1028 path 1029 <computeroutput>/my/build/dir/C32A1B47/blah/src/foo/xyzzy</computeroutput> 1030 can be pruned to <computeroutput>foo/xyzzy</computeroutput> 1031 using 1032 <option>--fullpath-after=/blah/src/</option>.</para> 1033 1034 <para>If you simply want to see the full path, just specify an 1035 empty string: <option>--fullpath-after=</option>. This isn't a 1036 special case, merely a logical consequence of the above rules.</para> 1037 1038 <para>Finally, you can use <option>--fullpath-after</option> 1039 multiple times. Any appearance of it causes Valgrind to switch 1040 to producing full paths and applying the above filtering rule. 1041 Each produced path is compared against all 1042 the <option>--fullpath-after</option>-specified strings, in the 1043 order specified. The first string to match causes the path to 1044 be truncated as described above. If none match, the full path 1045 is shown. This facilitates chopping off prefixes when the 1046 sources are drawn from a number of unrelated directories. 1047 </para> 1048 </listitem> 1049 </varlistentry> 1050 1051 <varlistentry id="opt.suppressions" xreflabel="--suppressions"> 1052 <term> 1053 <option><![CDATA[--suppressions=<filename> [default: $PREFIX/lib/valgrind/default.supp] ]]></option> 1054 </term> 1055 <listitem> 1056 <para>Specifies an extra file from which to read descriptions of 1057 errors to suppress. You may use up to 100 extra suppression 1058 files.</para> 1059 </listitem> 1060 </varlistentry> 1061 1062 <varlistentry id="opt.gen-suppressions" xreflabel="--gen-suppressions"> 1063 <term> 1064 <option><![CDATA[--gen-suppressions=<yes|no|all> [default: no] ]]></option> 1065 </term> 1066 <listitem> 1067 <para>When set to <varname>yes</varname>, Valgrind will pause 1068 after every error shown and print the line: 1069 <literallayout><computeroutput> ---- Print suppression ? --- [Return/N/n/Y/y/C/c] ----</computeroutput></literallayout> 1070 1071 The prompt's behaviour is the same as for the 1072 <option>--db-attach</option> option (see below).</para> 1073 1074 <para>If you choose to, Valgrind will print out a suppression for 1075 this error. You can then cut and paste it into a suppression file 1076 if you don't want to hear about the error in the future.</para> 1077 1078 <para>When set to <varname>all</varname>, Valgrind will print a 1079 suppression for every reported error, without querying the 1080 user.</para> 1081 1082 <para>This option is particularly useful with C++ programs, as it 1083 prints out the suppressions with mangled names, as 1084 required.</para> 1085 1086 <para>Note that the suppressions printed are as specific as 1087 possible. You may want to common up similar ones, by adding 1088 wildcards to function names, and by using frame-level wildcards. 1089 The wildcarding facilities are powerful yet flexible, and with a 1090 bit of careful editing, you may be able to suppress a whole 1091 family of related errors with only a few suppressions. 1092 <!-- commented out because it causes broken links in the man page 1093 For details on how to do this, see 1094 <xref linkend="manual-core.suppress"/>. 1095 --> 1096 </para> 1097 1098 <para>Sometimes two different errors 1099 are suppressed by the same suppression, in which case Valgrind 1100 will output the suppression more than once, but you only need to 1101 have one copy in your suppression file (but having more than one 1102 won't cause problems). Also, the suppression name is given as 1103 <computeroutput><insert a suppression name 1104 here></computeroutput>; the name doesn't really matter, it's 1105 only used with the <option>-v</option> option which prints out all 1106 used suppression records.</para> 1107 </listitem> 1108 </varlistentry> 1109 1110 <varlistentry id="opt.db-attach" xreflabel="--db-attach"> 1111 <term> 1112 <option><![CDATA[--db-attach=<yes|no> [default: no] ]]></option> 1113 </term> 1114 <listitem> 1115 <para>When enabled, Valgrind will pause after every error shown 1116 and print the line: 1117 <literallayout><computeroutput> ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ----</computeroutput></literallayout> 1118 1119 Pressing <varname>Ret</varname>, or <varname>N Ret</varname> or 1120 <varname>n Ret</varname>, causes Valgrind not to start a debugger 1121 for this error.</para> 1122 1123 <para>Pressing <varname>Y Ret</varname> or 1124 <varname>y Ret</varname> causes Valgrind to start a debugger for 1125 the program at this point. When you have finished with the 1126 debugger, quit from it, and the program will continue. Trying to 1127 continue from inside the debugger doesn't work.</para> 1128 1129 <para><varname>C Ret</varname> or <varname>c Ret</varname> causes 1130 Valgrind not to start a debugger, and not to ask again.</para> 1131 </listitem> 1132 </varlistentry> 1133 1134 <varlistentry id="opt.db-command" xreflabel="--db-command"> 1135 <term> 1136 <option><![CDATA[--db-command=<command> [default: gdb -nw %f %p] ]]></option> 1137 </term> 1138 <listitem> 1139 <para>Specify the debugger to use with the 1140 <option>--db-attach</option> command. The default debugger is 1141 GDB. This option is a template that is expanded by Valgrind at 1142 runtime. <literal>%f</literal> is replaced with the executable's 1143 file name and <literal>%p</literal> is replaced by the process ID 1144 of the executable.</para> 1145 1146 <para>This specifies how Valgrind will invoke the debugger. By 1147 default it will use whatever GDB is detected at build time, which 1148 is usually <computeroutput>/usr/bin/gdb</computeroutput>. Using 1149 this command, you can specify some alternative command to invoke 1150 the debugger you want to use.</para> 1151 1152 <para>The command string given can include one or instances of the 1153 <literal>%p</literal> and <literal>%f</literal> expansions. Each 1154 instance of <literal>%p</literal> expands to the PID of the 1155 process to be debugged and each instance of <literal>%f</literal> 1156 expands to the path to the executable for the process to be 1157 debugged.</para> 1158 1159 <para>Since <computeroutput><command></computeroutput> is likely 1160 to contain spaces, you will need to put this entire option in 1161 quotes to ensure it is correctly handled by the shell.</para> 1162 </listitem> 1163 </varlistentry> 1164 1165 <varlistentry id="opt.input-fd" xreflabel="--input-fd"> 1166 <term> 1167 <option><![CDATA[--input-fd=<number> [default: 0, stdin] ]]></option> 1168 </term> 1169 <listitem> 1170 <para>When using <option>--db-attach=yes</option> or 1171 <option>--gen-suppressions=yes</option>, Valgrind will stop so as 1172 to read keyboard input from you when each error occurs. By 1173 default it reads from the standard input (stdin), which is 1174 problematic for programs which close stdin. This option allows 1175 you to specify an alternative file descriptor from which to read 1176 input.</para> 1177 </listitem> 1178 </varlistentry> 1179 1180 <varlistentry id="opt.dsymutil" xreflabel="--dsymutil"> 1181 <term> 1182 <option><![CDATA[--dsymutil=no|yes [no] ]]></option> 1183 </term> 1184 <listitem> 1185 <para>This option is only relevant when running Valgrind on 1186 Mac OS X.</para> 1187 1188 <para>Mac OS X uses a deferred debug information (debuginfo) 1189 linking scheme. When object files containing debuginfo are 1190 linked into a <computeroutput>.dylib</computeroutput> or an 1191 executable, the debuginfo is not copied into the final file. 1192 Instead, the debuginfo must be linked manually by 1193 running <computeroutput>dsymutil</computeroutput>, a 1194 system-provided utility, on the executable 1195 or <computeroutput>.dylib</computeroutput>. The resulting 1196 combined debuginfo is placed in a directory alongside the 1197 executable or <computeroutput>.dylib</computeroutput>, but with 1198 the extension <computeroutput>.dSYM</computeroutput>.</para> 1199 1200 <para>With <option>--dsymutil=no</option>, Valgrind 1201 will detect cases where the 1202 <computeroutput>.dSYM</computeroutput> directory is either 1203 missing, or is present but does not appear to match the 1204 associated executable or <computeroutput>.dylib</computeroutput>, 1205 most likely because it is out of date. In these cases, Valgrind 1206 will print a warning message but take no further action.</para> 1207 1208 <para>With <option>--dsymutil=yes</option>, Valgrind 1209 will, in such cases, automatically 1210 run <computeroutput>dsymutil</computeroutput> as necessary to 1211 bring the debuginfo up to date. For all practical purposes, if 1212 you always use <option>--dsymutil=yes</option>, then 1213 there is never any need to 1214 run <computeroutput>dsymutil</computeroutput> manually or as part 1215 of your applications's build system, since Valgrind will run it 1216 as necessary.</para> 1217 1218 <para>Valgrind will not attempt to 1219 run <computeroutput>dsymutil</computeroutput> on any 1220 executable or library in 1221 <computeroutput>/usr/</computeroutput>, 1222 <computeroutput>/bin/</computeroutput>, 1223 <computeroutput>/sbin/</computeroutput>, 1224 <computeroutput>/opt/</computeroutput>, 1225 <computeroutput>/sw/</computeroutput>, 1226 <computeroutput>/System/</computeroutput>, 1227 <computeroutput>/Library/</computeroutput> or 1228 <computeroutput>/Applications/</computeroutput> 1229 since <computeroutput>dsymutil</computeroutput> will always fail 1230 in such situations. It fails both because the debuginfo for 1231 such pre-installed system components is not available anywhere, 1232 and also because it would require write privileges in those 1233 directories.</para> 1234 1235 <para>Be careful when 1236 using <option>--dsymutil=yes</option>, since it will 1237 cause pre-existing <computeroutput>.dSYM</computeroutput> 1238 directories to be silently deleted and re-created. Also note that 1239 <computeroutput>dsymutil</computeroutput> is quite slow, sometimes 1240 excessively so.</para> 1241 </listitem> 1242 </varlistentry> 1243 1244 <varlistentry id="opt.max-stackframe" xreflabel="--max-stackframe"> 1245 <term> 1246 <option><![CDATA[--max-stackframe=<number> [default: 2000000] ]]></option> 1247 </term> 1248 <listitem> 1249 <para>The maximum size of a stack frame. If the stack pointer moves by 1250 more than this amount then Valgrind will assume that 1251 the program is switching to a different stack.</para> 1252 1253 <para>You may need to use this option if your program has large 1254 stack-allocated arrays. Valgrind keeps track of your program's 1255 stack pointer. If it changes by more than the threshold amount, 1256 Valgrind assumes your program is switching to a different stack, 1257 and Memcheck behaves differently than it would for a stack pointer 1258 change smaller than the threshold. Usually this heuristic works 1259 well. However, if your program allocates large structures on the 1260 stack, this heuristic will be fooled, and Memcheck will 1261 subsequently report large numbers of invalid stack accesses. This 1262 option allows you to change the threshold to a different 1263 value.</para> 1264 1265 <para>You should only consider use of this option if Valgrind's 1266 debug output directs you to do so. In that case it will tell you 1267 the new threshold you should specify.</para> 1268 1269 <para>In general, allocating large structures on the stack is a 1270 bad idea, because you can easily run out of stack space, 1271 especially on systems with limited memory or which expect to 1272 support large numbers of threads each with a small stack, and also 1273 because the error checking performed by Memcheck is more effective 1274 for heap-allocated data than for stack-allocated data. If you 1275 have to use this option, you may wish to consider rewriting your 1276 code to allocate on the heap rather than on the stack.</para> 1277 </listitem> 1278 </varlistentry> 1279 1280 <varlistentry id="opt.main-stacksize" xreflabel="--main-stacksize"> 1281 <term> 1282 <option><![CDATA[--main-stacksize=<number> 1283 [default: use current 'ulimit' value] ]]></option> 1284 </term> 1285 <listitem> 1286 <para>Specifies the size of the main thread's stack.</para> 1287 1288 <para>To simplify its memory management, Valgrind reserves all 1289 required space for the main thread's stack at startup. That 1290 means it needs to know the required stack size at 1291 startup.</para> 1292 1293 <para>By default, Valgrind uses the current "ulimit" value for 1294 the stack size, or 16 MB, whichever is lower. In many cases 1295 this gives a stack size in the range 8 to 16 MB, which almost 1296 never overflows for most applications.</para> 1297 1298 <para>If you need a larger total stack size, 1299 use <option>--main-stacksize</option> to specify it. Only set 1300 it as high as you need, since reserving far more space than you 1301 need (that is, hundreds of megabytes more than you need) 1302 constrains Valgrind's memory allocators and may reduce the total 1303 amount of memory that Valgrind can use. This is only really of 1304 significance on 32-bit machines.</para> 1305 1306 <para>On Linux, you may request a stack of size up to 2GB. 1307 Valgrind will stop with a diagnostic message if the stack cannot 1308 be allocated. On AIX5 the allowed stack size is restricted to 1309 128MB.</para> 1310 1311 <para><option>--main-stacksize</option> only affects the stack 1312 size for the program's initial thread. It has no bearing on the 1313 size of thread stacks, as Valgrind does not allocate 1314 those.</para> 1315 1316 <para>You may need to use both <option>--main-stacksize</option> 1317 and <option>--max-stackframe</option> together. It is important 1318 to understand that <option>--main-stacksize</option> sets the 1319 maximum total stack size, 1320 whilst <option>--max-stackframe</option> specifies the largest 1321 size of any one stack frame. You will have to work out 1322 the <option>--main-stacksize</option> value for yourself 1323 (usually, if your applications segfaults). But Valgrind will 1324 tell you the needed <option>--max-stackframe</option> size, if 1325 necessary.</para> 1326 1327 <para>As discussed further in the description 1328 of <option>--max-stackframe</option>, a requirement for a large 1329 stack is a sign of potential portability problems. You are best 1330 advised to place all large data in heap-allocated memory.</para> 1331 </listitem> 1332 </varlistentry> 1333 1334 </variablelist> 1335 <!-- end of xi:include in the manpage --> 1336 1337 </sect2> 1338 1339 1340 <sect2 id="manual-core.mallocopts" xreflabel="malloc-related Options"> 1341 <title>malloc-related Options</title> 1342 1343 <!-- start of xi:include in the manpage --> 1344 <para id="malloc-related.opts.para">For tools that use their own version of 1345 <computeroutput>malloc</computeroutput> (e.g. Memcheck and 1346 Massif), the following options apply.</para> 1347 1348 <variablelist id="malloc-related.opts.list"> 1349 1350 <varlistentry id="opt.alignment" xreflabel="--alignment"> 1351 <term> 1352 <option><![CDATA[--alignment=<number> [default: 8 or 16, depending on the platform] ]]></option> 1353 </term> 1354 <listitem> 1355 <para>By default Valgrind's <function>malloc</function>, 1356 <function>realloc</function>, etc, return a block whose starting 1357 address is 8-byte aligned or 16-byte aligned (the value depends on the 1358 platform and matches the platform default). This option allows you to 1359 specify a different alignment. The supplied value must be greater 1360 than or equal to the default, less than or equal to 4096, and must be 1361 a power of two.</para> 1362 </listitem> 1363 </varlistentry> 1364 1365 </variablelist> 1366 <!-- end of xi:include in the manpage --> 1367 1368 </sect2> 1369 1370 1371 <sect2 id="manual-core.rareopts" xreflabel="Uncommon Options"> 1372 <title>Uncommon Options</title> 1373 1374 <!-- start of xi:include in the manpage --> 1375 <para id="uncommon.opts.para">These options apply to all tools, as they 1376 affect certain obscure workings of the Valgrind core. Most people won't 1377 need to use these.</para> 1378 1379 <variablelist id="uncommon.opts.list"> 1380 1381 <varlistentry id="opt.smc-check" xreflabel="--smc-check"> 1382 <term> 1383 <option><![CDATA[--smc-check=<none|stack|all> [default: stack] ]]></option> 1384 </term> 1385 <listitem> 1386 <para>This option controls Valgrind's detection of self-modifying 1387 code. If no checking is done, if a program executes some code, then 1388 overwrites it with new code, and executes the new code, Valgrind will 1389 continue to execute the translations it made for the old code. This 1390 will likely lead to incorrect behaviour and/or crashes.</para> 1391 1392 <para>Valgrind has three levels of self-modifying code detection: 1393 no detection, detect self-modifying code on the stack (which is used by 1394 GCC to implement nested functions), or detect self-modifying code 1395 everywhere. Note that the default option will catch the vast majority 1396 of cases. The main case it will not catch is programs such as JIT 1397 compilers that dynamically generate code <emphasis>and</emphasis> 1398 subsequently overwrite part or all of it. Running with 1399 <varname>all</varname> will slow Valgrind down noticeably. Running with 1400 <varname>none</varname> will rarely speed things up, since very little 1401 code gets put on the stack for most programs. The 1402 <function>VALGRIND_DISCARD_TRANSLATIONS</function> client request is 1403 an alternative to <option>--smc-check=all</option> that requires more 1404 effort but is much faster. 1405 <!-- commented out because it causes broken links in the man page 1406 ; see <xref 1407 linkend="manual-core-adv.clientreq"/> for more details. 1408 --> 1409 </para> 1410 1411 <para>Some architectures (including ppc32, ppc64 and ARM) require 1412 programs which create code at runtime to flush the instruction 1413 cache in between code generation and first use. Valgrind 1414 observes and honours such instructions. Hence, on ppc32/Linux, 1415 ppc64/Linux and ARM/Linux, Valgrind always provides complete, transparent 1416 support for self-modifying code. It is only on platforms such as 1417 x86/Linux, AMD64/Linux and x86/Darwin that you need to use this 1418 option.</para> 1419 </listitem> 1420 </varlistentry> 1421 1422 <varlistentry id="opt.read-var-info" xreflabel="--read-var-info"> 1423 <term> 1424 <option><![CDATA[--read-var-info=<yes|no> [default: no] ]]></option> 1425 </term> 1426 <listitem> 1427 <para>When enabled, Valgrind will read information about 1428 variable types and locations from DWARF3 debug info. 1429 This slows Valgrind down and makes it use more memory, but for 1430 the tools that can take advantage of it (Memcheck, Helgrind, 1431 DRD) it can result in more precise error messages. For example, 1432 here are some standard errors issued by Memcheck:</para> 1433 <programlisting><![CDATA[ 1434 ==15516== Uninitialised byte(s) found during client check request 1435 ==15516== at 0x400633: croak (varinfo1.c:28) 1436 ==15516== by 0x4006B2: main (varinfo1.c:55) 1437 ==15516== Address 0x60103b is 7 bytes inside data symbol "global_i2" 1438 ==15516== 1439 ==15516== Uninitialised byte(s) found during client check request 1440 ==15516== at 0x400633: croak (varinfo1.c:28) 1441 ==15516== by 0x4006BC: main (varinfo1.c:56) 1442 ==15516== Address 0x7fefffefc is on thread 1's stack]]></programlisting> 1443 1444 <para>And here are the same errors with 1445 <option>--read-var-info=yes</option>:</para> 1446 1447 <programlisting><![CDATA[ 1448 ==15522== Uninitialised byte(s) found during client check request 1449 ==15522== at 0x400633: croak (varinfo1.c:28) 1450 ==15522== by 0x4006B2: main (varinfo1.c:55) 1451 ==15522== Location 0x60103b is 0 bytes inside global_i2[7], 1452 ==15522== a global variable declared at varinfo1.c:41 1453 ==15522== 1454 ==15522== Uninitialised byte(s) found during client check request 1455 ==15522== at 0x400633: croak (varinfo1.c:28) 1456 ==15522== by 0x4006BC: main (varinfo1.c:56) 1457 ==15522== Location 0x7fefffefc is 0 bytes inside local var "local" 1458 ==15522== declared at varinfo1.c:46, in frame #1 of thread 1]]></programlisting> 1459 </listitem> 1460 </varlistentry> 1461 1462 <varlistentry id="opt.run-libc-freeres" xreflabel="--run-libc-freeres"> 1463 <term> 1464 <option><![CDATA[--run-libc-freeres=<yes|no> [default: yes] ]]></option> 1465 </term> 1466 <listitem> 1467 <para>This option is only relevant when running Valgrind on Linux.</para> 1468 1469 <para>The GNU C library (<function>libc.so</function>), which is 1470 used by all programs, may allocate memory for its own uses. 1471 Usually it doesn't bother to free that memory when the program 1472 ends—there would be no point, since the Linux kernel reclaims 1473 all process resources when a process exits anyway, so it would 1474 just slow things down.</para> 1475 1476 <para>The glibc authors realised that this behaviour causes leak 1477 checkers, such as Valgrind, to falsely report leaks in glibc, when 1478 a leak check is done at exit. In order to avoid this, they 1479 provided a routine called <function>__libc_freeres</function> 1480 specifically to make glibc release all memory it has allocated. 1481 Memcheck therefore tries to run 1482 <function>__libc_freeres</function> at exit.</para> 1483 1484 <para>Unfortunately, in some very old versions of glibc, 1485 <function>__libc_freeres</function> is sufficiently buggy to cause 1486 segmentation faults. This was particularly noticeable on Red Hat 1487 7.1. So this option is provided in order to inhibit the run of 1488 <function>__libc_freeres</function>. If your program seems to run 1489 fine on Valgrind, but segfaults at exit, you may find that 1490 <option>--run-libc-freeres=no</option> fixes that, although at the 1491 cost of possibly falsely reporting space leaks in 1492 <filename>libc.so</filename>.</para> 1493 </listitem> 1494 </varlistentry> 1495 1496 <varlistentry id="opt.sim-hints" xreflabel="--sim-hints"> 1497 <term> 1498 <option><![CDATA[--sim-hints=hint1,hint2,... ]]></option> 1499 </term> 1500 <listitem> 1501 <para>Pass miscellaneous hints to Valgrind which slightly modify 1502 the simulated behaviour in nonstandard or dangerous ways, possibly 1503 to help the simulation of strange features. By default no hints 1504 are enabled. Use with caution! Currently known hints are:</para> 1505 <itemizedlist> 1506 <listitem> 1507 <para><option>lax-ioctls: </option> Be very lax about ioctl 1508 handling; the only assumption is that the size is 1509 correct. Doesn't require the full buffer to be initialized 1510 when writing. Without this, using some device drivers with a 1511 large number of strange ioctl commands becomes very 1512 tiresome.</para> 1513 </listitem> 1514 <listitem> 1515 <para><option>enable-inner: </option> Enable some special 1516 magic needed when the program being run is itself 1517 Valgrind.</para> 1518 </listitem> 1519 </itemizedlist> 1520 </listitem> 1521 </varlistentry> 1522 1523 <varlistentry id="opt.kernel-variant" xreflabel="--kernel-variant"> 1524 <term> 1525 <option>--kernel-variant=variant1,variant2,...</option> 1526 </term> 1527 <listitem> 1528 <para>Handle system calls and ioctls arising from minor variants 1529 of the default kernel for this platform. This is useful for 1530 running on hacked kernels or with kernel modules which support 1531 nonstandard ioctls, for example. Use with caution. If you don't 1532 understand what this option does then you almost certainly don't 1533 need it. Currently known variants are:</para> 1534 <itemizedlist> 1535 <listitem> 1536 <para><option>bproc: </option> Support the 1537 <function>sys_broc</function> system call on x86. This is for 1538 running on BProc, which is a minor variant of standard Linux which 1539 is sometimes used for building clusters.</para> 1540 </listitem> 1541 </itemizedlist> 1542 </listitem> 1543 </varlistentry> 1544 1545 <varlistentry id="opt.show-emwarns" xreflabel="--show-emwarns"> 1546 <term> 1547 <option><![CDATA[--show-emwarns=<yes|no> [default: no] ]]></option> 1548 </term> 1549 <listitem> 1550 <para>When enabled, Valgrind will emit warnings about its CPU 1551 emulation in certain cases. These are usually not 1552 interesting.</para> 1553 </listitem> 1554 </varlistentry> 1555 1556 <varlistentry id="opt.require-text-symbol" 1557 xreflabel="--require-text-symbol"> 1558 <term> 1559 <option><![CDATA[--require-text-symbol=:sonamepatt:fnnamepatt]]></option> 1560 </term> 1561 <listitem> 1562 <para>When a shared object whose soname 1563 matches <varname>sonamepatt</varname> is loaded into the 1564 process, examine all the text symbols it exports. If none of 1565 those match <varname>fnnamepatt</varname>, print an error 1566 message and abandon the run. This makes it possible to ensure 1567 that the run does not continue unless a given shared object 1568 contains a particular function name. 1569 </para> 1570 <para> 1571 Both <varname>sonamepatt</varname> and 1572 <varname>fnnamepatt</varname> can be written using the usual 1573 <varname>?</varname> and <varname>*</varname> wildcards. For 1574 example: <varname>":*libc.so*:foo?bar"</varname>. You may use 1575 characters other than a colon to separate the two patterns. It 1576 is only important that the first character and the separator 1577 character are the same. For example, the above example could 1578 also be written <varname>"Q*libc.so*Qfoo?bar"</varname>. 1579 Multiple <varname> --require-text-symbol</varname> flags are 1580 allowed, in which case shared objects that are loaded into 1581 the process will be checked against all of them. 1582 </para> 1583 <para> 1584 The purpose of this is to support reliable usage of marked-up 1585 libraries. For example, suppose we have a version of GCC's 1586 <varname>libgomp.so</varname> which has been marked up with 1587 annotations to support Helgrind. It is only too easy and 1588 confusing to load the wrong, un-annotated 1589 <varname>libgomp.so</varname> into the application. So the idea 1590 is: add a text symbol in the marked-up library, for 1591 example <varname>annotated_for_helgrind_3_6</varname>, and then 1592 give the flag 1593 <varname>--require-text-symbol=:*libgomp*so*:annotated_for_helgrind_3_6</varname> 1594 so that when <varname>libgomp.so</varname> is loaded, Valgrind 1595 scans its symbol table, and if the symbol isn't present the run 1596 is aborted, rather than continuing silently with the 1597 un-marked-up library. Note that you should put the entire flag 1598 in quotes to stop shells expanding up the <varname>*</varname> 1599 and <varname>?</varname> wildcards. 1600 </para> 1601 </listitem> 1602 </varlistentry> 1603 1604 1605 </variablelist> 1606 <!-- end of xi:include in the manpage --> 1607 1608 </sect2> 1609 1610 1611 <sect2 id="manual-core.debugopts" xreflabel="Debugging Options"> 1612 <title>Debugging Options</title> 1613 1614 <!-- start of xi:include in the manpage --> 1615 <para id="debug.opts.para">There are also some options for debugging 1616 Valgrind itself. You shouldn't need to use them in the normal run of 1617 things. If you wish to see the list, use the 1618 <option>--help-debug</option> option.</para> 1619 <!-- end of xi:include in the manpage --> 1620 1621 </sect2> 1622 1623 1624 <sect2 id="manual-core.defopts" xreflabel="Setting Default Options"> 1625 <title>Setting Default Options</title> 1626 1627 <para>Note that Valgrind also reads options from three places:</para> 1628 1629 <orderedlist> 1630 <listitem> 1631 <para>The file <computeroutput>~/.valgrindrc</computeroutput></para> 1632 </listitem> 1633 1634 <listitem> 1635 <para>The environment variable 1636 <computeroutput>$VALGRIND_OPTS</computeroutput></para> 1637 </listitem> 1638 1639 <listitem> 1640 <para>The file <computeroutput>./.valgrindrc</computeroutput></para> 1641 </listitem> 1642 </orderedlist> 1643 1644 <para>These are processed in the given order, before the 1645 command-line options. Options processed later override those 1646 processed earlier; for example, options in 1647 <computeroutput>./.valgrindrc</computeroutput> will take 1648 precedence over those in 1649 <computeroutput>~/.valgrindrc</computeroutput>. 1650 </para> 1651 1652 <para>Please note that the <computeroutput>./.valgrindrc</computeroutput> 1653 file is ignored if it is marked as world writeable or not owned 1654 by the current user. This is because the 1655 <computeroutput>./.valgrindrc</computeroutput> can contain options that are 1656 potentially harmful or can be used by a local attacker to execute code under 1657 your user account. 1658 </para> 1659 1660 <para>Any tool-specific options put in 1661 <computeroutput>$VALGRIND_OPTS</computeroutput> or the 1662 <computeroutput>.valgrindrc</computeroutput> files should be 1663 prefixed with the tool name and a colon. For example, if you 1664 want Memcheck to always do leak checking, you can put the 1665 following entry in <literal>~/.valgrindrc</literal>:</para> 1666 1667 <programlisting><![CDATA[ 1668 --memcheck:leak-check=yes]]></programlisting> 1669 1670 <para>This will be ignored if any tool other than Memcheck is 1671 run. Without the <computeroutput>memcheck:</computeroutput> 1672 part, this will cause problems if you select other tools that 1673 don't understand 1674 <option>--leak-check=yes</option>.</para> 1675 1676 </sect2> 1677 1678 </sect1> 1679 1680 1681 1682 1683 <sect1 id="manual-core.pthreads" xreflabel="Support for Threads"> 1684 <title>Support for Threads</title> 1685 1686 <para>Threaded programs are fully supported.</para> 1687 1688 <para>The main thing to point out with respect to threaded programs is 1689 that your program will use the native threading library, but Valgrind 1690 serialises execution so that only one (kernel) thread is running at a 1691 time. This approach avoids the horrible implementation problems of 1692 implementing a truly multithreaded version of Valgrind, but it does 1693 mean that threaded apps run only on one CPU, even if you have a 1694 multiprocessor or multicore machine.</para> 1695 1696 <para>Valgrind doesn't schedule the threads itself. It merely ensures 1697 that only one thread runs at once, using a simple locking scheme. The 1698 actual thread scheduling remains under control of the OS kernel. What 1699 this does mean, though, is that your program will see very different 1700 scheduling when run on Valgrind than it does when running normally. 1701 This is both because Valgrind is serialising the threads, and because 1702 the code runs so much slower than normal.</para> 1703 1704 <para>This difference in scheduling may cause your program to behave 1705 differently, if you have some kind of concurrency, critical race, 1706 locking, or similar, bugs. In that case you might consider using the 1707 tools Helgrind and/or DRD to track them down.</para> 1708 1709 <para>On Linux, Valgrind also supports direct use of the 1710 <computeroutput>clone</computeroutput> system call, 1711 <computeroutput>futex</computeroutput> and so on. 1712 <computeroutput>clone</computeroutput> is supported where either 1713 everything is shared (a thread) or nothing is shared (fork-like); partial 1714 sharing will fail. 1715 </para> 1716 1717 1718 </sect1> 1719 1720 <sect1 id="manual-core.signals" xreflabel="Handling of Signals"> 1721 <title>Handling of Signals</title> 1722 1723 <para>Valgrind has a fairly complete signal implementation. It should be 1724 able to cope with any POSIX-compliant use of signals.</para> 1725 1726 <para>If you're using signals in clever ways (for example, catching 1727 SIGSEGV, modifying page state and restarting the instruction), you're 1728 probably relying on precise exceptions. In this case, you will need 1729 to use <option>--vex-iropt-precise-memory-exns=yes</option>. 1730 </para> 1731 1732 <para>If your program dies as a result of a fatal core-dumping signal, 1733 Valgrind will generate its own core file 1734 (<computeroutput>vgcore.NNNNN</computeroutput>) containing your program's 1735 state. You may use this core file for post-mortem debugging with GDB or 1736 similar. (Note: it will not generate a core if your core dump size limit is 1737 0.) At the time of writing the core dumps do not include all the floating 1738 point register information.</para> 1739 1740 <para>In the unlikely event that Valgrind itself crashes, the operating system 1741 will create a core dump in the usual way.</para> 1742 1743 </sect1> 1744 1745 1746 1747 1748 1749 1750 1751 1752 <sect1 id="manual-core.install" xreflabel="Building and Installing"> 1753 <title>Building and Installing Valgrind</title> 1754 1755 <para>We use the standard Unix 1756 <computeroutput>./configure</computeroutput>, 1757 <computeroutput>make</computeroutput>, <computeroutput>make 1758 install</computeroutput> mechanism. Once you have completed 1759 <computeroutput>make install</computeroutput> you may then want 1760 to run the regression tests 1761 with <computeroutput>make regtest</computeroutput>. 1762 </para> 1763 1764 <para>In addition to the usual 1765 <option>--prefix=/path/to/install/tree</option>, there are three 1766 options which affect how Valgrind is built: 1767 <itemizedlist> 1768 1769 <listitem> 1770 <para><option>--enable-inner</option></para> 1771 <para>This builds Valgrind with some special magic hacks which make 1772 it possible to run it on a standard build of Valgrind (what the 1773 developers call "self-hosting"). Ordinarily you should not use 1774 this option as various kinds of safety checks are disabled. 1775 </para> 1776 </listitem> 1777 1778 <listitem> 1779 <para><option>--enable-only64bit</option></para> 1780 <para><option>--enable-only32bit</option></para> 1781 <para>On 64-bit platforms (amd64-linux, ppc64-linux, 1782 amd64-darwin), Valgrind is by default built in such a way that 1783 both 32-bit and 64-bit executables can be run. Sometimes this 1784 cleverness is a problem for a variety of reasons. These two 1785 options allow for single-target builds in this situation. If you 1786 issue both, the configure script will complain. Note they are 1787 ignored on 32-bit-only platforms (x86-linux, ppc32-linux, 1788 arm-linux, x86-darwin). 1789 </para> 1790 </listitem> 1791 1792 </itemizedlist> 1793 </para> 1794 1795 <para>The <computeroutput>configure</computeroutput> script tests 1796 the version of the X server currently indicated by the current 1797 <computeroutput>$DISPLAY</computeroutput>. This is a known bug. 1798 The intention was to detect the version of the current X 1799 client libraries, so that correct suppressions could be selected 1800 for them, but instead the test checks the server version. This 1801 is just plain wrong.</para> 1802 1803 <para>If you are building a binary package of Valgrind for 1804 distribution, please read <literal>README_PACKAGERS</literal> 1805 <xref linkend="dist.readme-packagers"/>. It contains some 1806 important information.</para> 1807 1808 <para>Apart from that, there's not much excitement here. Let us 1809 know if you have build problems.</para> 1810 1811 </sect1> 1812 1813 1814 1815 <sect1 id="manual-core.problems" xreflabel="If You Have Problems"> 1816 <title>If You Have Problems</title> 1817 1818 <para>Contact us at <ulink url="&vg-url;">&vg-url;</ulink>.</para> 1819 1820 <para>See <xref linkend="manual-core.limits"/> for the known 1821 limitations of Valgrind, and for a list of programs which are 1822 known not to work on it.</para> 1823 1824 <para>All parts of the system make heavy use of assertions and 1825 internal self-checks. They are permanently enabled, and we have no 1826 plans to disable them. If one of them breaks, please mail us!</para> 1827 1828 <para>If you get an assertion failure 1829 in <filename>m_mallocfree.c</filename>, this may have happened because 1830 your program wrote off the end of a heap block, or before its 1831 beginning, thus corrupting head metadata. Valgrind hopefully will have 1832 emitted a message to that effect before dying in this way.</para> 1833 1834 <para>Read the <xref linkend="FAQ"/> for more advice about common problems, 1835 crashes, etc.</para> 1836 1837 </sect1> 1838 1839 1840 1841 <sect1 id="manual-core.limits" xreflabel="Limitations"> 1842 <title>Limitations</title> 1843 1844 <para>The following list of limitations seems long. However, most 1845 programs actually work fine.</para> 1846 1847 <para>Valgrind will run programs on the supported platforms 1848 subject to the following constraints:</para> 1849 1850 <itemizedlist> 1851 <listitem> 1852 <para>On x86 and amd64, there is no support for 3DNow! 1853 instructions. If the translator encounters these, Valgrind will 1854 generate a SIGILL when the instruction is executed. Apart from 1855 that, on x86 and amd64, essentially all instructions are supported, 1856 up to and including SSE4.2 in 64-bit mode and SSSE3 in 32-bit mode. 1857 Some exceptions: SSE4.2 AES instructions are not supported in 1858 64-bit mode, and 32-bit mode does in fact support the bare minimum 1859 SSE4 instructions to needed to run programs on MacOSX 10.6 on 1860 32-bit targets. 1861 </para> 1862 </listitem> 1863 1864 <listitem> 1865 <para>On ppc32 and ppc64, almost all integer, floating point and 1866 Altivec instructions are supported. Specifically: integer and FP 1867 insns that are mandatory for PowerPC, the "General-purpose 1868 optional" group (fsqrt, fsqrts, stfiwx), the "Graphics optional" 1869 group (fre, fres, frsqrte, frsqrtes), and the Altivec (also known 1870 as VMX) SIMD instruction set, are supported. Also, instructions 1871 from the Power ISA 2.05 specification, as present in POWER6 CPUs, 1872 are supported.</para> 1873 </listitem> 1874 1875 <listitem> 1876 <para>On ARM, essentially the entire ARMv7-A instruction set 1877 is supported, in both ARM and Thumb mode. ThumbEE and Jazelle are 1878 not supported. NEON and VFPv3 support is fairly complete. ARMv6 1879 media instruction support is mostly done but not yet complete. 1880 </para> 1881 </listitem> 1882 1883 <listitem> 1884 <para>If your program does its own memory management, rather than 1885 using malloc/new/free/delete, it should still work, but Memcheck's 1886 error checking won't be so effective. If you describe your 1887 program's memory management scheme using "client requests" (see 1888 <xref linkend="manual-core-adv.clientreq"/>), Memcheck can do 1889 better. Nevertheless, using malloc/new and free/delete is still 1890 the best approach.</para> 1891 </listitem> 1892 1893 <listitem> 1894 <para>Valgrind's signal simulation is not as robust as it could be. 1895 Basic POSIX-compliant sigaction and sigprocmask functionality is 1896 supplied, but it's conceivable that things could go badly awry if you 1897 do weird things with signals. Workaround: don't. Programs that do 1898 non-POSIX signal tricks are in any case inherently unportable, so 1899 should be avoided if possible.</para> 1900 </listitem> 1901 1902 <listitem> 1903 <para>Machine instructions, and system calls, have been implemented 1904 on demand. So it's possible, although unlikely, that a program will 1905 fall over with a message to that effect. If this happens, please 1906 report all the details printed out, so we can try and implement the 1907 missing feature.</para> 1908 </listitem> 1909 1910 <listitem> 1911 <para>Memory consumption of your program is majorly increased 1912 whilst running under Valgrind's Memcheck tool. This is due to the 1913 large amount of administrative information maintained behind the 1914 scenes. Another cause is that Valgrind dynamically translates the 1915 original executable. Translated, instrumented code is 12-18 times 1916 larger than the original so you can easily end up with 100+ MB of 1917 translations when running (eg) a web browser.</para> 1918 </listitem> 1919 1920 <listitem> 1921 <para>Valgrind can handle dynamically-generated code just fine. If 1922 you regenerate code over the top of old code (ie. at the same 1923 memory addresses), if the code is on the stack Valgrind will 1924 realise the code has changed, and work correctly. This is 1925 necessary to handle the trampolines GCC uses to implemented nested 1926 functions. If you regenerate code somewhere other than the stack, 1927 and you are running on an 32- or 64-bit x86 CPU, you will need to 1928 use the <option>--smc-check=all</option> option, and Valgrind will 1929 run more slowly than normal. Or you can add client requests that 1930 tell Valgrind when your program has overwritten code. 1931 </para> 1932 <para> On other platforms (ARM, PowerPC) Valgrind observes and 1933 honours the cache invalidation hints that programs are obliged to 1934 emit to notify new code, and so self-modifying-code support should 1935 work automatically, without the need 1936 for <option>--smc-check=all</option>.</para> 1937 </listitem> 1938 1939 <listitem> 1940 <para>Valgrind has the following limitations 1941 in its implementation of x86/AMD64 floating point relative to 1942 IEEE754.</para> 1943 1944 <para>Precision: There is no support for 80 bit arithmetic. 1945 Internally, Valgrind represents all such "long double" numbers in 64 1946 bits, and so there may be some differences in results. Whether or 1947 not this is critical remains to be seen. Note, the x86/amd64 1948 fldt/fstpt instructions (read/write 80-bit numbers) are correctly 1949 simulated, using conversions to/from 64 bits, so that in-memory 1950 images of 80-bit numbers look correct if anyone wants to see.</para> 1951 1952 <para>The impression observed from many FP regression tests is that 1953 the accuracy differences aren't significant. Generally speaking, if 1954 a program relies on 80-bit precision, there may be difficulties 1955 porting it to non x86/amd64 platforms which only support 64-bit FP 1956 precision. Even on x86/amd64, the program may get different results 1957 depending on whether it is compiled to use SSE2 instructions (64-bits 1958 only), or x87 instructions (80-bit). The net effect is to make FP 1959 programs behave as if they had been run on a machine with 64-bit IEEE 1960 floats, for example PowerPC. On amd64 FP arithmetic is done by 1961 default on SSE2, so amd64 looks more like PowerPC than x86 from an FP 1962 perspective, and there are far fewer noticeable accuracy differences 1963 than with x86.</para> 1964 1965 <para>Rounding: Valgrind does observe the 4 IEEE-mandated rounding 1966 modes (to nearest, to +infinity, to -infinity, to zero) for the 1967 following conversions: float to integer, integer to float where 1968 there is a possibility of loss of precision, and float-to-float 1969 rounding. For all other FP operations, only the IEEE default mode 1970 (round to nearest) is supported.</para> 1971 1972 <para>Numeric exceptions in FP code: IEEE754 defines five types of 1973 numeric exception that can happen: invalid operation (sqrt of 1974 negative number, etc), division by zero, overflow, underflow, 1975 inexact (loss of precision).</para> 1976 1977 <para>For each exception, two courses of action are defined by IEEE754: 1978 either (1) a user-defined exception handler may be called, or (2) a 1979 default action is defined, which "fixes things up" and allows the 1980 computation to proceed without throwing an exception.</para> 1981 1982 <para>Currently Valgrind only supports the default fixup actions. 1983 Again, feedback on the importance of exception support would be 1984 appreciated.</para> 1985 1986 <para>When Valgrind detects that the program is trying to exceed any 1987 of these limitations (setting exception handlers, rounding mode, or 1988 precision control), it can print a message giving a traceback of 1989 where this has happened, and continue execution. This behaviour used 1990 to be the default, but the messages are annoying and so showing them 1991 is now disabled by default. Use <option>--show-emwarns=yes</option> to see 1992 them.</para> 1993 1994 <para>The above limitations define precisely the IEEE754 'default' 1995 behaviour: default fixup on all exceptions, round-to-nearest 1996 operations, and 64-bit precision.</para> 1997 </listitem> 1998 1999 <listitem> 2000 <para>Valgrind has the following limitations in 2001 its implementation of x86/AMD64 SSE2 FP arithmetic, relative to 2002 IEEE754.</para> 2003 2004 <para>Essentially the same: no exceptions, and limited observance of 2005 rounding mode. Also, SSE2 has control bits which make it treat 2006 denormalised numbers as zero (DAZ) and a related action, flush 2007 denormals to zero (FTZ). Both of these cause SSE2 arithmetic to be 2008 less accurate than IEEE requires. Valgrind detects, ignores, and can 2009 warn about, attempts to enable either mode.</para> 2010 </listitem> 2011 2012 <listitem> 2013 <para>Valgrind has the following limitations in 2014 its implementation of ARM VFPv3 arithmetic, relative to 2015 IEEE754.</para> 2016 2017 <para>Essentially the same: no exceptions, and limited observance 2018 of rounding mode. Also, switching the VFP unit into vector mode 2019 will cause Valgrind to abort the program -- it has no way to 2020 emulate vector uses of VFP at a reasonable performance level. This 2021 is no big deal given that non-scalar uses of VFP instructions are 2022 in any case deprecated.</para> 2023 </listitem> 2024 2025 <listitem> 2026 <para>Valgrind has the following limitations 2027 in its implementation of PPC32 and PPC64 floating point 2028 arithmetic, relative to IEEE754.</para> 2029 2030 <para>Scalar (non-Altivec): Valgrind provides a bit-exact emulation of 2031 all floating point instructions, except for "fre" and "fres", which are 2032 done more precisely than required by the PowerPC architecture specification. 2033 All floating point operations observe the current rounding mode. 2034 </para> 2035 2036 <para>However, fpscr[FPRF] is not set after each operation. That could 2037 be done but would give measurable performance overheads, and so far 2038 no need for it has been found.</para> 2039 2040 <para>As on x86/AMD64, IEEE754 exceptions are not supported: all floating 2041 point exceptions are handled using the default IEEE fixup actions. 2042 Valgrind detects, ignores, and can warn about, attempts to unmask 2043 the 5 IEEE FP exception kinds by writing to the floating-point status 2044 and control register (fpscr). 2045 </para> 2046 2047 <para>Vector (Altivec, VMX): essentially as with x86/AMD64 SSE/SSE2: 2048 no exceptions, and limited observance of rounding mode. 2049 For Altivec, FP arithmetic 2050 is done in IEEE/Java mode, which is more accurate than the Linux default 2051 setting. "More accurate" means that denormals are handled properly, 2052 rather than simply being flushed to zero.</para> 2053 </listitem> 2054 </itemizedlist> 2055 2056 <para>Programs which are known not to work are:</para> 2057 <itemizedlist> 2058 <listitem> 2059 <para>emacs starts up but immediately concludes it is out of 2060 memory and aborts. It may be that Memcheck does not provide 2061 a good enough emulation of the 2062 <computeroutput>mallinfo</computeroutput> function. 2063 Emacs works fine if you build it to use 2064 the standard malloc/free routines.</para> 2065 </listitem> 2066 </itemizedlist> 2067 2068 </sect1> 2069 2070 2071 <sect1 id="manual-core.example" xreflabel="An Example Run"> 2072 <title>An Example Run</title> 2073 2074 <para>This is the log for a run of a small program using Memcheck. 2075 The program is in fact correct, and the reported error is as the 2076 result of a potentially serious code generation bug in GNU g++ 2077 (snapshot 20010527).</para> 2078 2079 <programlisting><![CDATA[ 2080 sewardj@phoenix:~/newmat10$ ~/Valgrind-6/valgrind -v ./bogon 2081 ==25832== Valgrind 0.10, a memory error detector for x86 RedHat 7.1. 2082 ==25832== Copyright (C) 2000-2001, and GNU GPL'd, by Julian Seward. 2083 ==25832== Startup, with flags: 2084 ==25832== --suppressions=/home/sewardj/Valgrind/redhat71.supp 2085 ==25832== reading syms from /lib/ld-linux.so.2 2086 ==25832== reading syms from /lib/libc.so.6 2087 ==25832== reading syms from /mnt/pima/jrs/Inst/lib/libgcc_s.so.0 2088 ==25832== reading syms from /lib/libm.so.6 2089 ==25832== reading syms from /mnt/pima/jrs/Inst/lib/libstdc++.so.3 2090 ==25832== reading syms from /home/sewardj/Valgrind/valgrind.so 2091 ==25832== reading syms from /proc/self/exe 2092 ==25832== 2093 ==25832== Invalid read of size 4 2094 ==25832== at 0x8048724: BandMatrix::ReSize(int,int,int) (bogon.cpp:45) 2095 ==25832== by 0x80487AF: main (bogon.cpp:66) 2096 ==25832== Address 0xBFFFF74C is not stack'd, malloc'd or free'd 2097 ==25832== 2098 ==25832== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) 2099 ==25832== malloc/free: in use at exit: 0 bytes in 0 blocks. 2100 ==25832== malloc/free: 0 allocs, 0 frees, 0 bytes allocated. 2101 ==25832== For a detailed leak analysis, rerun with: --leak-check=yes 2102 ]]></programlisting> 2103 2104 <para>The GCC folks fixed this about a week before GCC 3.0 2105 shipped.</para> 2106 2107 </sect1> 2108 2109 2110 <sect1 id="manual-core.warnings" xreflabel="Warning Messages"> 2111 <title>Warning Messages You Might See</title> 2112 2113 <para>Some of these only appear if you run in verbose mode 2114 (enabled by <option>-v</option>):</para> 2115 2116 <itemizedlist> 2117 2118 <listitem> 2119 <para><computeroutput>More than 100 errors detected. Subsequent 2120 errors will still be recorded, but in less detail than 2121 before.</computeroutput></para> 2122 2123 <para>After 100 different errors have been shown, Valgrind becomes 2124 more conservative about collecting them. It then requires only the 2125 program counters in the top two stack frames to match when deciding 2126 whether or not two errors are really the same one. Prior to this 2127 point, the PCs in the top four frames are required to match. This 2128 hack has the effect of slowing down the appearance of new errors 2129 after the first 100. The 100 constant can be changed by recompiling 2130 Valgrind.</para> 2131 </listitem> 2132 2133 <listitem> 2134 <para><computeroutput>More than 1000 errors detected. I'm not 2135 reporting any more. Final error counts may be inaccurate. Go fix 2136 your program!</computeroutput></para> 2137 2138 <para>After 1000 different errors have been detected, Valgrind 2139 ignores any more. It seems unlikely that collecting even more 2140 different ones would be of practical help to anybody, and it avoids 2141 the danger that Valgrind spends more and more of its time comparing 2142 new errors against an ever-growing collection. As above, the 1000 2143 number is a compile-time constant.</para> 2144 </listitem> 2145 2146 <listitem> 2147 <para><computeroutput>Warning: client switching stacks?</computeroutput></para> 2148 2149 <para>Valgrind spotted such a large change in the stack pointer 2150 that it guesses the client is switching to 2151 a different stack. At this point it makes a kludgey guess where the 2152 base of the new stack is, and sets memory permissions accordingly. 2153 You may get many bogus error messages following this, if Valgrind 2154 guesses wrong. At the moment "large change" is defined as a change 2155 of more that 2000000 in the value of the 2156 stack pointer register.</para> 2157 </listitem> 2158 2159 <listitem> 2160 <para><computeroutput>Warning: client attempted to close Valgrind's 2161 logfile fd <number></computeroutput></para> 2162 2163 <para>Valgrind doesn't allow the client to close the logfile, 2164 because you'd never see any diagnostic information after that point. 2165 If you see this message, you may want to use the 2166 <option>--log-fd=<number></option> option to specify a 2167 different logfile file-descriptor number.</para> 2168 </listitem> 2169 2170 <listitem> 2171 <para><computeroutput>Warning: noted but unhandled ioctl 2172 <number></computeroutput></para> 2173 2174 <para>Valgrind observed a call to one of the vast family of 2175 <computeroutput>ioctl</computeroutput> system calls, but did not 2176 modify its memory status info (because nobody has yet written a 2177 suitable wrapper). The call will still have gone through, but you may get 2178 spurious errors after this as a result of the non-update of the 2179 memory info.</para> 2180 </listitem> 2181 2182 <listitem> 2183 <para><computeroutput>Warning: set address range perms: large range 2184 <number></computeroutput></para> 2185 2186 <para>Diagnostic message, mostly for benefit of the Valgrind 2187 developers, to do with memory permissions.</para> 2188 </listitem> 2189 2190 </itemizedlist> 2191 2192 </sect1> 2193 2194 2195 2196 2197 2198 2199 </chapter> 2200