在我的Mac上使用Delve调试GO:“合并矮人失败:未知的加载命令0x32”

时间:2018-08-10 23:11:26

标签: go delve

IDE是Visual Studio Code。这是我打开调试器时的日志:

# _/Users/leon/Documents/Projects/GoLang/TutorialLearningGoForWebDevelopment
/usr/local/go/pkg/tool/darwin_amd64/link: /usr/local/go/pkg/tool/darwin_amd64/link: combining dwarf failed: Unknown load command 0x32 (50)
exit status 2
Process exiting with code: 1

开始版本:

go version go1.10.3 darwin/amd64

MacOS版本:

Mojave Version 10.14 Beta (18A353d)

Delve版本:

Delve Debugger
Version: 1.0.0
Build: $Id: c98a142125d0b17bb11ec0513bde346229b5f533 $

Visual Studio代码版本:

  Version 1.26.0-insider (1.26.0-insider)

launch.json几乎是自动生成的,仅更改了端口:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "remotePath": "",
            "port": 8080,
            "host": "127.0.0.1",
            "program": "${fileDirname}",
            "env": {},
            "args": [],
            "showLog": true,
            "trace": "verbose"
        }
    ]
}

找到一些类似的问题线程here,但没有找到解决方案。
我还安装了go1.11beta3,但是我不知道如何在VSCode调试中将其设置为默认值。


一种更准确的症状描述:
该错误不是在Delve端引起的,而是源于go程序的第一行:package main

为了防止有人需要阅读代码,我将整个文件包括在下面:

package main

import (
    "database/sql"
    "encoding/json"
    "fmt"
    "html/template"
    "io/ioutil"
    "net/http"
    "net/url"

    _ "github.com/mattn/go-sqlite3"

    "encoding/xml"
)

type Page struct {
    Name     string
    DBStatus bool
}

type SearchResult struct {
    Title  string `xml:"title,attr"`
    Author string `xml:"author,attr"`
    Year   string `xml:"hyr,attr"`
    ID     string `xml:"owi,attr"`
}

type ClassifySearchResponse struct {
    Results []SearchResult `xml:"works>work"`
}

type ClassifyBookResponse struct {
    BookData struct {
        Title  string `xml:"title,attr"`
        Author string `xml:"author,attr"`
        ID     string `xml:"owi,attr"`
    } `xml:"work"`
    Classification struct {
        MostPopular string `xml:"sft,attr"`
    } `xml:"recommendations>ddc>mostPopular"`
}

func main() {
    templates := template.Must(template.ParseFiles("templates/index.html"))

    db, _ := sql.Open("sqlite3", "dev_golang.db")

    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        p := Page{Name: "Gopher"}
        if name := r.FormValue("name"); name != "" {
            p.Name = name
        }
        p.DBStatus = db.Ping() == nil

        if err := templates.ExecuteTemplate(w, "index.html", p); err != nil {
            http.Error(w, err.Error(), http.StatusInternalServerError)
        }
    })

    http.HandleFunc("/search", func(w http.ResponseWriter, r *http.Request) {
        var results []SearchResult
        var err error

        if results, err = search(r.FormValue("search")); err != nil {
            http.Error(w, err.Error(), http.StatusInternalServerError)
        }

        encoder := json.NewEncoder(w)
        if err := encoder.Encode(results); err != nil {
            http.Error(w, err.Error(), http.StatusInternalServerError)
        }
    })

    http.HandleFunc("/books/add", func(w http.ResponseWriter, r *http.Request) {
        var book ClassifyBookResponse
        var err error

        if book, err = find(r.FormValue("id")); err != nil {
            http.Error(w, err.Error(), http.StatusInternalServerError)
        }

        if err = db.Ping(); err != nil {
            http.Error(w, err.Error(), http.StatusInternalServerError)
        }

        _, err = db.Exec("insert into books (pk, title, author, id, classification) values (?,?,?,?,?)",
            nil,
            book.BookData.Title,
            book.BookData.Author,
            book.BookData.Author,
            book.BookData.ID,
            book.Classification.MostPopular)

        if err != nil {
            http.Error(w, err.Error(), http.StatusInternalServerError)
        }
    })

    fmt.Println(http.ListenAndServe(":8080", nil))
}

func find(id string) (ClassifyBookResponse, error) {
    var c ClassifyBookResponse
    body, err := classifyAPI("http://classify.oclc.org/classify2/Classify?summary=true&owi=" + url.QueryEscape(id))

    if err != nil {
        return ClassifyBookResponse{}, err
    }

    err = xml.Unmarshal(body, &c)
    return c, err
}

func search(query string) ([]SearchResult, error) {
    var c ClassifySearchResponse
    fmt.Println("query, search(): " + query)
    body, err := classifyAPI("http://classify.oclc.org/classify2/Classify?summary=true&title=" + url.QueryEscape(query))

    if err != nil {
        fmt.Println(err.Error())
        return []SearchResult{}, err
    }

    err = xml.Unmarshal(body, &c)
    fmt.Println(c.Results)
    return c.Results, err
}

func classifyAPI(url string) ([]byte, error) {
    var resp *http.Response
    var err error

    if resp, err = http.Get(url); err != nil {
        return []byte{}, err
    }

    defer resp.Body.Close()

    return ioutil.ReadAll(resp.Body)
}

2 个答案:

答案 0 :(得分:4)

将GoLang升级到go1.11版本后,我再也遇到了这个问题。

答案 1 :(得分:1)

如果您通过自制软件安装了go,请执行以下操作:

dtype