EpicGamesExt / raddebugger

A native, user-mode, multi-process, graphical debugger.
MIT License
3.19k stars 167 forks source link

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

Open GloriousNull opened 1 month ago

GloriousNull commented 1 month ago

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 commented 1 month ago

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