logo

mstrace

Small Linux strace(1) implementationgit clone https://anongit.hacktivis.me/git/mstrace.git/

syscalls.sh (1102B)


  1. #!/bin/sh
  2. while read syscall args
  3. do
  4. fmt='"%s("'
  5. fmt_args='str_syscalls[nr]'
  6. fmt_sep=''
  7. n=0
  8. for i in $args; do
  9. case $i in
  10. "")
  11. break
  12. ;;
  13. "size")
  14. fmt="${fmt}${fmt_sep}\"%zd\""
  15. fmt_args="${fmt_args}, (size_t)args[$n]"
  16. ;;
  17. "off")
  18. fmt="${fmt}${fmt_sep}Pri_u"
  19. fmt_args="${fmt_args}, (off_t)args[$n]"
  20. ;;
  21. "uint")
  22. fmt="${fmt}${fmt_sep}Pri_u"
  23. fmt_args="${fmt_args}, (uint64_t)args[$n]"
  24. ;;
  25. "int")
  26. fmt="${fmt}${fmt_sep}Pri_i"
  27. fmt_args="${fmt_args}, (int64_t)args[$n]"
  28. ;;
  29. "oct")
  30. fmt="${fmt}${fmt_sep}Pri_o"
  31. fmt_args="${fmt_args}, (int64_t)args[$n]"
  32. ;;
  33. "hex"|"buf")
  34. fmt="${fmt}${fmt_sep}Pri_x"
  35. fmt_args="${fmt_args}, (int64_t)args[$n]"
  36. ;;
  37. "path")
  38. fmt="${fmt}${fmt_sep}Pri_str"
  39. fmt_args="${fmt_args}, read_str(args[$n], PATH_MAX)"
  40. ;;
  41. *)
  42. echo "syscalls.sh: error: Unhandled type ${i}" >&2
  43. exit 1
  44. esac
  45. : $((n+=1))
  46. fmt_sep=' ", " '
  47. done
  48. fmt="${fmt}"' ")"'
  49. printf ' case SYS_%s:\n' "$syscall"
  50. printf ' fprintf(stderr, %s, %s);\n' "$fmt" "$fmt_args"
  51. printf ' return;\n'
  52. done <syscalls.txt >syscalls_cases.h