gdb调试c语言在poll函数卡住,gdb调试包含popen的程序,程序停在popen中,导致gdb假死状态,无法退出...
1、程序中包含popen()调用,在使用gdb调试时,gdb假死,定位到程序运行到popen2、编写测试程序验证,确实如此,程序如下:int main(int argc, char *argv[]){char buf[128];FILE *pp;printf("%s,%d\n", __FILE__, __LINE__);if( (pp = popen("ls -l", "r")) == NULL
1、程序中包含popen()调用,在使用gdb调试时,gdb假死,定位到程序运行到popen
2、编写测试程序验证,确实如此,程序如下:
int main(int argc, char *argv[])
{
char buf[128];
FILE *pp;
printf("%s,%d\n", __FILE__, __LINE__);
if( (pp = popen("ls -l", "r")) == NULL ){
printf("popen() error!/n");
exit(1);
}
printf("%s,%d\n", __FILE__, __LINE__);
while(fgets(buf, sizeof buf, pp)){
printf("%s", buf);
}
printf("%s,%d\n", __FILE__, __LINE__);
pclose(pp);
printf("%s,%d\n", __FILE__, __LINE__);
return 0;
}
3、gdb日志
GNU gdb (GDB) 7.10.1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-openwrt-linux".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/g....
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/g....
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /mnt/nfs/work01/src2git/test-share/main...done.
(gdb) r
Starting program: /mnt/nfs/work01/src2git/test-share/main
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
main.c,92
^C^C^C^C
程序停在popen语句,ctrl+c无法退出。
4、google时,有人提出是popen fork进程导致GDB混乱,未给出好的解决办法(不使用popen)
https://daniel.haxx.se/blog/2...
是否有高手可以解决这个问题,或者有其他方法调用shell命令并获得返回值
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)