github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/debug/gosym/pclntab.go (about)

     1  // Copyright 2009 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  
     5  /*
     6   * Line tables
     7   */
     8  
     9  package gosym
    10  
    11  import (
    12  	"github.com/shogo82148/std/encoding/binary"
    13  	"github.com/shogo82148/std/sync"
    14  )
    15  
    16  // LineTableは、プログラムカウンタを行番号にマッピングするデータ構造です。
    17  //
    18  // Go 1.1以前では、各関数([Func] によって表される)は独自のLineTableを持ち、
    19  // 行番号はプログラム内のすべてのソース行を通じての番号付けに対応していました。
    20  // その絶対行番号は、別途ファイル名とファイル内の行番号に変換する必要がありました。
    21  //
    22  // Go 1.2では、データの形式が変更され、プログラム全体で単一のLineTableが存在し、
    23  // すべてのFuncが共有し、絶対行番号はなく、特定のファイル内の行番号のみが存在します。
    24  //
    25  // 大部分において、LineTableのメソッドはパッケージの内部詳細として扱うべきであり、
    26  // 呼び出し元は代わりに [Table] のメソッドを使用するべきです。
    27  type LineTable struct {
    28  	Data []byte
    29  	PC   uint64
    30  	Line int
    31  
    32  	// This mutex is used to keep parsing of pclntab synchronous.
    33  	mu sync.Mutex
    34  
    35  	// Contains the version of the pclntab section.
    36  	version version
    37  
    38  	// Go 1.2/1.16/1.18 state
    39  	binary      binary.ByteOrder
    40  	quantum     uint32
    41  	ptrsize     uint32
    42  	textStart   uint64
    43  	funcnametab []byte
    44  	cutab       []byte
    45  	funcdata    []byte
    46  	functab     []byte
    47  	nfunctab    uint32
    48  	filetab     []byte
    49  	pctab       []byte
    50  	nfiletab    uint32
    51  	funcNames   map[uint32]string
    52  	strings     map[uint32]string
    53  	// fileMap varies depending on the version of the object file.
    54  	// For ver12, it maps the name to the index in the file table.
    55  	// For ver116, it maps the name to the offset in filetab.
    56  	fileMap map[string]uint32
    57  }
    58  
    59  // PCToLineは、指定されたプログラムカウンタに対応する行番号を返します。
    60  //
    61  // Deprecated: 代わりにTableのPCToLineメソッドを使用してください。
    62  func (t *LineTable) PCToLine(pc uint64) int
    63  
    64  // LineToPCは、指定された行番号に対応するプログラムカウンタを返します。
    65  // ただし、maxpcより前のプログラムカウンタのみを考慮します。
    66  //
    67  // Deprecated: 代わりにTableのLineToPCメソッドを使用してください。
    68  func (t *LineTable) LineToPC(line int, maxpc uint64) uint64
    69  
    70  // NewLineTableは、エンコードされたデータに対応する新しいPC/行テーブルを返します。
    71  // Textは、対応するテキストセグメントの開始アドレスでなければなりません。
    72  // この値は、'runtime.text'シンボルに格納されている正確な値です。
    73  // この値は、バイナリがcgoを有効にしてビルドされた場合、
    74  // テキストセグメントの開始アドレスと異なる場合があります。
    75  func NewLineTable(data []byte, text uint64) *LineTable