r189495: Pull out some debug logic into a function for legibility

Code review feedback from Eric Christopher.