【问题标题】:Unable to attach to forked child process with GDB无法使用 GDB 附加到分叉的子进程
【发布时间】:2021-02-16 12:40:40
【问题描述】:

我有

gdbserver --multi :2345

在远程系统上运行。

myfile.c 的代码摘录如下:

    159: mppts_number = index;

    //-------------------------- FORK-------------------------------------

    pid = fork();
    if (pid == -1)
    {
        //syslog(LOG_INFO,"Error: Start Daemon failed (%s)\n");

        return -1;
    }
    else if (!pid)
    {
        sleep(30);
        ...
    }
    else
    {
        return 0;
    }

那我正在连接

(gdb) target extended-remote 192.168.10.248:2345
Remote debugging using 192.168.10.248:2345
(gdb) set remote exec-file a.out
(gdb) file a.out
Reading symbols from a.out...done.
(gdb) b 159
Breakpoint 1 at 0x11384: file myfile.c, line 159.
(gdb) r
Starting program: MYPATH/a.out
Reading ...
...
Breakpoint 1, main (argc=1, argv=0x7efff7c4) at myfile.c:159
159         mppts_number = index;
(gdb) n
163         pid = fork();
(gdb) n
164         if (pid == -1)
(gdb) p pid
$1 = 10459

如果我这样做了

(gdb) attach 10459
A program is being debugged already.  Kill it? (y or n) n
Not killed.
(gdb) continue
Continuing.
[Inferior 1 (process 10458) exited normally]
(gdb) attach 10459
Attaching to program: MYPATH, process 10459
Attaching to process 10459 failed

我在ps 中看不到任何进程。在中间我可以看到

# ps auxf | grep a.out
root     10458  0.0  0.1   1824   984 pts/0    t+   22:28   0:00  |           \_ a.out
root     10459  0.0  0.0      0     0 pts/0    Z+   22:28   0:00  |               \_ [a.out] <defunct>

所以,我不能附加到子项目。我还能这样做吗?

【问题讨论】:

    标签: gdb fork remote-debugging gdbserver


    【解决方案1】:

    啊,我需要在fork 之前做continue,所以这个过程没有停止。

    【讨论】:

      猜你喜欢
      • 2017-12-23
      • 1970-01-01
      • 2010-12-10
      • 1970-01-01
      • 2014-08-03
      • 2014-07-06
      • 1970-01-01
      • 2016-10-30
      • 1970-01-01
      相关资源
      最近更新 更多