Memcheck Cover는 Valgrind Memcheck Analysis를위한 Bash 도우미를 제공합니다.
또한 HTML 보고서 생성기 포맷 Valgrind RAW 보고서를 제공하고 이러한 결과를 해석하는 데 도움이되는 중요한 부분을 강조합니다.
CI 환경에서 쉽게 보고서를 생성 할 수 있습니다.
시연이 어떤 단어보다 낫다면 여기에서 생성 된 HTML 보고서 예를 찾을 수 있습니다.
memcheck_runner.sh 스크립트는 Valgrind의 Memcheck 도구 아래에서 바이너리를 실행하는 래퍼입니다.
memcheck_runner.sh 스크립트가 작동하려면 경로 환경 변수를 사용하여 다음 도구를 설치하고 액세스 할 수 있어야합니다.
bash Bash 버전 4 및 상단 만 지원됩니다.valgrind Valgrind 버전 3.13은 테스트되었으며 이전 버전은 의도 한대로 작동하지 않을 수 있습니다. 다음은 사용법입니다 ( --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.
유일한 필수 옵션은 --output-name 이며, 이는 출력 파일 경로와 이름을 정의합니다.
경로가 존재하지 않으면 생성됩니다.
.memcheck 확장은 generate_html_report.sh 스크립트와의 호환성을 위해 자동으로 추가됩니다.
예:
$ 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 " --ignore 옵션을 사용하여 위반 억제 파일을 지정할 수 있습니다.
이러한 억제 파일은 Valgrind의 억제 파일 규칙을 따라야합니다.
--gen-suppressions 옵션을 사용하여 보고서 내에서 억제를 생성 할 수 있습니다.
억제는 보고서에서 다음과 같습니다.
[...]
==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
[...]
이 호출은 Valgind의 보고서를 filename.memcheck 파일로 출력하여 my/output/path/ directory 내에서 생성되었습니다.
Valgrind 분석은 true 바이너리를 사용하여 실행하여 많은 매개 변수를 전달했습니다.
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.
--fullpath-after memcheck_runner.sh 로 전달하면 이전에 설명 된 효과를 가진 Valgrind로 직접 전달됩니다.
현재 Valgrind의 옵션은 사용자 정의 할 수 없습니다.
다음 옵션이 사용됩니다.
--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=yes자세한 내용은 Valgrind의 문서를 참조하십시오.
generate_html_report.sh 스크립트는 주어진 디렉토리에 모든 Memcheck 결과 파일이 포함 된 HTML 보고서를 생성합니다.
generate_html_report.sh 스크립트가 작동하려면 경로 환경 변수를 사용하여 다음 도구를 설치하고 액세스 할 수 있어야합니다.
bash Bash 버전 4 및 상단 만 지원됩니다.gawk gnu awk 4.1.4는 테스트되었고, 이전 버전은 의도 한대로 작동하지 않을 수 있습니다. 다음은 사용법입니다 ( --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.
생성기에는 두 가지 필수 매개 변수가 있습니다.
--input-dir ..memcheck 파일을 처리합니다.--output-dir . 기본 위반 설정이 귀하에게 맞지 않으면 각 위반 임계성을 조정할 수 있습니다.
사용 가능한 모든 중요도 설정 및 기본값이 포함 된 구성 파일은 --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. 기본 구성 파일은 memcheck-cover.config 파일의 현재 디렉토리에서 생성됩니다.
그런 다음 요구에 맞게 중요도를 변경하고 --config 그 옵션을 사용하여 발전기로 전달할 수 있습니다.
파일에서 중요도가 없으면 기본값이 적용됩니다.
유효하지 않은 매개 변수 또는 매개 변수 값으로 구성 파일을 전달하면 오류가 발생합니다.
예를 들어:
Error: Invalid configuration value 'dummy' for parameter: memcheck_violation_criticality['contains_unaddressable'] => dummy 중요도는 존재하지 않습니다.Error: Invalid configuration parameter: memcheck_violation_criticality['dummy_param'] => dummy_param 키는 memcheck_violation_criticality 에 존재하지 않습니다.다음은 다음과 같은 트리의 세대 예입니다.
my/output/path/
├── another_dir/
│ ├── a_report.memcheck
│ └── other_report.memcheck
└── filename.memcheck
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...결과는 다음과 같습니다.
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
이 옵션은 구성 파일을 통해서만 사용할 수 있습니다 ( -g |-generate-config 옵션 참조).
다음과 같은 연관 배열을 작성하여 정의 할 수 있습니다.
memcheck_path_prefix_replacement[ " <prefix_to_replace> " ]= " <replacement_value> " 주요 접두사 prefix_to_replace 교체 할 경로의 접두사 인 경우
그리고 값 replacement_value 는 대체 값입니다 (접두사를 완전히 제거하기 위해 비어있을 수 있음).
예를 들어 설정 :
memcheck_path_prefix_replacement[ " /var/user/repo " ]= " <repo> "다음 보고서 라인을 변환합니다.
==1== at 0x10101042: myFunc() (/var/user/repo/src/lib1/MyClass.cpp:14)
에게:
==1== at 0x10101042: myFunc() (<repo>/src/lib1/MyClass.cpp:14)
다중 교체를 정의 할 수 있습니다
이 옵션은 구성 파일을 통해서만 사용할 수 있습니다 ( -g |-generate-config 옵션 참조).
다음 연관 배열을 채우면 정의 할 수 있습니다 (둘 다 필요합니다).
memcheck_url_prefix_replacement[ " <path_prefix> " ]= " <repository_url_prefix> "
memcheck_url_prefix_replacement_type[ " <path_prefix> " ]= " <repository_type> " 여기서 key path_prefix 는 리포지토리 루트 디렉토리에 대한 파일 경로 접두사입니다.
value repository_url_prefix 는 저장소에 소스 제어 서버 접두사입니다.
다음은 몇 가지 예입니다.
그리고 value repository_type 지원되는 서버 유형 중 하나입니다 (케이스는 중요하지 않음).
예를 들어 설정 :
memcheck_url_prefix_replacement[ " /var/user/repo/ " ]= " https://github.com/example/example_project/blob/master/ "
memcheck_url_prefix_replacement_type[ " /var/user/repo/ " ]= " github "다음 보고서 라인을 변환합니다.
==1== at 0x10101042: myFunc() (/var/user/repo/src/lib1/MyClass.cpp:14)
에게:
==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>)
다중 교체를 정의 할 수 있습니다