views:

116

answers:

2

we're shipping a shell extension dll (registered with regsvr32). is there an easy way to get debug output from this dll from another application (so we can send these traces home when something is broken)?

any ideas? what's the easiest way to get logdata from the dll to another process?

+1  A: 

If it's a shell extension DLL, then doesn't it run as the logged-in user, and can't it therefore write to a log file in some suitable directory on disk? If so why then would you want it to write to another process?

ChrisW
Agreed with ChrisW. Write logdata to a text file; there are plenty of ways to obtain the log file from the user if you need it.
Robert Harvey
For performance reasons, you don't want the log file to be generated always; only when trying to repro particular problem.
Franci Penov
You can have e.g. a registry entry which the shell extension DLL would read to see whether you requested that it enable logging.
ChrisW
Yes, there are different ways of controlling the logging. Just wanted to point out that log shouldn't be always on.
Franci Penov
A: 

You can use Event Tracing for Windows (ETW) to trace your extension DLL execution. ETW has almost no overhead when no listener is active, so in normal conditions your DLL will incur no perf penalty; at the same time it allows for detailed output at various levels of details.

The way ETW works is when the APIs are called, they check if there is a listener subscribed to the traces from particular publisher and if no, nothing is generated. If there is a listener, only the traces to which the listener is subscribed are written to a memory-mapped file. Thus, only as much traces data is generated as requested.

ETW listeners can be activated at any time and the publisher does not have to be restarted. Also, ETW is not flavor bound and can be used in both debug and retail. Thus, if a customer of yours has a problem, you have to only send them the listener with instructions on how to run it and collect the info; you don't have to sent them an instrumented binary version. You can either write your own app that acts as a listener, or you can use the standard tracelog.exe and tracefmt.exe tools to get the traces written to a file.

To generate the necessary ETW code in your DLL, you can use the WPP preprocesor instead of directly using the ETW APIs.

Note: While all the links I post here are to the Windows Driver Kit documentation, ETW and WPP can be (and are heavily) used for regular user mode programs.

Franci Penov
What is the user-mode API?
ChrisW
ChriwW: re user-mode ETW API: see http://msdn.microsoft.com/en-us/library/aa964766%28VS.85%29.aspx and http://msdn.microsoft.com/en-us/library/aa363787(VS.85).aspx.
itowlson
At first look it doesn't seem like an "easy" or the "easiest" API.
ChrisW
No, the raw ETW APIs are not the "easiest" API. However, WPP simplifies things a lot.On a side note, we use WPP/ETW in our team for both diagnostic tracing and for performance measurements.
Franci Penov