ATTENTION ALL FANS!!! THIS BLOG HAS MOVED!!!
go to: http://www.taotekaching.com

Tuesday, February 03, 2009

Visual Studio Extensions, C++ Debugging, and Me…

So, I am lazy, as I believe most programmers are.  I follow Bill Cosby’s sage advice to work hard to keep from working.

At work I’d “inherited” a code-complete medium-sized application in C++ that requires somewhat extensive feature enhancements / changes (due to the customer, of course).

I’ve been noticing that it seems much easier to write very foreign looking code in C / C++ than it is in C#, and although this application was obviously brilliantly coded, it is quite foreign indeed, seeming to be more of a C+ application than full-on C or C++.

Nevertheless, I have my work cut out for me, and it needs to be done FAST.  I need to make changes and see what breaks, then fix it, and so on.  The problem was, no debugging code was written into the application at all.  What was I to do?  I could spend a good 2 to 3 weeks adding debug output to all the functions, but I don’t have 2 to 3 weeks.  WHAT DO I DO?

Introducing AutoDebugIndexer!  It’s a simple Visual Studio Extension in C# that tried to add an OutputDebugStringA to the beginning of every function it finds.  What’s great is it seems to work!

It simply recurses through all the CodeElements of each Project’s CodeModel, checks to see if each (as a C++ CodeElement) is a vsCMElementFunction, and if so, tries to slap an OutputDebugStringA containing the function’s FullName at the beginning of that function’s BodyTextDownload the source and see for yourself.  Really you only need to look at AutoDebug.cs, everything else is pretty much Extensibility Wizard code.

On a side note, this is an extremely simple solution here.  I did not try at all to make this pretty, nor make it work beyond C++.  The latter is easy, however.  You’d just test for the code type, at the very least at the project level, and if it is say C#, insert a System.Diagnostics.Debug.WriteLine(“blah”); instead of the OutputDebugStringA.

Hope this is as valuable to you as it certainly will be for me!

~ZagNut

Submit this story to DotNetKicks