123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081(** Nested tracing system for debugging. *)(* TRACING STUFF. A rewrite of Cil's tracing framework which is too slow for the
* large domains we output. The original code generated the document object
* even when the subsystem is not activated. *)openGoblint_stdopenGoblintCilopenPrettymoduleStrs=Set.Make(String)lettracing=Goblint_build_info.dune_profile="trace"letcurrent_loc=reflocUnknownletnext_loc=reflocUnknownlettrace_sys=refStrs.emptyletactivated=refStrs.emptyletactive_dep=Hashtbl.create9lettracevars=ref([]:stringlist)lettracelocs=ref([]:intlist)letaddsystemsys=trace_sys:=Strs.addsys!trace_sysletactivate(sys:string)(subsys:stringlist):unit=letsubs=List.fold_rightStrs.addsubsys(Strs.addsysStrs.empty)inactivated:=Strs.union!activatedsubs;Hashtbl.addactive_depsyssubsletdeactivate(sys:string):unit=activated:=Strs.diff!activated(tryHashtbl.findactive_depsyswithNot_found->Goblint_logs.Logs.error"Missing tracing active_dep for %s"sys;Strs.empty)letindent_level=ref0lettraceIndent()=indent_level:=!indent_level+2lettraceOutdent()=indent_level:=!indent_level-2lettraceTag(sys:string):Pretty.doc=letrecind(i:int):string=if(i<=0)then""else" "^(ind(i-1))in(text((ind!indent_level)^"%%% "^sys^": "))letprinttracesysd:unit=fprintstderr~width:max_int((traceTagsys)++d++line);flushstderrletgtracealwaysfsysvar?locdo_subsysfmt=letcond=(Strs.memsys!activated||always&&Strs.memsys!trace_sys)&&(* TODO: allow file, column in tracelocs? *)matchvar,locwith|Somes,Somel->(!tracevars=[]||List.mems!tracevars)&&(!tracelocs=[]||List.meml.line!tracelocs)|Somes,None->(!tracevars=[]||List.mems!tracevars)|None,Somel->(!tracelocs=[]||List.meml.line!tracelocs)|_->trueinifcondthenbegindo_subsys();gprintf(fsys)fmtendelseGobPretty.igprintf()fmtlettracesys?varfmt=gtracetrueprinttracesysvarignorefmt(* trace*
* l: include location
* i: indent after print, optionally activate subsys for sys
* u: outdent after print, deactivate subsys of sys
* c: continue/normal print w/o indent-change
*)lettracei(sys:string)?var?(subsys=[])fmt=letfsysd=printtracesysd;traceIndent()inletg()=activatesyssubsysingtracetruefsysvargfmtlettracecsysfmt=gtracefalseprinttracesysNoneignorefmtlettraceusysfmt=letfsysd=printtracesysd;traceOutdent()inletg()=deactivatesysingtracetruefsysNonegfmt