Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ###Javascript race condition debugging tool Copyright 2017 Usmar A. Padow (amigojapan) usmpadow@gmail.com
- ###It basically makes a program that has the same lines as your current program,
- ##but it also dumps the value of every variable every execution,
- ##so at the end you can use diff to find the point where the execution differed
- ###Reason:
- ##basically I am making a block programming language “simillar to scratch” and it can load projecct by
- ##a parameter to the URL, but when i do that it sometimes loads properly,, and it sometimes goes crazy
- ##and does nto seem to be executing a function it should be executing
- INPUT_JS_FILE="test1.txt"
- INTERLACED_FILE="interlaced.js"
- API="API.js"
- #then generate a file with the same number of dump_all() lines as lines of text in the JS code
- #line couont in bash
- LINE_COUNT="$(wc -l < $INPUT_JS_FILE)"
- #LINE_COUNT=$(expr $LINE_COUNT + 1) #correct off by one problem
- #delete extra whitespaces http://stackoverflow.com/questions/369758/how-to-trim-whitespace-from-a-bash-variable
- LINE_COUNT="$(echo -e "${LINE_COUNT}" | tr -d '[:space:]')"
- echo "LINE COUNT:${LINE_COUNT}"
- #http://unix.stackexchange.com/questions/81904/repeat-each-line-multiple-times
- while read line; do for i in {1..$LINE_COUNT}; do echo "dump_all();"; done; done < $INPUT_JS_FILE > dummy.js
- #how to interlace one file with another seperated by newlines, useful for translating!
- paste -d "\n" $INPUT_JS_FILE dummy.js > $INTERLACED_FILE
- #add an extra call, cause it does not add it before
- echo "dump_all();" >> $INTERLACED_FILE
- #then concatenate the folloing function to the bottm(the bottom so that line numbers remain the same)
- cat "${INTERLACED_FILE}" "${API}" > "TMP.js"
- mv TMP.js "${INTERLACED_FILE}"
- echo "now put the context of ${INTERLACED_FILE} into your web page, run until the race condition happens, and aldo run when the race codition does not happen. take a sample of the log of both"
- echo "finally do a diff between both outputs, the first difference bewteen outputs should be close to the cause of the race condition"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement