The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
46fo

vscode golang 调试时如何生成固定的名字,而不是__debug_bin3821025376.exe 这种随机名字?

  •  
  •   46fo · Apr 14, 2025 · 2423 views
    This topic created in 409 days ago, the information mentioned may be changed or developed.

    vscode golang 调试时如何生成固定的名字,而不是__debug_bin3821025376.exe 这种随机名字? 如果是 win 系统 程序带网络监听功能的话每次调试都需要允许防火墙操作。

    5 replies    2025-04-15 09:33:09 +08:00
    guanzhangzhang
        1
    guanzhangzhang  
       Apr 14, 2025   ❤️ 1
    github 搜索__debug_bin https://github.com/search?q=repo%3Ago-delve%2Fdelve%20__debug_bin&type=code
    走到这个逻辑 debugname = gobuild.DefaultDebugBinaryPath("__debug_bin")
    而 DefaultDebugBinaryPath 函数逻辑是 CreateTemp
    func DefaultDebugBinaryPath(name string) string {
    pattern := name
    if runtime.GOOS == "windows" {
    pattern += "*.exe"
    }
    f, err := os.CreateTemp(".", pattern)
    guanzhangzhang
        2
    guanzhangzhang  
       Apr 14, 2025   ❤️ 1
    只有设置 output 才是固定的,没设置就是上面逻辑
    FEINIAO233
        3
    FEINIAO233  
       Apr 14, 2025   ❤️ 3
    设置.vscode 目录下的 launch.json ,output 参数可以固定,类似
    {
    "version": "0.2.0",
    "configurations": [
    {
    "name": "调试主程序",
    "type": "go",
    "request": "launch",
    "mode": "auto",
    "program": "${workspaceFolder}/main.go",
    "env": {},
    "args": [],
    "cwd": "${workspaceFolder}",
    "output": "${workspaceFolder}/output/debug_app"
    }
    ]
    }
    46fo
        4
    46fo  
    OP
       Apr 15, 2025
    @guanzhangzhang
    @FEINIAO233 对的 对的 非常感谢两位老哥,我搜索、DS 都没问出结果来。
    46fo
        5
    46fo  
    OP
       Apr 15, 2025
    忘了去看 dlv 的源码了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1012 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 19:12 · PVG 03:12 · LAX 12:12 · JFK 15:12
    ♥ Do have faith in what you're doing.