Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mpers.sh 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh -e
  2. #
  3. # Copyright (c) 2015 Elvira Khabirova <lineprinter0@gmail.com>
  4. # Copyright (c) 2015-2019 The strace developers.
  5. # All rights reserved.
  6. #
  7. # SPDX-License-Identifier: LGPL-2.1-or-later
  8. [ "x${D:-0}" != x1 ] || set -x
  9. export LC_ALL=C
  10. MPERS_AWK="${0%/*}/mpers.awk"
  11. ARCH_FLAG=$1
  12. CC_ARCH_FLAG=$2
  13. PARSER_FILE=$3
  14. READELF="${READELF:-readelf}"
  15. CC="${CC-gcc}"
  16. CFLAGS="$CFLAGS -gdwarf-2 -c"
  17. CPP="${CPP-$CC -E}"
  18. CPPFLAGS="$CPPFLAGS -MM -MG"
  19. VAR_NAME='mpers_target_var'
  20. BITS_DIR="mpers-${ARCH_FLAG}"
  21. mkdir -p ${BITS_DIR}
  22. set -- $(sed -r -n \
  23. 's/^#[[:space:]]*include[[:space:]]+DEF_MPERS_TYPE\(([^)[:space:]]*)\)$/\1/p' \
  24. "${PARSER_FILE}")
  25. for m_type; do
  26. f_h="${BITS_DIR}/${m_type}.h"
  27. f_c="${BITS_DIR}/${m_type}.c"
  28. f_i="${BITS_DIR}/${m_type}.i"
  29. f_o="${BITS_DIR}/${m_type}.o"
  30. f_d1="${BITS_DIR}/${m_type}.d1"
  31. f_d2="${BITS_DIR}/${m_type}.d2"
  32. sed -e '
  33. /DEF_MPERS_TYPE('"${m_type}"')$/n
  34. /DEF_MPERS_TYPE/d
  35. /^[[:space:]]*#[[:space:]]*include[[:space:]]*"xlat\//d
  36. /^#[[:space:]]*include[[:space:]][[:space:]]*MPERS_DEFS$/ {s//'"${m_type} ${VAR_NAME}"';/;q}
  37. ' "${PARSER_FILE}" > "${f_c}"
  38. $CPP $CPPFLAGS "${f_c}" > "${f_i}"
  39. grep -F -q "${m_type}.h" "${f_i}" ||
  40. continue
  41. sed -i -e '/DEF_MPERS_TYPE/d' "${f_c}"
  42. $CC $CFLAGS $CC_ARCH_FLAG "${f_c}" -o "${f_o}"
  43. $READELF --debug-dump=info "${f_o}" > "${f_d1}"
  44. sed -r -n '
  45. /^[[:space:]]*<1>/,/^[[:space:]]*<1><[^>]+>: Abbrev Number: 0/!d
  46. /^[[:space:]]*<[^>]*><[^>]*>: Abbrev Number: 0/d
  47. s/^[[:space:]]*<[[:xdigit:]]+>[[:space:]]+//
  48. s/^[[:space:]]*((<[[:xdigit:]]+>){2}):[[:space:]]+/\1\n/
  49. s/[[:space:]]+$//
  50. p' "${f_d1}" > "${f_d2}"
  51. gawk -v VAR_NAME="$VAR_NAME" -v ARCH_FLAG="${ARCH_FLAG}" \
  52. -f "$MPERS_AWK" "${f_d2}" > "${f_h}"
  53. done