Bug 209061

Summary: devel/gdb: Fix gdb/i386 built on older kernels
Product: Ports & Packages Reporter: John Baldwin <jhb>
Component: Individual Port(s)Assignee: freebsd-ports-bugs (Nobody) <ports-bugs>
Status: Closed FIXED    
Severity: Affects Only Me CC: luca.pizzamiglio, trasz
Priority: --- Flags: luca.pizzamiglio: maintainer-feedback+
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
kgdb_i386.patch none

Description John Baldwin freebsd_committer freebsd_triage 2016-04-26 02:48:43 UTC
Created attachment 169704 [details]
kgdb_i386.patch

The kgdb targets use runtime assertions on native targets to verify that the helper arrays documenting the layout of things like the PCB and trapframe structures match.  Ideally these asserts would be compile time assertions, but they cannot be checked at compile time.  Instead, they are checked at runtime during gdb startup.

However, the layout of the i386 PCB changed when the AVX changes were merged to i386.  The constants in the i386 target assume the post-AVX layout, but gdb packages on stable branches might be built against pre-AVX worlds.  In that case, those gdb binaries will trigger these assertions on every invocation.

As a workaround, disable the PCB-related assertions on pre-AVX worlds.  If kgdb is run against a pre-AVX kernel it will not be able to parse the PCB correctly,
but userland debugging should work fine.  kgdb built against a pre-AVX world but against an AVX kernel should work fine.
Comment 1 luca.pizzamiglio 2016-04-27 09:20:25 UTC
Comment on attachment 169704 [details]
kgdb_i386.patch

The patch provided works perfectly and all my tests passed.
Patch approved.
Comment 2 commit-hook freebsd_committer freebsd_triage 2016-04-27 16:12:26 UTC
A commit references this bug:

Author: jhb
Date: Wed Apr 27 16:11:53 UTC 2016
New revision: 414115
URL: https://svnweb.freebsd.org/changeset/ports/414115

Log:
  Fix an issue with gdb triggering assertions in kgdb on i386.

  The kgdb targets use runtime assertions on native targets to verify
  that the helper arrays documenting the layout of things like the PCB
  and trapframe structures match.  Ideally these asserts would be
  compile time assertions, but they cannot be checked at compile time.
  Instead, they are checked at runtime during gdb startup.

  However, the layout of the i386 PCB changed when the AVX changes were
  merged to i386.  The constants in the i386 target assume the post-AVX
  layout, but gdb packages on stable branches might be built against
  pre-AVX worlds.  In that case, those gdb binaries will trigger these
  assertions on every invocation.

  As a workaround, disable the PCB-related assertions on pre-AVX worlds.
  If kgdb is run against a pre-AVX kernel it will not be able to parse
  the PCB correctly, but userland debugging should work fine.  kgdb
  built against a pre-AVX world but run against an AVX kernel should
  work fine.

  PR:		209061
  Reported by:	trasz
  Approved by:	luca.pizzamiglio@gmail.com (maintainer), swills

Changes:
  head/devel/gdb/Makefile
  head/devel/gdb/files/kgdb/i386fbsd-kern.c
Comment 3 commit-hook freebsd_committer freebsd_triage 2016-04-29 18:49:32 UTC
A commit references this bug:

Author: jhb
Date: Fri Apr 29 18:48:32 UTC 2016
New revision: 414287
URL: https://svnweb.freebsd.org/changeset/ports/414287

Log:
  MFH: r414115

  Fix an issue with gdb triggering assertions in kgdb on i386.

  The kgdb targets use runtime assertions on native targets to verify
  that the helper arrays documenting the layout of things like the PCB
  and trapframe structures match.  Ideally these asserts would be
  compile time assertions, but they cannot be checked at compile time.
  Instead, they are checked at runtime during gdb startup.

  However, the layout of the i386 PCB changed when the AVX changes were
  merged to i386.  The constants in the i386 target assume the post-AVX
  layout, but gdb packages on stable branches might be built against
  pre-AVX worlds.  In that case, those gdb binaries will trigger these
  assertions on every invocation.

  As a workaround, disable the PCB-related assertions on pre-AVX worlds.
  If kgdb is run against a pre-AVX kernel it will not be able to parse
  the PCB correctly, but userland debugging should work fine.  kgdb
  built against a pre-AVX world but run against an AVX kernel should
  work fine.

  PR:		209061
  Reported by:	trasz
  Approved by:	ports-secteam (junovitch)

Changes:
_U  branches/2016Q2/
  branches/2016Q2/devel/gdb/Makefile
  branches/2016Q2/devel/gdb/files/kgdb/i386fbsd-kern.c