mailing list of musl libc
 help / color / mirror / code / Atom feed
* Child process is blocked when debugging with gdb
@ 2019-06-11  3:46 徐露
  2019-06-21 20:31 ` dalias
  0 siblings, 1 reply; 3+ messages in thread
From: 徐露 @ 2019-06-11  3:46 UTC (permalink / raw)
  To: musl; +Cc: dalias

[-- Attachment #1: Type: text/plain, Size: 2585 bytes --]

Hi all,

I use Openwrt project and the version of musl-libc is 1.1.16. 

    I call wordexp() in my programs and it runs well. But when I debug my programs with gdb, it is blocked on wordexp().
    After some tests, I found that wordexp() call fork(), and after fork the child process is blocked.

    I write a demo and the source code is as follows.
```
#include <stdio.h>
#include <unistd.h>
int main()
{
 pid_t pid;
 pid = fork();
 if (!pid) {
  printf("== child process ==\n");
  while (1) {
   printf("--child--\n");
   sleep(1);
  }
 }
 printf("== parent process ==\n");
 sleep(20);
 return 0;
}
```

    The debug log is as follows. 
```
root@Linux:/# gdb /test 
GNU gdb (GDB) 8.2.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "arm-openwrt-linux".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /test...done.
(gdb) show follow-fork-mode 
Debugger response to a program call of fork or vfork is "parent".
(gdb) show detach-on-fork 
Whether gdb will detach the child of a fork is on.
(gdb) r
Starting program: /test 
[Detaching after fork from child process 1697]
== parent process ==
[Inferior 1 (process 1694) exited normally]
(gdb) 
```
    When the parent process is sleeping, I get these processes information.
```
root@Linux:/# ps | grep test
 1692 root     10916 S    gdb /test
 1694 root       680 S    /test
 1697 root       680 t    /test
 1706 root      1072 S    grep test
```

I have set gdb "follow-fork-mode" to "child", the child process can run, but I want to debug the parent process.

Besides, I have tried GDB 7.10.1 and musl-libc 1.1.22, the question still exists.
I also have swithed the C library to Glibc, and there is no question.

Could you please give us some pointers, thanks! I can supply more details as needed.

Best regards!
————————————————————— 
徐 露
全志科技 事业一部
 MOBI:+86 13425063650
 ADDR:广东省珠海市高新区唐家湾镇科技2路9号
 MAIL:xulu@allwinnertech.com


[-- Attachment #2: Type: text/html, Size: 8755 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Child process is blocked when debugging with gdb
  2019-06-11  3:46 Child process is blocked when debugging with gdb 徐露
@ 2019-06-21 20:31 ` dalias
  2019-06-26  3:06   ` 回复:[musl] " 徐露
  0 siblings, 1 reply; 3+ messages in thread
From: dalias @ 2019-06-21 20:31 UTC (permalink / raw)
  To: 徐露; +Cc: musl

On Tue, Jun 11, 2019 at 11:46:52AM +0800, 徐露 wrote:
> Hi all,
> 
> I use Openwrt project and the version of musl-libc is 1.1.16. 
> 
>     I call wordexp() in my programs and it runs well. But when I debug my programs with gdb, it is blocked on wordexp().
>     After some tests, I found that wordexp() call fork(), and after fork the child process is blocked.
> 
>     I write a demo and the source code is as follows.
> ```
> #include <stdio.h>
> #include <unistd.h>
> int main()
> {
>  pid_t pid;
>  pid = fork();
>  if (!pid) {
>   printf("== child process ==\n");
>   while (1) {
>    printf("--child--\n");
>    sleep(1);
>   }
>  }
>  printf("== parent process ==\n");
>  sleep(20);
>  return 0;
> }
> ```
> 
>     The debug log is as follows. 
> ```
> root@Linux:/# gdb /test 
> GNU gdb (GDB) 8.2.1
> Copyright (C) 2018 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.
> Type "show copying" and "show warranty" for details.
> This GDB was configured as "arm-openwrt-linux".
> Type "show configuration" for configuration details.
> For bug reporting instructions, please see:
> <http://www.gnu.org/software/gdb/bugs/>.
> Find the GDB manual and other documentation resources online at:
>     <http://www.gnu.org/software/gdb/documentation/>.
> For help, type "help".
> Type "apropos word" to search for commands related to "word"...
> Reading symbols from /test...done.
> (gdb) show follow-fork-mode 
> Debugger response to a program call of fork or vfork is "parent".
> (gdb) show detach-on-fork 
> Whether gdb will detach the child of a fork is on.
> (gdb) r
> Starting program: /test 
> [Detaching after fork from child process 1697]
> == parent process ==
> [Inferior 1 (process 1694) exited normally]
> (gdb) 
> ```
>     When the parent process is sleeping, I get these processes information.
> ```
> root@Linux:/# ps | grep test
>  1692 root     10916 S    gdb /test
>  1694 root       680 S    /test
>  1697 root       680 t    /test
>  1706 root      1072 S    grep test
> ```
> 
> I have set gdb "follow-fork-mode" to "child", the child process can run, but I want to debug the parent process.
> 
> Besides, I have tried GDB 7.10.1 and musl-libc 1.1.22, the question still exists.
> I also have swithed the C library to Glibc, and there is no question.
> 
> Could you please give us some pointers, thanks! I can supply more details as needed.

Sorry I missed this when you first sent it!

wordexp() reads back output from the child via a pipe, so the child
will stay blocked on writing to the pipe if it writes more than the
pipe buffer size without the parent reading anything back. You'll need
to let the parent advance past these reads before the child can exit.

Does that help?

Rich


^ permalink raw reply	[flat|nested] 3+ messages in thread

* 回复:[musl] Child process is blocked when debugging with gdb
  2019-06-21 20:31 ` dalias
@ 2019-06-26  3:06   ` 徐露
  0 siblings, 0 replies; 3+ messages in thread
From: 徐露 @ 2019-06-26  3:06 UTC (permalink / raw)
  To: musl; +Cc: Rich Felker

[-- Attachment #1: Type: text/plain, Size: 3535 bytes --]

On Fri, Jun 21, 2019 at 16:31:32PM -0400, Rich Felker wrote:
> On Tue, Jun 11, 2019 at 11:46:52AM +0800, 徐露 wrote:
> > Hi all,
> > 
> > I use Openwrt project and the version of musl-libc is 1.1.16. 
> > 
> >     I call wordexp() in my programs and it runs well. But when I debug my programs with gdb, it is blocked on wordexp().
> >     After some tests, I found that wordexp() call fork(), and after fork the child process is blocked.
> > 
> >     I write a demo and the source code is as follows.
> > ```
> > #include <stdio.h>
> > #include <unistd.h>
> > int main()
> > {
> >  pid_t pid;
> >  pid = fork();
> >  if (!pid) {
> >   printf("== child process ==\n");
> >   while (1) {
> >    printf("--child--\n");
> >    sleep(1);
> >   }
> >  }
> >  printf("== parent process ==\n");
> >  sleep(20);
> >  return 0;
> > }
> > ```
> > 
> >     The debug log is as follows. 
> > ```
> > root@Linux:/# gdb /test 
> > GNU gdb (GDB) 8.2.1
> > Copyright (C) 2018 Free Software Foundation, Inc.
> > License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
> > This is free software: you are free to change and redistribute it.
> > There is NO WARRANTY, to the extent permitted by law.
> > Type "show copying" and "show warranty" for details.
> > This GDB was configured as "arm-openwrt-linux".
> > Type "show configuration" for configuration details.
> > For bug reporting instructions, please see:
> > <http://www.gnu.org/software/gdb/bugs/>.
> > Find the GDB manual and other documentation resources online at:
> >     <http://www.gnu.org/software/gdb/documentation/>.
> > For help, type "help".
> > Type "apropos word" to search for commands related to "word"...
> > Reading symbols from /test...done.
> > (gdb) show follow-fork-mode 
> > Debugger response to a program call of fork or vfork is "parent".
> > (gdb) show detach-on-fork 
> > Whether gdb will detach the child of a fork is on.
> > (gdb) r
> > Starting program: /test 
> > [Detaching after fork from child process 1697]
> > == parent process ==
> > [Inferior 1 (process 1694) exited normally]
> > (gdb) 
> > ```
> >     When the parent process is sleeping, I get these processes information.
> > ```
> > root@Linux:/# ps | grep test
> >  1692 root     10916 S    gdb /test
> >  1694 root       680 S    /test
> >  1697 root       680 t    /test
> >  1706 root      1072 S    grep test
> > ```
> > 
> > I have set gdb "follow-fork-mode" to "child", the child process can run, but I want to debug the parent process.
> > 
> > Besides, I have tried GDB 7.10.1 and musl-libc 1.1.22, the question still exists.
> > I also have swithed the C library to Glibc, and there is no question.
> > 
> > Could you please give us some pointers, thanks! I can supply more details as needed.
> 
> Sorry I missed this when you first sent it!
> 
> wordexp() reads back output from the child via a pipe, so the child
> will stay blocked on writing to the pipe if it writes more than the
> pipe buffer size without the parent reading anything back. You'll need
> to let the parent advance past these reads before the child can exit.
> 
> Does that help?
Sorry. My description of the question is inaccurate. 
Forget about wordexp. Let's talk about the demo program. The source code is in the last mail.
The question:
The demo program runs well. If I debug the demo program(compile with musl) with gdb, even though the child process is created, but it can not run.

When I debug the demo program(compile with glibc) with gdb, the child process runs well.

Best regards !
xulu

[-- Attachment #2: Type: text/html, Size: 10741 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-06-26  3:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-11  3:46 Child process is blocked when debugging with gdb 徐露
2019-06-21 20:31 ` dalias
2019-06-26  3:06   ` 回复:[musl] " 徐露

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).