phoityne / hdx4vsc

Haskell Debugger Extension for Visual Studio Code.
https://marketplace.visualstudio.com/items?itemName=phoityne.phoityne-vscode
BSD 3-Clause "New" or "Revised" License
50 stars 9 forks source link

Cannot debug cabal build on macOS: cannot find source files #10

Closed stevecheckoway closed 4 years ago

stevecheckoway commented 4 years ago

Description

I'm trying to debug a program built with cabal rather than stack (although I'm unsure if that's relevant) on macOS and I get an error "loaded module can not find from path" at program start when a break point is defined in a file other than Main.hs and a warning "unsupported request command" when trying to step into a function defined in a file other than Main.hs.

The consequence of this bug is I cannot debug a multi-file project.

I have created a minimal example here. The launch.json is from the example config.

Steps to reproduce warning

First, clone the repository and run VS Code.

$ git clone https://github.com/stevecheckoway/debug-example
$ cd debug-example
$ /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code .

Second, set a break point on line 6 of Main.hs.

Third, press F5 to start debugging.

Fourth, press F11 to step into foo.

Results

The Debug Console outputs

Configuration read.
Starting GHCi.
Wait for a moment.

CWD: /Users/steve/programming/debug-example
CMD: cabal exec -- ghci-dap --interactive -i/Users/steve/programming/debug-example

Now, waiting for an initial prompt("Prelude>") from ghci.

Resolving dependencies...
[DAP][INFO] start ghci-dap-0.0.14.0.
GHCi, version 8.8.3: https://www.haskell.org/ghc/  :? for help
Loaded package environment from /Users/steve/programming/debug-example/dist-newstyle/tmp/environment.-90839/.ghc.environment.x86_64-darwin-8.8.3
Loaded package environment from /Users/steve/programming/debug-example/dist-newstyle/tmp/environment.-90839/.ghc.environment.x86_64-darwin-8.8.3
Prelude>:set prompt "<<DAP_CMD_END2>>\nH>>= "
H>>= :set prompt-cont "<<DAP_CMD_END2>>\nH>>= "
H>>= :dap-launch ...
H>>= :load /Users/steve/programming/debug-example/Main.hs
[1 of 2] Compiling Foo              ( Foo.hs, interpreted )
[2 of 2] Compiling Main             ( /Users/steve/programming/debug-example/Main.hs, interpreted )
Ok, two modules loaded.
H>>= :dap-context-modules ...
H>>= :dap-set-breakpoints ...
Breakpoint 0 activated at /Users/steve/programming/debug-example/Main.hs:6:8-19
H>>= :dap-set-function-breakpoints ...
H>>= :set -fno-break-on-exception
H>>= :set -fno-break-on-error
H>>= :dap-continue ...
Stopped in Main.main, /Users/steve/programming/debug-example/Main.hs:6:8-19
_result :: IO () = _
H>>= :dap-stacktrace ...
Empty history. Perhaps you forgot to use :trace?
H>>= :dap-scopes ...
H>>= :dap-variables ...
H>>= :dap-step-in ...
Stopped in Foo.foo, Foo.hs:6:7-20
_result :: [Char] = _
H>>= :dap-stacktrace ...
-1  : main (/Users/steve/programming/debug-example/Main.hs:6:8-19)
<end of history>
H>>= [WARNING][REQUEST] unsupported request command. {"command":"source","arguments":{"sourceReference":0,"source":{"name":null,"path":"./Foo.hs","sourceReference":null,"origine":null}},"type":"request","seq":15}

(I'm not sure if the origine is supposed to be spelled that way or not.)

VS Code opens a new editor tab Foo.hs, but it does not show the contents of the file. I have to stop the debugging at this point.

Steps to reproduce error

First, set a break point on line 6 of Foo.hs.

Second, press F5 to start debugging.

Results

The Debug Console shows

Configuration read.
Starting GHCi.
Wait for a moment.

CWD: /Users/steve/programming/debug-example
CMD: cabal exec -- ghci-dap --interactive -i/Users/steve/programming/debug-example

Now, waiting for an initial prompt("Prelude>") from ghci.

[DAP][INFO] start ghci-dap-0.0.14.0.
GHCi, version 8.8.3: https://www.haskell.org/ghc/  :? for help
Loaded package environment from /Users/steve/programming/debug-example/dist-newstyle/tmp/environment.-91109/.ghc.environment.x86_64-darwin-8.8.3
Loaded package environment from /Users/steve/programming/debug-example/dist-newstyle/tmp/environment.-91109/.ghc.environment.x86_64-darwin-8.8.3
Prelude>:set prompt "<<DAP_CMD_END2>>\nH>>= "
H>>= :set prompt-cont "<<DAP_CMD_END2>>\nH>>= "
H>>= :dap-launch ...
H>>= :load /Users/steve/programming/debug-example/Main.hs
[1 of 2] Compiling Foo              ( Foo.hs, interpreted )
[2 of 2] Compiling Main             ( /Users/steve/programming/debug-example/Main.hs, interpreted )
Ok, two modules loaded.
H>>= :dap-context-modules ...
H>>= :dap-set-breakpoints ...
H>>= [ERROR][APP] user error (loaded module can not find from path. </Users/steve/programming/debug-example/Foo.hs> [("Foo","./Foo.hs"),("Main","/Users/steve/programming/debug-example/Main.hs")])
:dap-continue ...
Hello world!
H>>= 
debugging completed. 
:quit
Leaving GHCi.

GHCi never broke at the break point.

phoityne commented 4 years ago

Hi.

Could you try this option ?

launch.json
cabal exec -- ghci-dap --interactive -i -i${workspaceFolder}

With stack, "-i" is applied twice, and it seems working.

stevecheckoway commented 4 years ago

That does indeed work!

Looking in the manual, the -i without a path means to set the search path to be empty. With that change, the full path to Foo.hs is reported when compiling it.

[1 of 2] Compiling Foo              ( /Users/steve/programming/debug-example/Foo.hs, interpreted )