2017-04-24 9 views
2

答: 基於putus答案,我想通了,下面的配置來構建和調試與點擊調試圍棋在Visual Studio代碼,並深入調試器標籤

首先你需要一個任務添加到用各自的標籤構建二進制文件。

{ 
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format 
    "version": "0.1.0", 
    "command": "bash", 
    "isShellCommand": true, 
    "args": [""], 
    "showOutput": "always", 
    "tasks": [ 
     { 
      "taskName": "buildBinWithTag", 
      "command": "go", 
      "args": ["build", "-o", "BinaryName", "-tags", "THISISATAG"], 
      "isShellCommand": true    
     }  
    ] 
} 

該任務應在調試器啓動之前執行。

{ 
    "version": "0.2.0", 
    "configurations": [ 
    { 
     "name": "DebugBinWithTag", //added config 
     "type": "go", 
     "request": "launch", 
     "mode": "exec", 
     "remotePath": "", 
     "port": 2345, 
     "host": "127.0.0.1", 
     "program": "${workspaceRoot}/BinaryName", 
     "env": {}, 
     "args": [], 
     "showLog": true, 
     "preLaunchTask": "buildBinWithTag" 
    } 
    ] 
} 

原題:我使用的是建立標籤用於編譯不同版本的圍棋程序和我編譯它「去建立標籤都有效THISISAFLAG」

//+build THISISAFLAG 

package main 

這完美的作品。但是有沒有辦法告訴調試器使用這些標誌。我嘗試使用類似以下的啓動配置,但它不起作用。

{ 
    "version": "0.2.0", 
    "configurations": [ 
    { 
     "name": "Launch", 
     "type": "go", 
     "request": "launch", 
     "mode": "debug", 
     "remotePath": "", 
     "port": 2345, 
     "host": "127.0.0.1", 
     "program": "${fileDirname}", 
     "env": {}, 
     "args": ["-flags THISISAFLAG"], 
     "showLog": true 
    } 
    ] 
} 

回答

1

您可以將預構建的二進制文件附加到調試器。

  1. 從命令行構建應用程序,例如, go build -o myapp.exe -tags THISISAFLAG
  2. 添加配置Launch Exelaunch.json

    { 
        "version": "0.2.0", 
        "configurations": [ 
        { 
         "name": "Launch Debug", //existing config 
         "type": "go", 
         "request": "launch", 
         "mode": "debug", 
         "remotePath": "", 
         "port": 2345, 
         "host": "127.0.0.1", 
         "program": "${fileDirname}", 
         "env": {}, 
         "args": [], 
         "showLog": true 
        }, 
        { 
         "name": "Launch EXE", //added config 
         "type": "go", 
         "request": "launch", 
         "mode": "exec", 
         "remotePath": "", 
         "port": 2345, 
         "host": "127.0.0.1", 
         "program": "${workspaceRoot}/myapp.exe", 
         "env": {}, 
         "args": [], 
         "showLog": true 
        } 
        ] 
    } 
    

注:

由於編譯器優化和this issue,可能無法顯示或(調試會話期間有不同的名稱,顯示一些變數見下文)。將來,構建應用程序以禁用編譯器優化時,您可能會添加-gcflags='-N -l'

enter image description here

+0

非常感謝!適用於調試! – David