=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ctfconv/ctfstrip,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- src/usr.bin/ctfconv/ctfstrip 2017/08/11 15:08:16 1.3 +++ src/usr.bin/ctfconv/ctfstrip 2017/08/12 16:33:11 1.4 @@ -1,8 +1,8 @@ #!/bin/sh # -# $OpenBSD: ctfstrip,v 1.3 2017/08/11 15:08:16 jasper Exp $ +# $OpenBSD: ctfstrip,v 1.4 2017/08/12 16:33:11 jasper Exp $ # -# Copyright (c) 2017 Martin Pieuchot +# 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 @@ -27,14 +27,20 @@ USAGE="usage: ${0##*/} [-S] [-o outfile] file" -while getopts "o:S" opt; do - case $opt in - S) STRIPFLAG=-g;; - o) OUTFILE="${OPTARG}";; - *) print -u2 "${USAGE}"; exit 1;; +for arg in "$@"; do + if [ -n "$OSET" ]; then + OUTFILE="$arg" + unset OSET + shift + continue + fi + case "$arg" in + -o) OSET=1; shift; continue;; + -S) STRIPFLAG=-g; shift; continue;; esac + shift + set -- "$@" "$arg" done -shift $((OPTIND-1)) if [[ $# == 0 ]]; then print -u2 "${USAGE}"; @@ -43,14 +49,21 @@ LABEL="unknown" TMPFILE=$(mktemp /tmp/.ctf.XXXXXXXXXX) +INFILE=$(eval "echo \${$#}") # Extract kernel version -if [[ "$1" == bsd* ]]; then - LABEL=`what $1 |tr -d '\n'|awk -F"$1 " '{ print $2 '\n' }'` +if [[ "$INFILE" == bsd* ]]; then + LABEL=`what $INFILE |tr -d '\n'|awk -F"${INFILE} " '{ print $2 '\n' }'` fi -ctfconv -o ${TMPFILE} -l "${LABEL}" $1 || cleanup +# 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 -objcopy --add-section .SUNW_ctf=${TMPFILE} ${STRIPFLAG} $1 ${OUTFILE} +if [[ $? == 0 ]]; then + objcopy --add-section .SUNW_ctf=${TMPFILE} ${STRIPFLAG} ${INFILE} ${OUTFILE} +else + strip ${STRIPFLAG} $@ -o ${OUTFILE} ${INFILE} +fi rm -f ${TMPFILE}