History log of /freebsd-current/usr.bin/gcore/elfcore.c
Revision Date Author Comments
# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# d95657a1 30-Jun-2022 John Baldwin <jhb@FreeBSD.org>

gcore: Use PT_GETREGSET for NT_THRMISC and NT_PTLWPINFO.

This avoids the need for dealing with converting lwpinfo for alternate
ABIs in gcore itself.

Reviewed by: markj
MFC after: 2 weeks
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D35667


# d2a3c30a 30-Jun-2022 John Baldwin <jhb@FreeBSD.org>

gcore: Remove unused typedefs.

These are no longer needed after commit 4965ac059da1 which used
PT_GETREGSET to fetch NT_PRSTATUS and NT_FPREGSET.

Reviewed by: markj, emaste
MFC after: 2 weeks
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D35665


# 81c857dd 06-Jun-2022 John Baldwin <jhb@FreeBSD.org>

gcore: Don't hardcode VM write permissions.

This ensures read-only PT_LOAD segments are not marked as writable in
the phdr flags.

Reviewed by: markj
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D35398


# ad52a7bb 06-Jun-2022 John Baldwin <jhb@FreeBSD.org>

gcore: Remove unused elf_note_arm_vfp function.

Fixes: add00c381e5c Use a regset for NT_ARM_VFP.


# f9ca52ba 12-May-2022 Andrew Turner <andrew@FreeBSD.org>

Use getpagesize in gcore to find the page size

Reviewed by: markj
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35194


# 931983ee 24-Mar-2022 John Baldwin <jhb@FreeBSD.org>

x86: Add a NT_X86_SEGBASES register set.

This register set contains the values of the fsbase and gsbase
registers. Note that these registers can already be controlled
individually via ptrace(2) via MD operations, so the main reason for
adding this is to include these register values in core dumps. In
particular, this will enable looking up the value of TLS variables
from core dumps in gdb.

The value of NT_X86_SEGBASES was chosen to match the value of
NT_386_TLS on Linux. The notes serve similar purposes, but FreeBSD
will never dump a note equivalent to NT_386_TLS (which dumps a single
segment descriptor rather than a pair of addresses) and picking a
currently-unused value in the NT_X86_* range could result in a future
conflict.

Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D34650


# b2cb74c2 23-Mar-2022 John Baldwin <jhb@FreeBSD.org>

arm,arm64: Add a NT_ARM_TLS read-only register set.

This register set exposes the per-thread TLS register. It matches the
layout used by Linux on arm64. Linux does not implement this note for
32-bit arm.

Reviewed by: andrew, markj
Sponsored by: University of Cambridge, Google, Inc.
Differential Revision: https://reviews.freebsd.org/D34595


# add00c38 23-Mar-2022 John Baldwin <jhb@FreeBSD.org>

Use a regset for NT_ARM_VFP.

This includes adding support for NT_ARM_VFP for 32-bit binaries
running under aarch64 kernels both for ptrace(), and coredumps via the
kernel and gcore.

Reviewed by: andrew, markj
Sponsored by: University of Cambridge, Google, Inc.
Differential Revision: https://reviews.freebsd.org/D34448


# 4965ac05 10-Mar-2022 John Baldwin <jhb@FreeBSD.org>

gcore: Use PT_GETREGSET to fetch NT_PRSTATUS and NT_FPREGSET.

Add a elf_putregnote() helper to build the ELF note for a register
set. Once nice result of this approach is that this reuses the
kernel's support for generating 32-bit register sets for 32-bit
processes avoiding the need to duplicate that logic in elf32core.c.

Reviewed by: markj
Sponsored by: University of Cambridge, Google, Inc.
Differential Revision: https://reviews.freebsd.org/D34447


# c8ca80e2 30-Nov-2021 Gordon Bergling <gbe@FreeBSD.org>

elf(3): Fix a typo in a sysctl description

- s/segement/segment/

MFC after: 3 days


# eae3ca5a 07-Dec-2019 Mark Johnston <markj@FreeBSD.org>

gcore: Avoid using vm_map_entry_t.

Use an internally defined structure instead, to avoid relying on kernel
structure details. No functional change intended.

MFC after: 1 week


# 6a51741f 16-Nov-2019 Justin Hibbits <jhibbits@FreeBSD.org>

gcore: Don't add VSX notes on powerpcspe

powerpcspe does not support VSX at all, but gets the 'VMX' notes for free,
providing the SPE registers.


# 5167f178 02-Jun-2018 Justin Hibbits <jhibbits@FreeBSD.org>

Included VSX registers in powerpc core dumps

Summary: Included VSX registers in powerpc core dumps (both kernel and gcore)

Submitted by: Luis Pires
Differential Revision: https://reviews.freebsd.org/D15512


# 1de7b4b8 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

various: general adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

No functional change intended.


# 27efb0a2 14-Sep-2017 John Baldwin <jhb@FreeBSD.org>

Add a NT_ARM_VFP ELF core note to hold VFP registers for each thread.

The core note matches the format and layout of NT_ARM_VFP on Linux.
Debuggers use the AT_HWCAP flags to determine how many VFP registers
are actually used and their format.

Reviewed by: mmel (earlier version w/o gcore)
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D12293


# 51645e83 29-Jun-2017 John Baldwin <jhb@FreeBSD.org>

Store a 32-bit PT_LWPINFO struct for 32-bit process core dumps.

Process core notes for a 32-bit process running on a 64-bit host need to
use 32-bit structures so that the note layout matches the layout of notes
of a core dump of a 32-bit process under a 32-bit kernel.

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D11407


# 86be94fc 30-Mar-2017 Tycho Nightingale <tychon@FreeBSD.org>

Add support for capturing 'struct ptrace_lwpinfo' for signals
resulting in a process dumping core in the corefile.

Also extend procstat to view select members of 'struct ptrace_lwpinfo'
from the contents of the note.

Sponsored by: Dell EMC Isilon


# 3ff51925 08-Feb-2017 John Baldwin <jhb@FreeBSD.org>

Trim trailing whitespace (mostly introduced in r313407).

Sponsored by: DARPA / AFRL


# 885f13dc 07-Feb-2017 John Baldwin <jhb@FreeBSD.org>

Copy the e_machine and e_flags fields from the binary into an ELF core dump.

In the kernel, cache the machine and flags fields from ELF header to use in
the ELF header of a core dump. For gcore, the copy these fields over from
the ELF header in the binary.

This matters for platforms which encode ABI information in the flags field
(such as o32 vs n32 on MIPS).

Reviewed by: kib
Sponsored by: DARPA / AFRL
Differential Revision: https://reviews.freebsd.org/D9392


# 8a263d91 20-Jul-2016 Conrad Meyer <cem@FreeBSD.org>

Mirror r303120 to gcore

Sponsored by: EMC / Isilon Storage Division


# bd0371c9 20-Jul-2016 Conrad Meyer <cem@FreeBSD.org>

Add extended segment support to gcore

A follow-up to r303099, D7255. Basically, apply the exact same change, with
the exact same rationale, to gcore. gcore's elfcore.c is largely a clone of
the kernel imgact_elf coredump facility.

Reviewed by: emaste (earlier version, not substantially different)
Requested by: jhb
Sponsored by: EMC / Isilon Storage Division
Differential Revision: https://reviews.freebsd.org/D7265


# ccb83afd 18-Jul-2016 John Baldwin <jhb@FreeBSD.org>

Include process IDs in core dumps.

When threads were added to the kernel, the pr_pid member of the
NT_PRSTATUS note was repurposed to store LWP IDs instead of process
IDs. However, the process ID was no longer recorded in core dumps.
This change adds a pr_pid field to prpsinfo (NT_PRSINFO). Rather than
bumping the prpsinfo version number, note parsers can use the note's
payload size to determine if pr_pid is present.

Reviewed by: kib, emaste (older version)
MFC after: 2 months
Differential Revision: https://reviews.freebsd.org/D7117


# c77547d2 14-Jul-2016 John Baldwin <jhb@FreeBSD.org>

Include command line arguments in core dump process info.

Fill in pr_psargs in the NT_PRSINFO ELF core dump note with command
line arguments.

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D7116


# 0367ff56 24-Jun-2016 Mark Johnston <markj@FreeBSD.org>

gcore: Forward pending signals when detaching from the target.

Otherwise gcore's ptrace attach operation can race with delivery of a
signal and cause it to be lost.

In collaboration with: Suraj Raju <sraju@isilon.com>
Reviewed by: bdrewery
Approved by: re (gjb, kib)
MFC after: 2 weeks
Sponsored by: EMC / Isilon Storage Division


# 6a4b6353 11-May-2016 Conrad Meyer <cem@FreeBSD.org>

Fix buffer overrun in gcore(1) NT_PRPSINFO

Use size of destination buffer, rather than a constant that may or may not
correspond to the source buffer, to restrict the length of copied strings. In
particular, pr_fname has 16+1 characters but MAXCOMLEN is 18+1.

Use strlcpy instead of strncpy to ensure the result is nul-terminated. This
seems to be what is expected of these fields.

Reported by: Coverity
CIDs: 1011302, 1011378
Sponsored by: EMC / Isilon Storage Division


# bc411bc2 14-Feb-2015 John Baldwin <jhb@FreeBSD.org>

Include OBJT_PHYS VM objects in ELF core dumps. In particular this
includes the shared page allowing debuggers to use the signal trampoline
code to identify signal frames in core dumps.

Differential Revision: https://reviews.freebsd.org/D1828
Reviewed by: alc, kib
MFC after: 1 week


# b5d4909e 14-Jan-2015 Justin Hibbits <jhibbits@FreeBSD.org>

Make use of the new Altivec ptrace support, to save the Altivec registers in
gcore.

MFC after: 2 weeks
Relnotes: yes


# 180e57e5 21-Nov-2014 John Baldwin <jhb@FreeBSD.org>

Improve support for XSAVE with debuggers.
- Dump an NT_X86_XSTATE note if XSAVE is in use. This note is designed
to match what Linux does in that 1) it dumps the entire XSAVE area
including the fxsave state, and 2) it stashes a copy of the current
xsave mask in the unused padding between the fxsave state and the
xstate header at the same location used by Linux.
- Teach readelf() to recognize NT_X86_XSTATE notes.
- Change PT_GET/SETXSTATE to take the entire XSAVE state instead of
only the extra portion. This avoids having to always make two
ptrace() calls to get or set the full XSAVE state.
- Add a PT_GET_XSTATE_INFO which returns the length of the current
XSTATE save area (so the size of the buffer needed for PT_GETXSTATE)
and the current XSAVE mask (%xcr0).

Differential Revision: https://reviews.freebsd.org/D1193
Reviewed by: kib
MFC after: 2 weeks


# 798d238f 30-Jul-2014 Kevin Lo <kevlo@FreeBSD.org>

Remove an unsed variable.


# 31d743df 26-Jul-2014 Marcel Moolenaar <marcel@FreeBSD.org>

Create 32-bit core files for 32-bit processes on 64-bit machines.
The 64-bit machine supported right now is amd64, but it's not too
hard to add powerpc64.

Obtained from: Juniper Networks, Inc.


# e344fb02 20-Apr-2013 Mikolaj Golub <trociny@FreeBSD.org>

Wrong cast.

MFC after: 1 month


# 7fe6d16e 20-Apr-2013 Mikolaj Golub <trociny@FreeBSD.org>

Sync gcore(1) with the recent changes in kernel code aimed at adding
procstat notes to a process core file.

Suggested by: jhb
MFC after: 1 month


# d1d6559b 10-Jul-2011 Xin LI <delphij@FreeBSD.org>

Match size_t and ssize_t by using %zu and %zd instead of %d.

MFC after: 1 month


# 7f08176e 22-Nov-2010 Attilio Rao <attilio@FreeBSD.org>

Add the ability for GDB to printout the thread name along with other
thread specific informations.

In order to do that, and in order to avoid KBI breakage with existing
infrastructure the following semantic is implemented:
- For live programs, a new member to the PT_LWPINFO is added (pl_tdname)
- For cores, a new ELF note is added (NT_THRMISC) that can be used for
storing thread specific, miscellaneous, informations. Right now it is
just popluated with a thread name.

GDB, then, retrieves the correct informations from the corefile via the
BFD interface, as it groks the ELF notes and create appropriate
pseudo-sections.

Sponsored by: Sandvine Incorporated
Tested by: gianni
Discussed with: dim, kan, kib
MFC after: 2 weeks


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 1d73ef97 14-Jul-2010 Attilio Rao <attilio@FreeBSD.org>

Fix the way the segments are included in the gcore outputs (with the
default invokation):
- Right now if segments are not writable are not included. Remove this.
- Right now if a segment is mapped with NOCORE the check is not honoured.
Change this by checking the newly added flag, from libutil,
KVME_FLAG_NOCOREDUMP.

Besides that, add a new flag (-f) that forces a 'full' dump of all the
segments excluding just the malformed ones. This might be used very
carefully as, among the reported segments, there could be memory
mapped areas that could be vital to program execution.

Sponsored by: Sandvine Incorporated
Discussed with: kib
Reviewed by: emaste
Tested by: Sandvine Incorporated
MFC after: 2 weeks


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# ebc5dece 19-Dec-2009 Attilio Rao <attilio@FreeBSD.org>

MFC r199805:
Change gcore in order to get rid of the procfs support and use FreeBSD's
specific interfaces. Main changes:
- now gcore recognizes threads within the the process and handle dumps on
a thread scope
- the process to be analyzed should be stopped while gcore runs
- gcore may not work with processes that are being debugged with gdb or
truss
- ptrace may let interruptible calls to return EINTR, thus dirtying
signals handling within the process

Sponsored by: Sandvine Incorporated


# 2e7ecbfb 25-Nov-2009 Attilio Rao <attilio@FreeBSD.org>

Change gcore in order to get rid of the procfs accesses and use FreeBSD's
specific sysctls and ptrace interfaces.
This change switches a bit gcore POLA that is summarized here:
- now gcore can recognize threads within the process and handle dumps
on thread-scope
- the process to be analyzed will be stopped during its gcore run
- gcore may not work with processes which are actively being analyzed
by gdb or truss
- the ptrace interface may cause syscalls to return EINTR, thus
interferring with signals handling within the process

Side note: <janitor task> the interface can be further lifted in order to
get rid of the very last procfs interfaces remnants and made more
suitable for copying with sysctl/ptrace interface </janitor task>.

Obtained from: Sandvine Incorporated
Reviewed by: emaste, rwatson
Sponsored by: Sandvine Incorporated
MFC: 1 month


# 9d37c171 04-Nov-2009 Ed Maste <emaste@FreeBSD.org>

MFC r197437:

Use %zu for size_t, not %zd.


# 7149ebf4 23-Sep-2009 Ed Maste <emaste@FreeBSD.org>

Use %zu for size_t, not %zd.

Submitted by: ru
MFC after: 1 week


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# fffc0a1e 18-Jul-2008 Xin LI <delphij@FreeBSD.org>

Use %zd for size_t. With this gcore(1) is WARNS=6 clean.


# affde8a9 10-Apr-2007 Ed Maste <emaste@FreeBSD.org>

Eliminate memory leak from an accidental malloc().


# 045b6fda 24-Mar-2006 Peter Wemm <peter@FreeBSD.org>

Make gcore(1) 64 bit safe. It was trying to parse the /proc/*/map file
using sscanf and truncating the start/end entries by writing them with a
32 bit int descriptor (%x). The upper bytes of the 64 bit vm_offset_t
variables (for little endian machines) were uninitialized. For big endian
machines, things would have been worse because it was storing the 32 bit
value in the upper half of the 64 bit variable. I've changed it to use
%lx and long types. That should work on all our platforms.


# 22c14714 12-Jul-2004 Robert Watson <rwatson@FreeBSD.org>

Teach gcore about the pathname field of '/proc/*/map' so that it doesn't
spin when its parser gets confused by a lack of end-of-line.

Submitted by: Dan Nelson <dan@dan.emsphone.com>
PR: 68839


# c4dd6db1 15-Feb-2004 David Malone <dwmalone@FreeBSD.org>

Fix some WARNS:
1) Remove some unused variables.
2) Mark some things aas static or __unused.
3) Cast to make sure we're comparing the same types.


# 9e0a9e98 13-Sep-2002 Peter Wemm <peter@FreeBSD.org>

Add #include <sys/queue.h> for sparc64's benefit. The MD includes there
have less polution.


# e0491636 13-Sep-2002 Peter Wemm <peter@FreeBSD.org>

Use a crowbar to move the a.out code out of gcore.c and into its own
file so that we have a chance of using gcore on non-i386 platforms. Use
linker sets to reduce the registration glue. Remove md-sparc.c, we do not
have an a.out sparc32 port. aoutcore.c was repocopied from gcore.c.


# 56d037c6 05-Sep-2002 Ian Dowse <iedowse@FreeBSD.org>

Include stdint.h to make this compile.

Submitted by: Garance A Drosihn <drosih@rpi.edu>


# f4ac32de 04-Sep-2002 David Malone <dwmalone@FreeBSD.org>

ANSIify function definitions.
Add some constness to avoid some warnings.
Remove use register keyword.
Deal with missing/unneeded extern/prototypes.
Some minor type changes/casts to avoid warnings.

Reviewed by: md5


# ed68d15d 25-Mar-2002 Philippe Charnier <charnier@FreeBSD.org>

Add FBSDID. Do not \n terminate err() strings. Spelling.


# ccbb36d5 12-Oct-2001 Bruce Evans <bde@FreeBSD.org>

Removed unused include of kernel-only file <sys/lock.h>.


# 889b293a 06-Jun-2001 Jonathan Lemon <jlemon@FreeBSD.org>

Null terminate buffer.

PR: 23150
Submitted by: Dan Nelson <dnelson@emsphone.com>
MFC in: 1 week


# 5e6220d9 02-May-2001 David E. O'Brien <obrien@FreeBSD.org>

* include/elf.h has been repo copied to include/elf-hints.h, and it no
longer includes machine/elf.h.
* consumers of elf.h now use the minimalist elf header possible.

This change is motivated by Binutils 2.11.0 and too much clashing over
our base elf headers and the Binutils elf headers.


# c815a20c 17-Apr-2000 David E. O'Brien <obrien@FreeBSD.org>

Change our ELF binary branding to something more acceptable to the Binutils
maintainers.

After we established our branding method of writing upto 8 characters of
the OS name into the ELF header in the padding; the Binutils maintainers
and/or SCO (as USL) decided that instead the ELF header should grow two new
fields -- EI_OSABI and EI_ABIVERSION. Each of these are an 8-bit unsigned
integer. SCO has assigned official values for the EI_OSABI field. In
addition to this, the Binutils maintainers and NetBSD decided that a better
ELF branding method was to include ABI information in a ".note" ELF
section.

With this set of changes, we will now create ELF binaries branded using
both "official" methods. Due to the complexity of adding a section to a
binary, binaries branded with ``brandelf'' will only brand using the
EI_OSABI method. Also due to the complexity of pulling a section out of an
ELF file vs. poking around in the ELF header, our image activator only
looks at the EI_OSABI header field.

Note that a new kernel can still properly load old binaries except for
Linux static binaries branded in our old method.

*
* For a short period of time, ``ld'' will also brand ELF binaries
* using our old method. This is so people can still use kernel.old
* with a new world. This support will be removed before 5.0-RELEASE,
* and may not last anywhere upto the actual release. My expiration
* time for this is about 6mo.
*


# 923502ff 29-Oct-1999 Poul-Henning Kamp <phk@FreeBSD.org>

useracc() the prequel:

Merge the contents (less some trivial bordering the silly comments)
of <vm/vm_prot.h> and <vm/vm_inherit.h> into <vm/vm.h>. This puts
the #defines for the vm_inherit_t and vm_prot_t types next to their
typedefs.

This paves the road for the commit to follow shortly: change
useracc() to use VM_PROT_{READ|WRITE} rather than B_{READ|WRITE}
as argument.


# c3aac50f 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 2062f4ee 17-Jul-1999 John Polstra <jdp@FreeBSD.org>

Make gcore work again. It was broken by a format change in the
procfs map file when object IDs were eliminated in the mega-commit
that included procfs_map.c revision 1.19.

The map file is a terrible hodge-podge. The fields that are used
mainly for kernel debugging should be moved out of it into a
separate file, so that the interface presented by the map file to
applications can remain stable in the face of VM system changes.


# 00bf1f30 31-Oct-1998 John Polstra <jdp@FreeBSD.org>

Fix errors detected by -Wformat.


# 52e7cc0a 19-Oct-1998 John Polstra <jdp@FreeBSD.org>

Make gcore work for ELF.