Gloucestershire recovered from 46-5 to enjoy the better of day two in their Division Two fixture with Leicestershire at Grace Road.