我在OSX上使用Xcode来开发命令行C应用程序.我还想使用Instruments来分析和查找内存泄漏.
但是,在从仪器内启动应用程序时,我找不到显示控制台的方法.我也无法附加到正在运行的命令行进程(它退出时出错):
这是一个示例代码:
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <setjmp.h>
static sigjmp_buf jmpbuf;
void handler(int sig) {
char c[BUFSIZ];
printf ("Got signal %d\n", sig);
printf ("Deseja sair? (s/n) ");
fgets(c, sizeof(c), stdin);
if(c[0] == 's') {
exit(0);
} else {
siglongjmp(jmpbuf, 1);
}
}
int main(void) {
char buf[BUFSIZ];
signal(SIGINT, handler);
sigsetjmp(jmpbuf, 1);
while(1) {
printf(">>>");
fgets(buf, sizeof(buf), stdin);
printf ("Introduziu: %s\n", buf);
}
return(0);
}
Run Code Online (Sandbox Code Playgroud)
这是我启动Instruments后尝试连接到xcode中正在运行的进程时出现的错误:
[Switching to process 1475]
[Switching to process 1475]
Error while running hook_stop: …Run Code Online (Sandbox Code Playgroud)