macos OS X 上的 gprof 问题:[程序] 不属于主机架构

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1101545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:15:56  来源:igfitidea点击:

Problem with gprof on OS X: [program] is not of the host architecture

macosgccgprof

提问by Jesse Beder

I'm having trouble running gprofon OS X. The file test.cis:

gprof在 OS X 上运行时遇到问题。文件test.c是:

#include <stdio.h>

int main() {
  printf("Hello, World!\n");
  return 0;
}

and my terminal looks like:

我的终端看起来像:

$ gcc -pg test.c
$ gcc -pg -o test test.c
$ ./test
Hello, World!
$ gprof test
gprof: file: test is not of the host architecture

Edit: also, it doesn't generate the file gmon.out.

编辑:此外,它不会生成文件gmon.out.

What's going on here?

这里发生了什么?

采纳答案by Curtis Tasker

The series of events here is supposed to work as follows:

这里的一系列事件应该如下工作:

  1. Compile code with -pgoption
  2. Link code with -pgoption
  3. Run program
  4. Program generates gmon.outfile
  5. Run gprof
  1. 使用-pg选项编译代码
  2. -pg选项的链接代码
  3. 运行程序
  4. 程序生成gmon.out文件
  5. gprof

The problem is that step 4 never happens. There's very little information out about this specific failure. The general consensus over the past few years seems to be that Apple would rather use shark instead, and they've been very lax about fixing bugs and such with gprof.

问题是第 4 步永远不会发生。关于此特定故障的信息很少。过去几年的普遍共识似乎是,Apple 更愿意使用shark 来代替,而且他们在使用gprof.

In short: Install Xcode, man shark

简而言之:安装Xcode, man shark

回答by mark4o

Unfortunately gprofdoes not work on Mac OS X. You'll probably want to use Sharkinstead. It is part of the developer tools in /Developer/Applications/Performance Tools/Shark.

不幸的是,gprof它不适用于 Mac OS X。您可能想Shark改用它。它是/Developer/Applications/Performance Tools/Shark.

Update:It appears as though gprofis now working on Mac OS X 10.6 (Snow Leopard), using the latest Developer Tools.

更新:看起来好像gprof现在正在使用最新的开发人员工具在 Mac OS X 10.6 (Snow Leopard) 上工作。

回答by D.Shawley

It sounds like testis built using an architecture that gprofdoesn't expect. Try the following:

听起来像是test使用一种gprof意想不到的架构构建的。请尝试以下操作:

$ cat > test2.c
#include <stdio.h>
int main() { printf("test\n"); return 0; }
^D
$ gcc -arch i386 -pg -o test2 test2.c
$ file test2
test2: Mach-O executable i386
$ ./test2
test
$ gprof test2
... bunch of output ...
$ gcc -arch ppc -pg -o test2 test2.c
$ file test2
test: Mach-O executable ppc
$ ./test2
test
$ gprof test2
gprof: file: test2 is not of the host architecture
$ arch -ppc gprof test2
... same bunch of output ...

The newer MacOS supports running executables from either the IBM PPC and Intel x86 architecture. Some of the tool chain seems to be a bit dense about this. Gprof seems to expect the executable to be in the native architecture. However, if you use the archutility to force the non-native architecture to be executed, then it seems to work properly. There was a discussion about this in another contexta little while ago. I included some useful links and some more information there.

较新的 MacOS 支持运行来自 IBM PPC 和 Intel x86 架构的可执行文件。一些工具链似乎对此有点密集。Gprof 似乎希望可执行文件位于本机架构中。但是,如果您使用该arch实用程序强制执行非本机架构,那么它似乎可以正常工作。有一个在另一语境中的讨论一会儿前。我在那里包含了一些有用的链接和更多信息。