0

In remix debug mode, we can see opcodes executed line by line for a transaction, is there any way we can print the list of opcode and their corresponding line number(maybe memory address?) when executing a transaction locally on a Geth client connected to a private chain? Maybe we need to instrument the Geth client? Some concrete idea or example would be really helpful! I want to collect this information for code coverage purpose.

New Edit: I figured out how to use debug.traceTransaction(), however, the returned JSON still misses some info, for example, in the remix debugger, a line of opcode such as

"PUSH1 40"

will only show "PUSH1" in the trace, how can I get the more detailed trace like the ones Remix debugger provides?

  • Geth provides debug_traceTransaction api that allows collecting information of the transaction execution. – Ismael Apr 25 at 3:25
  • New Edit: I figured out how to use debug.traceTransaction(), however, the returned JSON still misses some info, for example, in the remix debugger, a line of opcode such as "PUSH1 40" will only show "PUSH1" in the trace, how can I get the more detailed trace like the ones Remix debugger provides? – Huadong Feng Apr 29 at 19:39
  • It is supposed you will read the data from the contract bytecode using the value of PC. The bytes are read in line from the program code’s bytes array from Yellow's Paper 60s & 70s: Push Operations. – Ismael Apr 29 at 20:17
  • about the contract bytecode program counter, where do I get that information? After compiling a solidity contract with Solidity compiler, the bytecodes I get are "Bytecode" and "Runtime Bytecode"(Same thing when clicking details of a compiled contract in remix), I understand one is the bytecode during deployment, and one is the bytecode after a contract is been deployed, however, both do not contain pc information. – Huadong Feng Apr 29 at 22:06
  • PC is in the callback of traceTransaction, inside a log entry there's a 'pc' field. The bytecode of a contract is returned by eth.getCode, it is the runtime. – Ismael Apr 30 at 2:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.