Bug 192890 - [MAINTAINER] devel/gdb thread support fix on i386 FreeBSD 9.x
[MAINTAINER] devel/gdb thread support fix on i386 FreeBSD 9.x
Status: Closed FIXED
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s)
Latest
i386 Any
: --- Affects Some People
Assigned To: Tijl Coosemans
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2014-08-21 15:50 UTC by luca.pizzamiglio
Modified: 2014-08-21 18:40 UTC (History)
1 user (show)

See Also:


Attachments
Patch to fix the problem (1.00 KB, patch)
2014-08-21 15:50 UTC, luca.pizzamiglio
luca.pizzamiglio: maintainer‑approval+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description luca.pizzamiglio 2014-08-21 15:50:55 UTC
Created attachment 146116 [details]
Patch to fix the problem

On FreeBSD 9.x i386 systems, debugging applications with threads causes a crash of gdb.

Analysing the problem, I discovered a potential dangerous thread support initialization, causing the crash on this specific configuration.
However it's conceptually wrong.

When the libthr is loaded by gdb, the thread support want to add FreeBSD specific information to the current thread. Doing this, it cleans the thread list and re-add the current thread with the updated information (actually, the LWP id).
This operation call a free of the struct thread_info (clean/init the thread list) and a malloc of the same struct (add the current thread).
The problem is that a pointer to the struct thread_info is stored in another struct (about the execution context) and it's not updatable.

On FreeBSD 9.x i386 systems, the malloc return a new pointer; then the execution context contains a broken pointer.
On all other platform, the malloc return the same pointer and the execution context stays coherent.

This patch avoids to clean the thread list and to re-add the thread; it just update thread information of the current thread.

Tested on FreeBSD 9.3 on i386 and amd64 and FreeBSD 10 on i386.
Comment 1 John Marino freebsd_committer 2014-08-21 15:59:39 UTC
Thanks, straight to patch-ready
Comment 2 commit-hook freebsd_committer 2014-08-21 18:36:22 UTC
A commit references this bug:

Author: tijl
Date: Thu Aug 21 18:35:52 UTC 2014
New revision: 365578
URL: http://svnweb.freebsd.org/changeset/ports/365578

Log:
  On FreeBSD 9.x i386 systems, debugging applications with threads causes a
  crash of gdb.

  When the libthr is loaded by gdb, the thread support want to add FreeBSD
  specific information to the current thread. Doing this, it cleans the
  thread list and re-add the current thread with the updated information
  (actually, the LWP id).
  This operation call a free of the struct thread_info (clean/init the
  thread list) and a malloc of the same struct (add the current thread).
  The problem is that a pointer to the struct thread_info is stored in
  another struct (about the execution context) and it's not updatable.

  On FreeBSD 9.x i386 systems, the malloc return a new pointer; then the
  execution context contains a broken pointer.
  On all other platform, the malloc return the same pointer and the
  execution context stays coherent.

  This patch avoids to clean the thread list and to re-add the thread; it
  just update thread information of the current thread.

  PR:		192890
  Submitted by:	luca.pizzamiglio@gmail.com (maintainer)

Changes:
  head/devel/gdb/Makefile
  head/devel/gdb/files/fbsd-threads.c