1// Copyright 2023 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package pprof 6 7import ( 8 "errors" 9) 10 11// readMapping adds a mapping entry for the text region of the running process. 12// It uses the mach_vm_region region system call to add mapping entries for the 13// text region of the running process. Note that currently no attempt is 14// made to obtain the buildID information. 15func (b *profileBuilder) readMapping() { 16 if !machVMInfo(b.addMapping) { 17 b.addMappingEntry(0, 0, 0, "", "", true) 18 } 19} 20 21func readMainModuleMapping() (start, end uint64, exe, buildID string, err error) { 22 first := true 23 ok := machVMInfo(func(lo, hi, off uint64, file, build string) { 24 if first { 25 start, end = lo, hi 26 exe, buildID = file, build 27 } 28 // May see multiple text segments if rosetta is used for running 29 // the go toolchain itself. 30 first = false 31 }) 32 if !ok { 33 return 0, 0, "", "", errors.New("machVMInfo failed") 34 } 35 return start, end, exe, buildID, nil 36} 37