12.4 Introduction to Program debugging
Delphi provides a powerful built-in debugger (integrated Debugger), so debugging a program can be done without leaving the integrated development environment (IDE).
Program errors can be divided into two categories, that is, run-time error and logic fault. The so-called Run-time error is that the program can be compiled normally but at run time errors. Logic error refers to the errors in programming and implementation. The program statement is legal and executed successfully, but the execution results are not desirable.
For both types of errors, the debugger can help you locate errors quickly and help you find the real cause of the error and the way to fix it by tracking the program's running and monitoring the value of the variable.
The main contents of program debugging can be summarized as follows:
1. Preparation and commencement of commissioning;
2. Implementation of control procedures;
3. Use of breakpoints;
4. Check the value of the data.
program debugging only the user actually machine operation can really grasp. In this section, we mainly introduce the main problems in debugging and some key points. As for some very small problems, I believe that readers can be mastered in the actual application of the machine, thus not listed.
Preparation and initiation of 12.4.1 commissioning
program coding and debugging is a continuous cycle during program development, and can only be delivered to end users after you have thoroughly tested the program. In order to ensure the thoroughness of debugging, a detailed debugging plan should be developed before debugging. In general, the program should be divided into several relatively independent parts, debugging, in order to facilitate the rapid positioning of errors, to ensure that each part of the program is designed to run according to the requirements.
The debug plan is ready to start debugging the program.
Starting a debugging process includes:
1. Generate debugging information at compile time;
2. Run your program from Delphi.
In the process of debugging, the execution of the program is entirely within your control. You can suspend the execution of the program at any location to check the values of variables and data structures, to display the function call sequence, to modify the value of variables in the program to observe the effects of different values on the program behavior.
12.4.1.1 Generate debugging information
To use the internal debugger, you must select option| The Integrated debugging check box for the Environment menu references page. The box is selected by default.
You need to compile the engineering files using the Symbols debug information (debug symbol information) before you start debugging. Debug symbol information contains a symbol table that enables the debugger to establish a connection between the source code of the program and the machine codes generated by the compiler. This allows the corresponding source code to be viewed at the same time in the program execution.
Delphi automatically generates debug symbol information by default. The switch option in the integrated development environment is the debug information and local symbols check box for the option|project menu compiler Options page.
When the generated debug symbol information is used by the internal debugger, the compiler stores the debug symbol table in each corresponding. dcu file.
If you want to use turbo Debugger outside the integrated environment, you need to store debugging information in the final. exe file. To do this you need to select option| The Include TDW Debug info check box for the Project menu linker page.
Because storing debugging information greatly increases the size of the execution file, you should regenerate an execution file that does not contain debug information when debugging is complete.
12.4.1.2 Run the program
The program is run through the debugger, including the built-in debugger, and when the program is in a waiting state, the debugger can gain control and use the debugger's capabilities to check the status of the current program. By reasonably laying out the screen, the application's running window and code Editor (the Codes editor) do not overlap, allowing users to easily switch between them to observe the effect of code execution.
If you want to use command-line arguments to debug your program, you can pass the run| The Parameters menu opens the Run Parameters dialog box to set up.
Control of 12.4.2 program operation
Program to run the control method and use the following table.
Table 12.7 Method of program operation control and its use way
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Ways to use the method
───────────────────────────────
Run to cursor the Code Editor Accelerator menu running to the cursor position
Run to Cursor item (run to Cursor) run main Menu
F4
Trace into entry of the track (trace into) Run main Menu
Trace into Accelerator button
F7
Step over on the run main menu
Step Over acceleration button
F8
Run to breakpoint set breakpoint and run as normal
Suspend program execution run main Menu pause item
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Tracking and stepping are a step-by-step approach. But the meaning of "step" is different. It executes a simple program statement at a time for tracking. Jumps into the function or procedure when it encounters a function or procedure call that contains debugging information, and executes its first executable statement. For stepping, it executes a single executable statement of the current module at a time, regardless of whether the statement is a function or procedure call.
Run to the cursor position and run to the breakpoint are the program normally run to a certain source code location, and then into the debugging state. However, it is more flexible to run to a breakpoint than to run to the cursor position. Because breakpoints can be set more than once, you can also set a certain condition on a breakpoint. The program will not abort until the condition is met.