github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/coverage/decodecounter/decodecounterfile.go (about) 1 // Copyright 2021 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 package decodecounter 6 7 import ( 8 "github.com/shogo82148/std/internal/coverage" 9 "github.com/shogo82148/std/internal/coverage/stringtab" 10 "github.com/shogo82148/std/io" 11 ) 12 13 type CounterDataReader struct { 14 stab *stringtab.Reader 15 args map[string]string 16 osargs []string 17 goarch string 18 goos string 19 mr io.ReadSeeker 20 hdr coverage.CounterFileHeader 21 ftr coverage.CounterFileFooter 22 shdr coverage.CounterSegmentHeader 23 u32b []byte 24 u8b []byte 25 fcnCount uint32 26 segCount uint32 27 debug bool 28 } 29 30 func NewCounterDataReader(fn string, rs io.ReadSeeker) (*CounterDataReader, error) 31 32 // OsArgs returns the program arguments (saved from os.Args during 33 // the run of the instrumented binary) read from the counter 34 // data file. Not all coverage data files will have os.Args values; 35 // for example, if a data file is produced by merging coverage 36 // data from two distinct runs, no os args will be available (an 37 // empty list is returned). 38 func (cdr *CounterDataReader) OsArgs() []string 39 40 // Goos returns the GOOS setting in effect for the "-cover" binary 41 // that produced this counter data file. The GOOS value may be 42 // empty in the case where the counter data file was produced 43 // from a merge in which more than one GOOS value was present. 44 func (cdr *CounterDataReader) Goos() string 45 46 // Goarch returns the GOARCH setting in effect for the "-cover" binary 47 // that produced this counter data file. The GOARCH value may be 48 // empty in the case where the counter data file was produced 49 // from a merge in which more than one GOARCH value was present. 50 func (cdr *CounterDataReader) Goarch() string 51 52 // FuncPayload encapsulates the counter data payload for a single 53 // function as read from a counter data file. 54 type FuncPayload struct { 55 PkgIdx uint32 56 FuncIdx uint32 57 Counters []uint32 58 } 59 60 // NumSegments returns the number of execution segments in the file. 61 func (cdr *CounterDataReader) NumSegments() uint32 62 63 // BeginNextSegment sets up the reader to read the next segment, 64 // returning TRUE if we do have another segment to read, or FALSE 65 // if we're done with all the segments (also an error if 66 // something went wrong). 67 func (cdr *CounterDataReader) BeginNextSegment() (bool, error) 68 69 // NumFunctionsInSegment returns the number of live functions 70 // in the currently selected segment. 71 func (cdr *CounterDataReader) NumFunctionsInSegment() uint32 72 73 // NextFunc reads data for the next function in this current segment 74 // into "p", returning TRUE if the read was successful or FALSE 75 // if we've read all the functions already (also an error if 76 // something went wrong with the read or we hit a premature 77 // EOF). 78 func (cdr *CounterDataReader) NextFunc(p *FuncPayload) (bool, error)