Skip to content

Debugger::printValue uses decimal representation for all datatypes#339

Open
tolauwae wants to merge 6 commits into
mainfrom
fix/debugger-hex-floats
Open

Debugger::printValue uses decimal representation for all datatypes#339
tolauwae wants to merge 6 commits into
mainfrom
fix/debugger-hex-floats

Conversation

@tolauwae
Copy link
Copy Markdown
Member

Note

Attempt number two.

This simplifies the frontend which no longer has to parse the value of a stack element in hex if it's a float or in decimal if it's an integer. It can just always parse it as a decimal.

@tolauwae
Copy link
Copy Markdown
Member Author

PR #342 should fix the Latch framework from silently failing in the CI. Once merge in main the CI will show how this PR breaks the spec tests so we can fix it.

@abelstuker abelstuker force-pushed the fix/debugger-hex-floats branch from 539ec77 to 667abcc Compare April 7, 2026 01:57
@tolauwae
Copy link
Copy Markdown
Member Author

Spectest now fails because latch loses connection with the VM. I suspect the VM crashes for the first suite unwind.wast because of a segmentation fault in Debugger::dumpLocals, leading to the failed connection and timeout.

int firstFunFramePtr = m->csp;
while (m->callstack[firstFunFramePtr].block->block_type != 0) {

Here m->csp = -1 leading to a segmentation fault when it is used as an array index on line 582.

@tolauwae tolauwae mentioned this pull request Apr 17, 2026
@tolauwae tolauwae self-assigned this Apr 17, 2026
@tolauwae tolauwae force-pushed the fix/debugger-hex-floats branch from 050bdc5 to 89c6d8e Compare April 18, 2026 06:44
@tolauwae tolauwae force-pushed the fix/debugger-hex-floats branch from 89c6d8e to b1d9409 Compare May 17, 2026 20:54
@tolauwae tolauwae force-pushed the fix/debugger-hex-floats branch from b1d9409 to 566cec9 Compare May 27, 2026 07:50
MaartenS11 and others added 3 commits May 27, 2026 14:50
This simplifies the frontend which no longer has to parse the value of
a stack element in hex if it's a float or in decimal if it's an
integer. It can just always parse it as a decimal.
@tolauwae tolauwae force-pushed the fix/debugger-hex-floats branch from 566cec9 to 8f774e5 Compare May 27, 2026 12:50
@tolauwae
Copy link
Copy Markdown
Member Author

tolauwae commented May 27, 2026

@MaartenS11 After fixing the latch side parsing, I think this PR does not do what you think it does.

The PRIi64 macro interprets the unsigned integer value uint64 as a signed integer. But this actually contains a ieee754 double per the WASM spec.

I got this to work by using the PRIu64 macro instead and changing the parsing in latch.

However, the following you wrote does not seem true:

It can just always parse it as a decimal.

The decimal value is not the actual float, you still need to do conversion. In latch this conversion is now more complicated if anything.

(same for the 32 bit ofc)

Did I miss something?

@tolauwae tolauwae requested a review from MaartenS11 May 27, 2026 13:49
@MaartenS11
Copy link
Copy Markdown
Member

@MaartenS11 After fixing the latch side parsing, I think this PR does not do what you think it does.

The PRIi64 macro interprets the unsigned integer value uint64 as a signed integer. But this actually contains a ieee754 double per the WASM spec.

I got this to work by using the PRIu64 macro instead and changing the parsing in latch.

However, the following you wrote does not seem true:

It can just always parse it as a decimal.

The decimal value is not the actual float, you still need to do conversion. In latch this conversion is now more complicated if anything.

(same for the 32 bit ofc)

Did I miss something?

In MIO the value of a wam stack element is always of type Long, the idea here was that the value would always be represented as an integer (even if it's a float) so that the parsing never has to check the type field to determine how to parse it. Previously a float might be "value": 32a4which could not be parsed because this is not a valid integer. I assume latch has some special code so that this value is parsed as a float when the type is f32. By always representing this value in the same way no conditional parsing is needed.

data class WasmStackValue(
    val idx: Int,
    val type: String,
    val value: Long
)

Of course to see the actual float values it later needs conversion, which MIO also does when representing the values in the watch window, but internally the data is always represented in the same way.

when(stackElement.type) {
    "F32" -> Float.fromBits(stackElement.value)
    "F64" -> Double.fromBits(stackElement.value)
    else -> stackElement.value
})

I would also be fine with just having the hex value be prefixed with 0x, that would probably also fix the problem since 0x tells most parsers that the value is in hex and so it doesn't try parsing 32a4 as a regular integer.

@tolauwae tolauwae force-pushed the fix/debugger-hex-floats branch from a25740d to a70c1a2 Compare May 27, 2026 14:25
@tolauwae
Copy link
Copy Markdown
Member Author

Alright that makes sense. I changed everything to unsigned in that case. Should be decimal for all values now. There were a few in dump locals that were overlooked before too.

Thanks for the help. I will merge once the CI passes all checks.

@tolauwae
Copy link
Copy Markdown
Member Author

endianness spec test fail now

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.

2 participants