stack: Make debugging outputs optional

Merge from two slightly different lines of development.