zoukankan      html  css  js  c++  java
  • How use Instruments and display the console in Command Lines applications

    I'm using Xcode on OSX to develop command line C applications. I would also like to use Instruments to profile and find memory leaks.

    However, I couldn't find a way to display the console when launching the application from within Instruments. I'm also unable to attach to a running command line process (it exits with an error):

    Here's an example code:

    #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
    ", 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
    ", buf);
        }
    
        return(0);
    }

    Here's the error I got after launching Instruments, and trying to attach to the running process in 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.

    Any thoughts?

    share|improve this question
      add comment

    3 Answers

    See this question for your answer.

    From Brad Larson therein:

    Run your application from within Xcode to have the console output piped there. While your application is running, start Instruments and choose an appropriate instrument. Under Default Target in the menu bar, select iPhone or Computer (whichever is appropriate for what you're testing), and under Attach to Process find the name of your executable.

    When you click the record button, your application should start being profiled under Instruments while having its console output directed to Xcode. Unfortunately, this attachment process will need to come after the application has started, so you may have to profile the startup of your application separately.

    Edit: If that didn't work, you may just need to restart your computer. Have you done that yet?

  • 相关阅读:
    使用jedis操作redis常用方法
    PostgreSQL下安装pg_stat_statements
    redis+keepalived安装
    eclipse离线安装Activiti Designer插件
    PostgreSQL下安装pg_stat_statements
    mysql设置索引
    使用appium在android7.0真机上测试程序时报错command failed shell “ps ‘uiautomator’”的解决方式
    appium--adb版本过低
    appium报错--版本不匹配
    win7提示不是正版桌面变黑
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4640863.html
Copyright © 2011-2022 走看看