使用gaddr2line时的BFD未知命令

时间:2014-01-14 00:29:03

标签: c macos backtrace addr2line bfd

我正在尝试使用gaddr2line打印更漂亮版本的回溯符号。我只是从backtrace()获取地址,然后通过使用gaddr2line执行它来将它们提供给popen。在linux下使用addr2line工作正常,但由于某种原因,我在OS X上使用gaddr2line时会遇到奇怪的错误。在Mac OS上尝试这个时我不断得到BFD: ... : unknown load command ...我看到了一些帖子提到GDB,所以我尝试用自制软件安装,但这没有帮助。

这是我的代码:

    // set to the maximum possible path size
    char exe_path[4096];

    // Used to check if an error occured while setting up command
    bool error = false;

    // Check if we are running on Mac OS or not, and select appropriate command
    char* command;
    #ifdef __APPLE__
        // Check if 'gaddr2line' function is available, if not exit
        if( !system( "which gaddr2line > /dev/null 2>&1" ) ) {
            command = "gaddr2line -Cfspe";
            pid_t pid = getpid();
            int path_length = proc_pidpath( pid, exe_path, sizeof( exe_path ) );
            if( path_length <= 0 ) {
                writeLog( SIMPLOG_LOGGER, "Unable to get execution path. Defaulting to standard backtrace." );
                error = true;
            }
            exe_path[path_length] = 0;
        } else {
            writeLog( SIMPLOG_LOGGER, "Function 'gaddr2line' unavailable. Defaulting to standard backtrace. Please install package 'binutils' for better stacktrace output." );
            error = true;
        }
    #endif

这是输出:

gaddr2line -Cfspe /Users/nate/git/SimpleLogger/build/test 7408927
BFD: /Users/nate/git/SimpleLogger/build/test: unknown load command 0x2a
BFD: /Users/nate/git/SimpleLogger/build/test: unknown load command 0x28
BFD: /Users/nate/git/SimpleLogger/build/test: unknown load command 0x29
BFD: /Users/nate/git/SimpleLogger/build/test: unknown load command 0x2b

0 个答案:

没有答案