MIT S081 Lab 2 System Calls

Lab链接

一 实现trace功能

1 题目要求

In this assignment you will add a system call tracing feature that may help you when debugging later labs. You'll create a new trace system call that will control tracing. It should take one argument, an integer "mask", whose bits specify which system calls to trace. For example, to trace the fork system call, a program calls trace(1 << SYS_fork), where SYS_fork is a syscall number from kernel/syscall.h. You have to modify the xv6 kernel to print out a line when each system call is about to return, if the system call's number is set in the mask. The line should contain the process id, the name of the system call and the return value; you don't need to print the system call arguments. The trace system call should enable tracing for the process that calls it and any children that it subsequently forks, but should not affect other processes.

We provide a trace user-level program that runs another program with tracing enabled (see user/trace.c). When you're done, you should see output like this:

cpp 复制代码
$ trace 32 grep hello README
3: syscall read -> 1023
3: syscall read -> 966
3: syscall read -> 70
3: syscall read -> 0
$
$ trace 2147483647 grep hello README
4: syscall trace -> 0
4: syscall exec -> 3
4: syscall open -> 3
4: syscall read -> 1023
4: syscall read -> 966
4: syscall read -> 70
4: syscall read -> 0
4: syscall close -> 0
$
$ grep hello README
$
$ trace 2 usertests forkforkfork
usertests starting
test forkforkfork: 407: syscall fork -> 408
408: syscall fork -> 409
409: syscall fork -> 410
410: syscall fork -> 411
409: syscall fork -> 412
410: syscall fork -> 413
409: syscall fork -> 414
411: syscall fork -> 415
...
$   

trace是一个运行在用户空间的程序。 你需要实现一个用户空间程序 trace,它将启动另一个程序并启用跟踪功能。

trace调用时,会传入一个int类型的mask值,来指明需要对哪些系统调用trace。

获取argument,获取系统调用号、

相关推荐
m0_380921801 小时前
容器虚拟化基础之LXC
linux
cidgur1 小时前
svn and maven 自动部署shell脚本
linux
孤独野指针*P1 小时前
MoveIt 机械臂碰撞检测:从环境搭建到障碍物规避
linux·3d·机器人
刘某的Cloud2 小时前
SSH命令建立隧道
linux·运维·ssh·系统·shell
weixin_471525785 小时前
【gdb/sqlite3移植/mqtt】
linux·运维·服务器
大聪明-PLUS5 小时前
TCP/IP 协议族—理论与实践(一)
linux·嵌入式·arm·smarc
灵感__idea8 小时前
Hello 算法:让前端人真正理解算法
前端·javascript·算法
向葭奔赴♡8 小时前
CSS是什么?—— 网页的“化妆师”
前端·css
黑犬mo8 小时前
在Edge、Chrome浏览器上安装uBlock Origin插件
前端·edge
excel8 小时前
🧩 Vue 3 watch 源码详解(含完整注释)
前端·javascript·vue.js