我正在迭代调用者堆栈以生成返回堆栈。但是,最顶层的框架具有生成错误的正确函数名称和源文件路径,但行号大于文件中的行数。这是否属于某种运行时解析和行号偏斜?
function backtrace() {
i=${1:-0}
while caller $i >/dev/null ; do
caller $i | while read ln fn src ; do
printf >&2 " File \"%s\", line %d, in %s\n" \
"$src" "$ln" "$fn()"
done
(( i++ )) || true
done
}
除了这种情况之外,这个功能在任何地方都能完美运行。该文件包含107行,但错误的行号报告为第128行。
Traceback
File "/home/phillipc/dev/extra/CI/jenkins/lib/soap.sh", line 128, in soap()
File "./qasoap.sh", line 10, in request()
File "./qasoap.sh", line 36, in _qa_soap()
File "./qasoap.sh", line 147, in qa_soap()
File "./qasoap.sh", line 164, in main()
ERROR: traps.sh: Unhandled error (exitcode: 8)