srcmap

package
v1.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InstrMapping

type InstrMapping struct {
	S int32 // start offset in bytes within source (negative when non-existent!)
	L int32 // length in bytes within source (negative when non-existent!)
	F int32 // file index of source (negative when non-existent!)
	J byte  // jump type (i=into, o=out, -=regular)
	M int32 // modifier depth
}

type LineCol

type LineCol struct {
	Line uint32
	Col  uint32
}

type SourceID added in v1.9.1

type SourceID uint64

func (*SourceID) UnmarshalText added in v1.9.1

func (id *SourceID) UnmarshalText(data []byte) error

type SourceMap

type SourceMap struct {

	// per source, source offset -> line/col
	// This data is lazy-loaded.
	PosData map[SourceID][]LineCol
	// per bytecode byte, byte index -> instr
	Instr []InstrMapping
	// contains filtered or unexported fields
}

SourceMap is a util to map solidity deployed-bytecode positions to source-file, line and column position data. It is best used in combination with foundry.SourceMapFS to load the source-map. The source-map functionality is tested as part of the FS.

func ParseSourceMap

func ParseSourceMap(srcFs fs.FS, srcIDToPath map[SourceID]string, bytecode []byte, sourceMap string) (*SourceMap, error)

ParseSourceMap parses a solidity sourcemap: mapping bytecode indices to source references. See https://docs.soliditylang.org/en/latest/internals/source_mappings.html

The srcIDToPath is the mapping of source files, which will be read from the filesystem to transform token numbers into line/column numbers. Source-files are lazy-loaded when needed.

The source identifier mapping can be loaded through a foundry.SourceMapFS, also including a convenience util to load a source-map from an artifact.

func (*SourceMap) FormattedInfo

func (s *SourceMap) FormattedInfo(pc uint64) string

FormattedInfo is a convenience method to run Info, and turn it into a formatted string. Any error is turned into a string also, to make this simple to plug into logging.

func (*SourceMap) Info

func (s *SourceMap) Info(pc uint64) (source string, line uint32, col uint32, err error)

Info translates a program-counter (execution position in the EVM bytecode) into the source-code location that is being executed. This location is the source file-path, the line number, and column number. This may return an error, as the source-file is lazy-loaded to calculate the position data.

type SourceMapTracer

type SourceMapTracer struct {
	// contains filtered or unexported fields
}

func NewSourceMapTracer

func NewSourceMapTracer(srcMaps map[common.Address]*SourceMap, out io.Writer) *SourceMapTracer

func (*SourceMapTracer) Hooks added in v1.9.1

func (s *SourceMapTracer) Hooks() *tracing.Hooks

func (*SourceMapTracer) OnFault added in v1.9.1

func (s *SourceMapTracer) OnFault(pc uint64, opcode byte, gas, cost uint64, scope tracing.OpContext, depth int, err error)

func (*SourceMapTracer) OnOpCode added in v1.9.1

func (s *SourceMapTracer) OnOpCode(pc uint64, opcode byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL