Sure, the modern application of the term for a female dog has replaced the “gun” part, but the origin of the phrase dates back to the Age of Sail (1700’s to early 1800’s). Often times sailors in port would become beholden to ladies they’ve been holdin’ and the woman in question would become pregnant. Many times the children of these Ports of Booty Calls would be born on board the vessel to which the sail was assigned. Often to hasten the actual labor, the would put the woman in a hammock strapped in between two cannons and actually fire the cannons to induce labor. So to call someone a “son of a gun” is to imply that the person is the son of a prostitute.
Oh, and they no longer practice that method of childbirth today as people tend to get a bit worried about live cannon fire in hospitals. Wimps!