Hug*_*ira 21 c debugging macos xcode instruments
我在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:
sharedlibrary apply-load-rules all
Error while running hook_stop:
Invalid type combination in ordering comparison.
Error while running hook_stop:
Invalid type combination in ordering comparison.
Error while running hook_stop:
Error while running hook_stop:
Error while running hook_stop:
Error while running hook_stop:
Error while running hook_stop:
Error while running hook_stop:
Error while running hook_stop:
Unable to disassemble __CFInitialize.
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
tro*_*foe 15
为这个旧线程做贡献有点晚了,但我发现分析命令行实用程序的最佳方法是使用iprofiler(联机帮助页).这允许从命令行收集数据,只需将其添加到命令行的开头:
iprofiler -leaks -d $HOME/tmp
Run Code Online (Sandbox Code Playgroud)
(我有一个私有临时目录$HOME/tmp,因此您可能需要完全使用/tmp或保留-d命令行选项).
如果$FINDLEAKS已定义,我的测试脚本会自动将其添加到命令行(并且valgrind如果在Linux下运行,则会预先添加).
然后,这将生成一个.dtps文件(实际上是一个目录),可以使用Instruments加载和分析.
如果您正在编译使用,clang那么只需添加两个-O3和-g(clang不支持-pg命令行选项).
| 归档时间: |
|
| 查看次数: |
13437 次 |
| 最近记录: |