MEMCHECK Cover menyediakan penolong bash untuk analisis Valgrind Memcheck.
Ini juga menyediakan laporan HTML Report Generator Valgrind Raw dan menyoroti bagian -bagian penting untuk membantu Anda menafsirkan hasil tersebut.
Ini dapat dengan mudah digunakan di lingkungan CI Anda untuk secara otomatis menghasilkan laporan.
Demonstrasi lebih baik daripada kata -kata apa pun, Anda dapat menemukan contoh laporan HTML yang dihasilkan di sini.
Script memcheck_runner.sh adalah pembungkus yang akan menjalankan biner di bawah alat memcheck Valgrind.
Agar skrip memcheck_runner.sh berfungsi, alat -alat berikut harus diinstal dan dapat diakses menggunakan variabel lingkungan path:
bash Bash versi 4 dan hanya atas didukung.valgrind Valgrind Versi 3.13 diuji, versi yang lebih lama mungkin tidak berfungsi seperti yang dimaksudkan Inilah penggunaannya (dapat diakses menggunakan opsi --help ):
Usage: memcheck_runner.sh [OPTIONS]... -- [BIN] [BIN_ARG]...
Runs the BIN with the BIN_ARGs through valgrind memcheck analyser.
Options:
-h|--help Displays this help message.
-i|--ignore=FILE Provides valgrind FILE as the suppression file.
-o|--output-name=NAME [MANDATORY] Defines the output file name
(will be suffixed with the .memcheck extension).
-s|--gen-suppressions Enables valgrind suppression generation in the output
file, those can be used to create a suppression file.
--fullpath-after= (with nothing after the '=')
Show full source paths in call stacks.
--fullpath-after=STR Like --fullpath-after=, but only show the part of the
path after 'STR'. Allows removal of path prefixes.
Use this flag multiple times to specify a set of
prefixes to remove.
Satu-satunya opsi wajib adalah --output-name , yang akan menentukan jalur dan nama file output.
Jika jalan tidak ada, itu akan dibuat.
Ekstensi .memcheck akan secara otomatis ditambahkan ke dalam kompatibilitas dengan skrip generate_html_report.sh .
Contoh:
$ memcheck_runner.sh --output-name " my/output/path/filename " -- true can take useless params and still be one true self
Info: Output file set to: ' my/output/path/filename.memcheck '
Info: Creating output directory ' my/output/path/ '
Info: Running the following cmd with valgrind:
" true " " can " " take " " useless " " params " " and " " still " " be " " one " " true " " self " Anda dapat menentukan file penindasan pelanggaran menggunakan opsi --ignore .
File penindasan semacam itu harus mengikuti aturan file penindasan Valgrind.
Supresi dapat dihasilkan dalam laporan menggunakan opsi --gen-suppressions .
Penindasan akan terlihat seperti itu dalam laporan:
[...]
==21849== 4 bytes in 1 blocks are definitely lost in loss record 1 of 1
==21849== at 0x4C3017F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==21849== by 0x108687: breakage::evil_definitely_lost_func() (main.cpp:4)
==21849== by 0x10869B: main (main.cpp:10)
==21849==
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: definite
fun:_Znwm
fun:_ZN8breakage25evil_definitely_lost_funcEv
fun:main
}
==21849== LEAK SUMMARY:
==21849== definitely lost: 4 bytes in 1 blocks
[...]
Panggilan ini akan mengeluarkan laporan Valgind ke file filename.memcheck dalam my/output/path/ Directory, yang dalam contoh ini dibuat.
Analisis Valgrind dijalankan menggunakan biner true , melewatinya banyak parameter.
Dari dokumentasi Valgrind:
By default Valgrind only shows the filenames in stack traces, but not full paths to source files.
When using Valgrind in large projects where the sources reside in multiple different directories, this can be inconvenient.
`--fullpath-after` provides a flexible solution to this problem.
When this option is present, the path to each source file is shown, with the following all-important caveat:
if string is found in the path, then the path up to and including string is omitted, else the path is shown unmodified.
Note that string is not required to be a prefix of the path.
For example, consider a file named /home/janedoe/blah/src/foo/bar/xyzzy.c. Specifying --fullpath-after=/home/janedoe/blah/src/ will cause Valgrind to show the name as foo/bar/xyzzy.c.
Because the string is not required to be a prefix, --fullpath-after=src/ will produce the same output. This is useful when the path contains arbitrary machine-generated characters.
For example, the path /my/build/dir/C32A1B47/blah/src/foo/xyzzy can be pruned to foo/xyzzy using --fullpath-after=/blah/src/.
If you simply want to see the full path, just specify an empty string: --fullpath-after=. This isn't a special case, merely a logical consequence of the above rules.
Finally, you can use --fullpath-after multiple times. Any appearance of it causes Valgrind to switch to producing full paths and applying the above filtering rule.
Each produced path is compared against all the --fullpath-after-specified strings, in the order specified. The first string to match causes the path to be truncated as described above.
If none match, the full path is shown.
This facilitates chopping off prefixes when the sources are drawn from a number of unrelated directories.
Melewati --fullpath-after ke memcheck_runner.sh akan meneruskannya langsung ke Valgrind, memiliki efek yang dijelaskan sebelumnya.
Untuk saat ini, opsi Valgrind tidak dapat disesuaikan.
Opsi berikut digunakan:
--track-origins=yes--leak-check=full--show-reachable=yes--show-leak-kinds=all--show-leak-kinds=all--show-leak-kinds=definite,indirect,possible,reachable--num-callers=50--fair-sched=yesUntuk detail lebih lanjut, silakan merujuk ke dokumentasi Valgrind.
Skrip generate_html_report.sh akan menghasilkan laporan HTML dengan semua file hasil memcheck dalam direktori yang diberikan.
Untuk skrip generate_html_report.sh agar berfungsi, alat -alat berikut harus diinstal dan dapat diakses menggunakan variabel lingkungan path:
bash Bash versi 4 dan hanya atas didukung.gawk GNU AWK 4.1.4 diuji, versi yang lebih lama mungkin tidak berfungsi sebagaimana dimaksud Inilah penggunaannya (dapat diakses menggunakan opsi --help ):
Usage: generate_html_report.sh [OPTIONS]...
Parses all .memcheck files from a given directory and generates an HTML
report.
Options:
-h|--help Displays this help message.
-g|--generate-config Generates a 'memcheck-cover.config' file in the current
directory, containing the default configuration values.
-c|--config=FILE Loads the configuration from FILE. An example
configuration file can be generated using the
--generate-config option.
If this option is not set, or values are missing in
FILE, the default values will be used.
-i|--input-dir=DIR [MANDATORY] Defines the input directory where the
.memcheck files are.
The files will be searched in directories recursivly.
-o|--output-dir=DIR [MANDATORY] Defines the output directory where the
HTML report will be produced.
Ada dua parameter wajib untuk generator:
--input-dir yang mendefinisikan jalur di mana laporan memcheck akan diproses..memcheck yang ditemukan.--output-dir yang mendefinisikan jalur di mana laporan HTML akan dihasilkan. Jika pengaturan pelanggaran default tidak sesuai dengan Anda, setiap kekritisan pelanggaran dapat disesuaikan.
File konfigurasi, dengan semua pengaturan kritisitas yang tersedia dan nilai defaultnya, dapat dihasilkan menggunakan opsi --generate-config :
$ generate_html_report.sh --generate-config
Info: Generating configuration with default values: ' memcheck-cover.config ' ...
Done. The generated configuration can be modified and then loaded
by the current script using the --config option.
If a violation is not set, the default value will be used. File konfigurasi default dihasilkan di direktori saat ini di file memcheck-cover.config .
Anda kemudian dapat mengubah kekritisan apa pun agar sesuai dengan kebutuhan Anda, dan meneruskannya ke generator menggunakan opsi --config .
Jika ada kekritisan yang hilang dari file, yang default akan diterapkan.
Melewati file konfigurasi apa pun dengan parameter yang tidak valid atau nilai parameter akan menghasilkan kesalahan.
Misalnya:
Error: Invalid configuration value 'dummy' for parameter: memcheck_violation_criticality['contains_unaddressable'] => kritikalitas dummy tidak adaError: Invalid configuration parameter: memcheck_violation_criticality['dummy_param'] => Kunci dummy_param tidak ada untuk memcheck_violation_criticalityBerikut adalah contoh generasi, dengan pohon berikut:
my/output/path/
├── another_dir/
│ ├── a_report.memcheck
│ └── other_report.memcheck
└── filename.memcheck
Mari Jalankan Generator HTML:
generate_html_report.sh --input-dir " my/output/path/ " --output-dir " my/output/path/report/ " --config memcheck-cover.config
Info: Input directory set to: ' my/output/path/ '
Info: Loading configuration from file ' memcheck-cover.config ' ...
Info: Processing memcheck file ' filename.memcheck ' ...
Info: Processing memcheck file ' another_dir/a_report.memcheck ' ...
Info: Processing memcheck file ' another_dir/other_report.memcheck ' ...
Info: Generating index.html...Hasilnya akan terlihat seperti ini:
my/output/path/report/
├── another_dir/
│ ├── a_report.memcheck.html.part.js
│ └── other_report.memcheck.html.part.js
├── filename.memcheck.html.part.js
├── index.html
├── memcheck-cover.css
└── memcheck-cover.js
Opsi ini hanya tersedia melalui file konfigurasi (lihat -g | --generate-config opsi).
Ini dapat didefinisikan dengan mengisi array asosiatif berikut:
memcheck_path_prefix_replacement[ " <prefix_to_replace> " ]= " <replacement_value> " Di mana kunci prefix_to_replace adalah awalan jalur untuk diganti
Dan nilai replacement_value adalah nilai penggantian (dapat dibiarkan kosong untuk menghapus awalan secara lengkap)
Misalnya, pengaturan:
memcheck_path_prefix_replacement[ " /var/user/repo " ]= " <repo> "Akan mengonversi baris laporan berikut:
==1== at 0x10101042: myFunc() (/var/user/repo/src/lib1/MyClass.cpp:14)
Ke:
==1== at 0x10101042: myFunc() (<repo>/src/lib1/MyClass.cpp:14)
Beberapa penggantian dapat didefinisikan
Opsi ini hanya tersedia melalui file konfigurasi (lihat -g | --generate-config opsi).
Ini dapat didefinisikan dengan mengisi array asosiatif berikut (keduanya diperlukan):
memcheck_url_prefix_replacement[ " <path_prefix> " ]= " <repository_url_prefix> "
memcheck_url_prefix_replacement_type[ " <path_prefix> " ]= " <repository_type> " Di mana kunci path_prefix adalah awalan jalur file ke direktori root repositori.
Nilai repository_url_prefix adalah awalan server kontrol sumber ke repositori.
Berikut adalah beberapa contoh:
Dan nilai repository_type adalah salah satu jenis server yang didukung (case tidak masalah):
Misalnya, pengaturan:
memcheck_url_prefix_replacement[ " /var/user/repo/ " ]= " https://github.com/example/example_project/blob/master/ "
memcheck_url_prefix_replacement_type[ " /var/user/repo/ " ]= " github "Akan mengonversi baris laporan berikut:
==1== at 0x10101042: myFunc() (/var/user/repo/src/lib1/MyClass.cpp:14)
Ke:
==1== at 0x10101042: myFunc() (<a href="https://github.com/example/example_project/blob/master/src/lib1/MyClass.cpp#L14">/var/user/repo/src/lib1/MyClass.cpp:14</a>)
Beberapa penggantian dapat didefinisikan