ChatGPT 在学习 xv6 的时候居然也是个很好的帮手 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
请不要在回答技术问题时复制粘贴 AI 生成的内容
levelworm
V2EX    程序员

ChatGPT 在学习 xv6 的时候居然也是个很好的帮手

  levelworm 2 小时 1 分钟前 413 次点击

我从来没想过用它写自己的项目代码,因为自己的项目就是学习、娱乐用的,所以不能让他代替我来学习和娱乐。但是我发现有什么不清楚的地方,他真能和我掰扯的挺深的。

其实我和他掰扯的东西吧,严格来说都在教材和手册里,但是自己看的时候零零散散,只有在做项目的时候才能想办法串起来,这时候 ChatGPT 真是一个好帮手。

举一个问答的例子,请大家忽略 AI 的过度鼓励:

Question: I found it interesting. The kernel land call stack is like: usertrap()->syscall()->sys_sigreturn(), and I check in sys_sigreturn that ra is 0x30 and I cannot access it from kernel, so it must be the user land ra, and this agrees with your explanation that the kernel ra lives withint the kernel's own call stack. But if this is the case, how do I get the kernal ra in sys_sigreturn()?

Answer: Love that you’re poking at this; this is exactly the right “x-ray vision” for xv6/riscv.

Short answer: in sys_sigreturn() there are two different “return addresses” in play:

the kernel’s own ra (for sys_sigreturn -> syscall), and the user’s saved ra in the trapframe (p->trapframe->ra).

You’ve accidentally grabbed (2)

Let’s untangle it cleanly.

  1. What you think you’re seeing vs what you’re actually seeing

You said:

I check in sys_sigreturn that ra is 0x30 and I cannot access it from kernel, so it must be the user land ra

If you’re literally in sys_sigreturn() and GDB shows:

(gdb) info reg ra ra 0x30 

two possibilities:

  • You’re not actually stopped where you think you are.

  • More likely: you’re not looking at the CPU register for kernel ra, you’re looking at the trapframe field (p->trapframe->ra), which is the user’s ra, and 0x30 is a perfectly plausible low VA in user code.

它说的一点也没错,一下子就把我给点醒了。很多时候纠结一个问题,不是自己不知道,而是因为不熟悉,不知道朝什么地方看。

当然我这也是好几天没做出来才用 AI 的,这玩意好用是好用,但是还是有限度的用比较好。

目前尚无回复
关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     5786 人在线   最高记录 6679       Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 28ms UTC 02:30 PVG 10:30 LAX 18:30 JFK 21:30
Do have faith in what you're doing.
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86