User thread and os timer freeze,Photon System Firmware 0.5.4

You can add boatloads of Serial.print() statements to your code on strategically important places which give you feedback about strategically valuable variable values and states of your program.
If you need more you can even use hardware debugging which is explained in threads like these
https://community.particle.io/t/programmer-shield-installing-openocd-mac/15308
5 steps to setup and use a debugger with the Particle Photon

And there are tons of resources to be found online