加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
dbgvim 2.39 KB
一键复制 编辑 原始数据 按行查看 历史
glepnir 提交于 2024-08-31 16:54 . update
#!/bin/bash
# Function to print usage
print_usage() {
echo "Usage: dbgvim [-f filename -l lnum] [-t testfile] [functionname]"
echo " dbgvim help"
exit 1
}
# Check if help is requested or no arguments are passed
if [ "$1" == "help" ]; then
print_usage
fi
# Variables for function name, filename, line number, and test file
functionname=""
filename=""
lnum=""
testfile=""
# Parse command line arguments
while getopts "f:l:t:" opt; do
case $opt in
f) filename=$OPTARG ;;
l) lnum=$OPTARG ;;
t) testfile=$OPTARG ;;
\?) print_usage ;;
esac
done
shift $((OPTIND -1))
# Remaining argument should be the function name
if [ $# -eq 1 ]; then
functionname=$1
fi
# Determine which debugger to use
if command -v lldb &> /dev/null; then
debugger="lldb"
elif command -v gdb &> /dev/null; then
debugger="gdb"
else
echo "Neither lldb nor gdb is installed"
exit 1
fi
# Function to attach debugger to the process and set a breakpoint
attach_and_set_breakpoint() {
local pid=$1
if [ "$debugger" = "lldb" ]; then
if [ -n "$functionname" ]; then
lldb -p "$pid" -o "breakpoint set -n $functionname" -o "continue"
elif [ -n "$filename" ] && [ -n "$lnum" ]; then
lldb -p "$pid" -o "breakpoint set -f $filename -l $lnum" -o "continue"
else
lldb -p "$pid"
fi
elif [ "$debugger" = "gdb" ]; then
if [ -n "$functionname" ]; then
gdb -p "$pid" --batch -ex "break $functionname" -ex "continue"
elif [ -n "$filename" ] && [ -n "$lnum" ]; then
gdb -p "$pid" --batch -ex "break $filename:$lnum" -ex "continue"
else
gdb -p "$pid"
fi
fi
}
# Determine if we are in a Neovim or Vim directory
if [ -n "$testfile" ]; then
if [[ "$testfile" == *.lua || "$testfile" == *.vim ]]; then
if [ -f "./build/bin/nvim" ]; then
./build/bin/nvim --clean -u "$testfile"
elif [ -f "./src/vim" ]; then
./src/vim --clean -u "$testfile"
else
echo "Neither Neovim nor Vim binary found in the current directory."
exit 1
fi
else
echo "Test file must be a .lua or .vim file."
exit 1
fi
exit 0
fi
# Find and attach to the nvim process
pid=$(ps aux | grep "[.]\/build\/bin\/nvim --embed" | awk '{print $2}')
if [ -n "$pid" ]; then
attach_and_set_breakpoint "$pid"
fi
# Find and attach to the vim process
pid=$(ps aux | grep "src\/vim\|\.\/vim" | awk '{print $2}')
if [ -n "$pid" ]; then
attach_and_set_breakpoint "$pid"
fi
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化