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,获取系统调用号、

相关推荐
嵌入式×边缘AI:打怪升级日志15 小时前
Linux 驱动与应用开发核心自测题库(面试官问答完整版)
linux·运维·php
牛蛙点点申请出战16 小时前
IconFontViewer -- 一个可以在 Android Studio 中实时预览 IconFont 的插件
android·前端·intellij idea
是上好佳佳佳呀17 小时前
【前端(十三)】JavaScript 数组与字符串笔记
前端·javascript·笔记
巴沟旮旯儿17 小时前
vite项目配置文件和打包
前端·设计模式
薛定谔的悦17 小时前
储能充放电状态机执行逻辑详解
linux·数据库·能源·储能·bms
彩票管理中心秘书长17 小时前
Pinia 插件架构与组合式函数:如何让你的 Store 长出“超能力”
前端
彩票管理中心秘书长17 小时前
Pinia 比 Vuex 强在哪?我用同一个模块写了两种实现,你自己看
前端
yingyima17 小时前
用 Cron 加 Webhook 打通自动化工作的任督二脉
前端
JackieDYH17 小时前
CSS Flexbox 与 Grid 的默认行为-布局的底层机制
前端·css·html