Mastering The Art of Debugging in C BuilderArticle 2 - Watching It Closely
Master C Builder's Included Art
Second article - close observation
(2)
Use Evaluate / Modify (seeking value / modification)
The last way to display variables or code blocks is an evAaluate / Modify window. This window can be opened like opening the inspector, right-click on the code line you want EVALUATE / MODIFY (Q) "to select" Debug | Evaluate / Modify "will pop up the evAalog / Modify window. This window is used to evaluate the expression / variable and / or modified. Watches and / or Inspectors can also achieve the same feature. But if you want to modify, it is probably the best place.
"Take a look at the variables, now I want to see how my code is, not sitting here." I heard you like it. In the next section, we will follow the inside and outside of the function until the breakpoint (still remember what you are in front of it?).
STEPPING inside and outside the code block (single step execution / tracking)
One thing in this is to keep in mind, the vast majority of the most observed variables are dynamically updated. So when you track the new line, the value of the variable is automatically re-evaluated, and the value displayed in the window is updated to a new current value.
Okay, when you click on the breakpoint you set, you will see the variable you want to check. The next step is to execute in the code and the close-up observations actually happen unanimously (by using Watches / Inspectors and proceeding with the code).
STEpping type
This part explains seems very simple. But most of the following are to discuss what you can do (it seems else you have not heard it?). You can tell the debugger five "Stepping Types". We will explain in the order on the Run menu. I will give their shortcuts at the same time. The number of shortcuts using shortcuts during debugging will use menu options (compared to 10 keyboards and selected 10 menus, I think you know what better).
The first is "Step over" (executed in a function outside) or F8. This will cause the debugger to perform code to stop the code visible to the current function, or when running to the last row of the current function, the debugger returns to the calling function to stop. STEPPING OVER features are convenient when you know that the functions calling are not.
The next is "Trace INTO" (tracking to function) or F7. If the current line run is called a function, the debugger will bring us the first row of the called function (even if the invoke function, such as a WRITE property). Otherwise, execute the next line of the current line. This feature is very convenient when you want to see what this function is doing.
Next is "Trace to Next Source Line" or SHIFT-F7. The debugger runs to the next line with debugging information. This is the difference between "Trace Into", let us explain it. When we call a Windows API function without source code and this API function calls a callback function in our code. "Trace to Next Source Line" will stop in the first line of the callback function, and "Trace Into" ignores this callback function and stops in the next line of the current program. Then "Run To Cursor" (running to cursor) or f4. The debugger will run the code until the row where the cursor is located. This makes it easy to skip large pieces of code without setting up breakpoints (considering just pause once).
There is also "Run Until Return" or SHIFT-F8. The debugger will run the code until the current function returns to call his function. When you don't want to hand in hand to the function (if you fall into a loop, this process will become very lengthy), it will be very convenient to jump to the end of the function.
The last is "Program RESET" or CTRL-F2. The debugger interrupts the running program and returns to the debugger. Unless it is nothing to do, because the resources used by the object are not released !!! (In a database application, after 2-3 times, you will have to close and restart IDE, because the internal resources will be exhausted You have been warned). This is very useful when you have to stop executing programs.
Finally, it is "Run" or F9 at the place where the menu is very high. The debugger will run until the end, unless you click on a new breakpoint or an exception.
Stepping annotation
It is necessary to keep in mind that all of these single-step executions When the debugger passes the breakpoint, the debugger evaluates the breakpoint, if the breakpoint needs to stop. If an abnormality occurs, the debugger will stop.
As you can see, set breakpoints in the right place, check the variables and check in the code, we can do what it is really running with very close distance observation procedures. These functions are quite convenient when tracing the most difficult BUGS - logic bug.
Other tips
If you are really brave and have an experience in assembly language, you can open a "CPU View" CPU window in "View | Debug Windows | CPU". Here, not only the assembly instructions of the current executable instructions, as well as the contents of the CPU flag, the contents of the register, and the constant update memory impression.
Using the Call Stack ("View | Debug Windows | Call Stack") It can easily find the history call history before or before the breakpoint is encountered. Remember, here is just what function is called by what function is called, not a history of the real call process. Therefore, this window will be confused first. But as long as it comes to Stepping Through single-step tracking code to the function body, you will fully understand it.
C Builder4, 5, Watch, Local Variable, and Call Stack window can reside in the Code main window, which is more convenient to use. The debug layout can also be set in C Builder5 to use during debugging (for design layouts you used during design).
Use all the technologies I publish and plus a little patience and a pair of flavors, you should solve 99% bug. If you want to find bug, patience is necessary. Take some time, take a deep breath, don't let the setbacks are frightened. If necessary, go out for 5 minutes to dry, you will be surprised to find out what steps have been lost in the new vision or discover the beginning. If you have other techniques and prompts I feel that you should join this article, please tell us if you let us tell us, we will join your opinion in the later version.
Ok, I hope this article some extent help patient readers. If this is the case, I will be very happy to do my best work. Maybe all your BUGS is too much.
Original: Bill King
Translation: Hop Pacific - CKER
Copyright statement:
On the domestic website, there are many contents about C Builder, but more software, components are mainly. Most of the forum can not be satisfactory, very empty. The book is expensive, but the content is too expensive. For beginners who are insufficient, self-study is not enough, so they want to do our best.
All materials in the article come from foreign websites. Because E text is inconvenient, turn into Chinese. Because English and computers are not very good, the mistakes in the text are inevitable. If you feel useful, I plan to continue to collect some useful things.
If you have any comments and suggestions, please allow mailto: cker@sina.com
You can copy, distribute, download this document free. However, you may not take it, change this article, or use this article to see any form of interest.
Pacific
2001.2