进入子进程时gdb中断 [英] gdb break when entering child process

查看:153
本文介绍了进入子进程时gdb中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难解决这个问题;我有一个程序 iverilog ,该程序执行 system()调用来调用另一个程序 ivl 。我想调试第二个程序gdb中的 ivl ,但是当我用父进程调用gdb时,我无法让gdb在子进程中设置任何断点。程序如下所示:

I'm having a tough time figuring this one out; I have a program, iverilog that executes a system() call to invoke another program, ivl. I want to debug the second program, ivl in gdb, but I can't get gdb to set any breakpoints in the child process when I invoke gdb with the parent process. Here's what the programs look like:

//iverilog-main.cpp (Parent process)

int main(){
    //...
    system("ivl arg1 arg2");
    //...
    return 0;
}

//ivl-main.cpp (child process)

int main(){
    //...
    //stuff I want to debug
    //...
    return 0;
}

我正在运行的gdb命令是: gdb iverilog -x cmds.gdb

The gdb commands I'm running are: gdb iverilog -x cmds.gdb

# cmds.gdb
set args hello.v
set follow-fork-mode child
set breakpoint pending on
break ivl-main.cpp:main
run

不幸的是,gdb不会在 ivl-main.cpp处中断。 :main ,它只需完成就不会中断;我得到的输出是:

Unfortunately, gdb doesn't break at ivl-main.cpp:main,it just completes without ever breaking; the output I get is:

Starting program: /usr/local/bin/iverilog hello.v
[New process 18117]
process 18117 is executing new program: /bin/dash
[Inferior 2 (process 18117) exited normally]

我确定正在调用 ivl-main.cpp:main ,因为当我运行 ivl时程序在gdb中成功中断。

I'm certain ivl-main.cpp:main is being called because when I run the ivl program in gdb it successfully breaks there.

我的想法是,gdb不能将ivl-main.cpp识别为源文件。运行 gdb iverilog ,并且当它进入包含ivl-main.cpp作为源文件的子进程时,没有设置该断点。因此,我认为如果gdb进入子进程时为ivl-main.cpp设置了断点,则它应该可以工作。我能想到的唯一方法是在 system()调用中手动中断并进入子进程,然后设置断点。有没有更优雅的方法会在进入子进程时强制gdb中断?

My thinking is that gdb doesn't recognize ivl-main.cpp as a source file when its running gdb iverilog, and it's not setting that breakpoint when it enters the child process which does contain ivl-main.cpp as a source file. So I think if I set the breakpoint for ivl-main.cpp when gdb enters the child process, it should work. The only way I can think of doing this is to manually break at the system() call and step into the child process, then set the breakpoint. Is there a more elegant approach that would force gdb to break whenever entering a child process?

推荐答案

此答案提供了一种实现所需内容的方法。

This answer provides one way to achieve what you want.

理论上,设置跟随叉模式的孩子应该可以。

实际上, iverilog 本身可能是一个运行( fork s)多个命令的shell脚本,因此,每个 fork ,您将需要确定是否要继续调试父项或子项。一个错误的决定使您无法控制最终将执行程序的过程。这很可能解释了为什么它对您不起作用。

In practice, the iverilog is likely itself a shell script that runs (forks) multiple commands, so at every fork you will need to decide whether you want to continue debugging the parent or the child. One wrong decision and you've lost control of the process that will eventually execute your program. This very likely explains why it didn't work for you.

这篇关于进入子进程时gdb中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆