Tracking your cost basis
The simplest way to keep track of your cost basis is to note the amount of dividends on which you're taxed from year to year. By adding those amounts to what you originally paid for shares, you'll accurately reflect your total cost basis for the position. Some DRIPs will even keep track of your cost basis information for you.
What gets tricky is if you decide to sell only a portion of your shares. In that case, you'll have to choose which method to use to select the exact shares that you sell. Using a method like first in, first out will generally get you long-term treatment for any gains or losses, but if the stock has risen over time, that method will sometimes lead to larger taxable gains than others. By contrast, specific identification can allow you to choose shares with smaller gains, but you might not have held those shares long enough to get preferential long-term treatment.