www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - debugging code with mixins

reply Trass3r <un known.com> writes:
I often use mixins in my code.
This is nice programming-wise but really becomes painful when trying to  
debug cause it completely messes up dmd's line numbers.
Is there any solution to this in D?
Could we have some sort of "preprocessed source code" and use that for  
debugging?
Dec 02 2010
next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Thursday, December 02, 2010 14:16:50 Trass3r wrote:
 I often use mixins in my code.
 This is nice programming-wise but really becomes painful when trying to
 debug cause it completely messes up dmd's line numbers.
 Is there any solution to this in D?
 Could we have some sort of "preprocessed source code" and use that for
 debugging?

Well, there is an enhancement request for that sort of thing ( http://is.gd/i73ls ), but I think that the best thing to do at the moment is to ensure that your string mixins have no newlines in them. As long as there's no newlines, it doesn't screw up the line numbers in the error messages. Now, that doesn't really help you in finding where in the mixin the problem is, but it does help make sure that your error messages aren't all screwed up line number-wise. Personally, when I want to debug string mixins, I print out what they are (they're strings, so it's easy to do) and examine them. If you leave newlines in them, you could even do the math to figure out where the error is the mixin (or you could leave the newlines in and do just add a lot of writeln(__LINE__) statements to your mixin). It _is_ insentive not to make your string mixins too big and complicated though. Regardless, I'd advise making your string mixins not have newlines in them when you're not debugging them. Otherwise, all of the error messages following the mixins are messed up. - Jonathan M Davis
Dec 02 2010
prev sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
== Quote from Trass3r (un known.com)'s article
 I often use mixins in my code.
 This is nice programming-wise but really becomes painful when trying to
 debug cause it completely messes up dmd's line numbers.
 Is there any solution to this in D?
 Could we have some sort of "preprocessed source code" and use that for
 debugging?

Use #line on the first line of the mixin. ie: const gen_variant = ` #line 42 int ` ~ name ~ ` = 4.2f; // <- This is the real line 42 in the source file `; Regards
Dec 02 2010