Re: nios2: Remove binutils support for Nios II target
[binutils-gdb.git] / libbacktrace / install-debuginfo-for-buildid.sh.in
blob0b83a3660233aa9a719b5e0da44a6902207ed0bd
1 #!/bin/sh
3 # install-debug-info-for-buildid.sh -- Helper script for libbacktrace library
4 # testing.
5 # Copyright (C) 2019-2024 Free Software Foundation, Inc.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are
9 # met:
11 # (1) Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
14 # (2) Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in
16 # the documentation and/or other materials provided with the
17 # distribution.
19 # (3) The name of the author may not be used to
20 # endorse or promote products derived from this software without
21 # specific prior written permission.
23 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
35 # Extract build-id from src, and copy debug info of src to
36 # $build_id_dir/aa/bb...zz.debug.
38 set -e
40 sed=@SED@
41 awk=@AWK@
42 grep=@GREP@
43 objcopy=@OBJCOPY@
44 readelf=@READELF@
45 mkdir_p="@MKDIR_P@"
47 build_id_dir="$1"
48 src="$2"
50 buildid=$(LANG=C $readelf -n $src \
51 | $grep "Build ID" \
52 | $awk '{print $3}')
54 prefix=$(echo $buildid \
55 | $sed 's/^\(.\{2\}\).*/\1/')
57 remainder=$(echo $buildid \
58 | $sed 's/^.\{2\}//')
60 dir=$build_id_dir/$prefix
61 dst=$dir/$remainder.debug
63 $mkdir_p $dir
65 $objcopy --only-keep-debug $src $dst