The program you're thinking of is
texdef, by Martin Sharrer. It can be found here, but should already be included with your TeX distribution.
To find out how a macro is defined, you can type
latexdef <macro> or
texdef -t latex <macro> (if the first one doesn't work), where
<macro> is the name of the command you are interested in (without the initial
If you want to know the definition when certain packages or classes are loaded, you can tell latexdef using
-p [<options]<package> flag and
-c [<options>]<class> respectively (
article is used if no class is specified).
To find out how
TheSolution is defined if
hyperref is loaded with the draft option (which actually makes no difference), you would for instance type
latexdef -c exam -p [draft]hyperref -E TheSolution
TheSolution is an environment, so the definition of
endTheSolution is also shown. If
TheSolution had been a (dimension, skip, count, token sequence, …) register I would instead have ve added
-v to see its value.
To figure out in which file a macro is defined you can
-f, and you can then find out where this file is located using
kpsewhich <filename>. If
latexdef says that a macro is defined by LaTeX then it can probably be found in
fontmath.ltx, or in one of the other files in the same directory.
There are many more options, which you can see by running
texdef -h or by looking at the documentation.