douwengzao5790 2018-08-10 23:11
浏览 109
已采纳

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

The IDE is Visual Studio Code. Here is the log when I switching on the debugger:

# _/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:

go version go1.10.3 darwin/amd64

MacOS version:

Mojave Version 10.14 Beta (18A353d)

Delve version:

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

Visual Studio Code Version:

  Version 1.26.0-insider (1.26.0-insider)

The launch.json was nearly automatically generated, with port changed only:

{
    // 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"
        }
    ]
}

Finding out some similar problem threads here, I did not find a solution.
I also installed go1.11beta3, but I do not know how to make it default in terms of VSCode debugging.


One more accurate description of the symptom:
the error was NOT caused on Delve side, but originated from the very first line of the go program: package main

Just in case some one might need to read the code, I am including the whole file below:

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条回答 默认 最新

  • dongying2112 2018-09-27 15:54
    关注

    After upgrading GoLang to go1.11 release, I never met this problem any more.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?