_kgl_debug can be used to enable library cache related debug options.
Identify an SQL statement's full hash value:
select
ob.kglnahsv
--, ob.*
from
x$kglob ob
where
ob.kglnaobj = 'select * from tq84_a';
Start tracing:
alter system set "_kgl_debug" = "hash='c28c1d80fe6d4cffb5ebcf6bd7c3c0be' debug=33552";
Execute statement (likely in another session).
Stop tracing:
alter system set "_kgl_debug" = "hash='c28c1d80fe6d4cffb5ebcf6bd7c3c0be' debug=0";
As per MOS Note 2745080.1, from 18c forward, the debug level can be set to 99088 (= 33552 + 65536) which causes an invalidation of the specified cursor to be reported to the alert.log file (including the full trace file path name) so that an invalidation does not need to be grepped in all trace files:
alter system set "_kgl_debug"="hash= '552d9e82bf86a695a136485b680d47a7' debug=99088";