Coder Social home page Coder Social logo

unify: Job list about ucsan HOT 10 CLOSED

linD026 avatar linD026 commented on September 26, 2024
unify: Job list

from ucsan.

Comments (10)

linD026 avatar linD026 commented on September 26, 2024

@celizon @ZitingLi

from ucsan.

linD026 avatar linD026 commented on September 26, 2024

@celizon
Could you please check out the report message of this function for environment information that we will need in our project?
Like, how do they collect the information of threads, and how do they deal with the stack information?

After that, we can let the people who are responsible for the detect or report part know how to do their job with the information.

from ucsan.

linD026 avatar linD026 commented on September 26, 2024

I create the PR for the basic concept of how the detect and unify subsystems interact.

So your job is to implement the function in the src/unify file.

from ucsan.

celizon avatar celizon commented on September 26, 2024

已完成:task、stack、時間
未完成:行數

我們建立了Unify.cpp、Unify.h,以及main.cpp三個檔案,其中main.cpp是作為測試用,模擬怎麼調用Unify的函式。編譯後的執行檔暫時命名為example。下圖片example的輸出樣式,之後會再加上一行value change。
image

以下有3個問題需要請教:

問題1:stack的backtrace顯示問題
因為打包成一個.exe的關係,stack的backtrace()無法顯示內部經過的函式,只有記憶體位址。
如果在int main()直接調用unify函式,結果如下圖,backtrace()有5行。
image
如果在int main()內呼叫void func1(),並在func1()裡才調用unify函式,結果如下圖,backtrace()有6行,等於多了經過func1()的位址。
image

問題2:無法取得出現data race的行數。
有嘗試過使用__Line__和addr2line獲取行數,但不適用於我們的程式。網路上也查不到如何從外部程式碼取得目標程式碼的行數。

問題3:出現data race的時間擷取。
不確定時間是要拿time()還是clock (),前者是現實的執行時間,後者是程式內部的執行時間。目前是使用clock()。
image
image

from ucsan.

celizon avatar celizon commented on September 26, 2024

Unify.h 程式碼:

#pragma once
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <utility>
#include <map>
#include <fstream>
#include <time.h>
#include <unistd.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <execinfo.h>
using namespace std;

typedef class Task {
public:
	pid_t pid; /* from OS */
	int cpuid; /* from OS */
	bool read_write_state; /* read:true(1), write:false(0) */
	unsigned long long* address; /* Address of object */
	size_t size; /* size of object, unit is byte */
	clock_t current_time;
	vector<string> stack;
	Task(){};
	Task(unsigned long long* ptr, size_t _size, int state) {
		this->pid = getpid();
		this->cpuid = sched_getcpu();
		this->read_write_state = state;
		this->address = ptr;
		this->size = _size;
		this->current_time = clock();
	};
}task;

class Unify {
private:
	int line_number;
	size_t time;
public:
	map<pair<unsigned long long*, size_t>, vector<task> > task_container;
	void report_set_info(unsigned long long* ptr, size_t _size, int state);
	vector<string> collect_stack_info();
	void report_to_detect();
	void write_file();
};

from ucsan.

celizon avatar celizon commented on September 26, 2024

Unify.cpp 程式碼:

#include "Unify.h"

void Unify::report_set_info(unsigned long long* ptr, size_t _size, int state) {

    pair<unsigned long long*, size_t> v(ptr, _size);
    task t(ptr, _size, state);
    t.stack = collect_stack_info();
    task_container[v].push_back(t);
}

vector<string> Unify::collect_stack_info() {
    void* buffer[64];
    char** symbols;

    int num = backtrace(buffer, 64);

    symbols = backtrace_symbols(buffer, num);
    if (symbols == NULL) {
        perror("backtrace_symbols");
        exit(EXIT_FAILURE);
    }

    vector<string> temp;
    for (int i = 0; i < num; i++) {
        temp.push_back(symbols[i]);
    }

    free(symbols);
    return temp;
}

void Unify::report_to_detect() {

}

void Unify::write_file() {
    ofstream file;
    file.open("conclusion.txt");
    if (!file.is_open()){
	cout << "File cannot be open.";
    }
    else {
        for (map<pair<unsigned long long*, size_t>, vector<task> >::iterator it = task_container.begin(); it != task_container.end(); it++) {
            file << "address " << it->first.first << endl;
            file << "size " << it->first.second << endl;
            for (int i = 0; i < it->second.size(); i++) {
                file << "pid " << it->second[i].pid << endl;
                file << "cpuid " << it->second[i].cpuid << endl;
                file << "state " << it->second[i].read_write_state << endl;
		file << "time " << it->second[i].current_time << endl;
                for (int j = 0; j < it->second[i].stack.size(); j++) {
                    file << it->second[i].stack[j] << endl;
                }
            }
        }
	file.close();
    }
}

from ucsan.

linD026 avatar linD026 commented on September 26, 2024

For question 1, after using the backtrace() function, you should use the backtrace_symbols() function to translate the address.

Here is the manual page said:

Given the set of addresses returned by backtrace() in buffer,
backtrace_symbols() translates the addresses into an array of
strings that describe the addresses symbolically.

Other, it is totally fine.

from ucsan.

celizon avatar celizon commented on September 26, 2024

有使用backtrace_symbols(),不知道是哪裡少做,才會不傳內部function calls。
之前將backtrace直接放在main裡,是會顯示的,有參考backtrace()範例的做法。
三個檔案(main.cpp、Unify.h、Unify.h)一起編譯後,就無法顯示。

from ucsan.

linD026 avatar linD026 commented on September 26, 2024

OK, I will fix it.

And from your code, I don't see any that let us really need to use C++.
The only feature you use is OOP.
But for your code, the class you use is POD class type.
It seems like you are writing the C style of C++.
So I would rewrite the code to make the integration easier.

from ucsan.

linD026 avatar linD026 commented on September 26, 2024

The PR is here:

Please check this out.

from ucsan.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.