Dogs know when you’re upset and want to help, study says