]> git.ipfire.org Git - thirdparty/gcc.git/blame - libbacktrace/install-debuginfo-for-buildid.sh.in
Move 2 mklog scripts to legacy subfolder.
[thirdparty/gcc.git] / libbacktrace / install-debuginfo-for-buildid.sh.in
CommitLineData
fddbc193
TV
1#!/bin/sh
2
3# install-debug-info-for-buildid.sh -- Helper script for libbacktrace library
4# testing.
8d9254fc 5# Copyright (C) 2019-2020 Free Software Foundation, Inc.
fddbc193
TV
6
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are
9# met:
10
11# (1) Redistributions of source code must retain the above copyright
12# notice, this list of conditions and the following disclaimer.
13
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.
18
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.
22
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.
34
35# Extract build-id from src, and copy debug info of src to
36# $build_id_dir/aa/bb...zz.debug.
37
38set -e
39
40sed=@SED@
41awk=@AWK@
42grep=@GREP@
43objcopy=@OBJCOPY@
44readelf=@READELF@
45mkdir_p="@MKDIR_P@"
46
47build_id_dir="$1"
48src="$2"
49
50buildid=$($readelf -n $src \
51 | $grep "Build ID" \
52 | $awk '{print $3}')
53
54prefix=$(echo $buildid \
55 | $sed 's/^\(.\{2\}\).*/\1/')
56
57remainder=$(echo $buildid \
58 | $sed 's/^.\{2\}//')
59
60dir=$build_id_dir/$prefix
61dst=$dir/$remainder.debug
62
63$mkdir_p $dir
64
65$objcopy --only-keep-debug $src $dst