Skip to content

Commit 2247572

Browse files
committed
eth/tracers: add pc field to callTracer
1 parent 3954259 commit 2247572

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

eth/tracers/native/call.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ type callLog struct {
4545
// Position of the log relative to subcalls within the same trace
4646
// See https://github.com/ethereum/go-ethereum/pull/28389 for details
4747
Position hexutil.Uint `json:"position"`
48+
Pc uint64 `json:"pc"`
4849
}
4950

5051
type callFrame struct {
5152
Type vm.OpCode `json:"-"`
53+
Pc uint64 `json:"pc"`
5254
From common.Address `json:"from"`
5355
Gas uint64 `json:"gas"`
5456
GasUsed uint64 `json:"gasUsed"`
@@ -117,6 +119,7 @@ type callTracer struct {
117119
depth int
118120
interrupt atomic.Bool // Atomic flag to signal execution interruption
119121
reason error // Textual reason for the interruption
122+
lastPc uint64
120123
}
121124

122125
type callTracerConfig struct {
@@ -138,6 +141,7 @@ func newCallTracer(ctx *tracers.Context, cfg json.RawMessage, chainConfig *param
138141
OnEnter: t.OnEnter,
139142
OnExit: t.OnExit,
140143
OnLog: t.OnLog,
144+
OnOpcode: t.OnOpcode,
141145
},
142146
GetResult: t.GetResult,
143147
Stop: t.Stop,
@@ -173,6 +177,7 @@ func (t *callTracer) OnEnter(depth int, typ byte, from common.Address, to common
173177
Input: common.CopyBytes(input),
174178
Gas: gas,
175179
Value: value,
180+
Pc: t.lastPc,
176181
}
177182
if depth == 0 {
178183
call.Gas = t.gasLimit
@@ -219,6 +224,10 @@ func (t *callTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, fr
219224
t.gasLimit = tx.Gas()
220225
}
221226

227+
func (t *callTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
228+
t.lastPc = pc
229+
}
230+
222231
func (t *callTracer) OnTxEnd(receipt *types.Receipt, err error) {
223232
// Error happened during tx validation.
224233
if err != nil {
@@ -251,6 +260,7 @@ func (t *callTracer) OnLog(log *types.Log) {
251260
Topics: log.Topics,
252261
Data: log.Data,
253262
Position: hexutil.Uint(len(t.callstack[len(t.callstack)-1].Calls)),
263+
Pc: t.lastPc,
254264
}
255265
t.callstack[len(t.callstack)-1].Logs = append(t.callstack[len(t.callstack)-1].Logs, l)
256266
}

eth/tracers/native/gen_callframe_json.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)