WSL + Visual Studio -无法正确调试信号

zc0qhyus  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(106)

我正在Visual Studio下调试此代码(不是Visual Studio代码):

#include <cstdio>
#include <signal.h>
#include <unistd.h>

int n = 0;

void handleSignal(int sig) {
//it works from terminal but not from IDE
    printf("Signal received: %d - %d times\n", sig ,++n);
}

int main()
{
    printf("Hi From WSL! - PID: %d\n", getpid());
    auto s = signal(SIGUSR1, handleSignal);

    printf("signal was %d\n", s); // prints 0

    while (n<10) {
        printf("sleeping - %d\n", n);
        sleep(1);    
    }
    printf("Received signals %d timeskill , exiting\n", n);
    return 0;
}

字符串
我跑

kill -10 <pid of process>


如果我从bash运行代码,一切正常

# output if run from bash:
$ ./LinuxConsoleApplicationWsl.out
Hi From WSL! - PID: 4953
signal was 0
sleeping - 0
sleeping - 0
sleeping - 0
sleeping - 0
sleeping - 0
sleeping - 0
sleeping - 0
sleeping - 0
sleeping - 0
Signal received: 10 - 1 times
sleeping - 1
sleeping - 1
Signal received: 10 - 2 times
sleeping - 2
Signal received: 10 - 3 times
sleeping - 3
Signal received: 10 - 4 times
sleeping - 4
Signal received: 10 - 5 times
sleeping - 5
Signal received: 10 - 6 times
sleeping - 6
Signal received: 10 - 7 times
sleeping - 7
sleeping - 7
sleeping - 7
Signal received: 10 - 8 times
sleeping - 8
Signal received: 10 - 9 times
sleeping - 9
Signal received: 10 - 10 times
Received signals 10 timeskill , exiting


(do printfs and at 10th signal sent the app exits)但是如果我从visual studio运行它,我得到了这个未处理的异常:


的数据
我错过了什么?

luaexgnf

luaexgnf1#

我自己的回答:更新VS到版本17.6.5修复了这个问题,现在信号是可调试的。
作为一个说明,我报告说,“异常”仍然是这样通知,但与调试器的工作步进。

相关问题