I would concur with Kamala about doing this either at build time (-Gh (_penter); -GH (_pexit)), or otherwise perhaps by instrumenting the code itself with some macros. In both cases, I would probably add a global variable to enable or disable tracing, and this could be set either by conditional compilation, and/or by WinDbg. What you are trying to do with symbol enumeration will not work unless you disambiguate function and data. This is a lot of work; build time instrumentation is much, much easier, and achieves, I think, the same effect.
-Gh is semi-documented, but all it does is call a function named _penter (that you must supply) immediately upon entry to every function; -GH calls _pexit just prior to returning from a function. In the case of _penter, keep in mind that is really is called right away, before normal prolog code, so you have to account for this, depending on what you do. If all you want is a break point, then you could call the __debugbreak intrinsic. The potential issue here is what this very nonstandard stack frame might do to confuse WinDbg; I don’t know. Also, you must preserve and restore and registers that you use so that the normal prolog code, which will be called after _penter returns, finds what it is expecting.
-Gh/-GH can get quite messy at times, mostly due to the interaction with the normal prolog. If you don’t wish to use this approach, then a similar effect can be achieved by inserting a suitable macro as the first statement in a function; in this case, however, the expansion of the macro will execute after the prolog.
If you wish to go the symbol route, then you will want to look at IDebugSymbols in the WinDbg documentation. Note that this documentation is quite incomplete, fairly unclear, and parts of it just do not function as one might expect. In particular, I do not know how much there is in the way of accessible information about symbol type from the IDebugSymbols point of view. Actually, I’m sure it’s there, but if I recall correctly, it is returned in the form of some packed string separated by ‘*,’ and it’s not documented. In general, the DbgEng interfaces, while very powerful, would fairly be described, based on the documentation, as quirky and incomplete.
mm
===
You might want to exercise caution while adding breakpoints by enumerating symbols. If you inadvertently insert breakpoint on thunks or data, you could bring down the process. Anyway, you might have already given this some thought.
I would suggest http://debuginfo.com http:</http:> website in general and http://debuginfo.com/examples/src/EnumSymbols.cpp http: link in particular as a reference. Also, if it is feasible for you to add this instrumentation at compile time, I think newer versions of visual studio compilers provide an option to add prolog and epilog instrumentaion (You could add a build configuration that would include this compile time option). In my opinion that is the easiest way to add execution tracing to a program.
Kamala
-------------- Original message --------------
From: Yan Brenman
Hi everyone!
I want to implement collection of the real time execution trace of a program. For that I would
like to be able to set a breakpoint at entry point of every function in the program.
Can somebody please give an advice and may be a code sample on how it can be done in
WinDbg extension.
My intention was to traverse the symbol table and for every symbol which is in the .text
section I would get an address of the symbol. Obviously this would be an address of the
first instruction of the function. After that all I need to do is to insert a breakpoint at that
address. Unfortunately I could not find proper facilities offered by WinDbg extensions to be
able that (except setting breakpoint at address - that is available).
Does anybody has any idea on how it can be done?
Every bit of help will be greatly appreciated.
Thanks
— You are currently subscribed to windbg as: xxxxx@comcast.net To unsubscribe send a blank email to xxxxx@lists.osr.com
—
You are currently subscribed to windbg as: xxxxx@evitechnology.com To unsubscribe send a blank email to xxxxx@lists.osr.com</http:>