[4.8] Backport additional diagnostic support

Squashed commit of r198331, r198900, r201467,
and r201574 from trunk.

Change-Id: If0d68971ffac2e7bc48576e2453d799a446f7415