Rate This Document
Findability
Accuracy
Completeness
Readability

Filtering Safe Functions

You can add the -s/--safe-file parameter next to the devkit advisor dr-check command to skip data race check for specified safe functions during dynamic memory consistency checks.

To add the -s/--safe-file parameter, you need to specify the CFG configuration file, and write the names of filtered safe functions in the file. If the source file is a CPP file, write the name of the overloaded safe function.

Example of Filtering Safe Functions

In this example, the CFG configuration file is edited to filter safe functions. After a data race check is performed, safe functions are filtered.

  1. The following example describes how to add a lock for a user-defined class. Add safe functions to the configuration file specified by -s when needed.
    Content of the /home/advisor/test file:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    class my_custom_spinlock{
        std::atomic_flag is_locked ={false};
    public:
      void lock(){
          while (is_locked.test_and_set(std::memory_order_acquire)){}
      }
      
      void unlock (){
          is_locked .clear (std :: memory_order_release);
      }
    };
     
    int data_race = 0;
     
    my_custom_spinlock spinlock;
    void* first_thread(void* arg){
        spinlock.lock();
        data_race = 5;
        spinlock.unlock();
        return 0;
    }
     
    void* second_thread(void* arg){
        spinlock.lock();
        data_race = 3;
        spinlock.unlock();
        return 0;
    }
    

    /home/advisor/test: ELF file path. Replace the example path with the actual one.

  2. Perform a data race check.
    1
    devkit advisor dr-check -f /home/advisor/test
    

    The following information in bold indicates that two lines of code need to be modified.

    Executing data race check task, please wait...
    Scanned time: 2024/09/10 03:06:15
    
    Configuration:
        Elf filepath: /home/advisor/test
        Scan source code path: /home/testcase/project
        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 recommendable code lines to modify.
    
    For the details information, please check:
        /home/DevKit_Software/dr-check_20240910030615_554d.json
        /home/DevKit_Software/dr-check_20240910030615_554d.html
        /home/DevKit_Software/dr-check_20240910030615_554d.csv
  3. You can run the nm command to view the names of the reloaded first_thread and second_thread functions in the test file.
    1
    nm test
    

    Command output:

    1
    2
    0000000000400a84 T _Z12first_threadPv
    0000000000400ac4 T _Z13second_threadPv
    
  4. Create the safe_functions.cfg file and write the following content to the file:
    1
    2
    _Z12first_threadPv
    _Z13second_threadPv
    
  5. Perform the data race check again.
    devkit advisor dr-check -f /home/advisor/test -s /home/testcase/safe_functions.cfg

    /home/testcase/safe_functions.cfg: This CFG configuration file specifies the safe functions that are not checked during dynamic data race check. Modify the file as required.

    The following information in bold indicates that no code lines need to be modified when filtering safe functions.

    Executing data race check task, please wait...
    Scanned time: 2024/09/10 03:15:15
    Configuration:
        Elf filepath: /home/advisor/test
        Scan source code path: /home/testcase/project
        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 0 recommendable code lines to modify.
    For the details information, please check:
        /home/DevKit_Software/dr-check_20240910031515_663d.json
        /home/DevKit_Software/dr-check_20240910031515_663d.html
        /home/DevKit_Software/dr-check_20240910031515_663d.csv