Skip to content

Name the sign extension instructions in trace output - #422

Open
natozenbilek wants to merge 1 commit into
TOPLLab:mainfrom
natozenbilek:trace-sign-extension-names
Open

natozenbilek wants to merge 1 commit into
TOPLLab:mainfrom
natozenbilek:trace-sign-extension-names

Conversation

@natozenbilek

Copy link
Copy Markdown

Fixes #345.

The table of opcode names in src/Utils/macros.cpp ends at 0xbf, so in a TRACE=1 build the sign extension instructions from #333 (0xc0 to 0xc4) appear in the trace as OPCODE out of bounds.

This PR:

  • adds the names of the five instructions to debug_opcodes, using the same names as the comments in i_instr_extension
  • takes the bound in opcode_repr from the size of the table instead of the literal 192, so a new name only has to be added in one place

About the crash in the issue: I could not get the VM to crash on current main. opcode_repr has had a bounds check since 2022, so these opcodes were mislabeled rather than read out of bounds. If you saw the crash in another setup, I'm happy to look into it.

Testing

I built wdcli with TRACE=1 on macOS (arm64, Apple clang) and ran a small module with one exported function per instruction (i32.const or i64.const, the extension, then end), once on main and once on this branch:

Instruction main This branch
i32.extend8_s OPCODE out of bounds 0xc0 i32.extend8_s
i32.extend16_s OPCODE out of bounds 0xc1 i32.extend16_s
i64.extend8_s OPCODE out of bounds 0xc2 i64.extend8_s
i64.extend16_s OPCODE out of bounds 0xc3 i64.extend16_s
i64.extend32_s OPCODE out of bounds 0xc4 i64.extend32_s

All runs ended with status ok. A small harness that calls opcode_repr directly shows that 0xc5 and 0xff still return OPCODE out of bounds. macros.cpp compiles with -Wall -Wextra -Werror without warnings, and clang-format 20 reports no changes.

I tested with TRACE=1 only, because DEBUG=1 together with TRACE=1 does not build on main at the moment: dbg_dump_stack in macros.cpp still uses m->sp, m->stack and m->callstack. I can send a separate PR for that if it would help.

Draft #349 also extends this table (up to 0xd2) and lists 0xc0 to 0xc4 as UNDEFINED. Whichever of the two is merged second will need a small rebase in that hunk, and with the size-based bound #349 would no longer need to change the bound itself.

The opcode names used by opcode_repr ended at 0xbf, so in trace mode the
sign extension instructions added in TOPLLab#333 (0xc0 to 0xc4) were printed as
"OPCODE out of bounds". Add their names and take the bound from the size
of the table, so a new name only has to be added in one place.

Fixes TOPLLab#345

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trace mode does not support new sign extension instructions

1 participant