How to limit rotation without gimbal lock?

Thanks for your reply. I can add or subtract rotation, but I don’t think it will work in my case because how large the value it could add is depended on the working range which is ‘changed’ in world space when its owner rotates. Just imagine a camera gimbal with handle (but only has a work range less than 360 in yaw), which tries to keep a camera front all the time. If you rotate the handle over one circle, the camera rotates finally in yaw.
My case is that the gimbal lock happen(?) when I try to get its rotation, which make me hard to find out the correct working range in world space.