digitalmars.D - debugging code with mixins
- Trass3r (6/6) Dec 02 2010 I often use mixins in my code.
- Jonathan M Davis (16/22) Dec 02 2010 Well, there is an enhancement request for that sort of thing (
- Iain Buclaw (8/14) Dec 02 2010 Use #line on the first line of the mixin.
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
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
== Quote from Trass3r (un known.com)'s articleI 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