3 ms·
What if there was an option to rewrite the source .rs file into the matching layout? I'd imagine that could be useful in scenarios where one has to manually do
by ryanschneider 10y ago
What if there was an option to rewrite the source .rs file into the matching layout? I'd imagine that could be useful in scenarios where one has to manually do something with a dump or disassembly, etc. Plus then it could be linted against if a project wanted to ("code does not match in memory layout, use --rearrange-structs to correct").
- CUViper 10y agoIn generic code, the generated layouts can't even be written in a universal way, because they can vary depending on those input types.
- eddyb 10y agoYou can get it from debuginfo - just load your binary into any debug session (this might even work with no execution or core dump, just a blob of memory that from your program) and then you can cast char* to YourRustType* to be able to introspect it. On top of that, on nightly you have this flag: -Z print-type-sizes -- print layout information for each type encountered This is what the output looks like: https://github.com/rust-lang/rust/blob/13fd5e93deb41045c4de88c257d2b02ada2b1730/src/test/ui/print_type_sizes/padding.stdout https://github.com/rust-lang/rust/blob/13fd5e93deb41045c4de8...