github.com/neilgarb/delve@v1.9.2-nobreaks/Documentation/api/json-rpc/README.md (about)

     1  # JSON-RPC interface
     2  
     3  Delve exposes a [JSON-RPC](https://www.jsonrpc.org/specification_v1) API interface. 
     4  
     5  Note that this JSON-RPC interface is served over a streaming socket, *not* over HTTP.
     6  
     7  # API versions
     8  
     9  Delve currently supports two versions of its API. By default a headless instance of `dlv` will serve APIv1 for backward compatibility with old clients, however new clients should use APIv2 as new features will only be made available through version 2. To select APIv2 use `--api-version=2` command line argument. 
    10  Clients can also select APIv2 by sending a [SetApiVersion](https://godoc.org/github.com/go-delve/delve/service/rpccommon#RPCServer.SetApiVersion) request specifying `APIVersion = 2` after connecting to the headless instance.
    11  
    12  # API version 2 documentation
    13  
    14  All the methods of the type `service/rpc2.RPCServer` can be called using JSON-RPC, the documentation for these calls is [available on godoc](https://godoc.org/github.com/go-delve/delve/service/rpc2#RPCServer). 
    15  
    16  Note that all exposed methods take one single input parameter (usually called `args`) of a struct type and also return a result of a struct type. Also note that the method name should be prefixed with `RPCServer.` in JSON-RPC.
    17  
    18  # Example
    19  
    20  Your client wants to set a breakpoint on the function `main.main`.
    21  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:
    22  
    23  ```
    24  {"method":"RPCServer.FindLocation","params":[{"Scope":{"GoroutineID":-1,"Frame":0},"Loc":"main.main"}],"id":2}
    25  ```
    26  
    27  the response packet will look like this:
    28  
    29  ```
    30  {"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}
    31  ```
    32  
    33  Now your client should call the method `CreateBreakpoint` and specify `4199019` (the `pc` field in the response object) as the target address:
    34  
    35  ```
    36  {"method":"RPCServer.CreateBreakpoint","params":[{"Breakpoint":{"addr":4199019}}],"id":3}
    37  ```
    38  
    39  if this request is successful your client will receive the following response:
    40  
    41  ```
    42  {"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}
    43  ```