views:

318

answers:

1

Hi, so I'm using Visual Studio 2005 and for my current project I'm building a C# Add-In to handle the weaving of aspects for AspectC++. It's simple enough to gather the aspect and source files and feed them into the aspect compiler, but this generates new (modified) source files. I'm trying to emulate the standard AspectC++ Add-In: http://www.pure-systems.com/AspectC_Add-In.22+M54a708de802.0.html, so I'd like to leave the source files for the project unchanged as I feed in the woven files to the C++ compiler. Assuming I can even do this (not sure how), how would I get the debugger to point correctly to the original source files? I know that I'll have to uncheck the VS option so the source doesn't have to match the compiled version, but I'm at a loss for how to associate the two without modifying the source files directly. Any advice?

A: 

It sounds like you want to modify the source code just before or after the preprocessor. In this case you should use the #line directive, to tell the compiler what file and line it is really processing. This is how the preprocessor works, it includes all your header files into one massive file, this file contains #line directives, which enables the compiler to report errors for the correct line and specify the correct line in the symbols for the the debugger.

You should try just running the preprocessor on a source file. This will show you how the #line directive works. The cl.exe command line option /P will help you here. Remember you will require all the other preprocessor options like /D and /I required to compile the file for this to work.

http://msdn.microsoft.com/en-us/library/b5w2czay(VS.71).aspx

iain
So let's say I tried this. I'd collect my source and aspect files, feed them into the AspectC++ Compiler (Weaver), take the new woven source files and insert #line directives periodically throughout the modified file that point back to the original unwoven file. After all this, I'd send the woven files with the #line directives to the C++ compiler. Did I follow that correctly? When you say it works with the debugger, does that include breakpoints? Is there a way to do this without inserting directives - like by changing some project or file settings?
Actually, after reading over the AspectC++ manual, I discovered that the #line directives are generated as part of the weaving process. Now my question is, how do I supply the newly modified files into the C++ compiler from the C# Add-In?
That is probably the hard part. There VS api should support this. I am sure that some things like Bounds Checker and Purify have to change the code like this too.You should put the generated files in the Debug or Release directories so they don't polute the regular source files.
iain
That is nice of AspectC++ to insert the #line directives. This will tell the debugger where to enable breakpoints etc.
iain