srcmap

package
v1.20.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

type SourceID uint64

func (*SourceID) UnmarshalText

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

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

func (*SourceMapTracer) OnFault

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

func (*SourceMapTracer) OnOpCode

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