Bug 12203 - gdb internal error "infrun.c:2455" after trying to create realtime thread on Linux
Summary: gdb internal error "infrun.c:2455" after trying to create realtime thread on ...
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: 7.0
: P2 normal
Target Milestone: 7.6
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-08 17:11 UTC by Matthias Gerstner
Modified: 2012-07-20 17:34 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
test program to reproduce the crash (786 bytes, text/x-csrc)
2010-11-08 17:11 UTC, Matthias Gerstner
Details
debug log leading to the crash (1.29 KB, text/x-log)
2010-11-09 13:34 UTC, Matthias Gerstner
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Gerstner 2010-11-08 17:11:45 UTC
Created attachment 5115 [details]
test program to reproduce the crash

Hello!

I've run into a problem with GDB when the debugged application attempts to create a realtime thread on Linux e.g. with SCHED_RR as scheduler. If that operation fails due to missing priveleges (i.e. EPERM is returned from pthread_create()) then few instructions later gdb crashes with this:

-----
infrun.c:2455: internal-error: handle_inferior_event: Assertion `inf' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) 
-----

The crash is pretty much always reproducable but seems not to be deterministic. I.e. it doesn't always occur at the same time and place but is subject differences in runtime. So it's probably caused by some parallel thread or something.

When the same program is run as root then everything is fine (pthread_create() doesn't return with EPERM in that case).

My system is a Gentoo Linux running "GNU gdb (Gentoo 7.0.1 p1) 7.0.1". I was able to reproduce the crash also on a Ubuntu Linux running a somewhat newer gdb. The problem does *not* occur an older gdb like "GNU gdb 6.8" on my Gentoo system.

I've attached a small test program that is able to reproduce the crash if you set a breakpoint in main and step through until a few lines after the call to pthread_create(). Again this only works if you don't have the priveleges to create the thread.
Comment 1 Pedro Alves 2010-11-08 17:45:45 UTC
I think this a duplicate of PR 11692.  Please paste the gdb log leading to the crash with:

(gdb) set debug infrun 1
(gdb) set debug lin-lwp 1

So we can confirm it.
Comment 2 Matthias Gerstner 2010-11-09 13:34:47 UTC
Created attachment 5116 [details]
debug log leading to the crash

please find the attached log as requested
Comment 3 Pedro Alves 2010-11-09 15:11:53 UTC
Thanks for the logs.  Yep, it's the same root problem as PR 11692:

LLTA: KILL(SIG0) LWP 6742 (OK)
LLW: PTRACE_CONT LWP 6742, Unknown signal 77 (preempt 'handle')
error creating thread: Operation not permitted
LLW: waitpid 6742 received Trace/breakpoint trap (stopped)
LLTA: KILL(SIG0) LWP 6742 (OK)
LLW: Candidate event Trace/breakpoint trap (stopped) in LWP 6742.
SC:  kill LWP 6741 **<SIGSTOP>**
SC:  lwp kill 0 ERRNO-OK
WL: waitpid LWP 6741 received Stopped (signal) (stopped)
LLW: trap ptid is LWP 6742.
infrun: target_wait (-1, status) =
infrun:   -1 [process -1],
infrun:   status->kind = spurious
infrun.c:2455: internal-error: handle_inferior_event: Assertion `inf' failed.
A problem internal to GDB has been detected,

That target_wait result of "-1, spurious" means that this code in
linux-thread-db.c ran:

     /* Change ptids back into the higher level PID + TID format.  If
	 the thread is dead and no longer on the thread list, we will
	 get back a dead ptid.  This can occur if the thread death
	 event gets postponed by other simultaneous events.  In such a
	 case, we want to just ignore the event and continue on.  */

      ptid = thread_from_lwp (ptid);
      if (GET_PID (ptid) == -1)
	ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
Comment 4 Sourceware Commits 2012-07-20 17:27:37 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	palves@sourceware.org	2012-07-20 17:27:29

Modified files:
	gdb            : ChangeLog infrun.c linux-thread-db.c 
	gdb/testsuite  : ChangeLog 
Added files:
	gdb/testsuite/gdb.threads: create-fail.c create-fail.exp 

Log message:
	2012-07-20  Pedro Alves  <palves@redhat.com>
	
	PR threads/11692
	PR gdb/12203
	
	gdb/
	* infrun.c (handle_inferior_event) <new thread>: Don't special
	case minus_one_ptid.
	<TARGET_WAITKIND_SPURIOUS>: Ditto.
	* linux-thread-db.c (thread_get_info_callback): Don't return early
	if the thread is zombie.
	(thread_from_lwp): Change return type to void.  Rewrite stale
	comment.
	(attach_thread): Don't return early if the thread is zombie,
	instead set its "dying" flag.
	(thread_db_wait): Don't return TARGET_WAITKIND_SPURIOUS anymore.
	(find_new_threads_callback): Don't return early if the thread is
	zombie.
	
	gdb/testsuite/
	* gdb.threads/create-fail.c: New file.
	* gdb.threads/create-fail.exp: New file.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.14504&r2=1.14505
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/infrun.c.diff?cvsroot=src&r1=1.551&r2=1.552
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/linux-thread-db.c.diff?cvsroot=src&r1=1.104&r2=1.105
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.3300&r2=1.3301
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.threads/create-fail.c.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.threads/create-fail.exp.diff?cvsroot=src&r1=NONE&r2=1.1
Comment 5 Pedro Alves 2012-07-20 17:34:37 UTC
Patch checked in.