duanlu9816 2018-06-30 22:56
浏览 92
已采纳

Goland调试器的问题

I have got a strange bug in Golang.

OS: Linux Ubuntu 18.04.

CPU: AMD with 64 Bit Support.

IDE is Goland 2018.1.5.

Go version is 1.10.1.

Compiler is set to: 'Any'.

I have tried both 'gc' and 'gccgo' compilers. Result is the same.

In the program below, Debugger shows strange things. The 'aUnion' variable has "John" inside it, but the 'aRecord' variable which has a Union type in it, has no "John" inside.

If i 'fmt.Printf' them, they are both there, but Debugger shows no John inside 'aRecord'. Is that a debugger's bug?

The program is very simple. Just nested structs passed as a pointer.

    // 33.go.

    package main

    import "fmt"

    type Person struct {
        Name string
        Age  int
    }
    type GroupOfPeople struct {
        Name   string
        People []*Person
    }
    type Union struct {
        ID    int
        Group *GroupOfPeople
    }
    type Record struct {
        UnionField *Union
        Type       int
    }

    func main() {

        var aPerson *Person
        var people []*Person
        var aGroup *GroupOfPeople
        var aUnion *Union
        var aRecord *Record

        aPerson = &Person{
            Name: "John",
            Age:  10,
        }
        people = []*Person{aPerson}
        aGroup = &GroupOfPeople{
            Name:   "A Group",
            People: people,
        }
        aUnion = &Union{
            ID:    123,
            Group: aGroup,
        } // John is inside 'aUnion'.
        aRecord = &Record{
            UnionField: aUnion,
            Type:       666,
        }
        // John is NOT inside 'aRecord'.
        // WHY ?!
        fmt.Printf("aUnion: %+v.
", aUnion.Group.People[0])
        fmt.Printf("aRecord: %+v.
", aRecord.UnionField.Group.People[0])
    }

Thank you for help!

  • 写回答

1条回答 默认 最新

  • doujiaozhan2413 2018-07-01 13:15
    关注

    This is a problem in how GoLand handles the nesting for the values of these variables at runtime.

    I created this issue to track and fix it.

    Meanwhile, you can use the "Watches" functionality to watch for "aRecord.UnionField.Group.People" as an example, which will then correctly display the values. Sorry for the inconvenience.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP