AbbyMack is right. It is the nicotine in your lungs, due to your smoking habits. I advise you to leave your smoking and live a newer and a healthier lifestyle. You can try some physical activities to divert your attention from smoking again and embrace the healthy diet. You can also look for some treatments to quit smoking successfully.
It was the tar and nicotine in your lungs, which your body was trying to clear out. And it will take you several months to get the tar out of your lungs. Continuing to smoke will make your condition worse. So I advise you to stop smoking and practice a healthy lifestyle, to avoid more health problems related to smoking.
If you are smoking or been addicted to cigarette, then that's the reason why you're getting tar in your dry cough. But if the cough is already giving you so much pain, then you must see a doctor now to give you a proper advice on what to do with that problem of yours before it gets worst. But right now, you must consider quitting smoking or if you're having a hard time quitting, at least try to find better and other alternative.