小编Sba*_*ila的帖子

qemu 跟踪哪些指令?

我编写了以下代码,它逐步遍历/bin/ls并计算其指令:

#include <stdio.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/user.h>
#include <sys/reg.h>    
#include <sys/syscall.h>

int main()
{   
    pid_t child;
    child = fork(); //create child
    
    if(child == 0) {
        ptrace(PTRACE_TRACEME, 0, NULL, NULL);
        char* child_argv[] = {"/bin/ls", NULL};
        execv("/bin/ls", child_argv);
    }
    else {
        int status;
        long long ins_count = 0;
        while(1)
        {
            //stop tracing if child terminated successfully
            wait(&status);
            if(WIFEXITED(status))
                break;

                ins_count++;
                ptrace(PTRACE_SINGLESTEP, child, NULL, NULL);
        }

    printf("\n%lld Instructions executed.\n", ins_count);

    }
    
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

运行此代码可以执行大约 …

c linux ptrace qemu instructions

4
推荐指数
1
解决办法
2712
查看次数

标签 统计

c ×1

instructions ×1

linux ×1

ptrace ×1

qemu ×1