Dynamic Memory Consistency Check Functions
The tool checks for any memory inconsistency problems in dynamic mode when C/C++ source code is running on the Kunpeng platform, and also provides check reports and memory barrier insertion suggestions.
Dynamic memory consistency check can be performed on single-process applications and on multi-process applications in shared memory mode. The tool can check and analyze multi-process applications that use the following mechanisms (multi-process applications that use the execv function family are not supported):
- Shared memory
- System V shared memory (based on system calls such as shmget)
- POSIX shared memory (based on interfaces such as shm_open)
- Synchronization between the following processes
- POSIX semaphore and operations
- POSIX thread locks, including mutex locks and read/write locks
- POSIX message queues
Command Function
Dynamically checks memory consistency in the source code.
Syntax
devkit advisor dr-check [-h | --help] {-f ELF_FILE | --elf-file ELF_FILE} [-i INPUT_PATH | --input INPUT_PATH] [-ec {true,false} | --enable-collect {true,false}] [--start-collect PID] [--stop-collect PID] [-s SAFE_FILE | --safe-file SAFE_FILE] [-p ELF_PARAMS | --elf-params ELF_PARAMS] [-o OUTPUT_PATH | --output OUTPUT_PATH] [-sf SHIELD_FILE | --shield-file SHIELD_FILE] [-cf CONFIG_FILE | --config-file CONFIG_FILE] [-d REPORT_FILE | --decode REPORT_FILE] [-sr {true,false} | --summary-report {true,false}] [-eb {true,false} | --enable-backtrace {true,false}] [-em {true,false} | --enable-multiprocess {true,false}] [-eh {true,false} | --enable-history-filter {true,false}] [-dm REPORT_FILE | --decode-mp-report REPORT_FILE] [-r {all,json,html,csv} | --report-type {all,json,html,csv}] [-l {0,1,2,3} | --log-level {0,1,2,3}] [--set-timeout TIMEOUT]
Parameter Description
Parameter |
Option |
Description |
|---|---|---|
-h/--help |
- |
Obtains help information. |
-f/--elf-file |
- |
ELF file path. This parameter is mandatory. The ELF file to be tested must contain debugging information (add the -g option during compilation). The ELF file is the binary file generated after compiling the C/C++ program. |
-i/--input |
- |
Path to the source code folder corresponding to the ELF file. This parameter is optional. |
-ec/--enable-collect |
true/false |
Indicates whether to enable dynamic memory consistency check upon application startup. The default value is true. This parameter is optional.
|
--start-collect |
- |
Sends the signal of enabling dynamic memory consistency check to a specified process. This parameter is optional. NOTE:
The --start-collect option takes effect only when -ec is set to false. |
--stop-collect |
- |
Sends the signal of disabling dynamic memory consistency check to a specified process. This parameter is optional. NOTE:
The --stop-collect option takes effect only when -ec is set to true. |
-s/--safe-file |
- |
CFG configuration file. This parameter is optional. It specifies the safe functions that are skipped in dynamic memory consistency check. The name of a C++ function must be the name after the C++ function is reloaded. |
-p/--elf-params |
- |
Input parameters required for executing the ELF file. This parameter is optional. |
-o/--output |
- |
Path for storing scan reports. By default, scan reports are stored in the current execution path. A report name is the format of Module-name_Timestamp. This parameter is optional. |
-sf/--shield-file |
- |
CFG configuration file. This parameter is optional. It specifies the files and dynamic libraries that are excluded from dynamic memory consistency check. |
-cf/--config-file |
- |
JSON configuration file. This parameter is optional. It is a custom lock not included in dynamic memory consistency check. |
-d/--decode |
- |
Parses historical single-process report files. This parameter is optional. It specifies the historical single-process report files saved during the tool running. A maximum of 100 historical reports can be saved for each binary file. If this parameter is set, reports are parsed separately. NOTE:
|
-sr/--summary-report |
true/false |
Indicates whether to generate a simplified report. The default value is false. This parameter is optional.
NOTE:
|
-eb/--enable-backtrace |
true/false |
Indicates whether to enable call stack recording. The default value is false. This parameter is optional.
NOTE:
Enabling the call stack can improve the accuracy of memory consistency check results. |
-em/--enable-multiprocess |
true/false |
Indicates whether to enable check for multi-process applications in shared memory mode. This parameter is optional and its default value is false.
|
-eh/--enable-history-filter |
true/false |
Indicates whether to filter historical memory consistency check results. This parameter is optional and defaults to false.
|
-dm/--decode-mp-report |
- |
Parses historical multi-process report files. This parameter is optional. It specifies the number of saved historical multi-process report files, up to a maximum of 100 for each binary file. If this option is specified, the reports are parsed separately. Only multi-process reports in plain text format can be parsed. NOTE:
Historical report files are stored in advisor/dr_check_reports/{elf_name}_{md5sum(elf_path)}/Timestamp. The reports are in the formats of mp_timestamp.memtracer_mp_report and ELF file name_PID.memtracer_report (the main process file does not contain a PID).
|
-r/--report-type |
all/json/html/csv |
Scan report format, which defaults to all. This parameter is optional.
|
-l/--log-level |
0/1/2/3 |
Log level, which defaults to 1. This parameter is optional.
|
--set-timeout |
- |
Timeout interval of a task, in minutes. If the execution duration exceeds the timeout interval, the task exits. This parameter is optional. By default, there is no timeout interval. The task will be executed until it is complete. |
Example
Scan the ELF file in the /home/advisor/shm_basic directory and enable multi-process check. Modify the parameters based on your requirements.
1 | devkit advisor dr-check -f /home/advisor/shm_basic -em true |
The following information is displayed and a report is generated:
Executing dynamic memory consistency check task, please wait...
The pid of the memtracer process is 2993352
Scanned time: 2025/11/14 02:39:44
Configuration:
ELF filepath: /home/advisor/shm_basic
Scan source code path: None
Generate report path: /home/DevKit_Software
Generate report type: all
Task Timeout Interval: The timeout period is not set.
Log level: info
Summary:
There are 2 recommended code lines to modify.
For the detailed information on multi-thread races, please check:
/home/DevKit_Software/dr-check_shm_basic_20251114023944_fd8d.json
/home/DevKit_Software/dr-check_shm_basic_20251114023944_fd8d.html
/home/DevKit_Software/dr-check_shm_basic_20251114023944_fd8d.csv
For the detailed information on multi-process races, please check:
/home/DevKit_Software/dr-check-mp_20251114023944_58a4.html
The result varies according to the option setting.
- If -em is specified, both a multi-thread races report and a multi-process races report are generated.
- If -em is not specified, only a multi-thread races report is generated.
Output Report
Parameter |
Description |
|---|---|
Configuration |
Displays the paths to the software source file and executable file. |
Source File to Be Modified |
Displays information such as the path to the source file that needs to be modified. |