The tunability of topological surface states and controllable opening of the Dirac gap are of fundamental and practical interest in the field of topological materials. In the newly discovered topological crystalline insulators (TCIs), theory predicts that the Dirac node is protected by a crystalline symmetry and that the surface state electrons can acquire a mass if this symmetry is broken. Recent studies have detected signatures of a spontaneously generated Dirac gap in TCIs; however, the mechanism of mass formation remains elusive. In this work, we present scanning tunnelling microscopy (STM) measurements of the TCI Pb1−xSnxSe for a wide range of alloy compositions spanning the topological and non-topological regimes. The STM topographies reveal a symmetry-breaking distortion on the surface, which imparts mass to the otherwise massless Dirac electrons—a mechanism analogous to the long sought-after Higgs mechanism in particle physics. Interestingly, the measured Dirac gap decreases on approaching the trivial phase, whereas the magnitude of the distortion remains nearly constant. Our data and calculations reveal that the penetration depth of Dirac surface states controls the magnitude of the Dirac mass. At the limit of the critical composition, the penetration depth is predicted to go to infinity, resulting in zero mass, consistent with our measurements. Finally, we discover the existence of surface states in the non-topological regime, which have the characteristics of gapped, double-branched Dirac fermions and could be exploited in realizing superconductivity in these materials.