There are tons of debugging aids out there, and I'm sure all of us have our collection of routines and code snippets that we use to try to figure what the hell's going on in there, apart from Olly or some other real debugger.
Well, here's another tool I came up with. I like this one; it's a logging window you can attach to your program to display info while it's running. And I'm really kinda proud of myself at the moment because
this is my very first DLL! All these years and I never tried it; one day and I got one running. Not right off the bat, of course, 'cuz I had to make the usual stupid mistakes first ...
I opted for a DLL because I wanted to have minimum intrusion into the code being debugged; don't like having to link in extra modules, and I also don't like having to insert huge swaths of code to display stuff. This tool is, I think, a pretty good compromise. I call it LogBuddy.
Here's now it works:
1. You insert some minimal code into your program you want debugged: the header file at the top:
include LogBuddy.inc
and a not-too-big stub module at the end:
include LogBuddyStub.asm
2. In your code, you first need to initialize LogBuddy--this loads the DLL and gets all the procedure addresses in it:
CALL LogBuddyInit
3. At the point where you want the logging window to appear, you start LogBuddy like so, which creates the logging window:
INVOKE LogBuddyStart, OFFSET OurWinTitle ;or pass NULL to use the default window title
4. Now you can use it to log stuff. You have the following functions at your disposal:
- LogBuddyLogMsg(): Logs Windows messages (WM_xxxx)
- LogBuddyDumpMem(): Gives you a standard hex/ASCII memory dump display
- LogBuddyAddText(): Adds any text you want to the log
- LogBuddyAddSeparator(): Puts a visual separator in the log
- LogBuddyClearLog()
- LogBuddyLogVar(): Writes an item, "<var> = <value>" to the log in any of several formats
- LogBuddyWriteToFile()
These are all implemented through small stub routines in your code that call the DLL routines (using push-push-call). The stub checks for errors, so if the DLL isn't loaded for some reason it'll report that and prevent you from trying to call through null pointers.
The DLL can go in whatever folder your program is running from.
The log window has some toolbar buttons in it for interactive control as well. One nice feature is that if you're logging messages and you start getting overwhelmed by a flood of them, you can turn off logging, and turn it back on later.
Anyhow, maybe someone wants to give this a try. All the files should be in the .zip.
This is not finished. Several missing things and some issues:
1. Write to file is not yet implemented.
2. This only works with 32-bit assembly-language code. Later I might add support for C, but since I don't use 64-bit, probably won't do that. But when it gets closer to being finished I'll post my complete code here and you can modify it yourself.
3. I plan on improving the message logging to include WM_NOTIFY notifications and other additional information.
4. I still haven't gotten how to scroll my edit control (a RichEdit) to the end when I add stuff to it so the last info added is visible. Any advice here would be appreciated.
5. Still need to refine the clean-up phase, make sure all handles are released or deleted, etc. So far, I haven't noticed any major problems. Of course, the last thing you want is a buggy debugging tool!
Oh, and I managed to get all the bitmaps into the DLL without using any resource stuff. (Like someone here said, "Look Ma, no resources!") That BMP loading routine I came up with is a killer.