CLION 从脚本中调试c++ 程序

问题描述

在以下webget_t.sh脚本中调用了可执行程序webget

#!/bin/bash

WEB_HASH=`./apps/webget cs144.keithw.org /hasher/xyzzy | tee /dev/stderr | tail -n 1`
CORRECT_HASH="QWx0NhMPkoM/bJr/ohvHXlviFhOyYrYb+qqdOnwLYo4"

if [ "${WEB_HASH}" != "${CORRECT_HASH}" ]; then
    echo ERROR: webget returned output that did not match the test\'s expectations
    exit 1
fi
exit 0

想通过CLION在webget.cc上打断点并调试,直接debug 脚本肯定是不行的,因为webget和bash不属于同一个进程。

解决方法

在webget源码中加入

cout << "pid=_______________ " << getpid() <<endl;
for(int i=0;i<30;i++){
    
    
    cout<<"wait"<<i<<endl;
    sleep(1);
}

debug 脚本,然后看到终端输出进程号
在这里插入图片描述
之后借助clion的detach process 功能,找到2818号进程并attach。
等待30秒后,就可以和一般的c++程序一样进行调试了。

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_39849839/article/details/117431382
今日推荐