dap-mode的文档对我来说太简略了, 配了半天勉强可以对rust bin(就是整个可执行文件)进行debug, 但如何实现类似clion/vscode中对单独测试的调试? 我搜索了一下似乎没看到相关信息, 还请麻烦各位前辈指教.
暂时糊了一个脚本凑合用一下, 要是有更好的方案请各位大佬指出… 我是emacs新手, 很多东西还搞不清楚… ( 依赖 rustic 和 realgud )
(defun rust-my-debugger ()
"debugging unit test near point."
(interactive)
(let*((test-target (format "%s" (rustic-cargo--get-test-target)) )
)
(realgud:gdb (format "rust-debugger -t %s" test-target) nil)
)
)
调用rust-gdb的脚本: rust-debugger (依赖rustup)
#!/bin/bash
debugger=rust-gdb
gdbtmp=/tmp/gdbscript
binary=`cargo test --no-run 2>&1 >/dev/null | grep Executable | cut -d '(' -f2|cut -d ')' -f1 `
used_rustc="/rustc/"`rustc -Vv | grep commit-hash | cut -d' ' -f 2`
tool=`rustup toolchain list | grep '(default)' | cut -d' ' -f 1`
source_code="${HOME}/.rustup/toolchains/${tool}/lib/rustlib/src/rust"
while getopts t: opt
do
case "${opt}" in
t) name=${OPTARG};;
esac
done
echo "set filename-display absolute" > ${gdbtmp}
echo "set substitute-path ${used_rustc} ${source_code}" >> ${gdbtmp}
if [ ! -n "${name}" ]; then
echo "no testname"
else
echo "b ${name}" >> ${gdbtmp}
echo "run --test ${name}" >> ${gdbtmp}
fi
${debugger} ${binary} -x ${gdbtmp}