The phrase potentially has its origin in a Royal Navy direction that pregnant women aboard smaller naval vessels give birth in the space between the broadside guns, in order to keep the gangways and crew decks clear. Admiral William Henry Smyth wrote in his 1867 book, The Sailor’s Word-Book: “Son of a gun, an epithet conveying contempt in a slight degree, and originally applied to boys born afloat, when women were permitted to accompany their husbands to sea; one admiral declared he literally was thus cradled, under the breast of a gun-carriage.”
https://en.wikipedia.org/wiki/Son_of_a_gun
Checks out. Very interesting.
Since its naval, Jimmy Buffett comes to mind.
Son of a son of a gun.
EDIT: too much time was spent on this