Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Function calls in conditional breakpoints not supported #1803

Closed
blacktop opened this issue Jul 23, 2018 · 12 comments
Closed

Function calls in conditional breakpoints not supported #1803

blacktop opened this issue Jul 23, 2018 · 12 comments

Comments

@blacktop
Copy link

blacktop commented Jul 23, 2018

Running latest everything on Mac

cond bkpt: strings.EqualFold("pdf", plugin.name)

Failed to continue.

Steps to Reproduce:

{
  // 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": [
    {
      "name": "Scan",
      "type": "go",
      "request": "launch",
      "mode": "debug",
      "remotePath": "",
      "port": 2345,
      "host": "127.0.0.1",
      "program": "${workspaceRoot}",
      "env": {},
      "args": [
        "scan",
        "eicar.pdf"
      ],
      "showLog": true
    }
  ]
}
@blacktop
Copy link
Author

@ramya-rao-a

@ramya-rao-a
Copy link
Contributor

Please provide a small sample code along with the location where you tried to add the conditional breakpoint.

@blacktop
Copy link
Author

blacktop commented Jul 23, 2018

package main

import (
	"fmt"
	"strings"
)

func main() {
	list := [3]string{"1", "2", "3"}

	for _,num := range list {
		if strings.EqualFold("2", num){
			fmt.Println(num)       <=========== cond bp: `strings.EqualFold(num,"2")`
		}
	}
}

OUTPUT:

API server listening at: 127.0.0.1:11670
time="2018-07-25T21:26:10-04:00" level=info msg="launching process with args: [/Users/blacktop/go/src/github.com/blacktop/cond-bp-test/debug]" layer=debugger
time="2018-07-25T21:26:11-04:00" level=info msg="created breakpoint: &api.Breakpoint{ID:1, Name:\"\", Addr:0x10af68d, File:\"/Users/blacktop/go/src/github.com/blacktop/cond-bp-test/main.go\", Line:13, FunctionName:\"main.main\", Cond:\"strings.EqualFold(\\\"2\\\", num)\", Tracepoint:false, Goroutine:false, Stacktrace:0, Variables:[]string(nil), LoadArgs:(*api.LoadConfig)(0xc420024cc0), LoadLocals:(*api.LoadConfig)(0xc420024cf0), HitCount:map[string]uint64{}, TotalHitCount:0x0}" layer=debugger
time="2018-07-25T21:26:11-04:00" level=debug msg=continuing layer=debugger
"Failed to continue."

Breakpoint has an ! in it and when you hover on it it says: Conditional breakpoints not supported by this debug type

VSCode: 1.25.1
vscode-go: 0.6.84

@blacktop
Copy link
Author

^ I confirmed that this toy example does work in GoLand. Just FYI

@lggomez
Copy link
Contributor

lggomez commented Jul 29, 2018

There are 2 issues here:

  • The extension supports conditional breakpoints, but it looks like sometimes it still gives the unsopported warning when it shouldn't. I could reproduce it but I don't have a list of steps yet
  • Conditional expressions with external package references aren't working: the expression num == "2" works but fmt.Sprintf("%s",num) == "2" doesn't

I will look into the second issue first

@lggomez
Copy link
Contributor

lggomez commented Jul 29, 2018

I debugged the debug adapter and found out that this is actually a limitation of delve: https://github.com/derekparker/delve/blob/2a2d1040e9b85e069c101bf9916d333e9e3cf54d/pkg/proc/eval.go#L373-L403

I don't have Goland to compare but my guess is that they're either using another debugger or a fork/built-in solution

@blacktop
Copy link
Author

@lggomez thank you for digging into this! It is good to know it does work for the example you gave as I can use that (as I do ❤️ vscode and was sad it wasn't working). You can try Goland for free as a trial I believe? That is interesting that they are using a delve fork. Hmmm.

Anyway thanks again!

@blacktop
Copy link
Author

Maybe vscode-go could give a different error message to let the user know they can't use functions in conditional breakpoints?

@blacktop
Copy link
Author

Okay so my test was flawed. My greatest apologies to both of you 😞 I re-ran this func:

package main

import (
	"fmt"
)

func main() {
	list := [3]string{"1", "2", "3"}

	for _, num := range list {
		// if strings.EqualFold("2", num){
		fmt.Println(num) <=============== COND BP: strings.EqualFold("2", num)
		// }
	}
}

And it stopped in GoLand.... ON num=="1" !?!?! 😡

So cond breakpoints just "fail open" on GoLand where they "fail closed" on vscode.

Universe makes sense again and vscode is once again the one true editor!!! 🙏

@blacktop
Copy link
Author

I might be cool if vscode would say:

Hey, this cond bp isn't supported so we are going to turn it back into a regular bp. Cool?

@lggomez
Copy link
Contributor

lggomez commented Jul 29, 2018

@blacktop I sent a PR to make the logs more clear: #1815

Goland is a completely different beast: IntelliJ (the core IDE) has its AST engine, so they have implemented their own Go lexer/parser in order to make the most of it, and that's how the IDE refactorings look so seamless and assorted in comparison

I bet they use delve as the debug backend, and they may attempt to extract the function calls to a shadow variable in order to support this scenario. I'm just speculating though, their current implementation is closed source

@ramya-rao-a
Copy link
Contributor

This is some great investigation going on here :) Thanks @lggomez and @blacktop
I've merged the PR from @lggomez that adds the errors from delve into the logs.
Closing this issue as there isnt much we can do here

@ramya-rao-a ramya-rao-a changed the title Conditional breakpoints not supported by this debug type Function calls in conditional breakpoints not supported Jul 30, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Sep 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants