xref: /netbsd-src/external/gpl3/gcc.old/dist/libbacktrace/install-debuginfo-for-buildid.sh.in (revision 4c3eb207d36f67d31994830c0a694161fc1ca39b)
1627f7eb2Smrg#!/bin/sh
2627f7eb2Smrg
3627f7eb2Smrg# install-debug-info-for-buildid.sh -- Helper script for libbacktrace library
4627f7eb2Smrg# testing.
5*4c3eb207Smrg# Copyright (C) 2019-2020 Free Software Foundation, Inc.
6627f7eb2Smrg
7627f7eb2Smrg# Redistribution and use in source and binary forms, with or without
8627f7eb2Smrg# modification, are permitted provided that the following conditions are
9627f7eb2Smrg# met:
10627f7eb2Smrg
11627f7eb2Smrg#     (1) Redistributions of source code must retain the above copyright
12627f7eb2Smrg#     notice, this list of conditions and the following disclaimer.
13627f7eb2Smrg
14627f7eb2Smrg#     (2) Redistributions in binary form must reproduce the above copyright
15627f7eb2Smrg#     notice, this list of conditions and the following disclaimer in
16627f7eb2Smrg#     the documentation and/or other materials provided with the
17627f7eb2Smrg#     distribution.
18627f7eb2Smrg
19627f7eb2Smrg#     (3) The name of the author may not be used to
20627f7eb2Smrg#     endorse or promote products derived from this software without
21627f7eb2Smrg#     specific prior written permission.
22627f7eb2Smrg
23627f7eb2Smrg# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24627f7eb2Smrg# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25627f7eb2Smrg# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26627f7eb2Smrg# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27627f7eb2Smrg# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28627f7eb2Smrg# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29627f7eb2Smrg# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30627f7eb2Smrg# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31627f7eb2Smrg# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32627f7eb2Smrg# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33627f7eb2Smrg# POSSIBILITY OF SUCH DAMAGE.
34627f7eb2Smrg
35627f7eb2Smrg# Extract build-id from src, and copy debug info of src to
36627f7eb2Smrg# $build_id_dir/aa/bb...zz.debug.
37627f7eb2Smrg
38627f7eb2Smrgset -e
39627f7eb2Smrg
40627f7eb2Smrgsed=@SED@
41627f7eb2Smrgawk=@AWK@
42627f7eb2Smrggrep=@GREP@
43627f7eb2Smrgobjcopy=@OBJCOPY@
44627f7eb2Smrgreadelf=@READELF@
45627f7eb2Smrgmkdir_p="@MKDIR_P@"
46627f7eb2Smrg
47627f7eb2Smrgbuild_id_dir="$1"
48627f7eb2Smrgsrc="$2"
49627f7eb2Smrg
50627f7eb2Smrgbuildid=$($readelf -n $src \
51627f7eb2Smrg	      | $grep "Build ID" \
52627f7eb2Smrg	      | $awk '{print $3}')
53627f7eb2Smrg
54627f7eb2Smrgprefix=$(echo $buildid \
55627f7eb2Smrg	     | $sed 's/^\(.\{2\}\).*/\1/')
56627f7eb2Smrg
57627f7eb2Smrgremainder=$(echo $buildid \
58627f7eb2Smrg		| $sed 's/^.\{2\}//')
59627f7eb2Smrg
60627f7eb2Smrgdir=$build_id_dir/$prefix
61627f7eb2Smrgdst=$dir/$remainder.debug
62627f7eb2Smrg
63627f7eb2Smrg$mkdir_p $dir
64627f7eb2Smrg
65627f7eb2Smrg$objcopy --only-keep-debug $src $dst
66