dev environment

<aside> <img src="/icons/bug_gray.svg" alt="/icons/bug_gray.svg" width="40px" /> make qemu 时,‘runcmd’ 递归调用报错

user/sh.c: In function 'runcmd': user/sh.c:58:1: error: infinite recursion detected [-Werror=infinite-recursion] 58 | runcmd(struct cmd *cmd) | ^~~~~~

xv6-labs-2021/user/sh.c文件中, runcmd函数上面添加设置特殊属性的宏:

Untitled

</aside>

<aside> <img src="/icons/bug_gray.svg" alt="/icons/bug_gray.svg" width="40px" /> m1 mac stuck when compiling on m1 chip mac os

Fix boot on newer qemu #62

modify

kernel/start.c

kernel/kernelvec.S

kernel/riscv.h

start.c

riscv.h

</aside>

<aside> <img src="/icons/bug_gray.svg" alt="/icons/bug_gray.svg" width="40px" /> 为了修复了上面两个 bug,在 util 分支创建了2个 fix 提交,需要同步到其他所有分支。

使用 cherry-pick ,另外使用 git reset 把之前的历史提交合并为一条。

 2024-06-03 at 21.48.13.png

使用 shell 脚本 更新其他10个分支

#!/bin/bash

# fix commit 的哈希值
# 可以通过 git log -2 util 获取
fix_commits=("92f1ba5bebd88cd056abf424296650aa0693dc1c" "eaa749ac48ba3f5012aec493115e3b8adce3aeaf")

# 函数:合并历史 commit 并应用 fix commits
apply_fixes() {
    branch=$1

    git checkout $branch

    git reset $(git rev-list --max-parents=0 HEAD)
    git add .
    git commit --amend -m "archive"

    for commit in "${fix_commits[@]}"; do
        git cherry-pick $commit

        # 检查 cherry-pick 是否成功
        if [ $? -ne 0 ]; then
            echo "Failed to cherry-pick $commit on branch $branch."
            exit 1
        fi
    done

    echo "********************** $branch updated. **********************"
}

# 遍历其他分支
for branch in $(git branch | sed 's/\*//' | grep -vE "util|master|main"); do
    apply_fixes $branch
done

echo "********************** all success **********************"

Untitled

git push --force-with-lease --all

所有分支修复完毕。 开始进入实验部分

</aside>

<aside> <img src="/icons/bug_gray.svg" alt="/icons/bug_gray.svg" width="40px" /> vim lsp 我的编辑器环境为 vim + clangd lsp(language server protocol) 。由于缺失 compile_commands.json 不能正确识别头文件位置

一般来说可以使用 cmake 直接生成 compile_commands.json 文件,但 xv6 使用了 Makefile。只能使用折中一些的办法了

Bear is a tool that generates a compilation database for clang tooling. It can be used for any project based on Makefile.

brew install bear
# generates compile_commands.json
bear -- <your-build-command>

在使用 bear -- make qemu 之后得到了 compile_command.json , LSP 得以正常使用

(linux 上是 bear make qemu)

</aside>

labs

<aside> <img src="/icons/bug_gray.svg" alt="/icons/bug_gray.svg" width="40px" /> ./grade-lab-util sleep 报错 env: python: No such file or directory

安装了 python3 ,那么我创建一个 符号链接python 指向python3 就好了

sudo ln -s /usr/bin/python3 /usr/local/bin/python

还是有一些问题,生气!

那么直接改源码好了

diff --git a/grade-lab-util b/grade-lab-util
index 10a2ba4..399cdd4 100755
--- a/grade-lab-util
+++ b/grade-lab-util
@@ -1,10 +1,11 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3

</aside>

<aside> <img src="/icons/bug_gray.svg" alt="/icons/bug_gray.svg" width="40px" />

GDB 调试 xv6

GDB 需要 x81 架构, GDB 不支持 arm 架构的 m1 mac

gdb: The x86_64 architecture is required for this software.
Error: gdb: An unsatisfied requirement failed this build.

使用 lldb 替代

调试 xv6 的方式 https://pdos.csail.mit.edu/6.828/2022/labs/gdb.html

https://lldb.llvm.org/use/map.html#attach-to-a-remote-gdb-protocol-server-running-on-system-eorgadd-port-8000

</aside>

<aside> <img src="/icons/bug_gray.svg" alt="/icons/bug_gray.svg" width="40px" /> make: *** No rule to make target 'mkfs/mkfs.c', needed by 'mkfs/mkfs'. Stop.

世界是一个巨大的草台班子

由于上面的 GDB 问题,我打算临时切换到 阿里云服务器 x86,我克隆了自己的 Git 仓库,在 make qemu 的时候遇到了报错。于是看了一下 Makefile

mkfs/mkfs: mkfs/mkfs.c $K/fs.h $K/param.h
       gcc -Werror -Wall -I. -o mkfs/mkfs mkfs/mkfs.c

然后就去找 mkfs/mkfs.c 。问题来了,仓库里没有这个文件!如果是从官方仓库克隆是有 mkfs 这个文件夹的。我察觉的一丝异样,打开了 .gitignore 文件,感觉有些无语。

Untitled

Untitled

他的本意是 ignore mkfs 这个二进制文件,应该改为下面

diff --git a/.gitignore b/.gitignore
index b1d8932..7d66fa1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,7 +11,7 @@ entryother
 initcode
 initcode.out
 kernelmemfs
-mkfs
+mkfs/mkfs
 kernel/kernel
 user/usys.S
 .gdbinit

想必他是先提交了 mkfs/mkfs.c 后来又改的 .gitignore