Rate This Document
Findability
Accuracy
Completeness
Readability

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

Table 1 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.

  • true: Enable
  • false: Disable

--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:
  • Historical report files are stored in advisor/dr_check_reports/{elf_name}_{md5sum(elf_path)}/Timestamp. The report is in the format of ELF file name_PID_Timestamp.memtracer_report (the main process file does not contain a PID).
  • The ELF file corresponding to a historical report file specified by the -d option must match the ELF file specified by the -f option.

-sr/--summary-report

true/false

Indicates whether to generate a simplified report. The default value is false. This parameter is optional.

  • true: generates a simplified report in JSON format.
  • false: generates a full report specified by the -r option.
NOTE:
  • A simplified JSON report contains only address, location, type, file, line, function, source_code, core_code, and backtrace.
  • If both the -sr and -r options are specified and -sr is set to true, -r does not take effect.

-eb/--enable-backtrace

true/false

Indicates whether to enable call stack recording. The default value is false. This parameter is optional.

  • true: enables call stack recording.
  • false: disables call stack recording.
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.

  • true: enables the check, and generates multi-process memory consistency reports (HTML) and single-process inter-thread memory consistency reports (JSON/HTML/CSV).
  • false: disables the check in shared memory mode, and only generates single-process inter-thread memory consistency reports (JSON/HTML/CSV).

-eh/--enable-history-filter

true/false

Indicates whether to filter historical memory consistency check results. This parameter is optional and defaults to false.

  • true: Historical result filtering is enabled. The current scan is compared with the latest historical report, and the filtered results are displayed. However, the historical report still stores the full races report.
  • false: Historical result filtering is disabled. The current scan displays a full races report.

-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).
  • The -dm parameter can be used to parse the multi-process file (.memtracer_mp_report) corresponding to the historical report file. The specified historical report file must match the ELF file specified by -f.
  • The -d parameter can be used to parse the multi-thread file (.memtracer_report) corresponding to the historical report file. The specified historical report file must match the ELF file specified by -f.

-r/--report-type

all/json/html/csv

Scan report format, which defaults to all. This parameter is optional.
  • all: generates reports in JSON, HTML, and CSV formats.
  • json: generates a report only in JSON format.
  • html: generates a report only in HTML format.
  • csv: generates a report only in CSV format.

-l/--log-level

0/1/2/3

Log level, which defaults to 1. This parameter is optional.
  • 0: DEBUG
  • 1: INFO
  • 2: WARNING
  • 3: ERROR

--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

Table 2 Output report parameters

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.