go-delve / delve

Delve is a debugger for the Go programming language.
MIT License
23.08k stars 2.15k forks source link

[How to use]After executing continue, debugger stopped #3308

Closed maliyan closed 1 year ago

maliyan commented 1 year ago

Please answer the following before submitting your issue:

  1. What version of Delve are you using (dlv version)?

    $ dlv version
    Delve Debugger
    Version: 1.20.1
    Build: $Id: 96e65b6c615845d42e0e31d903f6475b0e4ece6e $
  2. What version of Go are you using? (go version)?

    # macOS
    go version go1.20.2 darwin/amd64
    # Linux
    go version go1.20.2 linux/amd64
  3. What operating system and processor architecture are you using? x86_64

  4. What did you do? I want to know how Fasthttp works, here is a very simple example.

    
    package main

import ( "flag" "fmt" "log"

    "github.com/valyala/fasthttp"

)

func main() { flag.Parse()

    h := requestHandler

    if err := fasthttp.ListenAndServe(":8080", h); err != nil {
            log.Fatalf("Error in ListenAndServe: %v", err)
    }

}

func requestHandler(ctx *fasthttp.RequestCtx) { fmt.Fprintf(ctx, "Hello, world!\n\n")

    fmt.Fprintf(ctx, "Request method is %q\n", ctx.Method())
    fmt.Fprintf(ctx, "RequestURI is %q\n", ctx.RequestURI())
    fmt.Fprintf(ctx, "Requested path is %q\n", ctx.Path())
    fmt.Fprintf(ctx, "Host is %q\n", ctx.Host())
    fmt.Fprintf(ctx, "Query string is %q\n", ctx.QueryArgs())
    fmt.Fprintf(ctx, "User-Agent is %q\n", ctx.UserAgent())
    fmt.Fprintf(ctx, "Connection has been established at %s\n", ctx.ConnTime())
    fmt.Fprintf(ctx, "Request has been started at %s\n", ctx.Time())
    fmt.Fprintf(ctx, "Serial request number for the current connection is %d\n", ctx.ConnRequestNum())
    fmt.Fprintf(ctx, "Your ip is %q\n\n", ctx.RemoteIP())

    fmt.Fprintf(ctx, "Raw request is:\n---CUT---\n%s\n---CUT---", &ctx.Request)

    ctx.SetContentType("text/plain; charset=utf8")

    // Set arbitrary headers
    ctx.Response.Header.Set("X-My-Header", "my-header-value")

    // Set cookies
    var c fasthttp.Cookie
    c.SetKey("cookie-name")
    c.SetValue("cookie-value")
    ctx.Response.Header.SetCookie(&c)

}


I want to do remote debugging as shown in the picture:
<img width="723" alt="image" src="https://user-images.githubusercontent.com/5624855/225832791-1503c391-d136-4da9-b9bc-9fe5a08b1b74.png">

Attach the process on Linux(debug server):
``` bash
dlv attach $(pgrep dlvDebug) --accept-multiclient --api-version=2 --headless=true --listen=":2345" --log=true 

API server listening at: [::]:2345
2023-03-17T14:50:46+08:00 warning layer=rpc Listening for remote connections (connections are not authenticated nor encrypted)
2023-03-17T14:50:46+08:00 info layer=debugger attaching to pid 28901
2023-03-17T14:50:46+08:00 warning layer=debugger gnu_debuglink link "libresolv-2.17.so.debug" not found in any debug info directory
2023-03-17T14:50:46+08:00 warning layer=debugger gnu_debuglink link "libpthread-2.17.so.debug" not found in any debug info directory
2023-03-17T14:50:46+08:00 warning layer=debugger gnu_debuglink link "libc-2.17.so.debug" not found in any debug info directory
2023-03-17T14:50:46+08:00 warning layer=debugger gnu_debuglink link "libdl-2.17.so.debug" not found in any debug info directory
2023-03-17T14:50:46+08:00 warning layer=debugger gnu_debuglink link "ld-2.17.so.debug" not found in any debug info directory
  1. What did you expect to see? when execute continue, it would show source code at break point.

  2. What did you see instead? Connect from MacOS(client), set break point, and then continue, debugger seems waitting for some kind of interactive.

image

After setting the breakpoint, the log output of the server is similar to this:

2023-03-17T14:53:19+08:00 debug layer=debugger continuing
aarzilli commented 1 year ago

It is very likely that, when you attach to that program, that line 16 will have already been executed. Use the debug or exec commands instead of attach.

maliyan commented 1 year ago

It is very likely that, when you attach to that program, that line 16 will have already been executed. Use the debug or exec commands instead of attach.

Thanks Reply. I have a question, what scene does attach use?

aarzilli commented 1 year ago

It's for attaching to a running process.