douou6696 2019-03-15 08:20
浏览 229

使用gdb调试禁用优化后,golang仍进行了优化

My main.go:

package main

import "fmt"
// main
func main() {
    fmt.Println("hello")
}

Build it:

go build -o main -gcflags '-N -l'

Hit breakpoint:

gdb main    
b runtime.(*mheap).sysAlloc
r

At line 540, i print v, it gives me "optimized out".
At line 549 print hint, it gives me: No symbol "hint" in current context.
What strange is that i can print *h.arenaHints value which infers hint.down is false, but line 550 still be steped into.

535 func (h *mheap) sysAlloc(n uintptr) (v unsafe.Pointer, size uintptr) {
536     n = round(n, heapArenaBytes)
537 
538     // First, try the arena pre-reservation.
539     v = h.arena.alloc(n, heapArenaBytes, &memstats.heap_sys)
540     if v != nil {
541         size = n
542         goto mapped
543     }
544 
545     // Try to grow the heap at a hint address.
546     for h.arenaHints != nil {
547         hint := h.arenaHints
548         p := hint.addr
549         if hint.down {
550             p -= n
551         }

So why disable optimization failed? Why line 550 can be steped into?

Env:
golang 1.12
ubuntu 18.04

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮