Chapter 7: Editing Code and Data
To patch C source code by inserting lines
To patch C source code by inserting lines
1 Define a macro containing the inserted statements. The macro must provide a
return value of 1 (true) in order for the program to continue after the macro is
executed.
2 Set a breakpoint on the C line following the point where the insertion should
occur and attach the macro to the breakpoint.
3 Start your program.
The program will run until the breakpoint is encountered. The debugger will
then interpret and execute the C statements in the macro, and continue
executing the program.
To patch C source code by deleting lines
1 Write a macro that sets the program counter to point to the first line of code
beyond the lines of code that you want to delete. The macro must provide a
return value of 1 (true) in order for the program to continue after the macro is
executed.
2 Set a breakpoint on the first line to be deleted and specify the macro with that
breakpoint.
3 Start your program.
The program will run until the breakpoint is encountered. The macro will
then set the program counter to the line specified in the macro. Program
execution will then continue, skipping the program lines between the
breakpoint and line specified in the macro.
Example
Consider the following code:
212