dishmaev / GoDebug

Go debugger (Delve) integration with Sublime Text 3
MIT License
25 stars 3 forks source link

message:could not find file #7

Open zrhoffman opened 4 years ago

zrhoffman commented 4 years ago

I am not having success using GoDebug to remote debug Apache Traffic Control ("Traffic Ops" component). When I press F5 and Enter to debug, I get this exception and stack trace:

Worker not started, put requests to the queue
Traceback (most recent call last):
  File "/home/zrhoffman/.config/sublime-text-3/Packages/GoDebug/sdworker.py", line 94, in _do_method
    response = connect.RPCServer.CreateBreakpoint(parms)
  File "/home/zrhoffman/.config/sublime-text-3/Packages/GoDebug/jsonrpctcp_client.py", line 328, in __call__
    return self._call_server(params)
  File "/home/zrhoffman/.config/sublime-text-3/Packages/GoDebug/jsonrpctcp_client.py", line 337, in _call_server
    return self.__client()
  File "/home/zrhoffman/.config/sublime-text-3/Packages/GoDebug/jsonrpctcp_client.py", line 133, in __call__
    result = self._call_single(requests[0])
  File "/home/zrhoffman/.config/sublime-text-3/Packages/GoDebug/jsonrpctcp_client.py", line 154, in _call_single
    response = self._receive2(notify)
  File "/home/zrhoffman/.config/sublime-text-3/Packages/GoDebug/jsonrpctcp_client.py", line 259, in _receive2
    raise JsonRpcTcpProtocolError(-32701, json_obj.get('error'))
GoDebug.jsonrpctcp_client.JsonRpcTcpProtocolError: <ProtocolError> code:-32701, message:could not find file /home/zrhoffman/go/src/github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/ping/ping.go, data:None
Exception thrown, details in file: stdout
reloading settings Packages/User/GoDebug.breakpoint-settings
reloading settings Packages/User/GoDebug.watch-settings

Steps to reproduce:

  1. Clone zrhoffman/trafficcontrol@debug_cdn-in-a-box in your GOPATH and navigate to infrastructure/cdn-in-a-box within the repo

  2. Run make debug (requires Docker and Docker Compose)

  3. Start the Docker environment with

    docker-compose down -v && docker-compose -f docker-compose.yml -f docker-compose.expose-ports.yml -f optional/docker-compose.debugging.yml up --force-recreate;
  4. In Sublime (using 3.3211, dev build) with GoDebug 0.3.9 on Arch Linux 5.4.18, set a breakpoint at traffic_ops/traffic_ops_golang/ping/ping.go:30

  5. Press F5, select the debug executable, and press Enter to start debugging.

After step 5 (but not before), the error and stack trace pasted above appears in the Sublime console.

  1. Make this HTTPS request, which should hit the breakpoint:

    curl -k https://localhost/api/2.0/ping
  2. Notice execution does not stop at the breakpoint.

Other information:

zrhoffman commented 4 years ago

To clarify, this error occurs when the GOPATH used for compiling is not the same GOPATH that you are using for debugging. Absolute paths are used in both cases, so the dlv server does not recognize the file that GoDebug tells it to set a breakpoint in.

zrhoffman commented 4 years ago

I think this bug is because GoDebug is calling CreateBreakpoint directly to create breakpoints, when really it should call FindLocation and pass the target address that it returns to CreateBreakpoint. From the Delve JSON-RPC documentation:


Example

Your client wants to set a breakpoint on the function main.main. The first step will be calling the method FindLocation with Scope = api.EvalScope{ GoroutineID: -1, Frame: 0} and Loc = "main.main". The JSON-RPC request packet should look like this:

{"method":"RPCServer.FindLocation","params":[{"Scope":{"GoroutineID":-1,"Frame":0},"Loc":"main.main"}],"id":2}

the response packet will look like this:

{"id":2,"result":{"Locations":[{"pc":4199019,"file":"/home/a/temp/callme/callme.go","line":31,"function":{"name":"main.main","value":4198992,"type":84,"goType":0}}]},"error":null}

Now your client should call the method CreateBreakpoint and specify 4199019 (the pc field in the response object) as the target address:

{"method":"RPCServer.CreateBreakpoint","params":[{"Breakpoint":{"addr":4199019}}],"id":3}

if this request is successful your client will receive the following response:

{"id":3,"result":{"Breakpoint":{"id":1,"name":"","addr":4199019,"file":"/home/a/temp/callme/callme.go","line":31,"functionName":"main.main","Cond":"","continue":false,"goroutine":false,"stacktrace":0,"LoadArgs":null,"LoadLocals":null,"hitCount":{},"totalHitCount":0}},"error":null}