簡體   English   中英

現在在 Macos 上使用 gdb 在 C 腳本中調試 hello world 時輸出(僅在 script.o 和 a.out 都存在時才有效)

[英]Now output when debugging hello world in a C script with gdb on Macos (only working when both script.o and a.out present)

我在Macos 11.2.3上安裝了gdb 我按照本教程進行了設置,目前有一個包含set startup-with-shell off的文件.gdbinit 我使用以下腳本:

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

int main (){
  printf("hello world");
  return 0;
}

然后我運行了命令:

$ gcc -Wall hello_world.c -o hello_world.o
$ gdb hello_world.o
(gdb) run
...
Starting program: /path/to/hello_world.o
[New Thread 0x2403 of process 10983]

但是不要打印出hello world

現在,如果用gcc hello_world.c生成a.out然后運行gdb hello_world.o (創建hello_world.oa.out )和(gdb) run現在(gdb) run我得到

$ gcc -Wall hello_world.c -o hello_world.o
$ gcc hello_world.c
$ gdb hello_world.o
...
(gdb) run
Starting program: /path/to/hello_world.o
[New Thread 0x2803 of process 15213]
[New Thread 0x1c03 of process 15213]
warning: unhandled dyld version (17)
hello world[Inferior 1 (process 15213) exited normally]

看來, gdb當有兩部作品hello_world.oa.out ,但不是hello_world.o孤單。 為什么? 我究竟做錯了什么? 如何運行gdb並獲取hello world輸出而不必同時使用$gcc -Wall hello_world.c -o hello_world.o$ gcc hello_world.c編譯腳本

編輯根據此 github 鏈接,Macos 似乎存在問題,其中提到了以下內容:

If after hitting run in `gdb`, you get "Starting program: /path/to/your/executable [args] [New Thread 0x2303 of process 795]" followed by a blank line which does not respond to anything, then you have hit GDB bug 24069. Check that you built the patched version from source.

我究竟做錯了什么?

您正在嘗試運行hello.o ,它不是可執行程序,無法運行。

您正在遵循的教程使用gcc hello_world.c -o hello_world -ggdb創建一個可執行文件(注意缺少-c參數)。

好的,我可以按照GDB Wiki BuildingOnDarwin上的說明解決問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM