Conversation
fischman-bcny
left a comment
There was a problem hiding this comment.
IWBN to ack in comments that these are truncating operations, with the explanation for why this is ok.
|
I like that idea - I wonder if they will get a bit too repetitive, but I can see if I can add them appropriately. Would be nice to get a second pair of eyes to verify that these are indeed safe (which I believe them to be). |
There are a number of places where we truncate to a 32-bit value from a 64-bit value as we may running a 32-bit binary on 64-bits. This silences some of the warnings by explicitly truncating the integers rather than implicitly performing the operation.
938f1d9 to
d628096
Compare
| gp.es = regs[21]; | ||
| gp.fs = regs[22]; | ||
| gp.gs = regs[23]; | ||
| // Truncate the value to 32-bit as these are 32-bit registers. |
There was a problem hiding this comment.
I guess I'm a bit confused about the point of CPUState64 being a union. Why not simply
memcpy(gp.regs, regs, sizeof(gp.regs));
and avoid the need to remember which of these need to be truncated, etc?
| inline void setPC(uint64_t pc) { | ||
| if (is32) | ||
| state32.setPC(pc); | ||
| state32.setPC(static_cast<uint32_t>(pc)); |
There was a problem hiding this comment.
As mentioned in slack, IMO better to have a helper like
// When debugging a 32-bit inferior on a 64-bit platform registers etc frequently need truncation to 32-bits with an assumption that the high bits are zero. This helper does the cast and asserts no information is lost in the process.
static inline truncate64To32Losslessly(uint64_t data) {
DS2ASSERT(data >> 32 == 0 && "64-bit value being truncated to 32-bits has non-zero high word");
return static_cast<uint32_t>(data);
}
| DS2ASSERT(_locations[i] != 0); | ||
| site = _sites.find(_locations[i])->second; | ||
| regIdx = i; | ||
| regIdx = static_cast<int>(i); |
There was a problem hiding this comment.
simpler to s/size_t/int/ at l.192?
There are a number of places where we truncate to a 32-bit value from a 64-bit value as we may running a 32-bit binary on 64-bits. This silences some of the warnings by explicitly truncating the integers rather than implicitly performing the operation.