How to dynamically adjust the angle of a bone to make it point in the correct direction

no worries i might be misunderstanding, in your first pic the X vector doesnt face forward (in relation to the gun) so i though you wanted to rotate that?