Explore impact of use zerocopy
in gdbstub_arch
deserialize impls
#169
Labels
API-ergonomics
Nothing's "broken", but the API could be improved
design-required
Getting this right will require some thought
gdbstub_arch
Related to code in `gdbstub_arch`
At the moment, most
Arch
implementations ingdbstub_arch
use a variant of the following field-by-field pattern to deserialize registers from the wire into a Rust struct:While I haven't looked at the generated asm yet, my suspicion is that LLVM isn't going to be clever enough to realize that this entire block of code can be implemented as a single memcpy from the
bytes
buffer, into the backing register struct (especially since, at this time, the backing structs aren't actually marked atrepr(C, packed)
).It seems plausible that if we leverage zerocopy to write a safe impl of a buf-to-struct memcpy, we might see a noticeable simplification and reduction in generated asm.
Unfortunately - this would necessitate a breaking change, as adding
repr(C, packed)
to structs, and/or rearranging the layout of existing register structs would be a semver incompatible refactor.An interesting follow-up thought: would it be possible to enable a truly zerocopy path here? e.g: change
gdbstub
APIs to expose the register struct with a lifetime tied back to the underlying packet buffer?Regarding the serialize path - things are complicated by the fact that serialization is currently a streaming operation, where the
gdb_serialize
code invokes a callback in order to write out hex-bytes one at a time.Theoretically, if we refactor the APIs to require the
gdb_serialize
code to require the use of zerocopy, it would be possible to tweak the contract to havegdbstub
bulk-convert a returned&[u8]
.More thought is required here.
The text was updated successfully, but these errors were encountered: