$trole = get_records_sql("SELECT roleid,capability,permission FROM {$CFG->prefix}role_capabilities WHERE roleid = $roleid");to pick the example I have just tracked down to backup/restore_form.php.
Well, sam pointed out to me that it should be possible to output a developer debug message when this happens, and indeed it is. I have just implemented this on the 1.9 stable branch and HEAD. MDL-12438 is the bug.