If your dog coughed up worms, then your dog needs to be dewormed. The most common worms found in dogs are:
Roundworms, Hookworms, Tapeworms, and Whipworms and Heartworms
In some cases these worms are passed from the mother to the puppy, in other cases such as tapeworms, they are contracted by other methods such as ingesting an infected flea. Most over the counter medicine will only kill one or two types of worms, so your best bet is to take a fecal sample to your vet to determine the type of worms your dog may have and then decide on treatment. Dogs should be checked for worms periodically even if they appear healthy. This is so if your pet does become ill, you are not fighting a worm infestation along with a more serious problem.
For additional information about worms, see this site
This is called Coprophagia . Many dogs eat their own feces. Some eat any feces they find. Cat feces seem to be a favorite. No cause has been determined as to why dogs do this though some believe it may be a dietary deficiency while others believe it to be an obsessive compulsion disorder. The best thing to do is try and curb your dog's tendancy to do it.
Number one thing to do is to get the temptation out of the picture by removing feces out of the yard as soon as possible and keep it cleaned up. You can also put hot sauce or other pepper product on them so the dog finds then terrible tasting. There are over the counter products that you can give your dog daily to prevent this condition. They work in some cases and if it works for you, then it’s an easy solution. You can buy them at most pet stores. :
It will be harder to treat if your dog eats it’s own feces right after going. You will need to be with your dog when it is going and divert your dog away from it, praising your dog when it does not try and eat it. A firm “leave it” and correction should be said when he tries to eat it and comes in handy in the future for other items you do not want your dog eating.
You can read more about Coprophagia here.
I hope this helps you with this frustrating and all to common problem.