1181254a7Smrg#!/bin/sh 2181254a7Smrg 3181254a7Smrg# install-debug-info-for-buildid.sh -- Helper script for libbacktrace library 4181254a7Smrg# testing. 5*b1e83836Smrg# Copyright (C) 2019-2022 Free Software Foundation, Inc. 6181254a7Smrg 7181254a7Smrg# Redistribution and use in source and binary forms, with or without 8181254a7Smrg# modification, are permitted provided that the following conditions are 9181254a7Smrg# met: 10181254a7Smrg 11181254a7Smrg# (1) Redistributions of source code must retain the above copyright 12181254a7Smrg# notice, this list of conditions and the following disclaimer. 13181254a7Smrg 14181254a7Smrg# (2) Redistributions in binary form must reproduce the above copyright 15181254a7Smrg# notice, this list of conditions and the following disclaimer in 16181254a7Smrg# the documentation and/or other materials provided with the 17181254a7Smrg# distribution. 18181254a7Smrg 19181254a7Smrg# (3) The name of the author may not be used to 20181254a7Smrg# endorse or promote products derived from this software without 21181254a7Smrg# specific prior written permission. 22181254a7Smrg 23181254a7Smrg# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24181254a7Smrg# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25181254a7Smrg# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26181254a7Smrg# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 27181254a7Smrg# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28181254a7Smrg# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29181254a7Smrg# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30181254a7Smrg# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31181254a7Smrg# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32181254a7Smrg# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33181254a7Smrg# POSSIBILITY OF SUCH DAMAGE. 34181254a7Smrg 35181254a7Smrg# Extract build-id from src, and copy debug info of src to 36181254a7Smrg# $build_id_dir/aa/bb...zz.debug. 37181254a7Smrg 38181254a7Smrgset -e 39181254a7Smrg 40181254a7Smrgsed=@SED@ 41181254a7Smrgawk=@AWK@ 42181254a7Smrggrep=@GREP@ 43181254a7Smrgobjcopy=@OBJCOPY@ 44181254a7Smrgreadelf=@READELF@ 45181254a7Smrgmkdir_p="@MKDIR_P@" 46181254a7Smrg 47181254a7Smrgbuild_id_dir="$1" 48181254a7Smrgsrc="$2" 49181254a7Smrg 50*b1e83836Smrgbuildid=$(LANG=C $readelf -n $src \ 51181254a7Smrg | $grep "Build ID" \ 52181254a7Smrg | $awk '{print $3}') 53181254a7Smrg 54181254a7Smrgprefix=$(echo $buildid \ 55181254a7Smrg | $sed 's/^\(.\{2\}\).*/\1/') 56181254a7Smrg 57181254a7Smrgremainder=$(echo $buildid \ 58181254a7Smrg | $sed 's/^.\{2\}//') 59181254a7Smrg 60181254a7Smrgdir=$build_id_dir/$prefix 61181254a7Smrgdst=$dir/$remainder.debug 62181254a7Smrg 63181254a7Smrg$mkdir_p $dir 64181254a7Smrg 65181254a7Smrg$objcopy --only-keep-debug $src $dst 66