簡體   English   中英

gdb無法在Mac OS X中調試“ Hello World”

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

我有以下smal C ++程序

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

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

我在Mac OS X Leopard的最新版本中使用以下命令進行編譯:

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

是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)

然后我嘗試使用fsf-gdb 7.1調試此程序:

fsf-gdb hello.exe

在main中設置一個斷點:

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

運行程序:

(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!!!");

並嘗試執行步驟,就會發生這種情況:

(gdb) n
0x00003045 in ?? ()

如果在Ubuntu Linux下執行相同的操作,則這是輸出:

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

其中gdb = 7.1和g ++ = 4.3.4

問題是什么 ???? 老實說,我不明白為什么這在Mac OS X中不起作用。

可能是Mac中使用的gdb版本或Mac中的gcc版本。 在Mac中,gdb還有哪些其他選擇?

提前致謝

PS:Apple Leopard的gdb不會產生此錯誤。 但是我想使用Eclipse CDT,並且它不能與Apple的gdb一起使用,這就是為什么我嘗試使用非Apple gdb版本的原因。

如果您使用與Mac捆綁在一起的gdb,則效果很好。 Apple的gcc包含一些特定於Apple的小型擴展,因此它並不與某些其他版本的gdb 100%兼容也就不足為奇了。 您可能還沒有正確構建自定義gdb。

您提到您的g ++是4.3.4,但是上面顯示的是4.0.1。

可能沒有重提實際問題,但請記住,當您出於調試目的進行編譯時,請使用-O0標志禁用編譯器優化。 如果在編譯時未將其傳遞給gcc,則在執行gdb的步驟執行時會得到“笨拙”的結果。

我的第一個想法是您的fsf-gdb不了解Mach-0二進制文件。

快速瀏覽一下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