Home | History | Annotate | Line # | Download | only in libbacktrace
      1 #!/bin/sh
      2 
      3 # install-debug-info-for-buildid.sh -- Helper script for libbacktrace library
      4 # testing.
      5 # Copyright (C) 2019-2024 Free Software Foundation, Inc.
      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 
     38 set -e
     39 
     40 sed=@SED@
     41 awk=@AWK@
     42 grep=@GREP@
     43 objcopy=@OBJCOPY@
     44 readelf=@READELF@
     45 mkdir_p="@MKDIR_P@"
     46 
     47 build_id_dir="$1"
     48 src="$2"
     49 
     50 buildid=$(LANG=C $readelf -n $src \
     51 	      | $grep "Build ID" \
     52 	      | $awk '{print $3}')
     53 
     54 prefix=$(echo $buildid \
     55 	     | $sed 's/^\(.\{2\}\).*/\1/')
     56 
     57 remainder=$(echo $buildid \
     58 		| $sed 's/^.\{2\}//')
     59 
     60 dir=$build_id_dir/$prefix
     61 dst=$dir/$remainder.debug
     62 
     63 $mkdir_p $dir
     64 
     65 $objcopy --only-keep-debug $src $dst
     66