How to find a function called by a UI command

Is there a way to find which function is called by a UI command?
For example, how can we find which function is called when ‘/gun/ion 27 53 0 3197.’ is executed?

The easiest way it to search for /gun/ion in Geant4/source directory (e.g. with grep).
That gives you and

ionCmd = new G4UIcommand("/gun/ion",this);

Then you check where ionCmd is used, and you find the function you seek in G4ParticleGunMessenger::SetNewValue(...).

More generally, go to Geant4 Cross Reference :
In Full-Text Search : /gun/ion

Thank you both very much. This is extremely helpful!