5

I'm trying to debug a revel app with visual studio but I can't get it to work.

I've seen this question how to debug revel framework(golang) application in visual studio code(vscode) but no answers yet...

I've tried with this config:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch",
      "type": "go",
      "request": "launch",
      "mode": "debug",
      "remotePath": "",
      "port": 2345,
      "host": "127.0.0.1",
      "program": "~/code/go/bin/revel",
      "env": {},
      "args": [],
      "showLog": true
    }
  ]
}

But I'm getting this error: Failed to continue: "The program attribute must point to valid directory, .go file or executable."

I think it must be the rebel binary the one to be run here, but I don't know how to pass the app path, should it go in "args"?

zapico
  • 2,396
  • 1
  • 21
  • 45
  • Any args you need to pass go in `args`, yes. There's [documentation available](https://code.visualstudio.com/docs/editor/debugging#_launchjson-attributes). – Adrian Jun 16 '17 at 13:11
  • Hi Zapico... maybe you need to point the path of `program` to go/bin/revel.d/your-app-folder/the-executable – Eloy Fernández Franco Jun 16 '17 at 13:29
  • Hi again... I am thinking about the compilation... revel is a framework that auto-reloads the executable file when you run it again, if you had changed something in the code (not on the deps)... but in this case I don´t know how could it work. Try and tell us. – Eloy Fernández Franco Jun 16 '17 at 13:45

1 Answers1

7

Yes it's possible.

  1. Suppose that the GOPATH is C:\Work\golang
  2. Revel project name is myapp, thus the location of the project (workspace) will be C:\Work\golang\src\myapp.
  3. Make some changes to the controllers etc...
  4. Run the application with revel run myapp, then press CTRL+C to exit. This step is necessary to generate corresponding go files. The generated file, i.e. the main package will be available under ${workspaceRoot}/app/tmp/main.go
  5. Configure launch.json as follows:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Launch",
                "type": "go",
                "request": "launch",
                "mode": "debug",
                "remotePath": "",
                "port": 2345,
                "host": "127.0.0.1",
                "env": {},
                "showLog": true,
                "program": "${workspaceRoot}/app/tmp/",
                "args": ["-importPath", "myapp", "-srcPath", "c:\\work\\golang\\src",  "-runMode", "dev"]
            }
        ]
    }
    
  6. The important parts are program and args parameters, while the other parameters are unmodified.

  7. Set breakpoint and start the delve debugger...

Debug revel application

EDIT:

  1. Setting args parameter to ["-importPath", "myapp", "-srcPath", "${workspaceRoot}/..", "-runMode", "dev"] also work, and I think this should work in other platforms (Mac, Linux) too.
  2. The error message is related to delve issue. See https://github.com/Microsoft/vscode-go/issues/986
putu
  • 6,218
  • 1
  • 21
  • 30
  • Thanks for your help!!! My dev env is mac so it's not exactly the same but it seems its "almost there". Now I'm getting this error: `could not launch process: dial tcp :64821: getsockopt: connection refused Process exiting with code: 1` – zapico Jun 16 '17 at 20:36
  • It seems its about my delve installation, I'll check it later. And this answer should be in Revel doc!!! ;) – zapico Jun 16 '17 at 20:45
  • Thanks for your help @putu, I'm facing different problems now ```["-importPath", "myapp", "-srcPath", "${workspaceRoot}/..", "-runMode", "dev"]``` – zapico Jun 17 '17 at 14:10
  • If I remove "-runMode" and "dev" from args, it runs, but it seems like it's not loading correctly some files (but it's debugging anyway, THANKS a lot), I think I have a problem with environments in revel or something... – zapico Jun 17 '17 at 14:13
  • Hello, I am able to show variable values in a floating windows, for a simple example like this(https://twitter.com/i/moments/880234757807898629), but not for a revel application, I can debug the revel app but not inspect the variables. Any suggestion? – Alvaro Denis Acosta Sep 03 '17 at 17:06
  • @AlvaroDenisAcosta Perhaps the debugger (and) vscode integration still have some issues. Once I've succeeded to display variable as shown in [https://imgur.com/a/2dL8g](https://imgur.com/a/2dL8g), but later it won't works. – putu Sep 06 '17 at 13:07