简体   繁体   English

gdb无法在Mac OS X中调试“ Hello World”

[英]gdb can not debug “hello world” in mac os x

I have the following smal C++ program 我有以下smal C ++程序

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    puts("!!!Hello World!!!");
    return EXIT_SUCCESS;
}

I compile in Mac OS X Leopard last release using: 我在Mac OS X Leopard的最新版本中使用以下命令进行编译:

g++ -g hello.cpp -o hello.exe

being g++: 是g ++:

host:bin macbook$ g++ --ver
Using built-in specs.
Target: i686-apple-darwin9
Configured with: /var/tmp/gcc/gcc-5493~1/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic --host=i686-apple-darwin9 --target=i686-apple-darwin9
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5493)

then I try to debug this program using fsf-gdb 7.1: 然后我尝试使用fsf-gdb 7.1调试此程序:

fsf-gdb hello.exe

put a breakpoint in main: 在main中设置一个断点:

(gdb) b main
Breakpoint 1 at 0x1f8f: file hello.cpp, line 5.

run the program: 运行程序:

(gdb) r
Starting program: /Users/horacio/work/software/gdb/gdb-7.2-inst/bin/hello.exe 

Breakpoint 1, main () at hello.cpp:5
5       puts("!!!Hello World!!!");

and try to step, and this happens: 并尝试执行步骤,就会发生这种情况:

(gdb) n
0x00003045 in ?? ()

This is the output if I do the same under Ubuntu Linux: 如果在Ubuntu Linux下执行相同的操作,则这是输出:

(gdb) n
!!!Hello World!!!
6       return EXIT_SUCCESS;

where gdb=7.1 and g++=4.3.4 其中gdb = 7.1和g ++ = 4.3.4

What is the problem ???? 问题是什么 ???? I honestly do not understand why this does not work in mac os x. 老实说,我不明白为什么这在Mac OS X中不起作用。

Maybe the problem is the gdb version used in mac or the gcc version in mac. 可能是Mac中使用的gdb版本或Mac中的gcc版本。 Which other alternatives exist for gdb in mac? 在Mac中,gdb还有哪些其他选择?

Thanks in advance 提前致谢

PS: Apple Leopard's gdb does not produce this error. PS:Apple Leopard的gdb不会产生此错误。 But I want to use Eclipse CDT, and it can not work with Apple's gdb, that is why I am trying to use a non-Apple gdb version. 但是我想使用Eclipse CDT,并且它不能与Apple的gdb一起使用,这就是为什么我尝试使用非Apple gdb版本的原因。

This works fine if you use the gdb bundled with Mac. 如果您使用与Mac捆绑在一起的gdb,则效果很好。 Apple's gcc includes some small Apple-specific extensions, so would not be surprised that it is not 100% compatible with some other version of gdb. Apple的gcc包含一些特定于Apple的小型扩展,因此它并不与某些其他版本的gdb 100%兼容也就不足为奇了。 You may also have built your custom gdb incorrectly. 您可能还没有正确构建自定义gdb。

You mention that your g++ is 4.3.4, but the one you show above is 4.0.1. 您提到您的g ++是4.3.4,但是上面显示的是4.0.1。

Propably not releted to the actual issue but do remember that when you compile for debugging purposes, disable compiler optimizations with -O0 flag. 可能没有重提实际问题,但请记住,当您出于调试目的进行编译时,请使用-O0标志禁用编译器优化。 If you don't pass that for gcc when compiling, you will get "funky" results when you are doing step execution with gdb. 如果在编译时未将其传递给gcc,则在执行gdb的步骤执行时会得到“笨拙”的结果。

My first thought was that your fsf-gdb doesn't understand Mach-0 binaries. 我的第一个想法是您的fsf-gdb不了解Mach-0二进制文件。

A quick look at Google came back with: http://reverse.put.as/2009/01/14/how-to-compile-gdb-and-other-apple-open-source-packages-in-mac-os-x/ which reveals that building gdb is not quite as trivial as one might think. 快速浏览一下Google,结果是: http : //reverse.put.as/2009/01/14/how-to-compile-gdb-and-other-apple-open-source-packages-in-mac-os -x /揭示了构建gdb并不像人们想象的那么简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM