使用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

duanjia4817
duanjia4817 我看到,即使用户代码也已优化,但golang运行时始终是优化的,无法手动更改。
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐