2015-04-25 55 views
1

設置考慮下面的代碼:GDB和LLDB 「燕子」 狀態的子進程在OS X

#include <stdio.h> 
#include <signal.h> 
#include <unistd.h> 
#include <sys/wait.h> 

int main(int ac, char** av) { 
    int status; 
    pid_t cpid = fork(); 
    if(0 == cpid) { /* Child */ 
     return *(volatile int*) 0; /* exits with signal 11 */ 
    } else { /* Parent */ 
     do { 
      waitpid(cpid, &status, WUNTRACED); 
      if(WIFSIGNALED(status)) { 
       printf("\nChild exited with signal %d\n\n", WTERMSIG(status)); 
       return 0; 
      } 
     } while (!WIFEXITED(status) && !WIFSIGNALED(status)); 
     printf("\nChild exited normally\n\n"); 
    } 
    return 0; 
} 

我從終端運行的應用程序預期的結果:

$ ./Fork4GdbTests.exe 

Child exited with signal 11 

運行App內LLDB(或GDB),奇怪的是,我得到:

$ lldb ./Fork4GdbTests.exe 
(lldb) target create "./Fork4GdbTests.exe" 
Current executable set to './Fork4GdbTests.exe' (x86_64). 
(lldb) r 
Process 46815 launched: './Fork4GdbTests.exe' (x86_64) 

Child exited normally 

Process 46815 exited with status = 0 (0x00000000) 

我的Makefile文件看起來像這樣(用於Cygwin的,也可以):

CC = gcc 
CFLAGS = -Wextra -Wall -Werror -Wno-unused-parameter -g 
.PHONY: all clean 
all: Fork4GdbTests.exe 
%.exe: %.o 
    $(CC) $(CFLAGS) $? $(LIBS) -o [email protected] 
clean: 
    rm -f *.o *.exe *.stackdump; 

在Cygwin中,我得到了從命令提示符和調試器中運行的預期結果。對於各種其他信號(如SIGFPE或通過kill()發送給孩子的任何信號)都會發生類似的行爲。

這是怎麼回事?

回答

1

這只是一個錯誤。由於它影響GDB & LLDB它可能是在CoreOS沒有調試器(儘管是同一人既沒有調試器的馬赫特定層,這樣也無法保證......)

無論如何,請文件,http://bugreporter.apple.com一個bug報告。