Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Debugging DSL code
Debugging DSL code [message #1780377] Sun, 21 January 2018 22:57 Go to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
Hello I followed the tutorial at https://blogs.itemis.com/en/debugging-dsls-in-xtext-and-eclipse

So far, I can put breakpoints in the DSL code, the _traces files are generated.

To give some context, in my setting DSL instances generate java classes (with the traces) that are then packaged are JAR and deployed in our processing engine.
Putting a breakpoint in the generated java code does suspend the executed class but not putting a breakpoint in the DSL.

Could you advise what to debug to understand what I am missing.
Re: Debugging DSL code [message #1780383 is a reply to message #1780377] Mon, 22 January 2018 04:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Are the trace files stored inside the jars?are the source files stored in the jars.
How are the class files created (by hand, maven, gradle)
Did you debug the debugger ?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 22 January 2018 04:48]

Report message to a moderator

Re: Debugging DSL code [message #1780384 is a reply to message #1780383] Mon, 22 January 2018 04:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
And of course you have to but the breakpoint to the dsl


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Debugging DSL code [message #1780392 is a reply to message #1780384] Mon, 22 January 2018 07:09 Go to previous messageGo to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
Hello Cristian,

thanks for answering. So yes the _trace files are in the jar with .class files that are created using maven (or using eclipse compilation to enable hot deploy). The sources are not in the jars, usually we have separate source jars. Yes the breakpoints are set in the DSL file. I debugged the breakpoint creation and it seems ok. I do not know where to start to debug the actual debugging itself.

Would it help to create a file with the java and dsl sources together? Usually when the sources are not present eclipse presents a dialog to add them.

I should also mentionned that i created a (java application) debug configuration that has the dsl project as source lookup.

[Updated on: Mon, 22 January 2018 07:16]

Report message to a moderator

Re: Debugging DSL code [message #1780393 is a reply to message #1780392] Mon, 22 January 2018 07:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
the sources need to be in the jar / source jar. and you need to configure the maven plugin to install the stuff. i dont even know if the maven plugin supports that stuff. (xtend maven plugin has AbstractXtendInstallDebugInfoMojo, did not find something like that at https://github.com/eclipse/xtext-maven at the first glance)

to debug setting breakpoints on dsl files debug the StratumBreakpointAdapterFactory (or its subclass)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Debugging DSL code [message #1780394 is a reply to message #1780393] Mon, 22 January 2018 07:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
i actually found https://bugs.eclipse.org/bugs/show_bug.cgi?id=485818

=> you would to contribute/fix that yourself


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Debugging DSL code [message #1780401 is a reply to message #1780394] Mon, 22 January 2018 08:30 Go to previous messageGo to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
If my understand is correct, the StratumBreakpointAdapterFactory describes whether or not the breakpoint is valid (and this is correctly set as I see the breakpoints enabled in the UI). I do not really see how the breakpoint is treated during runtime in there. Furthermore, most of the time I rely on eclipse compilation rather maven compilation. Therefore, I do not really see why extending the maven plugin is mandatory in a first step.


I though creating a breakpoint in the dsl would have created the corresponding breakpoint in java but this is apparently not the way it works.

Let me also add that the tutorial works perfectly. So it is not my platform but rather something missing in my project(s)

[Updated on: Mon, 22 January 2018 08:48]

Report message to a moderator

Re: Debugging DSL code [message #1780405 is a reply to message #1780401] Mon, 22 January 2018 08:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
the eclipse builder uses the trace files to store information about the dsl files to the class files.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Debugging DSL code [message #1780407 is a reply to message #1780405] Mon, 22 January 2018 08:51 Go to previous messageGo to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
Indeed but how it is treated at runtime. I mean the breakpoint is there, how do I check that the breakpoint is handle correctly at runtime.

My point beeing that the traces are there, the project and sources jars are part of the source lookup. Even if the source are not there, I should still see the debug perspective doing something and asking for the sources.

I am looking for something that would proove, disproove that the breakpoint is correct.
Re: Debugging DSL code [message #1780408 is a reply to message #1780407] Mon, 22 January 2018 08:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
i dont understand. is this about setting breakpoints? this is what the class does that i told you.

DebugSourceInstallingCompilationParticipant does the install in eclipse
SourceLookupJob does the source lookup when loading

you can have a look at
JavaBreakPointProvider as well


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Debugging DSL code [message #1780426 is a reply to message #1780408] Mon, 22 January 2018 10:52 Go to previous messageGo to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
So I compared the behavior of the tutorial that works and the behavior within my project and here is what I can report in terms of similarities/differences


1) I can set the breakpoints, in the sense that they appear in the UI and that there is not exception reported.
2) Enable a breakpoint calls the JavaBreakPointProvider.getBreakpointWithJavaLocation and as far as I can tell the IJavaLineBreakpoint instance is correct.
2) On clean project the DebugSourceInstallingCompilationParticipant is invoked and in the method buildFinished generatedJavaFile, traceToSource, rootTraceRegion, dslSourceFile, element are correct. There is one difference with the tutorial in the sense that at line 149 byteCode is null in my case and not in the tutorial.
3) SourceLookup is never invoked but that seems more a consequence than a cause.

At this point the best lead is that installer.installTrace(ByteStreams.toByteArray(contents)); returns null
Investigating there bring me to the TraceAsSmapInstaller class and within the installTrace method
	@Override
	public byte[] installTrace(byte[] javaClassBytecode) throws IOException {
		if (smap == null)
			return null;
		byte[] updatedByteCode = new SDEInstaller(javaClassBytecode, smap.getBytes()).getUpdatedByteCode();
		return updatedByteCode;
	}


there the problem is that smap is null and this is coming from the fact that the method createSmapInfo return an empty set.
In my traces there is something strange in the sense they are all marked as targetRegion.isUseForDebugging() = false

Now trying to understand why targetRegion.isUseForDebugging() is false. In other terms why the root TraceNode is marked as useForDebugging=false

[Updated on: Mon, 22 January 2018 11:01]

Report message to a moderator

Re: Debugging DSL code [message #1780431 is a reply to message #1780426] Mon, 22 January 2018 11:25 Go to previous messageGo to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
So the problem comes from the fact that the _generate methods are generated witht the isUseForDebugging to false. Any idea why?

  @Traced
  protected IGeneratorNode _generate(final EObject expression, final GeneratorContext context) {
    ILocationData _location = this._commonTraceExtensions.location(expression);
    CompositeGeneratorNode _traceNode = this._commonTraceExtensions.trace(_location, false);
    this._commonTraceExtensions.appendTemplate(_traceNode, __generate(expression,context));
    return _traceNode;
  }
Re: Debugging DSL code [message #1780435 is a reply to message #1780431] Mon, 22 January 2018 12:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
you have to explicitely do it. and you need 2.13.
see releasenotes here https://www.eclipse.org/Xtext/releasenotes.html

Quote:

Tracing

Tracing can now be used for debugging in generated Java code as well. The @Traced annotation now takes optionally a useForDebugging=true. The @TracedAccessors are now adds to the ._<feature>() extension method a ._<feature>(useForDebugging) extension method.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Debugging DSL code [message #1780439 is a reply to message #1780435] Mon, 22 January 2018 13:14 Go to previous messageGo to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
I added the @Traced(useForDebugging=true) on the relevant statements and now the installer.installTrace(ByteStreams.toByteArray(contents)) does not return null anymore.

The debugger still does not suspend the execution when I put a breakpoint in the dsl code but when put a breakpoint in the generated java code, the execution suspends and display the dsl code on the correct line and the step by step execution happens in the dsl code with proper variable display.

Almost there ... but not quite

Any idea?

[Updated on: Mon, 22 January 2018 13:38]

Report message to a moderator

Re: Debugging DSL code [message #1780445 is a reply to message #1780439] Mon, 22 January 2018 14:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
did you set the breakpoint on the dsl file in eclipse or still with that jar szenario?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Debugging DSL code [message #1780446 is a reply to message #1780445] Mon, 22 January 2018 14:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
did you try my example btw?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Debugging DSL code [message #1780447 is a reply to message #1780446] Mon, 22 January 2018 14:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
and did you debug

YourEditor.doSetInput
MyDslStratumBreakpointSupport
MyDslStratumBreakpointAdapterFactory

hopw does org.eclipse.debug.ui.actions.IToggleBreakpointsTarget registrations look like?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Debugging DSL code [message #1780448 is a reply to message #1780446] Mon, 22 January 2018 14:48 Go to previous messageGo to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
1) I did set the breakpoint in the DSL in the jar scenario but please not that the jar is not generated by maven but by the eclipse compilation. When I set the breakpoint in the DSL the process does not suspend. However it did suspend when I set the breakpoint in java. What is weird is that once suspended debugging works perfectly in the DSL (not in Java)
2) yes I did try your example and it works perfectly (this is the way I spot the difference requiring the usedebugging)
Re: Debugging DSL code [message #1780449 is a reply to message #1780448] Mon, 22 January 2018 15:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
does your code work when the dsl files are not from a jar?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Debugging DSL code [message #1780451 is a reply to message #1780449] Mon, 22 January 2018 15:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
besides this you could debug the internas of jdt as well JavaStratumLineBreakpoint

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Debugging DSL code [message #1780453 is a reply to message #1780447] Mon, 22 January 2018 16:03 Go to previous messageGo to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
Christian Dietrich wrote on Mon, 22 January 2018 14:48
and did you debug

YourEditor.doSetInput
MyDslStratumBreakpointSupport
MyDslStratumBreakpointAdapterFactory

hopw does org.eclipse.debug.ui.actions.IToggleBreakpointsTarget registrations look like?


Yes I did debug
MyDslStratumBreakpointSupport
MyDslStratumBreakpointAdapterFactory

but to look for what?

Same question for rg.eclipse.debug.ui.actions.IToggleBreakpointsTarget
what are you looking for.

Ready to debug the internal of jdt but again don't know what to look for
Re: Debugging DSL code [message #1780455 is a reply to message #1780453] Mon, 22 January 2018 16:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
still the question: does it work with no jars.
unfortunaely my knowledge is not really deeper than yours.
so i can only guess


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Debugging DSL code [message #1780456 is a reply to message #1780455] Mon, 22 January 2018 16:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
and i am looking for different code paths in my and your code

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Debugging DSL code [message #1780462 is a reply to message #1780456] Mon, 22 January 2018 17:35 Go to previous messageGo to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
ok will look in details. For information, I embeded the generated java class in main class without deploying on the processsing engine nor doing a jar and I get the same behavior
Re: Debugging DSL code [message #1780463 is a reply to message #1780462] Mon, 22 January 2018 17:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
hmmmm then i wonder where the difference to my example is

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Debugging DSL code [message #1780509 is a reply to message #1780463] Tue, 23 January 2018 14:37 Go to previous messageGo to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
Hello Cristian,
I tried again but I am going around circles here. Is there some documentation, design principles around the XText Debug support? At this point, I mainly need to know where to investigate. Such documentation would help me out.

I probably do not miss much since once I set the breakpoint in Java, the rest happens in the DSL exactly the way I expect it (line highlight, variables value), it just does not suspend when breakpoints are set in DSL.

The last resort would be to simplify my project but this is a tedious endeviour.
Re: Debugging DSL code [message #1780512 is a reply to message #1780509] Tue, 23 January 2018 15:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Are you sure your extensions are correct e.g. plugin.xml
I can only help you if I have something to reproduce


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Debugging DSL code [message #1780605 is a reply to message #1780512] Wed, 24 January 2018 14:27 Go to previous messageGo to next message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
After a deep (very deep) debug session, I figured it out and it was .... very very stupid.
    @Override
    protected String getClassNamePattern(XtextResource state) {
        String name = "*SampleActivity*"; 
        return name;
    }

does not work but
    @Override
    protected String getClassNamePattern(XtextResource state) {
        String name = "com.wkfsfrc.generated.sample_1_0_0.SampleActivity*"; 
        return name;
    }

does. It appears the pattern only accepts * as postfix. Did not investigate much more as I can always generate the prefix correctly. To my defense, what is an appropriate pattern was not clearly specified. :)
Good thing is that I had the opportunity to learn about the JDT

[Updated on: Wed, 24 January 2018 14:44]

Report message to a moderator

Re: Debugging DSL code [message #1780610 is a reply to message #1780605] Wed, 24 January 2018 15:17 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
yes unfortunately that place is tediours.
you should calclate the pattern/s from the resource


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:TemplateProposal leads to endless loop
Next Topic:Xbase-drived DSL - Eclipse codegen build on-demand
Goto Forum:
  


Current Time: Thu Mar 28 22:57:09 GMT 2024

Powered by FUDForum. Page generated in 0.03647 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top