Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Debugging Server-Side Isomorphic Libraries

    I was asked in another post (http://forums.smartclient.com/forum/...812#post234812) to explain how I had stepped into the Isomorphic Java libraries while debugging an issue I was experiencing.

    It's been so long since I setup my environment that I had, frankly, forgotten the detail of how I did, but I did a little poking around and if I have remembered to line up all my ducks properly, it turns out the preparation is easier than I remembered. This technique should work for more than just the Isomorphic libraries, and it's probably well (and better) documented elsewhere if you don't mind a quick trip to the Google, but since SmartGWT is the topic of this forum and it is with SmartGWT that I generally employ it, here goes...

    First things first, and no surprise, you need to install a decompiler in your Eclipse IDE. I appear to have installed JD-Eclipse, which you can find, along with installation instructions, at https://github.com/java-decompiler/jd-eclipse.

    Next, if you are running your app server as a separate process (I run Tomcat externally to Eclipse) you need to setup a debug configuration to attach the Eclipse debugger to that process:
    Click image for larger version

Name:	SCDecompile2.png
Views:	470
Size:	44.5 KB
ID:	234845


    Now, it's just a matter of decompiling the class you are interested in, which you do simply by opening the relevant package within the JAR file you will be working with, and then double-clicking the class you are interested in. For example, I often find I need to start with the com.isomorphic.datasource.DataSource.class contained in isomorphic_core_rpc.jar.

    Once I open the class and can see the decompiled source, I can set a breakpoint as normal. If I'm not sure which method I should set my breakpoint, I might set one in an often-called method, such as execute() in this case.

    How do I know which class I'm interested in? Often it's from an exception stack trace, in which case I should know the method name and line number also (I have set JD-Eclipse to show original line numbers in Window / Preferences / Java / Decompiler).

    Or perhaps I'm just seeing a behavior that I can't explain in my code. I can probably trace up to the point that I know I'm going to end up in Isomorphic code. If I simply step into that code without first decompiling the class, I have found that I am presented with the familiar "No source code found..." message - at least that's my experience.. However, if I have decompiled that class beforehand, it steps neatly right into it.

    Here you can see I set a breakpoint in our custom datasource class that extends com.isomorphic.sql.SQLDataSource. I have set the breakpoint on a line which I am quite certain will take me into the com.isomorphic.datasource.DataSource class:
    Click image for larger version

Name:	SCDecompile3.png
Views:	179
Size:	148.8 KB
ID:	234846



    Now when I step into the method I am taken right into the decompiled source:
    Click image for larger version

Name:	SCDecompile4.png
Views:	166
Size:	168.3 KB
ID:	234847


    Notice that the line number in the top of the stack trace shown in the bottom right of the screen (UIStateDS(DataSource).execute(DSRequest) line: 1901) corresponds to the line number in the decompiled source. In this case, then, my line numbers are lining up as I would hope and I don't have to resort to any undue jiggery-pokery. I have found that sometimes the line numbers get a bit mixed up. I don't know whether it's Eclipse, JD-Eclipse, the libraries, or just something in my environment. However, while in the Debug perspective the Debug tab shows the the exact line number on which the debugger is stopped. Since I have original line numbers showing I can usually find my way by cross-referencing the two. In most cases, though, the line numbers seem to be correct, but I point it out in case you can't understand why you suddenly stepped into the middle of a method...

    As far as I can tell, all the functions of the debugger are available to you here, so you can peek and poke to your heart's desire as you would within your own code. I could go on (and people say that I do), but you probably know your way around the debugger better than me. Once you have a decompiler installed, the key is to decompile your class before you step into it. Maybe there's something I'm overlooking which makes that easier, but to be honest with you it hasn't been worth my effort to investigate than further.

    With that said, if anyone would like to contribute any corrections or additions to what I have outlined here, please do so.

    #2
    Hi godonnell_ip,

    thank you for the detailed explanation. I'll try it and let you know how it worked for me.
    I did not know (nor expect) that Java has a "Source Maps" in its byte code by default.

    Best regards
    Blama

    Comment


      #3
      Hi godonnell_ip,

      I tried the feature and it is really easy to use, thanks again for the explanation.
      Could you explain in detail what you mean by
      If I simply step into that code without first decompiling the class, I have found that I am presented with the familiar "No source code found..." message - at least that's my experience.. However, if I have decompiled that class beforehand, it steps neatly right into it.
      Because I think I have a problem here. It works for me like you described with one difference:
      For me I can see the source code and set breakpoints, but when I step in an Isomorpic class with F5, Eclipse always opens a new tab for the same class and displays "Source not found" there.
      So I'm assuming I'm doing something wrong with the decompile. All I do is open the classes via doubleclick, which is enough to show the source. Is there some special "decompile" menu option I did not notice? Does the decompiler have a GUI or does it just work it's magic?

      Thank you & Best regards
      Blama

      Comment


        #4
        Hi Blama

        Sorry not to respond sooner.

        No, I didn't mean for you to do anything special to "decompile" the class - simply to do as you said, which is open the class in the editor so you can see the decompiled source. I don't think I made any other configuration changes to support the behavior I described, but I'll certainly double-check and let you know if I do see something.

        Regards,
        Gary

        Comment


          #5
          One thing I notice almost immediately is that in Window / Preferences / General / Editors / File Associations I have JD Class Viewer selected as the default viewer for *.class without source. You might want to check that is the same in your environment...

          Click image for larger version

Name:	EclipseFileAssociations.png
Views:	256
Size:	37.3 KB
ID:	241396

          Comment


            #6
            Hi godonnell_ip,

            thanks for the additional explanation. This did not work, either (it was already the way you show in the screenshot by default), so I searched further and tried this additional suggestion. No change either (new editor type is not displayed).

            Trying around I now found what seems to solve the problem:
            When the file is opened and "No Source" is displayed, click "Edit source lookup path", then (for me) I added isomorphic_core_rpc.jar (or the file one wnats to debug) via "Add variable" - "Extend" - "Select my SGWTPOWER_HOME" - "navigate to lib\isomorphic_core_rpc.jar".

            Now it seems that I can set breakpoints and also step though the code.

            Thanks again
            Blama

            Comment


              #7
              Originally posted by Blama View Post
              Hi godonnell_ip,
              So I'm assuming I'm doing something wrong with the decompile. All I do is open the classes via doubleclick, which is enough to show the source. Is there some special "decompile" menu option I did not notice? Does the decompiler have a GUI or does it just work it's magic?
              There is online GUI for Java decompiler available at http://www.decompiler.com/

              Comment

              Working...
              X