-
Notifications
You must be signed in to change notification settings - Fork 753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VM Debugging #1080
VM Debugging #1080
Changes from all commits
c1ba58e
af32613
a87b1b8
f9b3dd5
11a5710
915a38a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { debug as createDebugLogger } from 'debug' | ||
import { Account, Address, BN } from 'ethereumjs-util' | ||
import Common from '@ethereumjs/common' | ||
import { StateManager } from '../state/index' | ||
|
@@ -68,6 +69,9 @@ export default class Interpreter { | |
_runState: RunState | ||
_eei: EEI | ||
|
||
// Opcode debuggers (e.g. { 'push': [debug Object], 'sstore': [debug Object], ...}) | ||
private opDebuggers: any = {} | ||
|
||
constructor(vm: any, eei: EEI) { | ||
this._vm = vm // TODO: remove when not needed | ||
this._state = vm.stateManager | ||
|
@@ -193,6 +197,29 @@ export default class Interpreter { | |
memoryWordCount: this._runState.memoryWordCount, | ||
codeAddress: this._eei._env.codeAddress, | ||
} | ||
|
||
// Create opTrace for debug functionality | ||
let hexStack = [] | ||
hexStack = eventObj.stack.map((item: any) => { | ||
return '0x' + new BN(item).toString(16, 0) | ||
}) | ||
|
||
const name = eventObj.opcode.name | ||
const nameLC = name.toLowerCase() | ||
const opTrace = { | ||
pc: eventObj.pc, | ||
op: name, | ||
gas: '0x' + eventObj.gasLeft.toString('hex'), | ||
gasCost: '0x' + eventObj.opcode.fee.toString(16), | ||
stack: hexStack, | ||
depth: eventObj.depth, | ||
} | ||
|
||
if (!(nameLC in this.opDebuggers)) { | ||
this.opDebuggers[nameLC] = createDebugLogger(`vm:ops:${nameLC}`) | ||
} | ||
this.opDebuggers[nameLC](JSON.stringify(opTrace)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really nice. @jochem-brouwer You mentioned wanting to diff the geth / ethereumjs traces - would the most convenient thing be to have two files with JSONs of the respective traces? If so debug has custom formatters which might help with this. I think you could collect the steps into a trace and then write to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would guess this is a good suggestion since comparing might be easiest on a per file basis with some linux CLI tools? @jochem-brouwer WDYT? |
||
|
||
/** | ||
* The `step` event for trace output | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity - this is a simplification e.g the result is already formatted as COOGResult?
Should COOGResult be removed in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh oh oh, this actually sneaked in along doing debugging work for #1076, this shouldn't be here. 😏
@jochem-brouwer just to make you aware, can you please take care of this along working on #1081 respectively along some rebase since you are touching this code anyhow? Thanks!