install-debuginfo-for-buildid.sh.in 2.1 KB

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