| 1 |
<html> |
| 2 |
<head> |
| 3 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 4 |
<title>6. README_DEVELOPERS</title> |
| 5 |
<link rel="stylesheet" type="text/css" href="vg_basic.css"> |
| 6 |
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"> |
| 7 |
<link rel="home" href="index.html" title="Valgrind Documentation"> |
| 8 |
<link rel="up" href="dist.html" title="Valgrind Distribution Documents"> |
| 9 |
<link rel="prev" href="dist.readme-missing.html" title="5. README_MISSING_SYSCALL_OR_IOCTL"> |
| 10 |
<link rel="next" href="dist.readme-packagers.html" title="7. README_PACKAGERS"> |
| 11 |
</head> |
| 12 |
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
| 13 |
<div><table class="nav" width="100%" cellspacing="3" cellpadding="3" border="0" summary="Navigation header"><tr> |
| 14 |
<td width="22px" align="center" valign="middle"><a accesskey="p" href="dist.readme-missing.html"><img src="images/prev.png" width="18" height="21" border="0" alt="Prev"></a></td> |
| 15 |
<td width="25px" align="center" valign="middle"><a accesskey="u" href="dist.html"><img src="images/up.png" width="21" height="18" border="0" alt="Up"></a></td> |
| 16 |
<td width="31px" align="center" valign="middle"><a accesskey="h" href="index.html"><img src="images/home.png" width="27" height="20" border="0" alt="Up"></a></td> |
| 17 |
<th align="center" valign="middle">Valgrind Distribution Documents</th> |
| 18 |
<td width="22px" align="center" valign="middle"><a accesskey="n" href="dist.readme-packagers.html"><img src="images/next.png" width="18" height="21" border="0" alt="Next"></a></td> |
| 19 |
</tr></table></div> |
| 20 |
<div class="chapter"> |
| 21 |
<div class="titlepage"><div><div><h1 class="title"> |
| 22 |
<a name="dist.readme-developers"></a>6. README_DEVELOPERS</h1></div></div></div> |
| 23 |
<div class="literallayout"><p><br> |
| 24 |
Building and installing it<br> |
| 25 |
~~~~~~~~~~~~~~~~~~~~~~~~~~<br> |
| 26 |
To build/install from the GIT repository or from a distribution<br> |
| 27 |
tarball, refer to the section with the same name in README.<br> |
| 28 |
<br> |
| 29 |
Building Valgrind requires autoconf, GNU make and a suitable C<br> |
| 30 |
compiler.<br> |
| 31 |
<br> |
| 32 |
<br> |
| 33 |
Building and not installing it<br> |
| 34 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br> |
| 35 |
To run Valgrind without having to install it, run coregrind/valgrind<br> |
| 36 |
with the VALGRIND_LIB environment variable set, where <dir> is the root<br> |
| 37 |
of the source tree (and must be an absolute path). Eg:<br> |
| 38 |
<br> |
| 39 |
VALGRIND_LIB=~/grind/head4/.in_place ~/grind/head4/coregrind/valgrind <br> |
| 40 |
<br> |
| 41 |
This allows you to compile and run with "make" instead of "make install",<br> |
| 42 |
saving you time.<br> |
| 43 |
<br> |
| 44 |
Or, you can use the 'vg-in-place' script which does that for you.<br> |
| 45 |
<br> |
| 46 |
I recommend compiling with "make --quiet" to further reduce the amount of<br> |
| 47 |
output spewed out during compilation, letting you actually see any errors,<br> |
| 48 |
warnings, etc.<br> |
| 49 |
<br> |
| 50 |
<br> |
| 51 |
Building a distribution tarball<br> |
| 52 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br> |
| 53 |
To build a distribution tarball from the valgrind sources:<br> |
| 54 |
<br> |
| 55 |
make dist<br> |
| 56 |
<br> |
| 57 |
In addition to compiling, linking and packaging everything up, the command<br> |
| 58 |
will also attempt to build the documentation.<br> |
| 59 |
<br> |
| 60 |
If you only want to test whether the generated tarball is complete and runs<br> |
| 61 |
regression tests successfully, building documentation is not needed.<br> |
| 62 |
<br> |
| 63 |
make dist BUILD_ALL_DOCS=no<br> |
| 64 |
<br> |
| 65 |
If you insist on building documentation some embarrassing instructions<br> |
| 66 |
can be found in docs/README.<br> |
| 67 |
<br> |
| 68 |
<br> |
| 69 |
Running the regression tests<br> |
| 70 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br> |
| 71 |
<br> |
| 72 |
Running the regression tests requires GNU sed, python 3.9 or later, gdb,<br> |
| 73 |
and a suitable C++ compiler<br> |
| 74 |
<br> |
| 75 |
To build and run all the regression tests, run "make [--quiet] regtest".<br> |
| 76 |
<br> |
| 77 |
To run a subset of the regression tests, execute:<br> |
| 78 |
<br> |
| 79 |
perl tests/vg_regtest <name><br> |
| 80 |
<br> |
| 81 |
where <name> is a directory (all tests within will be run) or a single<br> |
| 82 |
.vgtest test file, or the name of a program which has a like-named .vgtest<br> |
| 83 |
file. Eg:<br> |
| 84 |
<br> |
| 85 |
perl tests/vg_regtest memcheck<br> |
| 86 |
perl tests/vg_regtest memcheck/tests/badfree.vgtest<br> |
| 87 |
perl tests/vg_regtest memcheck/tests/badfree<br> |
| 88 |
<br> |
| 89 |
The details of each vgtest run are logged to individual "vgtest.log"<br> |
| 90 |
files. These are listed, and non-passing tests detailed, in the<br> |
| 91 |
test-suite-overall.log file. (Token *.trs and test-suite.log files<br> |
| 92 |
are also created, for emulating automake-style testsuites, as expected<br> |
| 93 |
by tools such as bunsen.)<br> |
| 94 |
<br> |
| 95 |
<br> |
| 96 |
Running the performance tests<br> |
| 97 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br> |
| 98 |
To build and run all the performance tests, run "make [--quiet] perf".<br> |
| 99 |
<br> |
| 100 |
To run a subset of the performance suite, execute:<br> |
| 101 |
<br> |
| 102 |
perl perf/vg_perf <name><br> |
| 103 |
<br> |
| 104 |
where <name> is a directory (all tests within will be run) or a single<br> |
| 105 |
.vgperf test file, or the name of a program which has a like-named .vgperf<br> |
| 106 |
file. Eg:<br> |
| 107 |
<br> |
| 108 |
perl perf/vg_perf perf/<br> |
| 109 |
perl perf/vg_perf perf/bz2.vgperf<br> |
| 110 |
perl perf/vg_perf perf/bz2<br> |
| 111 |
<br> |
| 112 |
To compare multiple versions of Valgrind, use the --vg= option multiple<br> |
| 113 |
times. For example, if you have two Valgrinds next to each other, one in<br> |
| 114 |
trunk1/ and one in trunk2/, from within either trunk1/ or trunk2/ do this to<br> |
| 115 |
compare them on all the performance tests:<br> |
| 116 |
<br> |
| 117 |
perl perf/vg_perf --vg=../trunk1 --vg=../trunk2 perf/<br> |
| 118 |
<br> |
| 119 |
Writing regression tests<br> |
| 120 |
~~~~~~~~~~~~~~~~~~~~~~~~<br> |
| 121 |
<br> |
| 122 |
Each tool has a tests directory containing regression tests. There is also<br> |
| 123 |
the gdbserver_tests directory at the top level. Test directories may have<br> |
| 124 |
architecture, OS and and architecture-OS sub-directories for tests that are<br> |
| 125 |
specific to one architecture, OS or both.<br> |
| 126 |
<br> |
| 127 |
Once you have written a C or C++ executable that performs the required<br> |
| 128 |
tests you will have to modify and create several files. The new files that<br> |
| 129 |
will need adding are<br> |
| 130 |
(a) a .vgtest file, which controls the test<br> |
| 131 |
(b) a .stderr.exp file, which is the golden reference for any Valgrind output<br> |
| 132 |
Note that even if Valgrind doesn't produce any output you will need to<br> |
| 133 |
create an empty .stderr.exp file.<br> |
| 134 |
(c) [optional] a .stdout.exp file, the golden reference for any output from the<br> |
| 135 |
test executable<br> |
| 136 |
(d) [optional] filter files (see the test directories for examples).<br> |
| 137 |
<br> |
| 138 |
Quite often the output will depend on the platform the test is run on.<br> |
| 139 |
Getting the tests to be 'portable' can require filtering or adding multiple<br> |
| 140 |
.stderr.exp reference files.<br> |
| 141 |
<br> |
| 142 |
If the test only runs under certain conditions like the availability of functions<br> |
| 143 |
in libc or C++ standard versions you will need to modify configure.ac in the<br> |
| 144 |
top level directory. See AC_CHECK_FUNCS and the various blocks starting with<br> |
| 145 |
AC_MSG_CHECKING.<br> |
| 146 |
<br> |
| 147 |
In the test directory, modify Makefile.am. Add to EXTRA_DIST the .vgtest,<br> |
| 148 |
.stderr.exp and .stderr.out files. Add any filters to dist_noinst_SCRIPTS.<br> |
| 149 |
Add the test executable name to check_PROGRAMS. Try to respect the<br> |
| 150 |
formatting and alphabetical ordering of the Makefile.am. For simple C files that is<br> |
| 151 |
sufficient. If you needed to add a feature test to configure.ac then you should<br> |
| 152 |
use the same condition to add the executable name to check_PROGRAMS. If the<br> |
| 153 |
executable uses C++ you need to add exename_SOURCES. If the executable needs<br> |
| 154 |
special compilation or link options, use exename_CFLAGS, exename_CXXFLAGS,<br> |
| 155 |
exename_LDFLAGS or exename_LDADD. Finally in Makefile.am it's nice not to<br> |
| 156 |
have any warnings, even if they were done on purpose. See configure.ac<br> |
| 157 |
and various Makefile.am files for examples of using FLAG_W_*.<br> |
| 158 |
<br> |
| 159 |
The vgtest file contains the instructions for running the test. Typically<br> |
| 160 |
it will contain (with examples in quotes)<br> |
| 161 |
(a) the name of the test executable: "prog: exename"<br> |
| 162 |
(b) arguments for the test executable: "args: hello world"<br> |
| 163 |
(c) arguments for the Valgrind tool: "vgopts: -q"<br> |
| 164 |
(d) [optional] a check for prerequisites: "prereq: ! ../../tests/os_test darwin"<br> |
| 165 |
(e) [optional] a filter: "stderr_filter: filter_fdleak"<br> |
| 166 |
<br> |
| 167 |
See tests/vg_regtest for a full description of all possible vgtest directives.<br> |
| 168 |
<br> |
| 169 |
The easiest way to generate the expected files is to run the test. Create empty<br> |
| 170 |
files with touch (otherwise the test won't run) then run the test from the<br> |
| 171 |
top directory using perl and vg_regtest script (as in the "Running the<br> |
| 172 |
regression tests" section. Then copy "tool/tests/newtest.stderr.out" to<br> |
| 173 |
"tool/tests/newtest.stderr.exp". It is better to generate the .stdout.exp<br> |
| 174 |
file directly from the testcase. You can do that by redirecting stdout to<br> |
| 175 |
the expected file, for instance (in the test directory)<br> |
| 176 |
./newtest arg1 arg2 > newtest.stdout.exp<br> |
| 177 |
This is not always possible - sometimes there are tests that depend on the use<br> |
| 178 |
of client requests or have imperfect emulation of opcodes.<br> |
| 179 |
Make sure that the test runs and passes.<br> |
| 180 |
<br> |
| 181 |
The last file to change is .gitignore in the top directory. Add a new entry,<br> |
| 182 |
for example "/tool/tests/newtest".<br> |
| 183 |
<br> |
| 184 |
Check for mistakes in Makefile.am. In the top directory run<br> |
| 185 |
make post-regtest-checks<br> |
| 186 |
<br> |
| 187 |
You should only see<br> |
| 188 |
...checking makefile consistency<br> |
| 189 |
...checking header files and include directives<br> |
| 190 |
and no messages related to EXTRA_DIST.<br> |
| 191 |
<br> |
| 192 |
Commit access and try branches<br> |
| 193 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br> |
| 194 |
To get commit access to the valgrind git repository on sourceware<br> |
| 195 |
you will have to ask an existing developer and fill in the following<br> |
| 196 |
form: https://sourceware.org/cgi-bin/pdw/ps_form.cgi<br> |
| 197 |
<br> |
| 198 |
Every developer with commit access can use try branches. If you want to try a<br> |
| 199 |
branch before pushing you can push to a special named try branch as follows: <br> |
| 200 |
<br> |
| 201 |
git push origin $BRANCH:users/$USERNAME/try-$BRANCH<br> |
| 202 |
<br> |
| 203 |
Where $BRANCH is the branch name and $USERNAME is your user name.<br> |
| 204 |
<br> |
| 205 |
You can see the status of the builders here:<br> |
| 206 |
https://builder.sourceware.org/buildbot/#/builders?tags=valgrind-try<br> |
| 207 |
<br> |
| 208 |
The buildbot will also sent the patch author multiple success/failure emails.<br> |
| 209 |
<br> |
| 210 |
Afterwards you can delete the branch again:<br> |
| 211 |
<br> |
| 212 |
git push origin :users/$USERNAME/try-$BRANCH<br> |
| 213 |
<br> |
| 214 |
<br> |
| 215 |
Debugging Valgrind with GDB<br> |
| 216 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~<br> |
| 217 |
To debug the valgrind launcher program (<prefix>/bin/valgrind) just<br> |
| 218 |
run it under gdb in the normal way.<br> |
| 219 |
<br> |
| 220 |
Debugging the main body of the valgrind code (and/or the code for<br> |
| 221 |
a particular tool) requires a bit more trickery but can be achieved<br> |
| 222 |
without too much problem by following these steps:<br> |
| 223 |
<br> |
| 224 |
(1) Set VALGRIND_LAUNCHER to point to the valgrind executable. Eg:<br> |
| 225 |
<br> |
| 226 |
export VALGRIND_LAUNCHER=/usr/local/bin/valgrind<br> |
| 227 |
<br> |
| 228 |
or for an uninstalled version in a source directory $DIR:<br> |
| 229 |
<br> |
| 230 |
export VALGRIND_LAUNCHER=$DIR/coregrind/valgrind<br> |
| 231 |
export VALGRIND_LIB=$DIR/.in_place<br> |
| 232 |
<br> |
| 233 |
VALGRIND_LIB is where the default.supp and vgpreload_ libraries<br> |
| 234 |
are found (which is under /usr/libexec/valgrind for an installed<br> |
| 235 |
version).<br> |
| 236 |
<br> |
| 237 |
(2) Run gdb on the tool executable. Eg:<br> |
| 238 |
<br> |
| 239 |
gdb /usr/local/lib/valgrind/lackey-ppc32-linux<br> |
| 240 |
<br> |
| 241 |
or<br> |
| 242 |
<br> |
| 243 |
gdb $DIR/.in_place/memcheck-x86-linux<br> |
| 244 |
<br> |
| 245 |
(3) Do "handle SIGSEGV SIGILL nostop noprint" in GDB to prevent GDB from<br> |
| 246 |
stopping on a SIGSEGV or SIGILL:<br> |
| 247 |
<br> |
| 248 |
(gdb) handle SIGILL SIGSEGV nostop noprint<br> |
| 249 |
<br> |
| 250 |
If you are using lldb, then the equivalent command is<br> |
| 251 |
<br> |
| 252 |
(lldb) pro hand -p true -s false -n false SIGILL SIGSEGV<br> |
| 253 |
<br> |
| 254 |
(4) Set any breakpoints you want and proceed as normal for gdb. The<br> |
| 255 |
macro VG_(FUNC) is expanded to vgPlain_FUNC, so If you want to set<br> |
| 256 |
a breakpoint VG_(do_exec_inner), you could do like this in GDB:<br> |
| 257 |
<br> |
| 258 |
(gdb) b vgPlain_do_exec_inner<br> |
| 259 |
<br> |
| 260 |
Note: This is just an example, for various reasons internal<br> |
| 261 |
function names might be renamed or optimized out<br> |
| 262 |
(for example when building with --enable-lto).<br> |
| 263 |
<br> |
| 264 |
(5) Run the tool with required options (the --tool option is required<br> |
| 265 |
for correct setup), e.g.<br> |
| 266 |
<br> |
| 267 |
(gdb) run --tool=lackey pwd<br> |
| 268 |
<br> |
| 269 |
Steps (1)--(3) can be put in a .gdbinit file, but any directory names must<br> |
| 270 |
be fully expanded (ie. not an environment variable).<br> |
| 271 |
<br> |
| 272 |
A different and possibly easier way is as follows:<br> |
| 273 |
<br> |
| 274 |
(1) Run Valgrind as normal, but add the flag --wait-for-gdb=yes. This<br> |
| 275 |
puts the tool executable into a wait loop soon after it gains<br> |
| 276 |
control. This delays startup for a few seconds.<br> |
| 277 |
<br> |
| 278 |
(2) In a different shell, do "gdb /proc/<pid>/exe <pid>", where<br> |
| 279 |
<pid> you read from the output printed by (1). This attaches<br> |
| 280 |
GDB to the tool executable, which should be in the above mentioned<br> |
| 281 |
wait loop.<br> |
| 282 |
<br> |
| 283 |
(3) Do "cont" to continue. After the loop finishes spinning, startup<br> |
| 284 |
will continue as normal. Note that comment (3) above re passing<br> |
| 285 |
signals applies here too.<br> |
| 286 |
<br> |
| 287 |
The default build of Valgrind uses "-g -O2". This is OK most of the<br> |
| 288 |
time, but with sophisticated optimization it can be difficult to<br> |
| 289 |
see the contents of variables. A quick way to get to see function<br> |
| 290 |
variables is to temporarily add "__attribute__((optnone))" before<br> |
| 291 |
the function definition and rebuild. Alternatively modify<br> |
| 292 |
Makefile.all.am and remove -O2 from AM_CFLAGS_BASE. That will<br> |
| 293 |
require you to reconfigure and rebuild Valgrind.<br> |
| 294 |
<br> |
| 295 |
Self-hosting<br> |
| 296 |
~~~~~~~~~~~~<br> |
| 297 |
This section explains:<br> |
| 298 |
(A) How to configure Valgrind to run under Valgrind.<br> |
| 299 |
Such a setup is called self hosting, or outer/inner setup.<br> |
| 300 |
(B) How to run Valgrind regression tests in a 'self-hosting' mode,<br> |
| 301 |
e.g. to verify Valgrind has no bugs such as memory leaks.<br> |
| 302 |
(C) How to run Valgrind performance tests in a 'self-hosting' mode,<br> |
| 303 |
to analyse and optimise the performance of Valgrind and its tools.<br> |
| 304 |
<br> |
| 305 |
(A) How to configure Valgrind to run under Valgrind:<br> |
| 306 |
<br> |
| 307 |
(1) Check out 2 trees, "Inner" and "Outer". Inner runs the app<br> |
| 308 |
directly. Outer runs Inner.<br> |
| 309 |
<br> |
| 310 |
(2) Configure Inner with --enable-inner and build as usual.<br> |
| 311 |
<br> |
| 312 |
(3) Configure Outer normally and build+install as usual.<br> |
| 313 |
Note: You must use a "make install"-ed valgrind.<br> |
| 314 |
Do *not* use vg-in-place for the Outer valgrind.<br> |
| 315 |
<br> |
| 316 |
(4) Choose a very simple program (date) and try<br> |
| 317 |
<br> |
| 318 |
outer/.../bin/valgrind --sim-hints=enable-outer --trace-children=yes \<br> |
| 319 |
--smc-check=all-non-file \<br> |
| 320 |
--run-libc-freeres=no --tool=cachegrind -v \<br> |
| 321 |
inner/.../vg-in-place --vgdb-prefix=./inner --tool=none -v prog<br> |
| 322 |
<br> |
| 323 |
If you omit the --trace-children=yes, you'll only monitor Inner's launcher<br> |
| 324 |
program, not its stage2. Outer needs --run-libc-freeres=no, as otherwise<br> |
| 325 |
it will try to find and run __libc_freeres in the inner, while libc is not<br> |
| 326 |
used by the inner. Inner needs --vgdb-prefix=./inner to avoid inner<br> |
| 327 |
gdbserver colliding with outer gdbserver.<br> |
| 328 |
Currently, inner does *not* use the client request <br> |
| 329 |
VALGRIND_DISCARD_TRANSLATIONS for the JITted code or the code patched for<br> |
| 330 |
translation chaining. So the outer needs --smc-check=all-non-file to<br> |
| 331 |
detect the modified code.<br> |
| 332 |
<br> |
| 333 |
Debugging the whole thing might imply to use up to 3 GDB:<br> |
| 334 |
* a GDB attached to the Outer valgrind, allowing<br> |
| 335 |
to examine the state of Outer.<br> |
| 336 |
* a GDB using Outer gdbserver, allowing to<br> |
| 337 |
examine the state of Inner.<br> |
| 338 |
* a GDB using Inner gdbserver, allowing to<br> |
| 339 |
examine the state of prog.<br> |
| 340 |
<br> |
| 341 |
The whole thing is fragile, confusing and slow, but it does work well enough<br> |
| 342 |
for you to get some useful performance data. Inner has most of<br> |
| 343 |
its output (ie. those lines beginning with "==<pid>==") prefixed with a '>',<br> |
| 344 |
which helps a lot. However, when running regression tests in an Outer/Inner<br> |
| 345 |
setup, this prefix causes the reg test diff to fail. Give <br> |
| 346 |
--sim-hints=no-inner-prefix to the Inner to disable the production<br> |
| 347 |
of the prefix in the stdout/stderr output of Inner.<br> |
| 348 |
<br> |
| 349 |
The allocators in coregrind/m_mallocfree.c and VEX/priv/main_util.h are<br> |
| 350 |
annotated with client requests so Memcheck can be used to find leaks<br> |
| 351 |
and use after free in an Inner Valgrind.<br> |
| 352 |
<br> |
| 353 |
The Valgrind "big lock" is annotated with helgrind client requests<br> |
| 354 |
so Helgrind and DRD can be used to find race conditions in an Inner<br> |
| 355 |
Valgrind.<br> |
| 356 |
<br> |
| 357 |
All this has not been tested much, so don't be surprised if you hit problems.<br> |
| 358 |
<br> |
| 359 |
When using self-hosting with an outer Callgrind tool, use '--pop-on-jump'<br> |
| 360 |
(on the outer). Otherwise, Callgrind has much higher memory requirements. <br> |
| 361 |
<br> |
| 362 |
(B) Regression tests in an outer/inner setup:<br> |
| 363 |
<br> |
| 364 |
To run all the regression tests with an outer memcheck, do :<br> |
| 365 |
perl tests/vg_regtest --outer-valgrind=../outer/.../bin/valgrind \<br> |
| 366 |
--all<br> |
| 367 |
<br> |
| 368 |
To run a specific regression tests with an outer memcheck, do:<br> |
| 369 |
perl tests/vg_regtest --outer-valgrind=../outer/.../bin/valgrind \<br> |
| 370 |
none/tests/args.vgtest<br> |
| 371 |
<br> |
| 372 |
To run regression tests with another outer tool:<br> |
| 373 |
perl tests/vg_regtest --outer-valgrind=../outer/.../bin/valgrind \<br> |
| 374 |
--outer-tool=helgrind --all<br> |
| 375 |
<br> |
| 376 |
--outer-args allows to give specific arguments to the outer tool,<br> |
| 377 |
replacing the default one provided by vg_regtest.<br> |
| 378 |
<br> |
| 379 |
Note: --outer-valgrind must be a "make install"-ed valgrind.<br> |
| 380 |
Do *not* use vg-in-place.<br> |
| 381 |
<br> |
| 382 |
When an outer valgrind runs an inner valgrind, a regression test<br> |
| 383 |
produces one additional file <testname>.outer.log which contains the<br> |
| 384 |
errors detected by the outer valgrind. E.g. for an outer memcheck, it<br> |
| 385 |
contains the leaks found in the inner, for an outer helgrind or drd,<br> |
| 386 |
it contains the detected race conditions.<br> |
| 387 |
<br> |
| 388 |
The file tests/outer_inner.supp contains suppressions for <br> |
| 389 |
the irrelevant or benign errors found in the inner.<br> |
| 390 |
<br> |
| 391 |
A regression test running in the inner (e.g. memcheck/tests/badrw) will<br> |
| 392 |
cause the inner to report an error, which is expected and checked<br> |
| 393 |
as usual when running the regtests in an outer/inner setup.<br> |
| 394 |
However, the outer will often also observe an error, e.g. a jump<br> |
| 395 |
using uninitialised data, or a read/write outside the bounds of a heap<br> |
| 396 |
block. When the outer reports such an error, it will output the<br> |
| 397 |
inner host stacktrace. To this stacktrace, it will append the<br> |
| 398 |
stacktrace of the inner guest program. For example, this is an error<br> |
| 399 |
reported by the outer when the inner runs the badrw regtest:<br> |
| 400 |
==8119== Invalid read of size 2<br> |
| 401 |
==8119== at 0x7F2EFD7AF: ???<br> |
| 402 |
==8119== by 0x7F2C82EAF: ???<br> |
| 403 |
==8119== by 0x7F180867F: ???<br> |
| 404 |
==8119== by 0x40051D: main (badrw.c:5)<br> |
| 405 |
==8119== by 0x7F180867F: ???<br> |
| 406 |
==8119== by 0x1BFF: ???<br> |
| 407 |
==8119== by 0x3803B7F0: _______VVVVVVVV_appended_inner_guest_stack_VVVVVVVV_______ (m_execontext.c:332)<br> |
| 408 |
==8119== by 0x40055C: main (badrw.c:22)<br> |
| 409 |
==8119== Address 0x55cd03c is 4 bytes before a block of size 16 alloc'd<br> |
| 410 |
==8119== at 0x2804E26D: vgPlain_arena_malloc (m_mallocfree.c:1914)<br> |
| 411 |
==8119== by 0x2800BAB4: vgMemCheck_new_block (mc_malloc_wrappers.c:368)<br> |
| 412 |
==8119== by 0x2800BC87: vgMemCheck_malloc (mc_malloc_wrappers.c:403)<br> |
| 413 |
==8119== by 0x28097EAE: do_client_request (scheduler.c:1861)<br> |
| 414 |
==8119== by 0x28097EAE: vgPlain_scheduler (scheduler.c:1425)<br> |
| 415 |
==8119== by 0x280A7237: thread_wrapper (syswrap-linux.c:103)<br> |
| 416 |
==8119== by 0x280A7237: run_a_thread_NORETURN (syswrap-linux.c:156)<br> |
| 417 |
==8119== by 0x3803B7F0: _______VVVVVVVV_appended_inner_guest_stack_VVVVVVVV_______ (m_execontext.c:332)<br> |
| 418 |
==8119== by 0x4C294C4: malloc (vg_replace_malloc.c:298)<br> |
| 419 |
==8119== by 0x40051D: main (badrw.c:5)<br> |
| 420 |
In the above, the first stacktrace starts with the inner host stacktrace,<br> |
| 421 |
which in this case is some JITted code. Such code sometimes contains IPs<br> |
| 422 |
that points in the inner guest code (0x40051D: main (badrw.c:5)).<br> |
| 423 |
After the separator, we have the inner guest stacktrace.<br> |
| 424 |
The second stacktrace gives the stacktrace where the heap block that was<br> |
| 425 |
overrun was allocated. We see it was allocated by the inner valgrind<br> |
| 426 |
in the client arena (first part of the stacktrace). The second part is<br> |
| 427 |
the guest stacktrace that did the allocation.<br> |
| 428 |
<br> |
| 429 |
<br> |
| 430 |
(C) Performance tests in an outer/inner setup:<br> |
| 431 |
<br> |
| 432 |
To run all the performance tests with an outer cachegrind, do :<br> |
| 433 |
perl perf/vg_perf --outer-valgrind=../outer/.../bin/valgrind perf<br> |
| 434 |
<br> |
| 435 |
To run a specific perf test (e.g. bz2) in this setup, do :<br> |
| 436 |
perl perf/vg_perf --outer-valgrind=../outer/.../bin/valgrind perf/bz2<br> |
| 437 |
<br> |
| 438 |
To run all the performance tests with an outer callgrind, do :<br> |
| 439 |
perl perf/vg_perf --outer-valgrind=../outer/.../bin/valgrind \<br> |
| 440 |
--outer-tool=callgrind perf<br> |
| 441 |
<br> |
| 442 |
Note: --outer-valgrind must be a "make install"-ed valgrind.<br> |
| 443 |
Do *not* use vg-in-place.<br> |
| 444 |
<br> |
| 445 |
To compare the performance of multiple Valgrind versions, do :<br> |
| 446 |
perl perf/vg_perf --outer-valgrind=../outer/.../bin/valgrind \<br> |
| 447 |
--outer-tool=callgrind \<br> |
| 448 |
--vg=../inner_xxxx --vg=../inner_yyyy perf<br> |
| 449 |
(where inner_xxxx and inner_yyyy are the toplevel directories of<br> |
| 450 |
the versions to compare).<br> |
| 451 |
Cachegrind and cg_diff are particularly handy to obtain a delta<br> |
| 452 |
between the two versions.<br> |
| 453 |
<br> |
| 454 |
When the outer tool is callgrind or cachegrind, the following<br> |
| 455 |
output files will be created for each test:<br> |
| 456 |
<outertoolname>.out.<inner_valgrind_dir>.<tt>.<perftestname>.<pid><br> |
| 457 |
<outertoolname>.outer.log.<inner_valgrind_dir>.<tt>.<perftestname>.<pid><br> |
| 458 |
(where tt is the two letters abbreviation for the inner tool(s) run).<br> |
| 459 |
<br> |
| 460 |
For example, the command<br> |
| 461 |
perl perf/vg_perf \<br> |
| 462 |
--outer-valgrind=../outer_trunk/install/bin/valgrind \<br> |
| 463 |
--outer-tool=callgrind \<br> |
| 464 |
--vg=../inner_tchain --vg=../inner_trunk perf/many-loss-records<br> |
| 465 |
<br> |
| 466 |
produces the files<br> |
| 467 |
callgrind.out.inner_tchain.no.many-loss-records.18465<br> |
| 468 |
callgrind.outer.log.inner_tchain.no.many-loss-records.18465<br> |
| 469 |
callgrind.out.inner_tchain.me.many-loss-records.21899<br> |
| 470 |
callgrind.outer.log.inner_tchain.me.many-loss-records.21899<br> |
| 471 |
callgrind.out.inner_trunk.no.many-loss-records.21224<br> |
| 472 |
callgrind.outer.log.inner_trunk.no.many-loss-records.21224<br> |
| 473 |
callgrind.out.inner_trunk.me.many-loss-records.22916<br> |
| 474 |
callgrind.outer.log.inner_trunk.me.many-loss-records.22916<br> |
| 475 |
<br> |
| 476 |
<br> |
| 477 |
Printing out problematic blocks<br> |
| 478 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br> |
| 479 |
If you want to print out a disassembly of a particular block that<br> |
| 480 |
causes a crash, do the following.<br> |
| 481 |
<br> |
| 482 |
Try running with "--vex-guest-chase=no --trace-flags=10000000<br> |
| 483 |
--trace-notbelow=999999". This should print one line for each block<br> |
| 484 |
translated, and that includes the address.<br> |
| 485 |
<br> |
| 486 |
Then re-run with 999999 changed to the highest bb number shown.<br> |
| 487 |
This will print the one line per block, and also will print a<br> |
| 488 |
disassembly of the block in which the fault occurred.<br> |
| 489 |
<br> |
| 490 |
<br> |
| 491 |
Formatting the code with clang-format<br> |
| 492 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br> |
| 493 |
clang-format is a tool to format C/C++/... code. The root directory of the<br> |
| 494 |
Valgrind tree contains file .clang-format which is a configuration for this tool<br> |
| 495 |
and specifies a style for Valgrind. This gives you an option to use<br> |
| 496 |
clang-format to easily format Valgrind code which you are modifying.<br> |
| 497 |
<br> |
| 498 |
The Valgrind codebase is not globally formatted with clang-format. It means<br> |
| 499 |
that you should not use the tool to format a complete file after making changes<br> |
| 500 |
in it because that would lead to creating unrelated modifications.<br> |
| 501 |
<br> |
| 502 |
The right approach is to format only updated or new code. By using an<br> |
| 503 |
integration with a text editor, it is possible to reformat arbitrary blocks<br> |
| 504 |
of code with a single keystroke. Refer to the upstream documentation which<br> |
| 505 |
describes integration with various editors and IDEs:<br> |
| 506 |
https://clang.llvm.org/docs/ClangFormat.html.<br> |
| 507 |
<br> |
| 508 |
Updating zstd<br> |
| 509 |
~~~~~~~~~~~~~<br> |
| 510 |
Similar to libiberty, we have to import a copy of zstd rather than linking<br> |
| 511 |
with a library. There isn't (yet) a script to automate this, so it has to be<br> |
| 512 |
done manually.<br> |
| 513 |
<br> |
| 514 |
The version currently in use can be seen in coregrind/m_debuginfo/zstd.h.<br> |
| 515 |
Look for ZSTD_VERSION_MAJOR ZSTD_VERSION_MINOR and ZSTD_VERSION_RELEASE.<br> |
| 516 |
<br> |
| 517 |
- Get the source of zstd from<br> |
| 518 |
<br> |
| 519 |
https://github.com/facebook/zstd<br> |
| 520 |
<br> |
| 521 |
- Checkout the latest release tag (should be vMAJ.MIN.REL)<br> |
| 522 |
<br> |
| 523 |
- Copy {zstd git repo}/lib/zstd.h to coregrind/m_debuginfo/zstd.h<br> |
| 524 |
<br> |
| 525 |
- cd to {zstd git repo}/build/single_file_libs and run ./create_single_file_decoder.sh<br> |
| 526 |
<br> |
| 527 |
- You cannot simply copy and use the generated zstddeclib.c!<br> |
| 528 |
All calls to libc functions in this file need replacing with VG_ versions.<br> |
| 529 |
Merge the newly generated zstddeclib.c with coregrind/m_debuginfo/zstddeclib.c.<br> |
| 530 |
Make sure to keep the copy of the BSD license in the C file.<br> |
| 531 |
<br> |
| 532 |
<br> |
| 533 |
</p></div> |
| 534 |
</div> |
| 535 |
<div> |
| 536 |
<br><table class="nav" width="100%" cellspacing="3" cellpadding="2" border="0" summary="Navigation footer"> |
| 537 |
<tr> |
| 538 |
<td rowspan="2" width="40%" align="left"> |
| 539 |
<a accesskey="p" href="dist.readme-missing.html"><< 5. README_MISSING_SYSCALL_OR_IOCTL</a> </td> |
| 540 |
<td width="20%" align="center"><a accesskey="u" href="dist.html">Up</a></td> |
| 541 |
<td rowspan="2" width="40%" align="right"> <a accesskey="n" href="dist.readme-packagers.html">7. README_PACKAGERS >></a> |
| 542 |
</td> |
| 543 |
</tr> |
| 544 |
<tr><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td></tr> |
| 545 |
</table> |
| 546 |
</div> |
| 547 |
</body> |
| 548 |
</html> |