The instrument which shows how you are oriented is the attitude indicator: https://en.m.wikipedia.org/wiki/Attitude_indicator
The piloting skill of turning an upset airplane to right side up is called “unusual attitude recovery”: https://www.cfinotebook.net/notebook/maneuvers-and-procedure...
It is quite an interesting topic. Whole books were written about it. “Fundamentals of Spacecraft Attitude Determination and Control” is one I can warmly recommend. But if you just want a one sentence summary: “use quaternions” seems to be the prevailing wisdom.