index : builder | |
Archlinux32 build system | gitolite user |
summaryrefslogtreecommitdiff |
author | Erich Eckner <git@eckner.net> | 2018-01-21 15:51:23 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2018-01-21 15:51:23 +0100 |
commit | 322356cd803127f4eb5de2fdff309086d57a6828 (patch) | |
tree | c100febd613e77339f7b35911e7bf7b5f9faf6ad /bin/opcode | |
parent | 289131e5c9f58d8f9db3d7bf77c9de5452c198ca (diff) |
-rwxr-xr-x | bin/opcode | 49 |
@@ -24,6 +24,9 @@ # with Opcode_WILLAMETTE_Base # * Remove all line in Opcode_ARM_THUMB # return values + +# shellcheck disable=SC2001,SC2034,SC2086 + EXIT_FOUND=0 EXIT_NOT_FOUND=1 EXIT_USAGE=2 @@ -42,7 +45,8 @@ Line_Numbers=false Leading_Context=0 Trailing_Context=0 -source "${0%/*}/../conf/Opcode_list" # include opcodes from a separate file +# shellcheck source=lib/opcode_list +source "${0%/*}/../lib/opcode_list" # include opcodes from a separate file # GAS-specific opcodes (unofficial names) belonging to the x64 instruction set. # They are generated by GNU tools (e.g. GDB, objdump) and specify a variant of ordinal opcodes like NOP and MOV. @@ -162,7 +166,7 @@ usage() { echo "The script uses Intel opcode syntax. When used in conjunction with objdump, \`-M intel' must be set in order to prevent opcode translation using AT&T syntax." echo echo "BE AWARE THAT THE LIST OF KNOWN INSTRUCTIONS OR INSTRUCTIONS SUPPORTED BY PARTICULAR ARCHITECTURES (ESPECIALLY AMD'S) IS ONLY TENTATIVE AND MAY CONTAIN MISTAKES!" - kill -TRAP $TOP_PID + kill -TRAP "$TOP_PID" } list_contains() { # Returns 0 if $2 is in array $1, 1 otherwise. @@ -175,25 +179,25 @@ list_contains() { # Returns 0 if $2 is in array $1, 1 otherwise. build_instruction_set() { # $1 = enum { Arch, InstSet }, $2 = architecture or instruction set as obtained using -L or -l, $3 = "architecture"/"instruction set" to be used in error message local e - list_contains "`eval echo \\\$${1}List`" "$2" || (echo "$2 is not a valid $3."; usage) # Test if the architecture/instruction set is valid. - if [ -n "`eval echo \\\$${1}_${2}`" ]; then # Add the instruction set(s) if any. - for e in `eval echo \\\$${1}_${2}`; do # Skip duplicates. + list_contains "$(eval echo \\\$${1}List)" "$2" || (echo "$2 is not a valid $3."; usage) # Test if the architecture/instruction set is valid. + if [ -n "$(eval echo \\\$${1}_${2})" ]; then # Add the instruction set(s) if any. + for e in $(eval echo \\\$${1}_${2}); do # Skip duplicates. list_contains "$InstSet_Base" $e || InstSet_Base="$e $InstSet_Base" done fi if [ $Recursive = true ]; then - for a in `eval echo \\\$${1}Dep_$2`; do + for a in $(eval echo \\\$${1}Dep_$2); do build_instruction_set $1 $a "$3" done fi - InstSet_Base="`echo $InstSet_Base | sed 's/$ *//'`" # Remove trailing space. + InstSet_Base=$(echo $InstSet_Base | sed 's/$ *//') # Remove trailing space. } -trap "exit $EXIT_USAGE" TRAP # Allow usage() function to abort script execution. +trap 'exit $EXIT_USAGE' TRAP # Allow usage() function to abort script execution. export TOP_PID=$$ # PID of executing process. # Parse command line arguments. -while getopts ":ra:s:LliIcf:Fd:D:CvVm:nB:A:h" o; do +while getopts ":ra:s:LliIcf:d:D:CvVm:nB:A:h" o; do case $o in r) Recursive=true ;; a) build_instruction_set Arch "$OPTARG" "architecture" ;; @@ -205,19 +209,19 @@ while getopts ":ra:s:LliIcf:Fd:D:CvVm:nB:A:h" o; do echo $InstSet_Base exit $EXIT_USAGE else - echo -e "No instruction set or architecture set.\n" + echo -e "No instruction set or architecture set.\\n" usage fi ;; I) if [ -n "$InstSet_Base" ]; then for s in $InstSet_Base; do - echo -ne "\e[31;1m$s:\e[0m " + echo -ne "\\e[31;1m$s:\\e[0m " eval echo "\$Opcode_$s" done exit $EXIT_USAGE else - echo -e "No instruction set or architecture set.\n" + echo -e "No instruction set or architecture set.\\n" usage fi ;; @@ -226,12 +230,12 @@ while getopts ":ra:s:LliIcf:Fd:D:CvVm:nB:A:h" o; do # Unlike architectures, instruction sets are disjoint. Found=false for s in $InstSetList; do - for b in `eval echo \\\$InstSet_$s`; do + for b in $(eval echo \\\$InstSet_$s); do Found_In_Base=false - for i in `eval echo \\\$Opcode_$b`; do + for i in $(eval echo \\\$Opcode_$b); do if [[ "$i" =~ ^$OPTARG$ ]]; then - $Found_In_Base || echo -ne "Instruction set \e[33;1m$s\e[0m (base instruction set \e[32;1m$b\e[0m):" - echo -ne " \e[31;1m$i\e[0m" + $Found_In_Base || echo -ne "Instruction set \\e[33;1m$s\\e[0m (base instruction set \\e[32;1m$b\\e[0m):" + echo -ne " \\e[31;1m$i\\e[0m" Found_In_Base=true Found=true fi @@ -240,7 +244,7 @@ while getopts ":ra:s:LliIcf:Fd:D:CvVm:nB:A:h" o; do done done if [ $Found = false ]; then - echo -e "Operation code \e[31;1m$OPTARG\e[0m has not been found in the database of known instructions." \ + echo -e "Operation code \\e[31;1m$OPTARG\\e[0m has not been found in the database of known instructions." \ "Perhaps it is translated using other than Intel syntax. If obtained from objdump, check if the \`-M intel' flag is set." \ "Be aware that the search is case sensitive by default (you may use the -C flag, otherwise only lower case opcodes are accepted)." exit $EXIT_NOT_FOUND @@ -259,13 +263,13 @@ while getopts ":ra:s:LliIcf:Fd:D:CvVm:nB:A:h" o; do A) Trailing_Context=$OPTARG ;; h) usage ;; \?) - echo -e "Unknown option: -$OPTARG\n" + echo -e "Unknown option: -$OPTARG\\n" usage ;; esac done shift $((OPTIND-1)) -[ -n "$1" ] && echo -e "Unknown command line parameter: $1\n" && usage +[ -n "$1" ] && echo -e "Unknown command line parameter: $1\\n" && usage [ -z "$InstSet_Base" ] && usage # Create list of grep parameters. @@ -279,12 +283,13 @@ Grep_Params="--color=auto -B $Leading_Context -A $Trailing_Context" # Build regular expression for use in grep. RegEx="" for s in $InstSet_Base; do - eval RegEx=\"$RegEx \$Opcode_$s\" + eval 'RegEx="$RegEx $Opcode_'"$s"'"' done # Add leading and trailing opcode separators to prevent false positives. -RegEx="$Leading_Separator`echo $RegEx | sed "s/ /$(echo "$Trailing_Separator"|sed 's/[\/&]/\\\&/g')|$(echo "$Leading_Separator"|sed 's/[\/&]/\\\&/g')/g"`$Trailing_Separator" +RegEx="$Leading_Separator$(echo $RegEx | sed "s/ /$(echo "$Trailing_Separator"|sed 's/[\/&]/\\\&/g')|$(echo "$Leading_Separator"|sed 's/[\/&]/\\\&/g')/g")$Trailing_Separator" -[ $Verbose = true -a $Count_Matching = false ] && RegEx="$RegEx|\$" +[ $Verbose = true ] && [ $Count_Matching = false ] && RegEx="$RegEx|\$" +# shellcheck disable=SC2086 # The actual search. grep $Grep_Params -E "$RegEx" && exit $EXIT_FOUND || exit $EXIT_NOT_FOUND |