GDB explodes when debugging a multithreaded program that quickly forks and executes another program

I'm using GDB to debug my C program. It's a little unstable. Maybe it's because I don't use glibc, so it won't detect new threads until they break I fixed this problem by adding a breakpoint for immediate recovery (break if 0)

Today, however, I came across a wall

I need execve () to be very fast, so ordinary fork () is impossible (it will use a lot of memory) I can't VFORK () (I need a stack to set the pipeline, etc.) so I use the same method in this library( https://code.google.com/p/popen-noshell/ )Basically, only clone is used_ Clone VM This (or usually calling execve () – I really don't know) makes GDB really confused for some reason – basically, its output is as follows:

[New LWP 516]
[New LWP 520]
[New LWP 519]
[New LWP 521]
LWP 521 is executing new program: /bin/bash
Error in re-setting breakpoint 1: No source file named xxx.c.
Error in re-setting breakpoint 2: No source file named yyy.c.
Error in re-setting breakpoint 4: Function "zzz_main" not defined.
[LWP 521 exited]

Program received signal SIGTRAP,Trace/breakpoint trap.
[Switching to LWP 519]
0x00000000004307f8 in shell_execve ()
(gdb) info threads 
Id   Target Id         Frame 
* 5    LWP 519 "self-tes" 0x00000000004307f8 in shell_execve ()
4    LWP 520 "self-tes" 0x000000000040825f in ?? ()
3    LWP 516 "self-tes" 0x000000000040825f in ?? ()
2    LWP 515 "self-tes" 0x000000000040825f in ?? ()
1    LWP 512 "self-tes" 0x000000000040848a in ?? ()

GDB is basically confused about everything and thinks it's executing / bin / bash - it's not - there's no GDB running, but I need it to debug my program I tried to disable every fork and exec setting I could find, but I didn't enable "follow exec" and so on You can see that it tries to reset the breakpoint after execve()... Why? It no longer recognizes any frames or symbols because it completely erases the previous space and loads / bin / bash

How can GDB ignore the thread calling execve() without trying to load symbols for child processes?

Editor: Oh, I'm currently using x86_ 64 Linux 3.2. 0-27(Ubuntu).

EDIT2:GNU gdb(Ubuntu / Linaro 7.4-2012.04-0ubuntu2)7.4-2012.04

Editor 3: it is only checked with GDB 7.5 The same problem

Solution

I found a problem! Obviously, when cloning GDB (or libthread) is used as a hint to generate a child process (fork style) rather than just another thread, I forgot to mask the flag with sigchld Thank you @ r The prompt guided me in the right direction

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>