4

I have a small Rust program that reads and writes to stdin and stdout. This Rust executable is to be called from and interact with a Java program.

The Java program is started from the command line like this:

java -jar ${pathToJar} ${pathToMyRustExecutable} ${otherArgs}

It is a one-and-done kind of program and doesn't run in a loop, which makes it hard for me to attach the debugger to.

I've been reading through VSCode's documentation on tasks.json and launch.json and here's the best I could come up with so far.

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Launch CG Referee",
      "type": "shell",
      "command": "java",
      "args": [
        "-jar",
        "$HOME/.m2/repository/com/codingame/game/spring-2020/1.0-SNAPSHOT/spring-2020-1.0-SNAPSHOT-fat-tests.jar",
        "${workspaceFolder}/target/debug/spring-challenge-2020-rust.exe",
        "${workspaceFolder}/target/debug/spring-challenge-2020-rust.exe",
        "5842184981578562716"
      ]
    },
    {
      "type": "cargo",
      "subcommand": "build",
      "problemMatcher": [
        "$rustc"
      ],
      "group": "build",
      "label": "Build"
    },
    {
      "label": "Build and Launch CG Referee",
      "dependsOn": [
        "Build",
        "Launch CG Referee"
      ],
      "dependsOrder": "sequence"
    }
  ]
}
{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [    
    {
      "type": "lldb",
      "request": "attach",
      "name": "Debug",
      "preLaunchTask": "Build and Launch CG Referee",
      "program": "${workspaceFolder}/target/debug/spring-challenge-2020-rust.exe",
      "sourceLanguages": ["rust"]
    }
  ]
}

This succeeds in building my Rust code and launches the Java process, but it doesn't attach the debugger in time. The process ends before it does. I suspect it is because launch.json waits for the "preLaunchTask" to exit before trying to attach the debugger, but I haven't found anything in the docs that confirms that or a workaround to fix that.

How can I configure this properly?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
snowfrogdev
  • 5,963
  • 3
  • 31
  • 58
  • Possibly add a `let foo = false; while !foo {}` at the beginning of your program, then change the value of `foo` from the debugger to allow the program to continue once lldb is attached. – Jmb Jun 02 '20 at 07:52
  • @Jmb Yep. I now have that setup. Still the debugger doesn't attach. It really looks like it's waiting for the "preLaunchTask" to terminate. – snowfrogdev Jun 02 '20 at 11:01

0 Answers0