c - 如何在命令行应用程序中使用 Instruments 和显示控制台

标签 c xcode debugging macos instruments

<分区>

我在 OSX 上使用 Xcode 开发命令行 C 应用程序。我还想使用 Instruments 来分析和查找内存泄漏。

但是,当从 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);
}

这是我在启动 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.

有什么想法吗?

最佳答案

这很容易。查看屏幕截图。

screenshot

关于c - 如何在命令行应用程序中使用 Instruments 和显示控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1735000/

相关文章:

xcode - autoconf : command not found Installing Cappuccino (Objective J)

python - 请参阅 Pydev 调试中的队列项目

java - intellij GWT调试配置

c - 使用 Eclipse 时在 Windows 上分析 C 代码

C 程序在使用 scanf 获取用户输入时显示垃圾值

c - 比较运算符的求值顺序?

objective-c - 用灰色突出显示 UIImageView

c - 对 GetConsoleWindow 的 undefined reference

swift - 我无法在 Swift 3 中使用计时器更改 label.text

xcode - 作为根进程调试的测试目标