我让函数system()
调用一个已经编译的单独脚本。但我希望能够在该特定文件中的函数中设置断点。
所以:
档案一:
system("./fileB");
文件 B:
void main() {
/* etc */
}
我希望能够在调用系统命令后在 main 处设置断点。
任何帮助,将不胜感激!
较新版本的 GDB ( 7.1+ ) 可以一次调试多个程序,并且确实可以支持这一点:
运行程序.c
#include <stdlib.h>
int main()
{
system("./program-i-want-to-debug");
return 0;
}
程序我想调试.c
#include <stdio.h>
int main()
{
printf("Hello, World\n");
return 0;
}
运行程序.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 ) 编译程序。
也许我不明白你的意思。似乎在文件 A 上启动 gdb 调试并在“FileB:line of main”上设置断点可以解决您的问题。