Advertisement
amigojapan

Javascript race condition debugging tool Copyright 2017 Usma

Mar 27th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.06 KB | None | 0 0
  1. #!/bin/bash
  2. ###Javascript race condition debugging tool Copyright 2017 Usmar A. Padow (amigojapan) usmpadow@gmail.com
  3. ###It basically makes a program that has the same lines as your current program,
  4. ##but it also dumps the value of every variable every execution,
  5. ##so at the end you can use diff to find the point where the execution differed
  6. ###Reason:
  7. ##basically I am making a block programming language “simillar to scratch” and it can load projecct by
  8. ##a parameter to the URL,    but when i do that it sometimes loads properly,, and it sometimes goes crazy
  9. ##and does nto seem to be executing a function it should be executing
  10.  
  11. INPUT_JS_FILE="test1.txt"
  12. INTERLACED_FILE="interlaced.js"
  13. API="API.js"
  14.  
  15. #then generate a file with the same number of dump_all() lines as lines of text in the JS code
  16.  
  17. #line couont in bash
  18. LINE_COUNT="$(wc -l < $INPUT_JS_FILE)"
  19. #LINE_COUNT=$(expr $LINE_COUNT + 1) #correct off by one problem
  20. #delete extra whitespaces http://stackoverflow.com/questions/369758/how-to-trim-whitespace-from-a-bash-variable
  21. LINE_COUNT="$(echo -e "${LINE_COUNT}" | tr -d '[:space:]')"
  22. echo "LINE COUNT:${LINE_COUNT}"
  23.  
  24. #http://unix.stackexchange.com/questions/81904/repeat-each-line-multiple-times
  25. while read line; do for i in {1..$LINE_COUNT}; do echo "dump_all();"; done; done < $INPUT_JS_FILE > dummy.js
  26.  
  27. #how to interlace one file with another seperated by newlines, useful for translating!
  28. paste -d "\n" $INPUT_JS_FILE dummy.js  > $INTERLACED_FILE
  29.  
  30. #add an extra call, cause it does not add it before
  31. echo "dump_all();" >> $INTERLACED_FILE
  32.  
  33. #then concatenate the folloing function to the bottm(the bottom so that line numbers remain the same)
  34. cat "${INTERLACED_FILE}" "${API}" > "TMP.js"
  35. mv TMP.js "${INTERLACED_FILE}"
  36.  
  37. 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"
  38. 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