从 GitLab CI/CD 管道中使用 GDB 运行的程序中检索退出代码

问题描述 投票:0回答:1

我有一个自定义测试二进制文件,我用它来运行特定的系统测试(例如

./test test_case_1.yaml

退出代码

./test
表示系统测试是否成功。

我想防止自己将来出现段错误,这些错误很难通过用 gdb 包装程序调用来重现段错误。如果程序崩溃,我可以自动(无需用户输入:请参阅这个问题)打印堆栈跟踪并查看错误源自何处。

我当前的问题是,一旦启动 gdb,并且没有发生分段错误,我无法检索系统测试的退出代码并将其与我的 gitlab-ci 运行程序一起使用。如果程序崩溃,我怎样才能获得 gdb 回溯,否则只是

./test
的退出代码(就好像没有使用 gdb 一样)?

bash continuous-integration segmentation-fault gdb
1个回答
0
投票

根据 oguz 的回答,我想出了以下脚本:

if [ $? -eq 139 ]; then
  # Get the core dump location
  core_dump_location=$(cat /proc/sys/kernel/core_pattern)
  echo "Core dumps are stored in: $core_dump_location"

  # If it did, find the most recently created coredump and copy it to the current directory
  latest_coredump=$(ls -t ${core_dump_location}* | head -n 1)
  cp "$latest_coredump" .
  
  # Open the coredump with gdb and print the backtrace
  gdb -ex "bt" -batch ./test "$latest_coredump" 
fi
© www.soinside.com 2019 - 2024. All rights reserved.