In practical usage, they might communicate the same thing. However, the words themselves don't have the same meaning:
I was so worried about today's exam that I stayed up all night studying.
This means that you spent all night actually engaged in studying. This describes what you did while awake.
I was so worried about today's exam that I stayed up all night to study.
This means that you stayed up all night with the intention of studying. But whether or not you actually studied, or how much of the night was taken up with studying, is unknown. This only talks about why you stayed up all night.