You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
开发日志
按老师要求转移仓库:
解决 卡在 trap_return 的bug:
sendCommand中添加 console.log([GDB ->] ${command});onOutput中添加 console.log([<- GDB] ${line});整体架构:
各模块职责:
只做一件事:把高层指令翻译成 GDB MI2 协议命令,把 GDB 的输出解析成事件。
关键内容:
sendCommand('break-insert ...')→ 向 GDB 发原始 MI2 命令addBreakPoint(bp)→ 调用上面,同时把断点注册进this.breakpoints: Map<Breakpoint, Number>(key=断点对象,value=GDB编号)clearBreakPoints(file?)→ 遍历this.breakpoints,删掉属于该文件的所有断点——只能删它自己管的breakpoint、step-end、stopped等 Node.js 事件,供上层监听重点:
this.breakpoints是 MI2 维护的"我管理的断点"名单,clearBreakPoints只删名单里的断点。只是一张"状态转换表",定义了:当前在什么状态 + 发生什么事件 → 下一个状态是什么 + 要执行哪些 Action。
四个状态:
五个事件:
关键转换:
try_get_next_breakpoint_group_name+check_if_kernel_to_user_border_yet(均无自动运行 → UI暂停)low_level_switch_breakpoint_group_to_high_level(有自动运行 → 不暂停)check_if_user_to_kernel_border_yet(no-op → UI暂停)high_level_switch_breakpoint_group_to_low_level(有自动运行 → 不暂停)负责记忆各断点组的内容,并在组切换时协调 GDB 操作。
核心数据:
setBreakpointsArguments:用户在 VS Code 里设的断点(文件+行号列表)borders:该组的边界断点位置(如trap_return)hooks:该组的 hook 断点(命中时执行 JS 函数,读取进程名)currentBreakpointGroupName:当前活跃的断点组(初始 = "kernel")nextBreakpointGroup:下次 kernel→user 切换时要切到哪个组(由 hook 决定,如 "user-shell")核心方法
updateCurrentBreakpointGroup(updateTo, continueAfterUpdate):把上面三个模块连接起来,处理 VS Code 发来的 DAP 请求,也处理 GDB 发来的事件。
初始化流程
断点命中时的处理流程(核心)
osStateTransition 的逻辑
Hook 断点机制(决定下一个用户进程是谁)
完整数据流示意
以 rCore 从内核跑到 user-shell 为例:
这就是整个 OS 调试功能的完整逻辑链。状态机决定"停不停",断点组管理决定"GDB 里装哪些断点",边界断点是触发切换的开关,hook 断点是提前预判下一个进程名的机制。
All reactions