raddebugger icon indicating copy to clipboard operation
raddebugger copied to clipboard

Watch expression interpreter non 64bit signed integer right shift does not carry sign bit

Open GloriousNull opened this issue 1 year ago • 1 comments

Couldn't find similar issue so here it goes. version 0.9.11 but was present in 0.9.10 too.

BUG: Because watch tab expression interpreter evaluates expressions in 64 bit values for signed integers right shift does not carry sign bit for 32bit, 16bit, 8bit signed integers which is expected behaviour on x86. Maybe it's not that important but it caused me some confusion :D Attaching repro.

I could do PR with fix but quick fix caused weird watch display behaviour so I pass that to you :) Also you are missing EVAL_ExprKind_BitNot in eval_g_unary_prefix_op_table in eval_parser.c so "bit not" operation is not working in watch tab.

And watch incorrectly displays s32 value casted to u32 which is mentioned in repro. watch_interpreter_signed_integer_right_shift_bug.zip

GloriousNull avatar Jul 06 '24 16:07 GloriousNull

Bug is a bit more subtle than I assumed. Interpreter correctly carries sign for shifts because RDI_EvalOp_TruncSigned is being emitted by the eval_compiler but this is not the case for values that are positive and become negative in run-time due to shift left operation. So debugger treats such values as positive because it never sign extended them to S64 for interpreter

GloriousNull avatar Jul 06 '24 19:07 GloriousNull

Fixed in ab841035c03968f1cb471bd0656cb575bc781edd

ryanfleury avatar Oct 07 '25 21:10 ryanfleury