Skip to content

fix #1484: position of while incorrect in debug #1951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 13, 2017

Conversation

liufengyun
Copy link
Contributor

@liufengyun liufengyun commented Feb 6, 2017

This commit fix #1484: position of while incorrect in debug. Also, it introduces the infrastructure for testing debuggability.

To add a new debuggability test, just put a scala file like the follows under tests/debug with debug annotations (see the comment in code for detail):

object Test {

  def main(args: Array[String]): Unit = {
    var a = 1 + 2
    a = a + 3
    a = 4 + 5 // [break] [step: while]

    while (a * 8 < 100) { // [step: a += 1]
      a += 1              // [step: while] [cont: print]
    }

    print(a) // [break] [cont]
  }
}

Review @felixmulder .

@liufengyun
Copy link
Contributor Author

The debugging information is annotated as comments to the code in brackets:

val x = f(3) // [break] [next: line=5]
val y = 5
  1. A jdb command must be wrapped in brackets, like [step]. All jdb commands can be used.
  2. To check output of jdb for a command, use [cmd: expect].
  3. If expect is wrapped in double quotes, regex is supported.
  4. Break commands are collected and set globally.
  5. Other commands will be send to jdb in the order they appear in the source file

Note: jdb uses line number starts from 1

@liufengyun
Copy link
Contributor Author

As a side effect, this PR also tests bin/dotc and bin/dotr really work as expected.

@DarkDimius
Copy link
Contributor

Very nice!

Copy link
Contributor

@felixmulder felixmulder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice indeed!

LGTM, one question though - don't you want to run this on CI?

@liufengyun
Copy link
Contributor Author

liufengyun commented Feb 6, 2017 via email

@felixmulder
Copy link
Contributor

So please add it :)

You do so in the drone.yml file. Please note that you also have to sign the new file using the command: drone sign lampepfl/dotty

@smarter
Copy link
Member

smarter commented Feb 6, 2017

You do so in the drone.yml file. Please note that you also have to sign the new file using the command: drone sign lampepfl/dotty

It would be much better if this could just be another JUnit test, we already have too many different commands to run all tests.

@liufengyun
Copy link
Contributor Author

@felixmulder thanks for the tip, just added.

It would be much better if this could just be another JUnit test, we already have too many different commands to run all tests

The concern makes sense. However the debug test involves several processes and scripts, it would be a little awkward to do in JUnit. I can add a junit test to call the script when this becomes a problem.

@felixmulder
Copy link
Contributor

felixmulder commented Feb 7, 2017

@liufengyun - perhaps it would be possible to use jdb java interfaces directly instead of using expect?

It would be good to explore this before cementing on using the a script based solution, I agree with @smarter. If we can have this as unit tests, then that leads to less of a cognitive overhead when somebody looks at adding more of these tests in X day/weeks/years. :)

@smarter
Copy link
Member

smarter commented Feb 7, 2017

It's also necessary if we want the tests to run on Windows, we cannot rely on bash scripts then.

@smarter
Copy link
Member

smarter commented Feb 7, 2017

The "proper" way to do this would probably to use the JVM debugging APIs: https://docs.oracle.com/javase/8/docs/technotes/guides/jpda/architecture.html I don't know how complicated they are to use.

@liufengyun
Copy link
Contributor Author

I've checked JVM TI and JDI, both are possible alternative solutions. However, JVM TI requires writing C++ code, JDI involves technical details about the network connections and the debugging protocol.

From the point of view of maintenance, how much efforts we put in the implementation implies the cost it takes for a third person to maintain it. The JDB interface requires no knowledge from the API whatsoever, seems to be a much simpler approach to the problem.

WDYT ? @smarter @felixmulder

@smarter
Copy link
Member

smarter commented Feb 9, 2017

Another option would be to use http://scala-debugger.org/ though that would add a dependency on scala code to our test suite. For now, the simplest solution might be to disable the debugging tests when running on Windows.

@liufengyun
Copy link
Contributor Author

Thanks @smarter , scala-debugger looks much more friendly and approachable.

@DarkDimius
Copy link
Contributor

@liufengyun, note that as discussed during the meeting depending on scala artifacts isn't a good idea, as we'll need to compile&publish them before we test the compiler, ie you'll be building them with untested compiler.

@smarter
Copy link
Member

smarter commented Feb 9, 2017

as we'll need to compile&publish them before we test the compiler

As long as they are published with 2.11 and we support 2.11, we don't need to compile and publish them ourselves. If one day we stop supporting 2.11 artefacts then this is more problematic, but we can always publish scala-debugger with an already-tested and published version of dotty.

@DarkDimius
Copy link
Contributor

DarkDimius commented Feb 9, 2017 via email

@liufengyun
Copy link
Contributor Author

@smarter if the concern is about windows, then it's not a big issue, as the main thing used is expect scripts and JDB, both on windows as well. However, it depends on bin/dotc and bin/dotr, we have to have windows version of them first.

The driver script (link) is just a few lines, can easy be turned into powershell or the like.

@liufengyun
Copy link
Contributor Author

@felixmulder : just checked the home on drone is /root. I think it is more consistent to have a symbolic link of ivy2 under /root/.ivy2 than changing $HOME to the place where ivy2 is located. As the latter may invalidate other assumptions on $HOME and may cause potential problems.

@felixmulder
Copy link
Contributor

@liufengyun - sure, just remove the -ivy option and symlink before running sbt.

@felixmulder
Copy link
Contributor

This PR needs to be rebased and the .drone.yml signed once more since it changed in #1957

@felixmulder felixmulder merged commit 07b67a8 into scala:master Feb 13, 2017
@allanrenucci allanrenucci deleted the fix-1484 branch December 14, 2017 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[debug] code gen for WHILE loop unfriendly for debugging
4 participants