GDB调试中跳过jz指令跳转的简便方法咨询
jz Jump in GDB Without Temporary Breakpoints Great question—dealing with unwanted conditional jumps during debugging can get tedious with repetitive tbreak and jump commands. Let’s look at a few simpler, more efficient alternatives:
1. Skip the jz instruction entirely with $pc manipulation
The quickest fix is to directly advance the program counter past the jz instruction, so GDB never executes it. For x86, short jz (like your jz label2) is a 2-byte instruction, so you can run:
set $pc = $pc + 2
This immediately moves execution to the add eax, 0xf0 line. No need to mess with flags or breakpoints—just skip the jump entirely.
2. Flip the Zero Flag (ZF) directly before executing jz
Instead of resetting the entire eflags register, you can target just the Zero Flag (which jz checks) with a single command:
set $zf = 0
After running this, execute si as usual. Since ZF is now 0, the jz condition fails, and execution proceeds to add eax, 0xf0. This is more precise than modifying the full eflags register and saves you typing out the entire register value.
3. Save the target address for quick repeated jumps
If you need to avoid this jump multiple times, first look up the address of add eax, 0xf0 using disas (disassemble the current function). Then store that address in a GDB variable:
set $add_eax_addr = 0x<your_add_instruction_address>
Later, whenever you hit the jz line, just run:
jump *$add_eax_addr
This skips the jump and lands you directly at the add instruction, and you only need to look up the address once.
Quick Verification Tip
You can check the Zero Flag state anytime to confirm your change worked:
info registers eflags
Look for the ZF bit—1 means the flag is set (jump will trigger), 0 means it’s clear (jump won’t happen).
内容的提问来源于stack exchange,提问作者rual93

