2013-05-26 72 views
3

我有函數system()調用已經編譯過的單獨腳本。但我希望能夠在THAT特定文件中的函數中設置斷點。通過系統執行外部程序時的GDB斷點()

所以:

文件:

system("./fileB"); 

文件B:

void main() { 
/* etc */ 
} 

我希望能夠在主要設置斷點系統命令後調用。

任何幫助,將不勝感激!

回答

3

較新版本的GDB的(7.1+)可以debug multiple programs at once並且確實可以支持這一點:

運行program.c

#include <stdlib.h> 

int main() 
{ 
    system("./program-i-want-to-debug"); 
    return 0; 
} 

程序多多益善到debug.c

#include <stdio.h> 

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

run-program.gdb

set detach-on-fork off 
set target-async on 
set pagination off 
set non-stop on 

add-inferior -exec program-i-want-to-debug 
break program-i-want-to-debug.c:5 
file run-program 
run 

inferior 3 
backtrace 

樣品會議

$ gdb -q -x run-program.gdb 
Added inferior 2 
Breakpoint 1 at 0x400441: file program-i-want-to-debug.c, line 5. 
[New process 20297] 
process 20297 is executing new program: /usr/bin/bash 
process 20297 is executing new program: /home/scottt/Dropbox/stackoverflow/program-i-want-to-debug 
Reading symbols from /home/scottt/Dropbox/stackoverflow/program-i-want-to-debug...done. 

Breakpoint 1, main() at program-i-want-to-debug.c:5 
5  printf("Hello, World\n"); 
[Switching to inferior 3 [process 20297] (/home/scottt/Dropbox/stackoverflow/program-i-want-to-debug)] 
[Switching to thread 2 (process 20297)] 
#0 main() at program-i-want-to-debug.c:5 
5  printf("Hello, World\n"); 
#0 main() at program-i-want-to-debug.c:5 

顯然,你會想編譯調試信息的程序(GCC -g)。

0

也許我不明白你的觀點。看起來,在文件A上啓動gdb調試並在「FileB:main of line」上設置斷點即可解決您的問題。