[BACK]Return to ctfstrip CVS log [TXT][DIR] Up to [local] / src / usr.bin / ctfconv

File: [local] / src / usr.bin / ctfconv / ctfstrip (download)

Revision 1.12, Tue Oct 15 10:27:25 2019 UTC (4 years, 7 months ago) by mpi
Branch: MAIN
CVS Tags: OPENBSD_7_5_BASE, OPENBSD_7_5, OPENBSD_7_4_BASE, OPENBSD_7_4, OPENBSD_7_3_BASE, OPENBSD_7_3, OPENBSD_7_2_BASE, OPENBSD_7_2, OPENBSD_7_1_BASE, OPENBSD_7_1, OPENBSD_7_0_BASE, OPENBSD_7_0, OPENBSD_6_9_BASE, OPENBSD_6_9, OPENBSD_6_8_BASE, OPENBSD_6_8, OPENBSD_6_7_BASE, OPENBSD_6_7, HEAD
Changes since 1.11: +11 -4 lines

Include the .SUNW_ctf section in bsd.gdb

Once the section has been built from the DWARF symbols also add it to
the debug kernel.  That makes ddb(4) print the correct number of args
in function backtraces in such kernel as well.

While here make comment fit in 80 columns.

ok jasper@

#!/bin/sh
#
# $OpenBSD: ctfstrip,v 1.12 2019/10/15 10:27:25 mpi Exp $
#
# Copyright (c) 2017 Martin Pieuchot
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

set -o posix

cleanup() {
	rm -f ${TMPFILE}
	exit 1
}

usage() {
	echo "usage: $(basename $0) [-S] [-o outfile] file" >&2
	exit 1
}

trap "cleanup" 1 2 3 13 15

while getopts So: opt; do
	case $opt in
		S)	STRIPFLAG=-g;;
		o)	OUTFILE="$OPTARG";;
		\?)	usage;;
	esac
done

shift $((OPTIND - 1))

if [ $# -ne 1 ]; then
	usage
fi

INFILE="$1"
LABEL="unknown"
TMPFILE=$(mktemp /tmp/.ctf.XXXXXXXXXX)

# Extract kernel version
if [ -z "${INFILE##bsd*}" ]; then
	LABEL=`what "$INFILE" | sed -n '$s/^   //p'`
fi

# If ctfstrip was passed a file that lacks useful debug sections, ctfconv will
# fail.  So try to run ctfconv and silently fallback to plain strip(1) if that
# failed.
ctfconv -o ${TMPFILE} -l "${LABEL}" "${INFILE}" 2> /dev/null

if [ $? -eq 0 ]; then
	objcopy  ${STRIPFLAG} \
		--add-section .SUNW_ctf=${TMPFILE} "${INFILE}" ${OUTFILE}

	# Also add CTF data to the debug kernel
	if [ -z "${INFILE##bsd.gdb}" ]; then
		objcopy --add-section .SUNW_ctf=${TMPFILE} "${INFILE}"
	fi
else
	strip ${STRIPFLAG} ${OUTFILE:+"-o${OUTFILE}"} "${INFILE}"
fi

rm -f ${TMPFILE}