Question

I wrote a code that is capable to produce coverage data of itself with the map file and without the need of another application debugging it and its also capable of generating a xml report compatible with Cobertura report and OpenCover for further analisis and graphic reports.

Thing is, so far i have to call the function to generate the report manually and the idea is to generate it automatically as soon as the process is exiting.

My first approach was to try and write hooks at RtlExitUserProcess/RtlExitUserThread/ExitProcess but each function cover some specific case, if you force the process to end (kill it using taskkill for example) or close the application console window with CTRL+C the behavior changes.

Is there any way i can create a reliable callback that will be always called when the application is about to end? Just like when you are debugging another app and when the process dies you receive a debug event with detailed information.

Thanks in advance

Was it helpful?

Solution

No, you cannot hook the termination of your own process. If you could, then a malicious (or just buggy) program could hook it an then refuse to follow through with the termination. It's different for a debugger because the debugger is a separate program.

Were I writing your program, I'd just put my reporting code in the finalization section of the relevant unit. The Delphi RTL will call it as the program shuts down, generally in reverse order that the units were initialized in, which again is generally the order in which units were used. Use your analysis unit early in the program, and it will get finalized late in the termination sequence, allowing you to capture as much data as possible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top