Non-detectable self-modifying assembler code
If your program contains non-detectable, self-modifying code that modifies an instruction while the containing compilation unit is being debugged, the result can be unpredictable, including an abnormal termination (ABEND) of z/OS® Debugger. If your program contains self-modifying code that completely replaces an instruction while the containing compilation unit is being debugged and you do not step through the code that modifies the instruction, the result might not be an ABEND. However, z/OS Debugger might miss a breakpoint on that instruction or display a message indicating an invalid hook address at delete. If you do step through the code that modifies the instruction, the instruction that is moved may contain a breakpoint causing a z/OS Debugger failure when the modified instruction is executed.
The following coding techniques can be used to minimize problems debugging non-detectable, self-modifying code:
- Define instructions to be modified by using DC instructions instead
of executable instructions. For example, use the instruction
ModInst DC X'4700',S(Target)
instead of the instructionBC 0,Target
.Code that modifies an instruction defined by an instruction op-code Code that modifies an instruction defined by a DC ModInst BC 0,Target ... MVI ModInst+1,X'F0'
ModInst DC X'4700',S(Target) ... MVI ModInst+1,X'F0'
- Do not modify part of an instruction. Instead, replace an
instruction with one that is generated with a DC or marked as modified
by use of the EQAMODIN macro. The following table compares coding
techniques:
Code that modifies an instruction Corresponding code that replaces an instruction with one defined by a DC ModInst BC 0,Target ... MVI ModInst+1,X'F0'
ModInst BC 0,Target ... MVC ModInst(4),NewInst ... NewInst DC X'47F0',S(Target)
Code that modifies an instruction Corresponding code that replaces an instruction marked by EQAMODIN ModInst BC 0,Target ... MVI ModInst+1,X'F0'
ModInst BC 0,Target ... MVC ModInst(4),NewInst ... EQAMODIN NewInst NewInst BC 15,Target