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 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题