Geometry and topology of chiral anomalies in gauge theories